private static void ExecuteMigrations(MigrationProfile profile)
        {
            if (!_migrations.ContainsKey(profile))
            {
                throw new ArgumentException(string.Format("Migrations for profile {0} have not been built.", profile));
            }

            if (_migrations.Count == 0)
            {
                ConsoleHelpers.Error("No migrations stored in profile.");
                return;
            }

            ConsoleHelpers.Information(string.Format("Executing migrations for {0} profile.", profile));
            Console.WriteLine();
            foreach (KeyValuePair <int, IMigration> migration in _migrations[profile])
            {
                var scriptName = migration.Value.GetType().FullName;
                if (!_schemaVersion.IsScriptApplied(scriptName))
                {
                    ConsoleHelpers.Information(" " + migration.Key + ". " + scriptName);
                    migration.Value.Execute();
                    _schemaVersion.SetScriptAsApplied(scriptName);
                }
            }
            Console.WriteLine();
            ConsoleHelpers.Success(string.Format("Completed {0} profile.", profile));
        }
        private static void BuildListOfMigrations(MigrationProfile profile)
        {
            var migrations = new SortedList <int, IMigration>();

            ConsoleHelpers.Information(string.Format("Building list of migrations for {0} profile", profile));

            Assembly assembly = typeof(Program).Assembly;

            List <Type> types = assembly
                                .GetExportedTypes()
                                .Where(type => type.IsConcrete() && type.Is <IMigration>())
                                .Where(type => type.HasAttribute <MigrationAttribute>())
                                .Where(type => type.GetOneAttribute <MigrationAttribute>().Profile.Equals(profile))
                                .ToList();

            foreach (Type type in types)
            {
                var attribute = type.GetOneAttribute <MigrationAttribute>();
                var migration = (IMigration)Activator.CreateInstance(type, _client);

                migrations.Add(attribute.Order, migration);
            }

            _migrations.Add(profile, migrations);

            ConsoleHelpers.Success("Done");
        }
示例#3
0
文件: Settings.cs 项目: tiuub/KeeOtp2
        private void Settings_Load(object sender, EventArgs e)
        {
            this.Left = this.host.MainWindow.Left + 20;
            this.Top  = this.host.MainWindow.Top + 20;

            foreach (MigrationMode migrationMode in Enum.GetValues(typeof(MigrationMode)))
            {
                MigrationProfile migrationProfile = new MigrationProfile(migrateModeString[migrationMode], migrationMode, migrateModePlaceholder[migrationMode]["find"], migrateModePlaceholder[migrationMode]["replace"]);
                comboBoxMigrationProfileIndexes.Add(comboBoxMigrate.Items.Add(migrationProfile.name), migrationProfile);
            }
            if (comboBoxMigrate.Items.Count > 0)
            {
                comboBoxMigrate.SelectedIndex = 0;
            }

            loadConfig();

            timerClock.Start();
        }
示例#4
0
文件: Settings.cs 项目: tiuub/KeeOtp2
        // Interaction events

        private void buttonMigrate_Click(object sender, EventArgs e)
        {
            if (comboBoxMigrate.SelectedIndex > -1 &&
                comboBoxMigrationProfileIndexes.ContainsKey(comboBoxMigrate.SelectedIndex))
            {
                this.currentMigrationProfile = comboBoxMigrationProfileIndexes[comboBoxMigrate.SelectedIndex];
                if (!string.IsNullOrEmpty(currentMigrationProfile.name) && MessageBox.Show(String.Format(KeeOtp2Statics.MessageBoxMigrationConfirmation, currentMigrationProfile.name), KeeOtp2Statics.Migration, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.removeAfterMigration = ((MessageBox.Show(KeeOtp2Statics.MessageBoxMigrationRemoveStringAfterMigration, KeeOtp2Statics.Migration, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) ? true : false);
                    if (currentMigrationProfile.findPlaceholder.Count > 0 && currentMigrationProfile.replacePlaceholder.Count > 0)
                    {
                        this.migrateAutoType = ((MessageBox.Show(String.Format(KeeOtp2Statics.MessageBoxMigrationReplacePlaceholder, string.Join("/", currentMigrationProfile.findPlaceholder.Values), string.Join("/", currentMigrationProfile.replacePlaceholder.Values)), KeeOtp2Statics.Migration, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) ? true : false);
                    }
                    else
                    {
                        this.migrateAutoType = false;
                    }

                    this.buttonOK.Enabled = false;

                    this.backgroundWorkerMigrate.RunWorkerAsync();
                }
            }
        }
示例#5
0
 public MigrationAttribute(MigrationProfile profile, int order)
 {
     Profile = profile;
     Order   = order;
 }