本文整理汇总了C#中MainWindowViewModel.CreateNewPlugin方法的典型用法代码示例。如果您正苦于以下问题:C# MainWindowViewModel.CreateNewPlugin方法的具体用法?C# MainWindowViewModel.CreateNewPlugin怎么用?C# MainWindowViewModel.CreateNewPlugin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MainWindowViewModel
的用法示例。
在下文中一共展示了MainWindowViewModel.CreateNewPlugin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateViewModelWithGraph001
internal static MainWindowViewModel CreateViewModelWithGraph001()
{
/** Imagine a graph like this:
* +RUNNING-+ +--------+
* +---------->|ServiceA+-------+ *----------------->|ServiceB|
* | +---+----+ | | Need Running +---+----+
* | | | | |
* | | | | |
* | | | | |
* | | | | |
* +---+-----+ +---+-----+ +RUNNING*-+ +---+-----+
* |ServiceAx| |PluginA-1| |PluginA-2| |PluginB-1|
* +----+----+ +---------+ +---------+ +---------+
* |
* |
* +----+-----+ +----------------------+
* |PluginAx-1| |Plugin.Without.Service|
* +----------+ +----------------------+
*/
MainWindowViewModel vm = new MainWindowViewModel();
Assert.That( vm.LabState.Engine.IsRunning, Is.False );
// Services
IServiceInfo serviceA = vm.CreateNewService( "ServiceA" );
Assert.That( vm.ServiceInfos.Contains( serviceA ) );
Assert.That( vm.ServiceInfos.Count == 1 );
Assert.That( vm.LabState.LabServiceInfos.Count == 1 );
Assert.That( vm.LabState.LabServiceInfos.Where( x => x.ServiceInfo == serviceA ).Count() == 1 );
LabServiceInfo labServiceA = vm.LabState.LabServiceInfos.Where( x => x.ServiceInfo == serviceA ).First();
IServiceInfo serviceB = vm.CreateNewService( "ServiceB" );
Assert.That( vm.ServiceInfos.Contains( serviceB ) );
Assert.That( vm.ServiceInfos.Count == 2 );
Assert.That( vm.LabState.LabServiceInfos.Count == 2 );
Assert.That( vm.LabState.LabServiceInfos.Where( x => x.ServiceInfo == serviceB ).Count() == 1 );
IServiceInfo serviceAx = vm.CreateNewService( "ServiceAx", serviceA );
Assert.That( vm.ServiceInfos.Contains( serviceAx ) );
Assert.That( vm.ServiceInfos.Count == 3 );
Assert.That( vm.LabState.LabServiceInfos.Count == 3 );
Assert.That( vm.LabState.LabServiceInfos.Where( x => x.ServiceInfo == serviceAx ).Count() == 1 );
LabServiceInfo labServiceAx = vm.LabState.LabServiceInfos.Where( x => x.ServiceInfo == serviceAx ).First();
Assert.That( labServiceAx.ServiceInfo.Generalization == labServiceA.ServiceInfo );
Assert.That( serviceA.Generalization == null );
Assert.That( serviceB.Generalization == null );
Assert.That( serviceAx.Generalization == serviceA );
// Plugins
IPluginInfo pluginWithoutService = vm.CreateNewPlugin( "Plugin.Without.Service" );
IPluginInfo pluginA1 = vm.CreateNewPlugin( "Plugin.A1", serviceA );
IPluginInfo pluginA2 = vm.CreateNewPlugin( "Plugin.A2", serviceA );
IPluginInfo pluginAx1 = vm.CreateNewPlugin( "Plugin.Ax1", serviceAx );
IPluginInfo pluginB1 = vm.CreateNewPlugin( "Plugin.B1", serviceB );
vm.SetPluginDependency( pluginA2, serviceB, DependencyRequirement.Running );
Assert.That( pluginA2.ServiceReferences.Count == 1 );
Assert.That( pluginA2.ServiceReferences[0].Reference == serviceB );
Assert.That( pluginA2.ServiceReferences[0].Requirement == DependencyRequirement.Running );
Assert.That( serviceA.Implementations.Count == 2 );
Assert.That( serviceB.Implementations.Count == 1 );
Assert.That( serviceAx.Implementations.Count == 1 );
// Set configuration
var cLayer1 = vm.LabState.Engine.Configuration.Layers.Create( "Test layer" );
var result = cLayer1.Items.Add( serviceA.ServiceFullName, ConfigurationStatus.Running, "Test reason" );
Assert.That( result.Success );
var cLayer2 = vm.LabState.Engine.Configuration.Layers.Create( "Test layer 2" );
result = cLayer2.Items.Add( pluginA2.PluginFullName, ConfigurationStatus.Running, "Test reason 2" );
Assert.That( result.Success );
// Testing tests
foreach( var si in vm.ServiceInfos )
{
EquivalenceExtensions.AssertServiceEquivalence( si, si, true );
}
foreach( var pi in vm.PluginInfos )
{
EquivalenceExtensions.AssertPluginEquivalence( pi, pi, true );
}
EquivalenceExtensions.AssertManagerEquivalence( vm.LabState.Engine.Configuration, vm.LabState.Engine.Configuration );
return vm;
}