Complete User and Role Migration in Tool

This commit is contained in:
Thomas Hounsell 2015-10-06 20:54:14 +01:00
parent b1058db213
commit 2ca45d30df
6 changed files with 162 additions and 68 deletions

View File

@ -118,7 +118,7 @@ public string FullBuildString
} }
} }
public string GenerateLabUrl() => Lab.Replace('/', '-').ToLower(); public string GenerateLabUrl() => (Lab ?? "").Replace('/', '-').ToLower();
} }
public class Build public class Build

View File

@ -26,6 +26,8 @@ public class BuildModel
public DateTime? LeakDate { get; set; } public DateTime? LeakDate { get; set; }
public MongoLevelOfFlight FlightLevel { get; set; } public MongoLevelOfFlight FlightLevel { get; set; }
public string LabUrl { get; set; }
public bool IsLeaked public bool IsLeaked
{ {
get get
@ -68,6 +70,8 @@ public string FullBuildString
return sb.ToString(); return sb.ToString();
} }
} }
public string GenerateLabUrl() => (Lab ?? "").Replace('/', '-').ToLower();
} }
public class Build public class Build

View File

@ -1,4 +1,6 @@
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,7 +9,7 @@
namespace RedisMongoMigration.Mongo namespace RedisMongoMigration.Mongo
{ {
public class MongoMember public class MemberModel
{ {
[BsonId] [BsonId]
public Guid Id { get; set; } public Guid Id { get; set; }
@ -28,4 +30,42 @@ public class MongoMember
public DateTime LockoutWindowStart { get; set; } public DateTime LockoutWindowStart { get; set; }
public int LockoutWindowAttempts { get; set; } public int LockoutWindowAttempts { get; set; }
} }
public class MongoMember
{
private const string _buildCollectionName = "members";
private MongoClient _dbClient;
private IMongoCollection<MemberModel> _buildCollection;
public MongoMember()
{
_dbClient = new MongoClient(new MongoClientSettings()
{
Server = new MongoServerAddress("localhost", 27017)
});
_buildCollection = _dbClient.GetDatabase("BuildFeed").GetCollection<MemberModel>(_buildCollectionName);
}
public List<MemberModel> Select()
{
var task = _buildCollection.Find(new BsonDocument()).ToListAsync();
task.Wait();
return task.Result;
}
public void Insert(MemberModel item)
{
item.Id = Guid.NewGuid();
var task = _buildCollection.InsertOneAsync(item);
task.Wait();
}
public void InsertAll(IEnumerable<MemberModel> items)
{
var task = _buildCollection.InsertManyAsync(items);
task.Wait();
}
}
} }

View File

@ -1,4 +1,6 @@
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,7 +9,7 @@
namespace RedisMongoMigration.Mongo namespace RedisMongoMigration.Mongo
{ {
public class MongoRole public class RoleModel
{ {
[BsonId] [BsonId]
public Guid Id { get; set; } public Guid Id { get; set; }
@ -16,4 +18,42 @@ public class MongoRole
public Guid[] Users { get; set; } public Guid[] Users { get; set; }
} }
public class MongoRole
{
private const string _buildCollectionName = "roles";
private MongoClient _dbClient;
private IMongoCollection<RoleModel> _buildCollection;
public MongoRole()
{
_dbClient = new MongoClient(new MongoClientSettings()
{
Server = new MongoServerAddress("localhost", 27017)
});
_buildCollection = _dbClient.GetDatabase("BuildFeed").GetCollection<RoleModel>(_buildCollectionName);
}
public List<RoleModel> Select()
{
var task = _buildCollection.Find(new BsonDocument()).ToListAsync();
task.Wait();
return task.Result;
}
public void Insert(RoleModel item)
{
item.Id = Guid.NewGuid();
var task = _buildCollection.InsertOneAsync(item);
task.Wait();
}
public void InsertAll(IEnumerable<RoleModel> items)
{
var task = _buildCollection.InsertManyAsync(items);
task.Wait();
}
}
} }

View File

