Ejemplo n.º 1
0
        private static void MigrateCorruptedTimes(string name)
        {
            using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
            {
                var migrationStartDate = new DateTime(2012, 12, 20);
                var corruptedTimes     = database.Time.Where(m => m.Disconnected > migrationStartDate).ToList();

                foreach (var corruptedTime in corruptedTimes)
                {
                    corruptedTime.TotalMinutes = (corruptedTime.Disconnected - corruptedTime.Joined).TotalMinutes;
                }

                database.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public static void MigratePrevServerGroups(string name)
        {
            lock (MigratePrevServerGroupsLock)
            {
                var directory = string.Format(@"{0}\{1}\PrevServerGroups", BasicHelper.DataDirectory, name);
                if (PersistentDictionaryFile.Exists(directory))
                {
                    LogService.Debug("Start migrating 'PrevServerGroups' data.");

                    var oldDictionary = new PersistentDictionary <uint, string>(directory);

                    using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
                    {
                        foreach (var oldDictionaryEntry in oldDictionary)
                        {
                            oldDictionaryEntry.Value.Split(';').Select(int.Parse).ForEach(oldServerGroup =>
                            {
                                database.PreviousServerGroup.AddObject(new PreviousServerGroup
                                {
                                    Id = Guid.NewGuid(),
                                    ClientDatabaseId = (int)oldDictionaryEntry.Key,
                                    ServerGroup      = oldServerGroup,
                                    Creation         = DateTime.UtcNow
                                });
                            });
                        }

                        database.SaveChanges();
                    }

                    oldDictionary.Flush();
                    oldDictionary.Dispose();

                    PersistentDictionaryFile.DeleteFiles(directory);
                    Directory.Delete(directory);

                    LogService.Debug("Finished migrating 'PrevServerGroups' data.");
                }
            }
        }
Ejemplo n.º 3
0
        public static void MigrateModerates(string name)
        {
            lock (MigrateModeratesLock)
            {
                var directory = string.Format(@"{0}\{1}\Moderates", BasicHelper.DataDirectory, name);
                if (PersistentDictionaryFile.Exists(directory))
                {
                    LogService.Debug("Start migrating 'Moderates' data.");

                    var oldDictionary = new PersistentDictionary <string, ModeratedClientEntity>(directory);

                    using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
                    {
                        foreach (var oldDictionaryEntry in oldDictionary)
                        {
                            database.Moderate.AddObject(new Moderate
                            {
                                Id = Guid.NewGuid(),
                                ClientDatabaseId    = (int)oldDictionaryEntry.Value.User,
                                ModeratorDatabaseId = (int)oldDictionaryEntry.Value.Moderator,
                                ServerGroup         = (int)oldDictionaryEntry.Value.ServerGroup,
                                Type     = (byte)oldDictionaryEntry.Value.Type,
                                Creation = oldDictionaryEntry.Value.Moderated
                            });
                        }

                        database.SaveChanges();
                    }

                    oldDictionary.Flush();
                    oldDictionary.Dispose();

                    PersistentDictionaryFile.DeleteFiles(directory);
                    Directory.Delete(directory);

                    LogService.Debug("Finished migrating 'Moderates' data.");
                }
            }
        }
Ejemplo n.º 4
0
        public static void MigrateSticky(string name)
        {
            lock (MigrateStickyLock)
            {
                var directory = string.Format(@"{0}\{1}\Sticky", BasicHelper.DataDirectory, name);
                if (PersistentDictionaryFile.Exists(directory))
                {
                    LogService.Debug("Start migrating 'Sticky' data.");

                    var oldDictionary = new PersistentDictionary <Guid, StickyClientEntity>(directory);

                    using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
                    {
                        foreach (var oldDictionaryEntry in oldDictionary)
                        {
                            database.Sticky.AddObject(new Sticky
                            {
                                Id = Guid.NewGuid(),
                                ClientDatabaseId = (int)oldDictionaryEntry.Value.ClientDatabaseId,
                                ChannelId        = (int)oldDictionaryEntry.Value.ChannelId,
                                StickTime        = (int)oldDictionaryEntry.Value.StickTime,
                                Creation         = oldDictionaryEntry.Value.Creation
                            });
                        }

                        database.SaveChanges();
                    }

                    oldDictionary.Flush();
                    oldDictionary.Dispose();

                    PersistentDictionaryFile.DeleteFiles(directory);
                    Directory.Delete(directory);

                    LogService.Debug("Finished migrating 'Sticky' data.");
                }
            }
        }
Ejemplo n.º 5
0
        public static void MigrateTimes(string name)
        {
            lock (MigrateTimesLock)
            {
                var directory = string.Format(@"{0}\{1}\Times", BasicHelper.DataDirectory, name);
                if (PersistentDictionaryFile.Exists(directory))
                {
                    LogService.Debug("Start migrating 'Times' data.");

                    var oldDictionary = new PersistentDictionary <string, TimeClientEntity>(directory);

                    using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
                    {
                        foreach (var oldDictionaryEntry in oldDictionary)
                        {
                            database.Time.AddObject(new Time
                            {
                                Id = Guid.NewGuid(),
                                ClientDatabaseId = (int)oldDictionaryEntry.Value.User,
                                Joined           = oldDictionaryEntry.Value.Joined,
                                Disconnected     = oldDictionaryEntry.Value.Disconnected,
                                TotalMinutes     = (oldDictionaryEntry.Value.Disconnected - oldDictionaryEntry.Value.Joined).TotalMinutes
                            });
                        }

                        database.SaveChanges();
                    }

                    oldDictionary.Flush();
                    oldDictionary.Dispose();

                    PersistentDictionaryFile.DeleteFiles(directory);
                    Directory.Delete(directory);

                    LogService.Debug("Finished migrating 'Times' data.");
                }
            }
        }
Ejemplo n.º 6
0
        public static void MigrateSingleServer(string name)
        {
            if (!Directory.Exists(".\\Data\\"))
            {
                Directory.CreateDirectory(".\\Data\\");
            }
            if (!File.Exists(".\\Data\\" + name + ".sdf"))
            {
                File.Copy(".\\BotDatabase.sdf", ".\\Data\\" + name + ".sdf");
            }

            using (var oldDatabase = new BotDatabaseEntities())
            {
                oldDatabase.Away.ToList().ForEach(oldDatabase.DeleteObject);
                oldDatabase.Moderate.ToList().ForEach(oldDatabase.DeleteObject);
                oldDatabase.PreviousServerGroup.ToList().ForEach(oldDatabase.DeleteObject);
                oldDatabase.Seen.ToList().ForEach(oldDatabase.DeleteObject);
                oldDatabase.Sticky.ToList().ForEach(oldDatabase.DeleteObject);
                oldDatabase.Time.ToList().ForEach(oldDatabase.DeleteObject);
                oldDatabase.Vote.ToList().ForEach(oldDatabase.DeleteObject);
                oldDatabase.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        public static void MigrateSeen(string name)
        {
            lock (MigrateSeenLock)
            {
                var directory = string.Format(@"{0}\{1}\Seen", BasicHelper.DataDirectory, name);
                if (PersistentDictionaryFile.Exists(directory))
                {
                    LogService.Debug("Start migrating 'Seen' data.");

                    var oldDictionary = new PersistentDictionary <uint, DateTime>(directory);

                    using (var database = new BotDatabaseEntities(GetInstanceConnectionString(name)))
                    {
                        foreach (var oldDictionaryEntry in oldDictionary)
                        {
                            database.Seen.AddObject(new Seen
                            {
                                Id = Guid.NewGuid(),
                                ClientDatabaseId = (int)oldDictionaryEntry.Key,
                                LastSeen         = oldDictionaryEntry.Value
                            });
                        }

                        database.SaveChanges();
                    }

                    oldDictionary.Flush();
                    oldDictionary.Dispose();

                    PersistentDictionaryFile.DeleteFiles(directory);
                    Directory.Delete(directory);

                    LogService.Debug("Finished migrating 'Seen' data.");
                }
            }
        }