diff --git a/BuildFeed/App_Start/DatabaseConfig.cs b/BuildFeed/App_Start/DatabaseConfig.cs deleted file mode 100644 index ddd69d6..0000000 --- a/BuildFeed/App_Start/DatabaseConfig.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Configuration; - -namespace BuildFeed -{ - public static class DatabaseConfig - { - public static string Host { get; private set; } - public static int Port { get; private set; } - public static long Database { get; private set; } - - static DatabaseConfig() - { - Host = ConfigurationManager.AppSettings["data:ServerHost"]; - - int port; - bool success = int.TryParse(ConfigurationManager.AppSettings["data:ServerPort"], out port); - if (!success) - { - port = 6379; // redis default port - } - Port = port; - - long db; - success = long.TryParse(ConfigurationManager.AppSettings["data:ServerDB"], out db); - if (!success) - { - db = 0; // redis default db - } - Database = db; - } - } -} \ No newline at end of file diff --git a/BuildFeed/App_Start/MongoConfig.cs b/BuildFeed/App_Start/MongoConfig.cs new file mode 100644 index 0000000..2060768 --- /dev/null +++ b/BuildFeed/App_Start/MongoConfig.cs @@ -0,0 +1,26 @@ +using System.Configuration; + +namespace BuildFeed +{ + internal static class MongoConfig + { + public static string Host { get; private set; } + public static int Port { get; private set; } + public static string Database { get; private set; } + + static MongoConfig() + { + Host = !string.IsNullOrEmpty(ConfigurationManager.AppSettings["data:MongoHost"]) ? ConfigurationManager.AppSettings["data:MongoHost"] : "localhost"; + + int _port; + bool success = int.TryParse(ConfigurationManager.AppSettings["data:MongoPort"], out _port); + if (!success) + { + _port = 27017; // mongo default port + } + Port = _port; + + Database = !string.IsNullOrEmpty(ConfigurationManager.AppSettings["data:MongoDB"]) ? ConfigurationManager.AppSettings["data:MongoDB"] : "MongoAuth"; + } + } +} \ No newline at end of file diff --git a/BuildFeed/BuildFeed.csproj b/BuildFeed/BuildFeed.csproj index 1b3f0a6..87a75d5 100644 --- a/BuildFeed/BuildFeed.csproj +++ b/BuildFeed/BuildFeed.csproj @@ -190,7 +190,7 @@ - + diff --git a/BuildFeed/Models/Build.cs b/BuildFeed/Models/Build.cs index b45dbdb..6031313 100644 --- a/BuildFeed/Models/Build.cs +++ b/BuildFeed/Models/Build.cs @@ -4,9 +4,6 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; -using NServiceKit.DataAnnotations; -using NServiceKit.DesignPatterns.Model; -using NServiceKit.Redis; using Required = System.ComponentModel.DataAnnotations.RequiredAttribute; using System.Web.Mvc; @@ -15,7 +12,7 @@ namespace BuildFeed.Models { [DataObject] - public class Build : IHasId + public class Build { [Key] [AutoIncrement] @@ -116,7 +113,7 @@ public string FullBuildString [DataObjectMethod(DataObjectMethodType.Select, true)] public static IEnumerable Select() { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); return client.GetAll(); @@ -126,7 +123,7 @@ public static IEnumerable Select() [DataObjectMethod(DataObjectMethodType.Select, false)] public static Build SelectById(long id) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); return client.GetById(id); @@ -136,7 +133,7 @@ public static Build SelectById(long id) [DataObjectMethod(DataObjectMethodType.Select, false)] public static IEnumerable SelectInBuildOrder() { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); return client.GetAll() @@ -151,7 +148,7 @@ public static IEnumerable SelectInBuildOrder() [DataObjectMethod(DataObjectMethodType.Select, false)] public static IEnumerable SelectInVersionOrder() { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); return client.GetAll() @@ -166,7 +163,7 @@ public static IEnumerable SelectInVersionOrder() [DataObjectMethod(DataObjectMethodType.Select, false)] public static IEnumerable SelectBuildVersions() { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); var results = client.GetAll() @@ -181,7 +178,7 @@ public static IEnumerable SelectBuildVersions() [DataObjectMethod(DataObjectMethodType.Select, false)] public static IEnumerable SelectBuildYears() { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); var results = client.GetAll().Where(b => b.BuildTime.HasValue) @@ -195,7 +192,7 @@ public static IEnumerable SelectBuildYears() [DataObjectMethod(DataObjectMethodType.Select, false)] public static IEnumerable SelectBuildLabs() { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); var results = client.GetAll() @@ -210,7 +207,7 @@ public static IEnumerable SelectBuildLabs() [DataObjectMethod(DataObjectMethodType.Select, false)] public static IEnumerable SelectBuildLabs(byte major, byte minor) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); var results = client.GetAll() @@ -227,7 +224,7 @@ public static IEnumerable SelectBuildLabs(byte major, byte minor) [DataObjectMethod(DataObjectMethodType.Insert, true)] public static void Insert(Build item) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); item.Id = client.GetNextSequence(); @@ -242,7 +239,7 @@ public static void Update(Build item) item.Added = old.Added; item.Modified = DateTime.Now; - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); client.Store(item); @@ -252,7 +249,7 @@ public static void Update(Build item) [DataObjectMethod(DataObjectMethodType.Insert, false)] public static void InsertAll(IEnumerable items) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); client.StoreAll(items); @@ -262,7 +259,7 @@ public static void InsertAll(IEnumerable items) [DataObjectMethod(DataObjectMethodType.Delete, true)] public static void DeleteById(long id) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); client.DeleteById(id); diff --git a/BuildFeed/Models/MetaItem.cs b/BuildFeed/Models/MetaItem.cs index aa6d42b..4af77f0 100644 --- a/BuildFeed/Models/MetaItem.cs +++ b/BuildFeed/Models/MetaItem.cs @@ -31,7 +31,7 @@ public class MetaItem : IHasId [DataObjectMethod(DataObjectMethodType.Select, false)] public static IEnumerable Select() { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); return client.GetAll(); @@ -41,7 +41,7 @@ public static IEnumerable Select() [DataObjectMethod(DataObjectMethodType.Select, true)] public static IEnumerable SelectByType(MetaType type) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); return from t in client.GetAll() @@ -53,7 +53,7 @@ public static IEnumerable SelectByType(MetaType type) [DataObjectMethod(DataObjectMethodType.Select, false)] public static MetaItem SelectById(MetaItemKey id) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); return client.GetById(id); @@ -64,7 +64,7 @@ public static MetaItem SelectById(MetaItemKey id) public static IEnumerable SelectUnusedLabs() { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); var labs = Build.SelectBuildLabs(); @@ -83,7 +83,7 @@ where usedLabs.All(ul => ul.Id.Value != l) public static IEnumerable SelectUnusedVersions() { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); var versions = Build.SelectBuildVersions(); @@ -102,7 +102,7 @@ where usedLabs.All(ul => ul.Id.Value != v.ToString()) public static IEnumerable SelectUnusedYears() { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); var years = Build.SelectBuildYears(); @@ -120,7 +120,7 @@ where usedYears.All(ul => ul.Id.Value != y.ToString()) [DataObjectMethod(DataObjectMethodType.Insert, true)] public static void Insert(MetaItem item) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); client.Store(item); @@ -130,7 +130,7 @@ public static void Insert(MetaItem item) [DataObjectMethod(DataObjectMethodType.Update, true)] public static void Update(MetaItem item) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); client.Store(item); @@ -140,7 +140,7 @@ public static void Update(MetaItem item) [DataObjectMethod(DataObjectMethodType.Insert, false)] public static void InsertAll(IEnumerable items) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); client.StoreAll(items); @@ -150,7 +150,7 @@ public static void InsertAll(IEnumerable items) [DataObjectMethod(DataObjectMethodType.Delete, true)] public static void DeleteById(long id) { - using (RedisClient rClient = new RedisClient(DatabaseConfig.Host, DatabaseConfig.Port, db: DatabaseConfig.Database)) + using (RedisClient rClient = new RedisClient(MongoConfig.Host, MongoConfig.Port, db: MongoConfig.Database)) { var client = rClient.As(); client.DeleteById(id); diff --git a/RedisMongoMigration/Redis/MetaItem.cs b/RedisMongoMigration/Redis/MetaItem.cs new file mode 100644 index 0000000..8942968 --- /dev/null +++ b/RedisMongoMigration/Redis/MetaItem.cs @@ -0,0 +1,46 @@ +using NServiceKit.DataAnnotations; +using NServiceKit.DesignPatterns.Model; +using System; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace RedisMongoMigration.Redis +{ + [DataObject] + public class MetaItem : IHasId + { + [Key] + [Index] + public MetaItemKey Id { get; set; } + + public string PageContent { get; set; } + + public string MetaDescription { get; set; } + } + + public struct MetaItemKey + { + public string Value { get; set; } + public MetaType Type { get; set; } + + public MetaItemKey(string id) + { + var items = id.Split(':'); + Type = (MetaType)Enum.Parse(typeof(MetaType), items[0]); + Value = items[1]; + } + + public override string ToString() + { + return $"{Type}:{Value}"; + } + } + + public enum MetaType + { + Lab, + Version, + Source, + Year + } +} diff --git a/RedisMongoMigration/Redis/RedisMember.cs b/RedisMongoMigration/Redis/RedisMember.cs new file mode 100644 index 0000000..ad82a61 --- /dev/null +++ b/RedisMongoMigration/Redis/RedisMember.cs @@ -0,0 +1,36 @@ +using NServiceKit.DataAnnotations; +using NServiceKit.DesignPatterns.Model; +using System; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace RedisMongoMigration.Redis +{ + + [DataObject] + public class RedisMember : IHasId + { + [Key] + [Index] + public Guid Id { get; set; } + + [Key] + public string UserName { get; set; } + public byte[] PassHash { get; set; } + public byte[] PassSalt { get; set; } + + [Key] + public string EmailAddress { get; set; } + + public bool IsApproved { get; set; } + public bool IsLockedOut { get; set; } + + public DateTime CreationDate { get; set; } + public DateTime LastActivityDate { get; set; } + public DateTime LastLockoutDate { get; set; } + public DateTime LastLoginDate { get; set; } + + public DateTime LockoutWindowStart { get; set; } + public int LockoutWindowAttempts { get; set; } + } +} diff --git a/RedisMongoMigration/Redis/RedisRole.cs b/RedisMongoMigration/Redis/RedisRole.cs new file mode 100644 index 0000000..3c33534 --- /dev/null +++ b/RedisMongoMigration/Redis/RedisRole.cs @@ -0,0 +1,21 @@ +using NServiceKit.DataAnnotations; +using NServiceKit.DesignPatterns.Model; +using System; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace RedisMongoMigration.Redis +{ + [DataObject] + public class RedisRole : IHasId + { + [Key] + [Index] + public Guid Id { get; set; } + + [Key] + public string RoleName { get; set; } + + public Guid[] Users { get; set; } + } +} diff --git a/RedisMongoMigration/RedisMongoMigration.csproj b/RedisMongoMigration/RedisMongoMigration.csproj index 3d96459..329b7a1 100644 --- a/RedisMongoMigration/RedisMongoMigration.csproj +++ b/RedisMongoMigration/RedisMongoMigration.csproj @@ -63,6 +63,9 @@ + + +