@ -9,8 +9,10 @@
using RBuild = RedisMongoMigration.Redis.Build; using RBuild = RedisMongoMigration.Redis.Build;
using MongoLevelOfFlight = RedisMongoMigration.Mongo.MongoLevelOfFlight; using MongoLevelOfFlight = RedisMongoMigration.Mongo.MongoLevelOfFlight;
using RedisLevelOfFlight = RedisMongoMigration.Redis.RedisLevelOfFlight; using RedisLevelOfFlight = RedisMongoMigration.Redis.RedisLevelOfFlight;
using MMember = RedisMongoMigration.Mongo.MongoMember; using MMemberModel = RedisMongoMigration.Mongo.MemberModel;
using RMember = RedisMongoMigration.Redis.RedisMember; using RMember = RedisMongoMigration.Redis.RedisMember;
using MMember = RedisMongoMigration.Mongo.MongoMember;
using MRoleModel = RedisMongoMigration.Mongo.RoleModel;
using RRole = RedisMongoMigration.Redis.RedisRole; using RRole = RedisMongoMigration.Redis.RedisRole;
using MRole = RedisMongoMigration.Mongo.MongoRole; using MRole = RedisMongoMigration.Mongo.MongoRole;
@ -38,14 +40,16 @@ static void Main(string[] args)
SourceType = b.SourceType, SourceType = b.SourceType,
SourceDetails = b.SourceDetails, SourceDetails = b.SourceDetails,
LeakDate = b.LeakDate, LeakDate = b.LeakDate,
FlightLevel = ExchangeFlights(b.FlightLevel) FlightLevel = ExchangeFlights(b.FlightLevel),
LabUrl = b.GenerateLabUrl()
}; };
MBuild m = new MBuild(); MBuild mb = new MBuild();
m.InsertAll(builds); mb.InsertAll(builds);
Console.WriteLine("Builds: Complete"); Console.WriteLine("Builds: Complete");
var members = from r in RMember.Select() var members = from r in RMember.Select()
select new MMember() select new MMemberModel()
{ {
CreationDate = r.CreationDate, CreationDate = r.CreationDate,
EmailAddress = r.EmailAddress, EmailAddress = r.EmailAddress,
@ -61,15 +65,19 @@ static void Main(string[] args)
PassSalt = r.PassSalt, PassSalt = r.PassSalt,
UserName = r.UserName UserName = r.UserName
}; };
MMember mm = new MMember();
mm.InsertAll(members);
Console.WriteLine("Members: Complete"); Console.WriteLine("Members: Complete");
var roles = from r in RRole.Select() var roles = from r in RRole.Select()
select new MRole() select new MRoleModel()
{ {
Id = r.Id, Id = r.Id,
RoleName = r.RoleName, RoleName = r.RoleName,
Users = r.Users Users = r.Users
}; };
MRole mr = new MRole();
mr.InsertAll(roles);
Console.WriteLine("Roles: Complete"); Console.WriteLine("Roles: Complete");
Console.ReadKey(); Console.ReadKey();

View File

@ -9,69 +9,71 @@
namespace RedisMongoMigration.Redis namespace RedisMongoMigration.Redis
{ {
[DataObject] [DataObject]
public class Build : IHasId<long> public class Build : IHasId<long>
{ {
[Key] [Key]
[AutoIncrement] [AutoIncrement]
[Index] [Index]
public long Id { get; set; } public long Id { get; set; }
public byte MajorVersion { get; set; } public byte MajorVersion { get; set; }
public byte MinorVersion { get; set; } public byte MinorVersion { get; set; }
public ushort Number { get; set; } public ushort Number { get; set; }
public ushort? Revision { get; set; } public ushort? Revision { get; set; }
public string Lab { get; set; } public string Lab { get; set; }
public DateTime? BuildTime { get; set; } public DateTime? BuildTime { get; set; }
public DateTime Added { get; set; } public DateTime Added { get; set; }
public DateTime Modified { get; set; } public DateTime Modified { get; set; }
public TypeOfSource SourceType { get; set; } public TypeOfSource SourceType { get; set; }
public string SourceDetails { get; set; } public string SourceDetails { get; set; }
public DateTime? LeakDate { get; set; } public DateTime? LeakDate { get; set; }
public RedisLevelOfFlight FlightLevel { get; set; } public RedisLevelOfFlight FlightLevel { get; set; }
public bool IsLeaked public bool IsLeaked
{ {
get get
{
switch (SourceType)
{ {
switch (SourceType) case TypeOfSource.PublicRelease:
{ case TypeOfSource.InternalLeak:
case TypeOfSource.PublicRelease: case TypeOfSource.UpdateGDR:
case TypeOfSource.InternalLeak: return true;
case TypeOfSource.UpdateGDR: default:
return true; return false;
default:
return false;
}
}
}
public string FullBuildString
{
get
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}.{1}.{2}", MajorVersion, MinorVersion, Number);
if (Revision.HasValue)
{
sb.AppendFormat(".{0}", Revision);
}
if (!string.IsNullOrWhiteSpace(Lab))
{
sb.AppendFormat(".{0}", Lab);
}
if (BuildTime.HasValue)
{
sb.AppendFormat(".{0:yyMMdd-HHmm}", BuildTime);
}
return sb.ToString();
} }
}
} }
public string FullBuildString
{
get
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0}.{1}.{2}", MajorVersion, MinorVersion, Number);
if (Revision.HasValue)
{
sb.AppendFormat(".{0}", Revision);
}
if (!string.IsNullOrWhiteSpace(Lab))
{
sb.AppendFormat(".{0}", Lab);
}
if (BuildTime.HasValue)
{
sb.AppendFormat(".{0:yyMMdd-HHmm}", BuildTime);
}
return sb.ToString();
}
}
public string GenerateLabUrl() => (Lab ?? "").Replace('/', '-').ToLower();
public static IEnumerable<Build> Select() public static IEnumerable<Build> Select()
{ {
using (RedisClient rClient = new RedisClient("localhost", 6379, db: 1)) using (RedisClient rClient = new RedisClient("localhost", 6379, db: 1))