public SingleOperationViewModel(OperationModel operationModel, UserControl view) : base(operationModel, view) { #if !DEBUG try { #endif Operation = Activator.CreateInstance(OperationModel.Type) as IOperation; if (Operation is null) { throw new ArgumentException("Cannot Construct Operation."); } foreach (KeyValuePair <string, JToken> sectionData in Operation.RequiredConfigSections) { (ConfigSectionAttribute attribute, ConfigSectionBase section) = PluginService.CreateConfigSection(sectionData.Key, sectionData.Value); if (section is null) { throw new ArgumentException("Cannot Construct ConfigSection."); } ConfigSections.Add((attribute, section)); Items.Add( new TabItem { Header = attribute.Name, Content = section }); } #if !DEBUG } catch (Exception) { System.Reactive.Linq.Observable.FromAsync( () => MessageBox.ShowAndGetResult( "警告", "插件加载出现错误,请检查是否安装了所需的插件。操作可能出现不正常的行为。", view.GetVisualRoot() as Window, false), RxApp.MainThreadScheduler) .Subscribe(_ => { }); } #endif }
public BatchOperationViewModel(OperationModel operationModel, UserControl view) : base(operationModel, view) { #if !DEBUG try { #endif ConfigSectionAttribute batchAttribute = Attribute.GetCustomAttribute(typeof(BatchIOConfigSection), typeof(ConfigSectionAttribute)) as ConfigSectionAttribute; BatchIOConfigSection batchConfig = new(); ConfigSections.Add((batchAttribute, batchConfig)); Items.Add( new TabItem { Header = batchAttribute?.Name, Content = batchConfig }); Operation = Activator.CreateInstance(OperationModel.Type) as IOperation; if (Operation is null) { throw new ArgumentException("Cannot Construct Operation."); } foreach ((string key, JToken value) in Operation.RequiredConfigSections) { // Exclude if (key == ConfigSectionBase.IOConfigSectionId) { continue; } (ConfigSectionAttribute attribute, ConfigSectionBase section) = PluginService.CreateConfigSection(key, value); if (section is null) { throw new ArgumentException("Cannot Construct ConfigSection."); } ConfigSections.Add((attribute, section)); Items.Add( new TabItem { Header = attribute.Name, Content = section }); } #if !DEBUG } catch (Exception) { Observable.FromAsync( () => MessageBox.ShowAndGetResult( "警告", "插件加载出现错误,请检查是否安装了所需的插件。操作可能出现不正常的行为。", view.GetVisualRoot() as Window, false), RxApp.MainThreadScheduler) .Subscribe(_ => { }); } #endif }