void ObservableServiceReferences_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { MockServiceReferenceInfo reference = (MockServiceReferenceInfo)e.NewItems[0]; YodiiGraphVertex pluginVertex = FindOrCreatePluginVertex((PluginInfo)reference.Owner); YodiiGraphVertex refVertex = FindOrCreateServiceVertex((IServiceInfo)reference.Reference); YodiiGraphEdge refEdge = new YodiiGraphEdge(pluginVertex, refVertex, reference) { ID = currentId++ }; this.AddEdge(refEdge); } else if (e.Action == NotifyCollectionChangedAction.Remove) { IServiceReferenceInfo reference = (IServiceReferenceInfo)e.OldItems[0]; Debug.Assert(reference != null); this.RemoveEdgeIf( e2 => e2.IsServiceReference && e2.Source.IsPlugin && e2.Source.LabPluginInfo.PluginInfo == reference.Owner && e2.Target.IsService && e2.Target.LabServiceInfo.ServiceInfo == reference.Reference); } RaiseGraphUpdateRequested(); }
internal void BindServiceRequirement(IServiceReferenceInfo reference) { Debug.Assert(!_serviceReferences.Contains(reference)); Debug.Assert(reference.Owner == this); _serviceReferences.Add(reference); }
/// <summary> /// Assert equivalence between two IServiceReferenceInfo, in the context of Yodii.Lab. /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void AssertServiceReferenceEquivalence(IServiceReferenceInfo a, IServiceReferenceInfo b) { if (a == null && b == null) { return; } Assert.That(a != null && b != null); }
public VMIService( VMIContextViewModel ctx, IServiceReferenceInfo service, VMIBase parent ) : base(ctx, parent) { _serviceRef = service; _service = service.Reference; Label = service.Reference.ServiceFullName; OnError = service.HasError; if( service.Reference.IsDynamicService ) Assembly = service.Reference.AssemblyInfo.AssemblyName; _pluginRunner = VMIContext.Context.GetService<PluginRunner>( true ); _pluginRunner.ApplyDone += new EventHandler<ApplyDoneEventArgs>( OnApplyDone ); DetailsTemplateName = "ServiceRefDetails"; _owner = new VMIPlugin( ctx, service.Owner, this ); _reference = new VMIService( ctx, service.Reference, this ); _allReferencingPlugins = new Dictionary<VMIPlugin,RunningRequirement>(); ImplementedBy = new VMCollection<VMAlias<VMIPlugin>, IPluginInfo>( _service.Implementations, ( info ) => { return new VMAlias<VMIPlugin>( VMIContext.FindOrCreate( info ), this ); } ); }
internal void BindServiceRequirement( IServiceReferenceInfo reference ) { Debug.Assert( !_serviceReferences.Contains( reference ) ); Debug.Assert( reference.Owner == this ); _serviceReferences.Add( reference ); }
public VMIService FindOrCreate( IServiceReferenceInfo item ) { VMIService s = null; if( !_serviceRefs.TryGetValue( item, out s ) ) { s = FindOrCreateDynamic( item.Reference ); if( s == null ) s = new VMIService( this, item, null ); _serviceRefs.Add( item, s ); } return s; }
bool CheckReference( IServiceReferenceInfo serviceRef, BitArray parseMap, ref int cost ) { // If the reference is a reference to an external service if( !serviceRef.Reference.IsDynamicService ) { return true; // todo check if the service is available in the service container. } // Checks if at least one of the implementations of the service is available in the current map. bool implAvailable = serviceRef.Reference.Implementations.Count > 0; // If the service is really needed and is not available, return the reference cannot be resolved. if( serviceRef.Requirements >= RunningRequirement.MustExist && !implAvailable ) return false; else { Debug.Assert( serviceRef.Requirements < RunningRequirement.MustExist || implAvailable ); bool isPossible = false; if( !implAvailable ) { switch( serviceRef.Requirements ) { // the plugin is stopped but it's optional -> whatever ! case RunningRequirement.Optional: return true; case RunningRequirement.OptionalTryStart: cost += 10; return true; } } else { foreach( IPluginInfo impl in serviceRef.Reference.Implementations ) { PluginData data = _mappingDic.GetValueWithDefault( impl, null ); if( data != null ) { // if the plugin is running in this map if( parseMap[data.Index] ) { isPossible = true; switch( serviceRef.Requirements ) { // the plugin is started but we don't really need it -> +10 if its not currently running. case RunningRequirement.Optional: case RunningRequirement.MustExist: if( !IsPluginRunning( impl ) ) cost += 10; break; // the plugin is started and we want it -> +0 (its what we want) case RunningRequirement.OptionalTryStart: case RunningRequirement.MustExistTryStart: case RunningRequirement.MustExistAndRun: break; } } else { switch( serviceRef.Requirements ) { // the plugin is stopped but it's optional -> whatever ! case RunningRequirement.Optional: case RunningRequirement.MustExist: isPossible = true; break; // the plugin is stopped but we wants it -> +10 case RunningRequirement.OptionalTryStart: cost += 10; break; // the plugin is stopped but we absolutely needs it -> impossible. case RunningRequirement.MustExistTryStart: case RunningRequirement.MustExistAndRun: isPossible = false; break; } } } else isPossible = false; } } return isPossible; } }
/// <summary> /// Assert equivalence between two IServiceReferenceInfo, in the context of Yodii.Lab. /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void AssertServiceReferenceEquivalence( IServiceReferenceInfo a, IServiceReferenceInfo b ) { if( a == null && b == null ) return; Assert.That( a != null && b != null ); }
bool CheckReference(IServiceReferenceInfo serviceRef, BitArray parseMap, ref int cost) { // If the reference is a reference to an external service if (!serviceRef.Reference.IsDynamicService) { return(true); // todo check if the service is available in the service container. } // Checks if at least one of the implementations of the service is available in the current map. bool implAvailable = serviceRef.Reference.Implementations.Count > 0; // If the service is really needed and is not available, return the reference cannot be resolved. if (serviceRef.Requirements >= RunningRequirement.MustExist && !implAvailable) { return(false); } else { Debug.Assert(serviceRef.Requirements < RunningRequirement.MustExist || implAvailable); bool isPossible = false; if (!implAvailable) { switch (serviceRef.Requirements) { // the plugin is stopped but it's optional -> whatever ! case RunningRequirement.Optional: return(true); case RunningRequirement.OptionalTryStart: cost += 10; return(true); } } else { foreach (IPluginInfo impl in serviceRef.Reference.Implementations) { PluginData data = _mappingDic.GetValueWithDefault(impl, null); if (data != null) { // if the plugin is running in this map if (parseMap[data.Index]) { isPossible = true; switch (serviceRef.Requirements) { // the plugin is started but we don't really need it -> +10 if its not currently running. case RunningRequirement.Optional: case RunningRequirement.MustExist: if (!IsPluginRunning(impl)) { cost += 10; } break; // the plugin is started and we want it -> +0 (its what we want) case RunningRequirement.OptionalTryStart: case RunningRequirement.MustExistTryStart: case RunningRequirement.MustExistAndRun: break; } } else { switch (serviceRef.Requirements) { // the plugin is stopped but it's optional -> whatever ! case RunningRequirement.Optional: case RunningRequirement.MustExist: isPossible = true; break; // the plugin is stopped but we wants it -> +10 case RunningRequirement.OptionalTryStart: cost += 10; break; // the plugin is stopped but we absolutely needs it -> impossible. case RunningRequirement.MustExistTryStart: case RunningRequirement.MustExistAndRun: isPossible = false; break; } } } else { isPossible = false; } } } return(isPossible); } }