示例#1
0
        private void ComparePlugin(OldPlugin oldPlugin, Plugin newPlugin)
        {
            var propertiesToCompare = new HashSet <string>
            {
                nameof(Plugin.IsEnabled),
                nameof(Plugin.PluginType),
                nameof(Plugin.LastKnownGoodDllPath),
                nameof(Plugin.AudioPreviewPreDelay),
                nameof(Plugin.IsReported),
                nameof(Plugin.DontReport),
                nameof(Plugin.PluginName),
                nameof(Plugin.PluginVendor),
                nameof(Plugin.HasMetadata),
                nameof(Plugin.IsSupported),
                nameof(Plugin.VstPluginId),
            };
            var comparer = new PropertyComparisonHelper(oldPlugin, newPlugin);

            comparer.CompareProperties(propertiesToCompare);

            ComparePluginLocation(oldPlugin.PluginLocation, newPlugin.PluginLocation);
            comparer.AddVisitedProperty(nameof(oldPlugin.PluginLocation));

            newPlugin.Presets.Count.Should().Be(oldPlugin.Presets.Count);

            foreach (var oldPreset in oldPlugin.Presets)
            {
                var newPreset = (from p in newPlugin.Presets where p.PresetId == oldPreset.PresetId select p)
                                .FirstOrDefault();
                ComparePreset(oldPreset, newPreset);
            }

            comparer.AddVisitedProperty(nameof(oldPlugin.Presets));

            CompareTypes(oldPlugin.DefaultTypes, newPlugin.DefaultTypes);
            comparer.AddVisitedProperty(nameof(oldPlugin.DefaultTypes));

            CompareModes(oldPlugin.DefaultModes, newPlugin.DefaultCharacteristics);

            newPlugin.PluginCapabilities.Should().BeEquivalentTo(oldPlugin.PluginCapabilities);
            comparer.AddVisitedProperty(nameof(oldPlugin.PluginCapabilities));

            newPlugin.PluginInfo.Should().BeEquivalentTo(oldPlugin.PluginInfo);
            comparer.AddVisitedProperty(nameof(oldPlugin.PluginInfo));

            CompareBankFiles(oldPlugin.AdditionalBankFiles, newPlugin.AdditionalBankFiles);
            comparer.AddVisitedProperty(nameof(oldPlugin.AdditionalBankFiles));


            newPlugin.DefaultControllerAssignments.Should().BeEquivalentTo(oldPlugin.DefaultControllerAssignments);
            comparer.AddVisitedProperty(nameof(oldPlugin.DefaultControllerAssignments));

            comparer.GetUnvisitedProperties().Should().BeEmpty();
        }
        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);
        }