Ejemplo n.º 1
0
        private void ComparePreset(OldPreset oldPreset, Preset newPreset)
        {
            newPreset.Should().NotBeNull();

            var propertiesToCompare = new HashSet <string>
            {
                nameof(OldPreset.PresetId),
                nameof(OldPreset.IsIgnored),
                nameof(OldPreset.LastExported),
                nameof(OldPreset.PresetSize),
                nameof(OldPreset.PresetCompressedSize),
                nameof(OldPreset.PresetHash)
            };

            var metadataPropertiesToCompare = new HashSet <string>
            {
                nameof(OldPreset.PresetName),
                nameof(OldPreset.Author),
                nameof(OldPreset.Comment),
                nameof(OldPreset.BankPath)
            };

            var originalMetadataPropertiesToCompare = new HashSet <string>
            {
                nameof(OldPreset.PresetName),
                nameof(OldPreset.Author),
                nameof(OldPreset.Comment),
                nameof(OldPreset.SourceFile),
                nameof(OldPreset.BankPath)
            };

            var comparer = new PropertyComparisonHelper(oldPreset, newPreset);

            comparer.CompareProperties(propertiesToCompare);
            comparer.AddVisitedProperty(nameof(OldPreset.Plugin));
            comparer.AddVisitedProperty(nameof(OldPreset.IsMetadataModified));
            comparer.GetUnvisitedProperties().Should().BeEmpty();

            comparer = new PropertyComparisonHelper(oldPreset, newPreset.Metadata);
            comparer.CompareProperties(metadataPropertiesToCompare);
            comparer.AddVisitedProperty(nameof(OldPreset.Types));
            comparer.GetUnvisitedProperties().Should().BeEmpty();

            comparer = new PropertyComparisonHelper(oldPreset, newPreset.OriginalMetadata);
            comparer.CompareProperties(originalMetadataPropertiesToCompare);
            comparer.AddVisitedProperty(nameof(OldPreset.Types));
            comparer.AddVisitedProperty(nameof(OldPreset.Plugin));
            comparer.GetUnvisitedProperties().Should().BeEmpty();

            CompareTypes(oldPreset.Types, newPreset.OriginalMetadata.Types);
            CompareTypes(oldPreset.Types, newPreset.Metadata.Types);

            CompareModes(oldPreset.Modes, newPreset.OriginalMetadata.Characteristics);
            CompareModes(oldPreset.Modes, newPreset.Metadata.Characteristics);
        }
Ejemplo n.º 2
0
        private void MigratePreset(Preset oldPreset, NewModels.Preset newPreset)
        {
            var propertiesToMigrate = new HashSet <string>
            {
                nameof(Preset.PresetId),
                nameof(Preset.PresetHash),
                nameof(Preset.LastExported),
                nameof(Preset.PresetCompressedSize),
                nameof(Preset.PresetSize),
            };

            var metadataPropertiesToMigrate = new HashSet <string>
            {
                nameof(Preset.Author),
                nameof(Preset.Comment),
                nameof(Preset.BankPath),
                nameof(Preset.SourceFile),
                nameof(Preset.PresetName)
            };

            foreach (var propertyName in propertiesToMigrate)
            {
                var oldValue = PropertyHelper.GetPropertyValue(oldPreset, propertyName);
                PropertyHelper.SetPropertyValue(newPreset, propertyName, oldValue);
            }

            foreach (var propertyName in metadataPropertiesToMigrate)
            {
                var oldValue = PropertyHelper.GetPropertyValue(oldPreset, propertyName);
                PropertyHelper.SetPropertyValue(newPreset.OriginalMetadata, propertyName, oldValue);
            }

            MigrateModes(oldPreset.Modes, newPreset.OriginalMetadata.Characteristics);
            MigrateTypes(oldPreset.Types, newPreset.OriginalMetadata.Types);

            newPreset.SetFromPresetParser(newPreset.OriginalMetadata);
        }
Ejemplo n.º 3
0
        public NewModels.Plugin MigratePlugin(Plugin oldPlugin)
        {
            _presetDataPersister.OpenDatabase().Wait();
            var newPlugin = new NewModels.Plugin();

            if (oldPlugin.PluginLocation != null)
            {
                newPlugin.PluginLocation = new NewModels.PluginLocation();
                MigratePluginLocation(oldPlugin, oldPlugin.PluginLocation, newPlugin.PluginLocation);
            }

            foreach (var preset in oldPlugin.Presets)
            {
                var data = _dbContext.GetPresetData(preset);

                if (data == null)
                {
                    // The preset data is null for some reason, skip this one
                    continue;
                }

                UpdateCounter++;
                var currentPreset = oldPlugin.Presets.IndexOf(preset) + 1;

                if (UpdateCounter > 111)
                {
                    MigrationProgressUpdated?.Invoke(this,
                                                     new MigrationProgessEventArgs(
                                                         $"({CurrentPlugin}/{OldPlugins.Count}) {oldPlugin.PluginName} Preset {currentPreset} / {oldPlugin.Presets.Count}"));
                    UpdateCounter = 0;
                }

                var newPreset = new NewModels.Preset();
                newPreset.Plugin = newPlugin;
                newPlugin.Presets.Add(newPreset);

                MigratePreset(preset, newPreset);


                newPreset.Plugin = newPlugin;
                newPreset.OriginalMetadata.Plugin = newPlugin;
                _presetDataPersister.PersistPreset(newPreset.OriginalMetadata, data, true).Wait();
            }


            var propertiesToMigrate = new HashSet <string>
            {
                nameof(Plugin.PluginType),
                nameof(Plugin.PluginName),
                nameof(Plugin.LastKnownGoodDllPath),
                nameof(Plugin.PluginVendor),
                nameof(Plugin.VstPluginId),
                nameof(Plugin.IsEnabled),
                nameof(Plugin.IsReported),
                nameof(Plugin.IsSupported),
                nameof(Plugin.DontReport),
                nameof(Plugin.DefaultControllerAssignments),
            };

            foreach (var propertyName in propertiesToMigrate)
            {
                var oldValue = PropertyHelper.GetPropertyValue(oldPlugin, propertyName);
                PropertyHelper.SetPropertyValue(newPlugin, propertyName, oldValue);
            }

            MigrateModes(oldPlugin.DefaultModes, newPlugin.DefaultCharacteristics);
            MigrateTypes(oldPlugin.DefaultTypes, newPlugin.DefaultTypes);

            if (oldPlugin.PluginInfo != null)
            {
                newPlugin.PluginInfo = new NewModels.VstPluginInfoSurrogate();
            }

            MigratePluginInfo(oldPlugin.PluginInfo, newPlugin.PluginInfo);
            MigratePluginCapabilities(oldPlugin.PluginCapabilities, newPlugin.PluginCapabilities);
            MigrateBankFiles(oldPlugin.AdditionalBankFiles, newPlugin.AdditionalBankFiles);

            _dataPersister.SavePlugin(newPlugin);
            _dataPersister.SavePresetsForPlugin(newPlugin);
            _presetDataPersister.CloseDatabase().Wait();
            return(newPlugin);
        }