/// <summary> /// Gets whether this plugin can reference the given service. /// </summary> /// <param name="this">This plugin.</param> /// <param name="service">Service to reference.</param> /// <returns>True if this plugin can have a reference to the service.</returns> public static bool CanReference(this IPluginInfo @this, IServiceInfo service) { var thisPluginRoot = @this.GetServiceFamilyRoot(); var referenceRoot = service.GetServiceFamilyRoot(); return(thisPluginRoot != referenceRoot || @this.AllServices().Contains(service)); }
private static bool IsEurekaConfigured(IConfiguration config, IServiceInfo info) { var clientConfigsection = config.GetSection(EUREKA_PREFIX); int childCount = clientConfigsection.GetChildren().Count(); return(childCount > 0 || info is EurekaServiceInfo); }
ServiceData RegisterService(FinalConfiguration finalConfig, IServiceInfo s) { ServiceData data; if (_services.TryGetValue(s.ServiceFullName, out data)) { return(data); } //Set default status ConfigurationStatus serviceStatus = finalConfig.GetStatus(s.ServiceFullName); // Handle generalization. ServiceData dataGen = null; if (s.Generalization != null) { dataGen = RegisterService(finalConfig, s.Generalization); } Debug.Assert((s.Generalization == null) == (dataGen == null)); if (dataGen == null) { data = new ServiceData(this, s, serviceStatus); _serviceFamilies.Add(data.Family); } else { data = new ServiceData(s, dataGen, serviceStatus); } _services.Add(s.ServiceFullName, data); return(data); }
static void Main(string[] args) { Console.WriteLine("Service Controller Console.."); //Identify the wire-encoding format; in this case we have selected //BinaryFormatter BinaryClientFormatterSinkProvider cltFormatter = new BinaryClientFormatterSinkProvider(); //Identify the communication protocol used to interact with server. //The wire-encoding details are also specified here TcpClientChannel cltChannel = new TcpClientChannel("ControllerChannel", cltFormatter); //Registration of communication protocol and wire-encoding format to be used //by remoting infrastructure ChannelServices.RegisterChannel(cltChannel); //Instantiation of Remote type (Service MetaInformation) IServiceInfo serviceInfo = Activator.GetObject(typeof(IServiceInfo), "tcp://localhost:15000/HeartBeatServiceInfo.rem") as IServiceInfo; //Service meta-information is retrieved to determine the actual //location of the heartbeat service ServiceInfo heartBeatInfo = serviceInfo.QueryServiceInfo; Console.WriteLine("Starting Service : " + heartBeatInfo.FriendlyName); //Instantiation of heartbeat service IService hbService = Activator.GetObject(typeof(IService), heartBeatInfo.Location) as IService; hbService.Start(); Console.ReadLine(); }
public static void RegisterDiscoveryClient( this ContainerBuilder container, IConfiguration config, string serviceName, IDiscoveryLifecycle lifecycle = null) { if (container == null) { throw new ArgumentNullException(nameof(container)); } if (string.IsNullOrEmpty(serviceName)) { throw new ArgumentNullException(nameof(serviceName)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } IServiceInfo info = GetNamedDiscoveryServiceInfo(config, serviceName); AddDiscoveryServices(container, info, config, lifecycle); }
/// <summary> /// Determines which factories should be used /// for a particular service request. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo"/> object that describes the target factory.</param> /// <returns>A factory instance.</returns> public virtual IFactory GetFactory(IServiceInfo serviceInfo) { if (_entries.ContainsKey(serviceInfo)) return _entries[serviceInfo]; return null; }
private ExecutionResult GetResult(IServiceInfo info, IExecutionContext context, String exitMessage) { String message = ""; if (exitMessage == null) { if (context.ExecutionFailed) { message = _errMessageResolver.Resolve(context.ErrorCode); context.KeyValues.Set("error", context.ErrorCode); } else { message = info.SuccessMessage; } } else { message = exitMessage; } message = context.KeyValues.Apply(message); ExecutionResult result = new ExecutionResult(context, message); return(result); }
/// <summary> /// Determines whether or not an <see cref="IFactory"/> instance /// can be used to create the given service described by the <paramref name="serviceInfo"/> object. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo"/> object that describes the service to be created.</param> /// <returns><c>True</c> if the service can be created; otherwise, it will return <c>false</c>.</returns> public override bool ContainsFactory(IServiceInfo serviceInfo) { var serviceType = serviceInfo.ServiceType; var serviceName = serviceInfo.ServiceName; // Use the default implementation for // non-generic types if (!serviceType.IsGenericType && !serviceType.IsGenericTypeDefinition) return base.ContainsFactory(serviceInfo); // If the service type is a generic type, determine // if the service type can be created by a // standard factory that can create an instance // of that generic type (e.g., IFactory<IGeneric<T>> var result = base.ContainsFactory(serviceInfo); // Immediately return a positive match, if possible if (result) return true; if (serviceType.IsGenericType && !serviceType.IsGenericTypeDefinition) { // Determine the base type definition var baseDefinition = serviceType.GetGenericTypeDefinition(); // Check if there are any generic factories that can create // the entire family of services whose type definitions // match the base type var genericServiceInfo = new ServiceInfo(serviceName, baseDefinition, serviceInfo.ArgumentTypes); result = base.ContainsFactory(genericServiceInfo); } return result; }
/// <summary> /// Obtains the <see cref="IFactory"/> instance that can instantiate the /// service described by the <paramref name="serviceInfo"/> object instance. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo"/> object that describes the service to be created.</param> /// <returns>A <see cref="IFactory"/> instance if the service can be instantiated; otherwise, it will return <c>false</c>.</returns> public override IFactory GetFactory(IServiceInfo serviceInfo) { // Attempt to create the service type using // the strongly-typed arguments var factory = base.GetFactory(serviceInfo); var serviceType = serviceInfo.ServiceType; var serviceName = serviceInfo.ServiceName; // Use the default factory for this service type if no other factory exists var defaultServiceInfo = new ServiceInfo(serviceInfo.ServiceName, serviceInfo.ServiceType); if (factory == null && base.ContainsFactory(defaultServiceInfo)) { factory = base.GetFactory(defaultServiceInfo); } // Attempt to create the service type using // the generic factories, if possible if (factory == null && serviceType.IsGenericType) { var definitionType = serviceType.GetGenericTypeDefinition(); var genericServiceInfo = new ServiceInfo(serviceName, definitionType, serviceInfo.ArgumentTypes); factory = base.GetFactory(genericServiceInfo); } return(factory); }
/// <summary> /// Gets whether this plugin can reference the given service. /// </summary> /// <param name="this">This plugin.</param> /// <param name="service">Service to reference.</param> /// <returns>True if this plugin can have a reference to the service.</returns> public static bool CanReference( this IPluginInfo @this, IServiceInfo service ) { var thisPluginRoot = @this.GetServiceFamilyRoot(); var referenceRoot = service.GetServiceFamilyRoot(); return thisPluginRoot != referenceRoot || @this.AllServices().Contains( service ); }
// TODO Use Dictionary<CVertex(Service), CKVertex(Plugin)> private IVertex buildThree(IServiceInfo service, int deph) { /* ServiceVertex generalizationService = null; * ServiceVertex currentService = new ServiceVertex(this, service); * * if (service.Generalization != null) * { * generalizationService = buildThree(service.Generalization, ++deph); * } * * if (generalizationService != null) * { * AddVertex(generalizationService); * AddVertex(currentService); * * AddEdge(new CKEdge(currentService, generalizationService)); * } * else * { * AddVertex(currentService); * } * * // Finnaly add plugin implementation * foreach (IPluginInfo implementation in _serviceInfo.Implementations) * { * CKVertex pluginImplementation = new CKVertex(String.Format("Plugin : {0}", implementation.PluginFullName)); * AddVertex(pluginImplementation); * AddEdge(new CKEdge(currentService, pluginImplementation)); * }*/ return(new ServiceVertex(service)); // currentService; }
/// <summary> /// Adds a <see cref="IFactory"/> to the current <see cref="IFactoryStorage"/> object. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo"/> object that describes the target factory.</param> /// <param name="factory">The <see cref="IFactory"/> instance that will create the object instance.</param> public virtual void AddFactory(IServiceInfo serviceInfo, IFactory factory) { lock (_lock) { _entries[serviceInfo] = factory; } }
private static void AddDiscoveryServices(IServiceCollection services, IServiceInfo info, IConfiguration config, IDiscoveryLifecycle lifecycle) { var clientConfigsection = config.GetSection(EUREKA_PREFIX); int childCount = clientConfigsection.GetChildren().Count(); if (childCount > 0 || info is EurekaServiceInfo) { EurekaServiceInfo einfo = info as EurekaServiceInfo; var clientSection = config.GetSection(EurekaClientOptions.EUREKA_CLIENT_CONFIGURATION_PREFIX); services.Configure <EurekaClientOptions>(clientSection); services.PostConfigure <EurekaClientOptions>((options) => { PivotalEurekaConfigurer.UpdateConfiguration(config, einfo, options); }); var instSection = config.GetSection(EurekaInstanceOptions.EUREKA_INSTANCE_CONFIGURATION_PREFIX); services.Configure <EurekaInstanceOptions>(instSection); services.PostConfigure <EurekaInstanceOptions>((options) => { PivotalEurekaConfigurer.UpdateConfiguration(config, einfo, options); }); AddEurekaServices(services, lifecycle); } else { throw new ArgumentException("Discovery client type UNKNOWN, check configuration"); } }
private static IServiceCollection DoAdd(IServiceCollection services, IServiceInfo info, DiscoveryOptions config) { DiscoveryClientFactory factory = new DiscoveryClientFactory(info, config); services.Add(new ServiceDescriptor(typeof(IDiscoveryClient), factory.Create, ServiceLifetime.Singleton)); return(services); }
ListViewItem CreateItem <T>(object provider, IServiceInfo info, T target) { bool needProxy = false; if (target is ITorrentDownloadServiceProvider) { var dp = target as ITorrentDownloadServiceProvider; needProxy = dp.RequireBypassGfw; } else { var dp = target as IResourceProvider; needProxy = dp.RequireBypassGfw; } var item = new ListViewItem(new[] { info.Name, info.Version.ToString(), needProxy ? "需要" : "不需要", "等待测试..." }) { Tag = target, UseItemStyleForSubItems = true }; if (info.Icon != null) { var key = provider.GetType().FullName; il.Images.Add(key, Utility.Get20PxImageFrom16PxImg(info.Icon)); item.ImageKey = key; } else { item.ImageKey = "_"; } item.Group = provider is IResourceProvider ? lv.Groups[0] : lv.Groups[1]; return(item); }
private static bool IsConsulConfigured(IConfiguration config, IServiceInfo info) { var clientConfigsection = config.GetSection(CONSUL_PREFIX); int childCount = clientConfigsection.GetChildren().Count(); return(childCount > 0); }
internal ServiceData(IConfigurationSolver solver, IServiceInfo s, ConfigurationStatus serviceStatus, StartDependencyImpact impact = StartDependencyImpact.Unknown) : this(s, serviceStatus, impact) { Family = new ServiceFamily(solver, this); _inheritedServicesWithThis = new ServiceData[] { this }; Initialize(); }
private static void AddDiscoveryServices(IServiceCollection services, IServiceInfo info, IConfiguration config, IDiscoveryLifecycle lifecycle) { var netOptions = config.GetSection(InetOptions.PREFIX).Get <InetOptions>(); if (IsEurekaConfigured(config, info)) { ConfigureEurekaServices(services, config, info, netOptions); AddEurekaServices(services, lifecycle); } else if (IsConsulConfigured(config, info)) { ConfigureConsulServices(services, config, info, netOptions); AddConsulServices(services, config, lifecycle); } else if (IsKubernetesConfigured(config)) { ConfigureKubernetesServices(services, config); AddKubernetesServices(services); } else { throw new ArgumentException("Discovery client type UNKNOWN, check configuration"); } services.TryAddTransient <DiscoveryHttpMessageHandler>(); services.AddSingleton <IServiceInstanceProvider>(p => p.GetService <IDiscoveryClient>()); }
/// <summary> /// Constructor /// </summary> /// <param name="template">Requiered characteristic template</param> /// <param name="service">Required parent service</param> /// <param name="presentationFormat">Optional overriding of presentation format</param> public KnownCharacteristicInfo(ICharacteristicTemplate template, IServiceInfo service, CharacteristicProperties properties, IPresentationFormat presentationFormat) { Template = template ?? throw new ArgumentNullException(nameof(template)); Service = service ?? throw new ArgumentNullException(nameof(service)); PresentationFormat = presentationFormat ?? template.PresentationFormat; Properties = properties; }
public bool IsConfigured(IConfiguration configuration, IServiceInfo serviceInfo = null) { return(configuration .GetSection(KubernetesDiscoveryOptions.KUBERNETES_DISCOVERY_CONFIGURATION_PREFIX) .GetChildren() .Any()); }
/// <summary> /// Registers a service with a dependency map. /// </summary> /// <param name="map">The dependency map.</param> /// <param name="service">The service that will be registered with the dependency map.</param> internal static void Register(this DependencyMap map, IServiceInfo service) { var serviceName = service.ServiceName; var serviceType = service.ServiceType; var implementingType = service.ImplementingType; map.AddService(serviceName, serviceType, implementingType); }
public WorkerNodeHostedService(ILogger <WorkerNodeHostedService> logger , WorkerNode workerNode , IServiceInfo serviceInfo) { _serviceName = serviceInfo.ShortName; _workerNode = workerNode; _logger = logger; }
public int CompareTo(IServiceInfo other) { if (this == other) { return(0); } return(_assemblyQualifiedName.CompareTo(other.AssemblyQualifiedName)); }
/// <summary> /// Determines which service should be used as the default service for the given service type. /// </summary> /// <param name="serviceType">The service type.</param> /// <param name="services">The list of services that implement the service type.</param> /// <returns>The <see cref="IServiceInfo"/> instance that will determine </returns> public IServiceInfo GetDefaultService(Type serviceType, IEnumerable <IServiceInfo> services) { IServiceInfo result = null; result = _picker.ChooseDefaultServiceFrom(serviceType, services); return(result); }
internal ServiceReferenceInfo( IPluginInfo ownerPlugin, IServiceInfo referencedService, DependencyRequirement requirement ) { Debug.Assert( ownerPlugin != null ); Debug.Assert( referencedService != null ); _owner = ownerPlugin; _reference = referencedService; _requirement = requirement; }
internal void UpdateConfiguration(IServiceInfo si, DiscoveryOptions config) { EurekaServiceInfo eurekaInfo = si as EurekaServiceInfo; if (eurekaInfo != null) { UpdateConfiguration(eurekaInfo, config); } }
/// <summary> /// Determines which factories should be used /// for a particular service request. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo"/> object that describes the target factory.</param> /// <returns>A factory instance.</returns> public virtual IFactory GetFactory(IServiceInfo serviceInfo) { if (_entries.ContainsKey(serviceInfo)) { return(_entries[serviceInfo]); } return(null); }
public GeneralCharacteristicInfo(IServiceInfo service, Guid uuid, CharacteristicProperties properties, IPresentationFormat presentationFormat) : base(uuid) { Service = service ?? throw new ArgumentNullException(nameof(service)); PresentationFormat = presentationFormat ?? WellKnownPresentationFormats.Unknown; Properties = properties; // derive name from UUID Name = GetDefaultName(); }
internal ServiceReferenceInfo(IPluginInfo ownerPlugin, IServiceInfo referencedService, DependencyRequirement requirement) { Debug.Assert(ownerPlugin != null); Debug.Assert(referencedService != null); _owner = ownerPlugin; _reference = referencedService; _requirement = requirement; }
/// <summary> /// 服务注册与系统配置 /// </summary> /// <param name="configuration"><see cref="IConfiguration"/></param> /// <param name="services"><see cref="IServiceInfo"/></param> /// <param name="environment"><see cref="IHostEnvironment"/></param> /// <param name="serviceInfo"><see cref="ServiceInfo"/></param> public SharedServicesRegistration(IConfiguration configuration , IServiceCollection services , IHostEnvironment environment , IServiceInfo serviceInfo) { _configuration = configuration; _environment = environment; _services = services; _serviceInfo = serviceInfo; }
internal ServiceInfo(string serviceFullName, IAssemblyInfo assemblyInfo, IServiceInfo generalization = null) { Debug.Assert(!String.IsNullOrEmpty(serviceFullName)); Debug.Assert(assemblyInfo != null); _serviceFullName = serviceFullName; _assemblyInfo = assemblyInfo; _generalization = generalization; _implementations = new CKObservableSortedArrayList <PluginInfo>((a, b) => CaseInsensitiveComparer.Default.Compare(a.PluginFullName, b.PluginFullName), false); }
internal ServiceInfo( string serviceFullName, IAssemblyInfo assemblyInfo, IServiceInfo generalization = null ) { Debug.Assert( !String.IsNullOrEmpty( serviceFullName ) ); Debug.Assert( assemblyInfo != null ); _serviceFullName = serviceFullName; _assemblyInfo = assemblyInfo; _generalization = generalization; _implementations = new CKObservableSortedArrayList<PluginInfo>( ( a, b ) => CaseInsensitiveComparer.Default.Compare( a.PluginFullName, b.PluginFullName ), false ); }
/// <summary> /// Determines whether or not an <see cref="IFactory" /> instance /// can be used to create the given service described by the <paramref name="serviceInfo" /> object. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo" /> object that describes the service to be created.</param> /// <returns><c>True</c> if the service can be created; otherwise, it will return <c>false</c>.</returns> public override bool ContainsFactory(IServiceInfo serviceInfo) { var serviceType = serviceInfo.ServiceType; var serviceName = serviceInfo.ServiceName; // Use the default implementation for // non-generic types if (!serviceType.IsGenericType && !serviceType.IsGenericTypeDefinition) { return(base.ContainsFactory(serviceInfo)); } // If the service type is a generic type, determine // if the service type can be created by a // standard factory that can create an instance // of that generic type (e.g., IFactory<IGeneric<T>> var result = base.ContainsFactory(serviceInfo); // Immediately return a positive match, if possible if (result) { return(true); } if (!serviceType.IsGenericType || serviceType.IsGenericTypeDefinition) { return(false); } // Determine the base type definition var baseDefinition = serviceType.GetGenericTypeDefinition(); // Check if there are any generic factories that can create // the entire family of services whose type definitions // match the base type var genericServiceInfo = new ServiceInfo(serviceName, baseDefinition, serviceInfo.ArgumentTypes); result = base.ContainsFactory(genericServiceInfo); if (result) { return(true); } if (baseDefinition == typeof(IFactory <>)) { var typeArguments = serviceType.GetGenericArguments(); var actualServiceType = typeArguments[0]; var actualServiceInfo = new ServiceInfo(serviceName, actualServiceType, serviceInfo.ArgumentTypes); return(base.ContainsFactory(actualServiceInfo)); } return(false); }
/// <summary> /// 服务注册与系统配置 /// </summary> /// <param name="configuration"><see cref="IConfiguration"/></param> /// <param name="services"><see cref="IServiceInfo"/></param> /// <param name="environment"><see cref="IHostEnvironment"/></param> /// <param name="serviceInfo"><see cref="ServiceInfo"/></param> public SharedServicesRegistration(IConfiguration configuration , IServiceCollection services , IHostEnvironment environment , IServiceInfo serviceInfo) { _configuration = configuration; _environment = environment; _services = services; _serviceInfo = serviceInfo; _schedulingJobs = Enumerable.Empty <Type>(); }
/// <summary> /// Gets all the services that are supported by this plugin (its <see cref="IPluginInfo.Service"/> and all its <see cref="IServiceInfo.Generalization"/>. /// </summary> /// <param name="this">This plugin information.</param> /// <returns>The Service and its generalizations.</returns> public static IEnumerable <IServiceInfo> AllServices(this IPluginInfo @this) { IServiceInfo s = @this.Service; while (s != null) { yield return(s); s = s.Generalization; } }
private ServiceLoader(string path, string name) { Assembly asm = Assembly.LoadFrom(path + "/" + name); var info = asm.GetType(asm.FullName.Substring(0, asm.FullName.IndexOf(",")) + ".ServiceInfo"); if(info == null || !typeof(IServiceInfo).IsAssignableFrom(info)) throw new Exception(asm.FullName.Substring(0, asm.FullName.IndexOf(",")) + ".ServiceInfo가 존재하지 않거나 IServiceInfo를 상속받지 않습니다."); _info = (IServiceInfo)Activator.CreateInstance(info); _service = _info.GetService(); _manager = new ManagerProcessor(this, File.ReadAllLines(path + "/manager.ns")); }
public AddServiceWindow( ICKObservableReadOnlyCollection<IServiceInfo> availableServices, IServiceInfo selectedService = null ) { AvailableServices = availableServices; this.DataContext = this; if( selectedService != null ) { SelectedGeneralization = selectedService; } InitializeComponent(); this.NewServiceNameTextBox.Focus(); }
public AddPluginWindow( ICKObservableReadOnlyCollection<IServiceInfo> availableServices, IServiceInfo selectedService = null ) { _serviceReferences = new Dictionary<IServiceInfo, DependencyRequirement>(); AvailableServices = availableServices; if( selectedService != null && availableServices.Count > 0 ) { SelectedService = selectedService; } this.DataContext = this; InitializeComponent(); this.NewPluginNameTextBox.Focus(); }
/// <summary> /// Obtains the <see cref="IFactory"/> instance that can instantiate the /// service described by the <paramref name="serviceInfo"/> object instance. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo"/> object that describes the service to be created.</param> /// <returns>A <see cref="IFactory"/> instance if the service can be instantiated; otherwise, it will return <c>false</c>.</returns> public override IFactory GetFactory(IServiceInfo serviceInfo) { // Attempt to create the service type using // the strongly-typed arguments var factory = base.GetFactory(serviceInfo); var serviceType = serviceInfo.ServiceType; var serviceName = serviceInfo.ServiceName; // Use the default factory for this service type if no other factory exists var defaultServiceInfo = new ServiceInfo(serviceInfo.ServiceName, serviceInfo.ServiceType); if (factory == null && base.ContainsFactory(defaultServiceInfo)) factory = base.GetFactory(defaultServiceInfo); // Attempt to create the service type using // the generic factories, if possible if (factory != null || !serviceType.IsGenericType) return factory; var definitionType = serviceType.GetGenericTypeDefinition(); var genericServiceInfo = new ServiceInfo(serviceName, definitionType, serviceInfo.ArgumentTypes); if (base.ContainsFactory(genericServiceInfo)) return base.GetFactory(genericServiceInfo); if (definitionType != typeof(IFactory<>)) return factory; var typeArguments = serviceType.GetGenericArguments(); var actualServiceType = typeArguments[0]; var info = new ServiceInfo(serviceName, actualServiceType, serviceInfo.ArgumentTypes); if (base.ContainsFactory(info)) { var actualFactory = base.GetFactory(info); Func<IFactoryRequest, object> factoryMethod = request => actualFactory; factory = new FunctorFactory<IFactory>(factoryMethod); } return factory; }
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 ); } ); }
public VMIService( VMIContextViewModel ctx, IServiceInfo service, VMIBase parent ) : base(ctx, parent) { _service = service; Label = service.ServiceFullName; if( !service.HasError && service.Implementations.Count == 0 ) ErrorMessage = "No implementation"; else ErrorMessage = _service.ErrorMessage; OnError = ErrorMessage != null; if( service.IsDynamicService ) Assembly = service.AssemblyInfo.AssemblyName; DetailsTemplateName = "ServiceDetails"; _pluginRunner = VMIContext.Context.GetService<PluginRunner>( true ); _pluginRunner.ApplyDone += new EventHandler<ApplyDoneEventArgs>( OnApplyDone ); _allReferencingPlugins = new Dictionary<VMIPlugin, RunningRequirement>(); ImplementedBy = new VMCollection<VMAlias<VMIPlugin>, IPluginInfo>( _service.Implementations, ( info ) => { return new VMAlias<VMIPlugin>( VMIContext.FindOrCreate( info ), null ); } ); }
/// <summary> /// Obtains the <see cref="IFactory"/> instance that can instantiate the /// service described by the <paramref name="serviceInfo"/> object instance. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo"/> object that describes the service to be created.</param> /// <returns>A <see cref="IFactory"/> instance if the service can be instantiated; otherwise, it will return <c>false</c>.</returns> public override IFactory GetFactory(IServiceInfo serviceInfo) { // Attempt to create the service type using // the strongly-typed arguments IFactory factory = base.GetFactory(serviceInfo); Type serviceType = serviceInfo.ServiceType; string serviceName = serviceInfo.ServiceName; // Use the default factory for this service type if no other factory exists factory = GetDefaultFactory(serviceName, serviceType, factory); // Attempt to create the service type using // the generic factories, if possible if (factory != null || !serviceType.IsGenericType) return factory; Type definitionType = serviceType.GetGenericTypeDefinition(); var genericServiceInfo = new ServiceInfo(serviceName, definitionType, serviceInfo.ArgumentTypes); // Find the generic factory that can specifically handle the given argument types bool containsGenericFactory = base.ContainsFactory(genericServiceInfo); if (containsGenericFactory) return base.GetFactory(genericServiceInfo); // Use the default generic factory if we can't match the given arguments var defaultGenericServiceInfo = new ServiceInfo(serviceName, definitionType); if (base.ContainsFactory(defaultGenericServiceInfo)) return base.GetFactory(defaultGenericServiceInfo); if (definitionType != typeof (IFactory<>)) return factory; Type[] typeArguments = serviceType.GetGenericArguments(); Type actualServiceType = typeArguments[0]; factory = GetGenericFactory(serviceInfo, factory, serviceName, actualServiceType); return factory; }
/// <summary> /// Obtains the <see cref="IFactory"/> instance that can instantiate the /// service described by the <paramref name="serviceInfo"/> object instance. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo"/> object that describes the service to be created.</param> /// <returns>A <see cref="IFactory"/> instance if the service can be instantiated; otherwise, it will return <c>false</c>.</returns> public override IFactory GetFactory(IServiceInfo serviceInfo) { // Attempt to create the service type using // the strongly-typed arguments var factory = base.GetFactory(serviceInfo); var serviceType = serviceInfo.ServiceType; var serviceName = serviceInfo.ServiceName; // Use the default factory for this service type if no other factory exists var defaultServiceInfo = new ServiceInfo(serviceInfo.ServiceName, serviceInfo.ServiceType); if (factory == null && base.ContainsFactory(defaultServiceInfo)) factory = base.GetFactory(defaultServiceInfo); // Attempt to create the service type using // the generic factories, if possible if (factory == null && serviceType.IsGenericType) { var definitionType = serviceType.GetGenericTypeDefinition(); var genericServiceInfo = new ServiceInfo(serviceName, definitionType, serviceInfo.ArgumentTypes); factory = base.GetFactory(genericServiceInfo); } return factory; }
internal LiveServiceInfo( ServiceData s, YodiiEngine engine ) : base(engine, s, s.ServiceInfo.ServiceFullName) { _serviceInfo = s.ServiceInfo; }
/// <summary> /// Set an existing plugin's dependency to an existing service. /// </summary> /// <param name="plugin">Plugin</param> /// <param name="service">Service the plugin depends on</param> /// <param name="runningRequirement">How the plugin depends on the service</param> public void SetPluginDependency( IPluginInfo plugin, IServiceInfo service, DependencyRequirement runningRequirement ) { if( plugin == null ) throw new ArgumentNullException( "plugin" ); if( service == null ) throw new ArgumentNullException( "service" ); if( !ServiceInfos.Contains( (ServiceInfo)service ) ) throw new InvalidOperationException( "Service does not exist in this Lab" ); if( !PluginInfos.Contains( (PluginInfo)plugin ) ) throw new InvalidOperationException( "Plugin does not exist in this Lab" ); _labStateManager.SetPluginDependency( (PluginInfo)plugin, (ServiceInfo)service, runningRequirement ); }
/// <summary> /// Sets service as selected. /// </summary> /// <param name="serviceInfo">Service to select</param> public void SelectService( IServiceInfo serviceInfo ) { YodiiGraphVertex vertexToSelect = Graph.Vertices.Where( x => x.IsService && x.LabServiceInfo.ServiceInfo == serviceInfo ).First(); SelectedVertex = vertexToSelect; }
/// <summary> /// Removes and deletes a service. /// </summary> /// <param name="serviceInfo">Service to remove</param> public void RemoveService( IServiceInfo serviceInfo ) { _labStateManager.RemoveService( (ServiceInfo)serviceInfo ); }
/// <summary> /// Creates a new named service, which specializes another service. /// </summary> /// <param name="serviceName">Name of the new service</param> /// <param name="generalization">Specialized service</param> /// <returns>New service</returns> public IServiceInfo CreateNewService( string serviceName, IServiceInfo generalization = null ) { if( serviceName == null ) throw new ArgumentNullException( "serviceName" ); ServiceInfo newService = _labStateManager.CreateNewService( serviceName, (ServiceInfo)generalization ); return newService; }
/// <summary> /// Creates a new named plugin, which implements an existing service. /// </summary> /// <param name="pluginName">Name of the new plugin</param> /// <param name="service">Implemented service</param> /// <returns>New plugin</returns> public IPluginInfo CreateNewPlugin( string pluginName, IServiceInfo service ) { if( String.IsNullOrWhiteSpace( pluginName ) ) throw new ArgumentNullException( "pluginName" ); if( service != null && !ServiceInfos.Contains<IServiceInfo>( service ) ) throw new InvalidOperationException( "Service does not exist in this Lab" ); PluginInfo newPlugin = _labStateManager.CreateNewPlugin( pluginName, (ServiceInfo)service ); return newPlugin; }
private bool RaiseNewService( string name, IServiceInfo generalization = null ) { if( NewServiceCreated != null ) { NewServiceEventArgs args = new NewServiceEventArgs() { ServiceName = name, Generalization = generalization }; // Raise event NewServiceCreated( this, args ); if( args.CancelReason != null ) { MessageBox.Show( args.CancelReason, "Couldn't create service", MessageBoxButton.OK, MessageBoxImage.Stop, MessageBoxResult.OK ); return false; } } return true; }
public VMIService FindOrCreateDynamic( IServiceInfo item ) { VMIService s = null; if( !_dynamicServices.TryGetValue( item, out s ) && item.IsDynamicService ) { s = new VMIService( this, item, null ); _dynamicServices.Add( item, s ); } return s; }
public VMIService FindOrCreate( IServiceInfo item ) { VMIService s = null; if( !_allServices.TryGetValue( item, out s ) ) { s = new VMIService( this, item, null ); _allServices.Add( item, s ); } return s; }
/// <summary> /// Assert equivalence between two IServiceInfo, in the context of Yodii.Lab. /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void AssertServiceEquivalence( IServiceInfo a, IServiceInfo b, bool inspectPlugins = false ) { if( a == null && b == null ) return; Assert.That( a != null && b != null ); Assert.That( a.ServiceFullName == b.ServiceFullName ); AssertServiceEquivalence( a.Generalization, b.Generalization, inspectPlugins ); Assert.That( a.Implementations.Count == b.Implementations.Count ); if( inspectPlugins ) { foreach( var pluginB in b.Implementations ) { Assert.That( a.Implementations.Where( x => x.PluginFullName == pluginB.PluginFullName ).Count() == 1 ); var pluginA = a.Implementations.Where( x => x.PluginFullName == pluginB.PluginFullName ).First(); AssertPluginEquivalence( pluginA, pluginB, false ); } } }
public SolvedServiceSnapshot( ServiceData s ) : base(s) { _serviceInfo = s.ServiceInfo; }
private int WriteLabels(Excel.Worksheet sheet, int row, int tcol, int vcol, int qcol, IObjectInfo objectInfo, IServiceInfo serviceInfo, IHistoricalQuery query, bool localTime) { //write Item ID WriteLabel(sheet, row, vcol, objectInfo.FullName, "Item ID"); if (tcol == _startCol) WriteCommon(sheet, row, tcol, "Item ID"); //write Item Description row++; WriteLabel(sheet, row, vcol, objectInfo.Description, "Item Description"); if (tcol == _startCol) WriteCommon(sheet, row, tcol, "Item Description"); //write Engineering Unit row++; WriteLabel(sheet, row, vcol, "", "Engineering Unit"); if (tcol == _startCol) WriteCommon(sheet, row, tcol, "Engineering Unit"); string link = serviceInfo.Name; string[] s = link.Split('/'); //write Data Source row++; WriteLabel(sheet, row, vcol, s[s.Length - 1], "Data Source"); if (tcol == _startCol) WriteCommon(sheet, row, tcol, "Data Source"); //write Location row++; WriteLabel(sheet, row, vcol, s[s.Length - 2], "Location"); if (tcol == _startCol) WriteCommon(sheet, row, tcol, "Location"); //write aggregation ID row++; WriteLabel(sheet, row, vcol, query.Aggregate.Id.ToString(), "Aggregation ID"); if (tcol == _startCol) WriteCommon(sheet, row, tcol, "Aggregation ID"); //Write aggretation name row++; WriteLabel(sheet, row, vcol, query.Aggregate.Name, "Aggregation Name"); if (tcol == _startCol) WriteCommon(sheet, row, tcol, "Aggregation Name"); //Write start time row++; if (query.StartTime.IsRelativeTime) WriteTimeLabel(sheet, row, vcol, query.StartTime.RelativeTime, "Start Time"); else { DateTime starttime; if (localTime) starttime = query.StartTime.AbsoluteTime.ToLocalTime(); else starttime = query.StartTime.AbsoluteTime.ToUniversalTime(); WriteTimeLabel(sheet, row, vcol, starttime, "Start Time"); } if (tcol == _startCol) WriteCommon(sheet, row, tcol, "Start Time"); //Write end time row++; if (query.EndTime.IsRelativeTime) WriteTimeLabel(sheet, row, vcol, query.EndTime.RelativeTime, "End Time"); else { DateTime endtime; if (localTime) endtime = query.EndTime.AbsoluteTime.ToLocalTime(); else endtime = query.EndTime.AbsoluteTime.ToUniversalTime(); WriteTimeLabel(sheet, row, vcol, endtime, "End Time"); } if (tcol == _startCol) WriteCommon(sheet, row, tcol, "End Time"); //Write resample intervals row++; WriteLabel(sheet, row, vcol, query.Resample, "Resample interval(in seconds)"); if (tcol == _startCol) WriteCommon(sheet, row, tcol, "Resample interval(in seconds)"); //Write time zone row++; string timezone; if (localTime) timezone = "Local time"; else timezone = "UTC time"; WriteLabel(sheet, row, vcol, timezone, "Timestamps time zone"); if (tcol == _startCol) WriteCommon(sheet, row, tcol, "Timestamps time zone"); //Write space row++; return row; }
/// <summary> /// Gets the generic factory for a concrete service type. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo"/> object that describes the service to be created.</param> /// <param name="factory">The factory instance that will be used to create the service.</param> /// <param name="serviceName">The name of the service.</param> /// <param name="actualServiceType">The service type.</param> /// <returns>A factory instance that can create the generic type.</returns> private IFactory GetGenericFactory(IServiceInfo serviceInfo, IFactory factory, string serviceName, Type actualServiceType) { var info = new ServiceInfo(serviceName, actualServiceType, serviceInfo.ArgumentTypes); if (base.ContainsFactory(info)) { IFactory actualFactory = base.GetFactory(info); Func<IFactoryRequest, object> factoryMethod = request => actualFactory; factory = new FunctorFactory<IFactory>(factoryMethod); } return factory; }
/// <summary> /// Determines whether or not a factory exists in storage. /// </summary> /// <param name="serviceInfo">The <see cref="IServiceInfo"/> object that describes the target factory.</param> /// <returns>Returns <c>true</c> if the factory exists; otherwise, it will return <c>false</c>.</returns> public virtual bool ContainsFactory(IServiceInfo serviceInfo) { return _entries.ContainsKey(serviceInfo); }
private void ClearGeneralizationButton_Click( object sender, RoutedEventArgs e ) { SelectedGeneralization = null; }