public IComponentDescriptor RegisterDisabledComponent(IServiceDescriptor service, string componentId, Type componentType) { var component = RegisterComponent(service, componentId, componentType); component.Plugin.Disable("Disabled component."); return(component); }
public IComponentDescriptor RegisterComponent(IServiceDescriptor service, string componentId, Type componentType) { var plugin = RegisterPlugin(service.Plugin); var component = RegisterComponent(new ComponentRegistration(plugin, service, componentId, new TypeName(componentType))); return(component); }
public void InstallService(IServiceDescriptor serviceDescriptor) { PropertyDataCollection outParams; long returnValue; var inParamsCollection = new List<PropertyDataObject>(); inParamsCollection.Add(new PropertyDataObject() { Name = "Name", Value = serviceDescriptor.Name }); inParamsCollection.Add(new PropertyDataObject() { Name = "DisplayName", Value = serviceDescriptor.DisplayName }); inParamsCollection.Add(new PropertyDataObject() { Name = "PathName", Value = serviceDescriptor.Path }); inParamsCollection.Add(new PropertyDataObject() { Name = "ServiceType", Value = (ushort)serviceDescriptor.Type }); inParamsCollection.Add(new PropertyDataObject() { Name = "ErrorControl", Value = (ushort)serviceDescriptor.ErrorControl }); inParamsCollection.Add(new PropertyDataObject() { Name = "StartMode", Value = Enum.GetName(typeof(ServiceStartMode), serviceDescriptor.StartMode) }); inParamsCollection.Add(new PropertyDataObject() { Name = "DesktopInteract", Value = serviceDescriptor.DesktopInteraction }); inParamsCollection.Add(new PropertyDataObject() { Name = "StartName", Value = serviceDescriptor.UserAccount}); inParamsCollection.Add(new PropertyDataObject() { Name = "StartPassword", Value = serviceDescriptor.Password }); inParamsCollection.Add(new PropertyDataObject() { Name = "ServiceDependencies", Value = serviceDescriptor.ServiceDependencies.ToArray<string>() }); _handler.Handle("Create", inParamsCollection, out outParams); returnValue = long.Parse(outParams["ReturnValue"].Value.ToString()); if (returnValue != 0) { throw new ProcessInstrumentationException(@"{0} {1}.", ExceptionMessages.Win32_ServiceControlFail, _errorMessageProvider.GetErrorMessage(ErrorMessageProvider.ErrorClass.Win32_Service_Create, returnValue)); } }
/// <summary> /// Creates a component registration. /// </summary> /// <param name="plugin">The plugin to which the component will belong.</param> /// <param name="service">The service implemented by the component.</param> /// <param name="componentId">The component id.</param> /// <param name="componentTypeName">The component type name, or null to use the default component type specified by the service.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="plugin"/>, <paramref name="service"/>, /// <paramref name="componentId"/> is null.</exception> public ComponentRegistration(IPluginDescriptor plugin, IServiceDescriptor service, string componentId, TypeName componentTypeName) { Plugin = plugin; Service = service; ComponentId = componentId; ComponentTypeName = componentTypeName; }
/// <inheritdoc /> public IServiceDescriptor RegisterService(ServiceRegistration serviceRegistration) { if (serviceRegistration == null) { throw new ArgumentNullException("serviceRegistration"); } return(dataBox.Write(data => { if (data.GetPluginById(serviceRegistration.Plugin.PluginId) != serviceRegistration.Plugin) { throw new ArgumentException("The specified plugin descriptor does not belong to this registry.", "serviceRegistration"); } if (data.GetServiceById(serviceRegistration.ServiceId) != null) { throw new ArgumentException(string.Format("There is already a service registered with id '{0}'.", serviceRegistration.ServiceId), "serviceRegistration"); } IServiceDescriptor otherService = data.GetServiceByServiceTypeName(serviceRegistration.ServiceTypeName); if (otherService != null) { throw new ArgumentException(string.Format("There is already a service registered with type name '{0}'. This service has id '{1}' and the other service has id '{2}'.", serviceRegistration.ServiceTypeName, serviceRegistration.ServiceId, otherService.ServiceId), "serviceRegistration"); } ServiceDescriptor service = new ServiceDescriptor(this, serviceRegistration); data.RegisterService(service); return service; })); }
private static long CalculateHash(IServiceDescriptor descriptor) { return(((((long)descriptor.Lifecycle * 397) ^ descriptor.ServiceType.GetHashCode()) * 397) ^ (descriptor.ImplementationInstance ?? descriptor.ImplementationType ?? (object)descriptor.ImplementationFactory).GetHashCode()); }
private void RegisterComponent(string componentId, TypeName typeName, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor) { var componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, componentId, typeName); registry.RegisterComponent(componentRegistration); }
/// <summary> /// /// </summary> /// <param name="serviceName"></param> /// <returns></returns> public IServiceDescriptor GetServiceDescriptor(string serviceName) { Guard.NotNull(serviceName, "serviceName"); IServiceDescriptor desc = null; Metadatas.TryGetValue(serviceName, out desc); return(desc); }
//TODO: public void OnServiceDescriptorResolved(IServiceDescriptor serviceDescriptor) { var errorNavigation = serviceDescriptor.ServiceType.GetAttribute <RedirectToErrorAttribute>(true); if (errorNavigation != null) { serviceDescriptor.Extensions[ControllerListener.ErrorNavigation] = errorNavigation; } }
public static string GetEndpointUrl(IServiceDescriptor serviceDescriptor, string endpoint) { return(GetEndpointUrl( serviceDescriptor.Secured, serviceDescriptor.Server, serviceDescriptor.Port, serviceDescriptor.ServiceName, endpoint )); }
public static bool TryAdd([NotNull] this IServiceCollection collection, [NotNull] IServiceDescriptor descriptor) { if (!collection.Any(d => d.ServiceType == descriptor.ServiceType)) { collection.Add(descriptor); return(true); } return(false); }
/// <inheritdoc /> public bool HasService(Type serviceType) { if (serviceType == null) { throw new ArgumentNullException("serviceType"); } IServiceDescriptor descriptor = registry.Services.GetByServiceType(serviceType); return(descriptor != null && !descriptor.IsDisabled); }
private void VerifyServiceTraitsType(IServiceDescriptor service, ref bool success) { try { service.ResolveTraitsType(); } catch (Exception ex) { success = false; dispatchLogger.Log(LogSeverity.Error, "Unresolvable service traits type.", ex); } }
private void RegisterBuiltInComponent(IPluginDescriptor builtInPluginDescriptor, string serviceId, Type serviceType, object component) { IServiceDescriptor serviceDescriptor = registry.RegisterService( new ServiceRegistration(builtInPluginDescriptor, serviceId, new TypeName(serviceType))); registry.RegisterComponent( new ComponentRegistration(builtInPluginDescriptor, serviceDescriptor, serviceId, new TypeName(component.GetType())) { ComponentHandlerFactory = new InstanceHandlerFactory(component) }); }
private void RegisterEventHandlerProxy(Type interfaceType, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor, string componentId) { var proxyType = typeof(EventHandlerProxy <>).MakeGenericType(interfaceType.GetGenericArguments()); var typeName = new TypeName(proxyType).ConvertToPartialAssemblyName(); var componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, Guid.NewGuid().ToString(), typeName); componentRegistration.ComponentProperties.Add("target", string.Format("${{{0}}}", componentId)); registry.RegisterComponent(componentRegistration); }
public IServiceDescriptor[] GetServiceDescriptors <T>() { var serviceType = typeof(T); IServiceDescriptor[] descriptors; if (!TypeMap.TryGetValue(serviceType, out descriptors)) { descriptors = new IServiceDescriptor[0]; } return(descriptors); }
private static ConstructorInfo GetConstructorInfo(IServiceDescriptor serviceDescriptor) { var ctor = serviceDescriptor.ImplementationType.GetConstructors().FirstOrDefault() ?? serviceDescriptor.ImplementationType.GetConstructor(Type.EmptyTypes); if (ctor == null) { throw new ArgumentException( $"No constructor was found for type {serviceDescriptor.ImplementationType}"); } return(ctor); }
/// <summary> /// Discovers all of the available installer types for a given service. /// </summary> /// <param name="service">The service.</param> /// <returns> /// An array of zero-or-more non-abstract installer types. /// </returns> public static Type[] DiscoverInstallerTypes(IServiceDescriptor service) { if (s_ServiceInstallerTypes == null) { s_ServiceInstallerTypes = TypeMeta.DiscoverImplementations <ZenjectServiceInstaller>(); } var genericInstallerType = typeof(ZenjectServiceInstaller <>).MakeGenericType(service.ServiceType); return(s_ServiceInstallerTypes .Where(installerType => genericInstallerType.IsAssignableFrom(installerType)) .Where(installerType => !installerType.IsAbstract && installerType.IsClass) .ToArray()); }
private ServiceEntry CreateServiceEntry(IServiceDescriptor service) { var entry = new ServiceEntry(); entry.Title = service.Title; entry.Descriptor = service; entry.AvailableInstallerTypes = ZenjectServiceInstaller.DiscoverInstallerTypes(service); entry.InheritedInstallers = this.targetConfigurationObject.InheritedInstallers .Where(x => x.TargetService == service) .ToArray(); this.targetInstallerComponents.TryGetValue(service, out entry.Installer); entry.InstallerActive = entry.Installer != null && this.targetActiveInstallers.Contains(entry.Installer); entry.ClosestInheritedInstaller = this.targetConfigurationObject.FindClosestInheritedInstallerForService(service); entry.TargetInstaller = (entry.ClosestInheritedInstaller != null && !entry.InstallerActive) ? entry.ClosestInheritedInstaller : entry.Installer; if (entry.TargetInstaller != null) { entry.TargetInstallerTitle = NicifyNamespaceQualifiedInstallerTitle(entry.TargetInstaller.GetType()); } entry.DominantInstaller = this.targetConfigurationObject.FindDominantInstallerForService(service); if (entry.TargetInstaller != null) { string targetInstallerHint = NicifyInstallerTitle(entry.TargetInstaller.GetType()); if (targetInstallerHint.StartsWith(entry.Title)) { targetInstallerHint = targetInstallerHint.Substring(entry.Title.Length).TrimStart(' ', '-'); } if (!string.IsNullOrEmpty(targetInstallerHint)) { if (EditorGUIUtility.isProSkin) { entry.Title += " <color=white>(" + targetInstallerHint + ")</color>"; } else { entry.Title += " <color=grey>(" + targetInstallerHint + ")</color>"; } } } return(entry); }
private void RegisterComponent(Type interfaceType, string componentId, TypeName typeName, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor) { ComponentRegistration componentRegistration; if (IsAnEventHandler(interfaceType)) { componentRegistration = RegisterEventHandlerProxy(interfaceType, plugin, serviceDescriptor, componentId); } else { componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, componentId, typeName); } registry.RegisterComponent(componentRegistration); }
public void TryAddWithEnumerableReturnsTrueIfAnyAdded() { // Arrange var collection = new ServiceCollection(); // Act var ds = new IServiceDescriptor[] { new ServiceDescriber().Transient <IFakeService, FakeService>(), new ServiceDescriber().Transient <IFakeService, FakeService>() }; // Assert Assert.True(collection.TryAdd(ds)); var descriptor = Assert.Single(collection); Assert.Equal(typeof(IFakeService), descriptor.ServiceType); Assert.Null(descriptor.ImplementationInstance); Assert.Equal(LifecycleKind.Transient, descriptor.Lifecycle); }
internal OperationDescriptor(MethodInfo method, string operationName, IServiceDescriptor serviceDescriptor) { Extensions = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase); Method = method; ParameterNames = method.GetParameters().Select(p => p.Name).ToArray(); OperationName = operationName; ServiceDescriptor = serviceDescriptor; Executor = method.GetFunc(); NameSelector = method.GetAttribute <OperationNameSelectorAttribute>(true); MethodSelector = method.GetAttribute <OperationSelectorAttribute>(true); Filters = method.GetAttributes <OperationFilterAttribute>(true).Distinct().ToArray(); Bindings = method.GetParameters().Select(p => new BindingInfo(p)).ToArray(); var descAttr = Method.GetAttribute <DescriptionAttribute>(true); if (descAttr != null) { Description = descAttr.Description; } }
public static void Register(this IUnityContainer container, IServiceDescriptor serviceDescriptor) { LifetimeManager lifetimeManager = null; switch (serviceDescriptor.Lifecycle) { case LifecycleKind.Singleton: lifetimeManager = new ContainerControlledLifetimeManager(); break; case LifecycleKind.Scoped: lifetimeManager = new HierarchicalLifetimeManager(); break; case LifecycleKind.Transient: lifetimeManager = new TransientLifetimeManager(); break; } if (serviceDescriptor.ImplementationInstance != null) container.RegisterInstance(serviceDescriptor.ServiceType, serviceDescriptor.ImplementationInstance); else container.RegisterType(serviceDescriptor.ServiceType, serviceDescriptor.ImplementationType, lifetimeManager); }
private void BuildDependencyTree(IServiceDescriptor serviceDescriptor, Node <IServiceDescriptor> rootNode) { var ctor = GetConstructorInfo(serviceDescriptor); foreach (var param in ctor.GetParameters()) { var type = param.ParameterType; if (type.IsSupportedCtorParam()) { var node = new Node <IServiceDescriptor> { ParentNode = rootNode, Data = _typeRegistrations.Get(type) }; rootNode.ChildNodes.Add(node); BuildDependencyTree(_typeRegistrations.Get(type), node); } } }
protected virtual void RegisterToPeerContext(Channel channel, long priority, IServiceDescriptor serviceDescriptor) { if (channel == null) { ThrowHelper.ThrowArgumentNullException("channel"); } Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContextLock.Lock(); try { NetworkPeerDataContext context = Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContext; if (context == null) { context = new NetworkPeerDataContext(); } PropertyItem root = new PropertyItem(Id, string.Format("{0};{1}", channel.ServerEndpoints.ToList <AddressEndPoint>()[0].Port.ToString(), priority.ToString())); if (serviceDescriptor != null) { Dictionary <string, PropertyItem> items = serviceDescriptor.CreateServiceProperty(); if (items != null) { foreach (KeyValuePair <string, PropertyItem> kv in items) { root.PropertyItems.Add(kv.Key, kv.Value); } } } context.PropertyItems[Id] = root; Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContext = context; } finally { Forge.Net.TerraGraf.NetworkManager.Instance.Localhost.PeerContextLock.Unlock(); } }
public ServiceResolvedContext(IServiceDescriptor serviceDescriptor, IServiceRequest req, IServiceResponse resp) { ServiceDescriptor = serviceDescriptor; Request = req; Response = resp; }
public virtual ManagerStateEnum Start(long priority, IServiceDescriptor serviceDescriptor) { if (this.ManagerState != ManagerStateEnum.Started) { if (priority < 0) { ThrowHelper.ThrowArgumentOutOfRangeException("priority"); } if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, initializing service...", LOG_PREFIX)); } OnStart(ManagerEventStateEnum.Before); try { ChannelServices.Initialize(); this.ChannelId = ConfigurationAccessHelper.GetValueByPath(NetworkServiceConfiguration.Settings.CategoryPropertyItems, string.Format("Services/{0}", Id)); if (string.IsNullOrEmpty(this.ChannelId)) { this.ChannelId = Id; } Channel channel = LookUpChannel(); if (channel.ServerEndpoints.Count == 0) { throw new InvalidConfigurationException(string.Format("Channel '{0}' has not got listening server endpoint(s).", channel.ChannelId)); } ServiceBaseServices.Initialize(); if (!ServiceBaseServices.IsContractRegistered(typeof(TIServiceProxyType))) { ServiceBaseServices.RegisterContract(typeof(TIServiceProxyType), typeof(TServiceProxyImplementationType)); } this.mPriority = priority; this.mServiceDescriptor = serviceDescriptor; RegisterToPeerContext(channel, priority, serviceDescriptor); this.ManagerState = ManagerStateEnum.Started; if (LOGGER.IsInfoEnabled) { LOGGER.Info(string.Format("{0}, service successfully initialized.", LOG_PREFIX)); } } catch (Exception) { this.ManagerState = ManagerStateEnum.Fault; throw; } OnStart(ManagerEventStateEnum.After); } return(this.ManagerState); }
public GenericService(IServiceDescriptor descriptor) { _descriptor = descriptor; }
public InstanceService(IServiceDescriptor descriptor) { _descriptor = descriptor; }
private static long CalculateHash(IServiceDescriptor descriptor) { return ((((long)descriptor.Lifecycle * 397) ^ descriptor.ServiceType.GetHashCode()) * 397) ^ (descriptor.ImplementationInstance ?? descriptor.ImplementationType).GetHashCode(); }
public IServiceCollection Add(IServiceDescriptor descriptor) { _descriptors.Add(descriptor); return this; }
public CreateInstanceCallSite(IServiceDescriptor descriptor) { _descriptor = descriptor; }
public IComponentDescriptor RegisterDisabledComponent(IServiceDescriptor service, string componentId, Type componentType) { var component = RegisterComponent(service, componentId, componentType); component.Plugin.Disable("Disabled component."); return component; }
public IComponentDescriptor RegisterComponent(IServiceDescriptor service, string componentId, Type componentType) { var plugin = RegisterPlugin(service.Plugin); var component = RegisterComponent(new ComponentRegistration(plugin, service, componentId, new TypeName(componentType))); return component; }
public ServiceDetailsTreeModel(IServiceDescriptor serviceDescriptor) { this.serviceDescriptor = serviceDescriptor; }
private void VerifyServiceType(IServiceDescriptor service, ref bool success) { try { service.ResolveServiceType(); } catch (Exception ex) { success = false; dispatchLogger.Log(LogSeverity.Error, "Unresolvable service type.", ex); } }
private static ComponentRegistration RegisterEventHandlerProxy(Type interfaceType, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor, string componentId) { var proxyType = typeof(EventHandlerProxy<>).MakeGenericType(interfaceType.GetGenericArguments()); var typeName = new TypeName(proxyType).ConvertToPartialAssemblyName(); var componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, Guid.NewGuid().ToString(), typeName); componentRegistration.ComponentProperties.Add("target", string.Format("${{{0}}}", componentId)); return componentRegistration; }
internal OperationDescriptor(MethodInfo method, string operationName, IServiceDescriptor serviceDescriptor) { Extensions = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase); Method = method; ParameterNames = method.GetParameters().Select(p => p.Name).ToArray(); OperationName = operationName; ServiceDescriptor = serviceDescriptor; Executor = method.GetFunc(); NameSelector = method.GetAttribute<OperationNameSelectorAttribute>(true); MethodSelector = method.GetAttribute<OperationSelectorAttribute>(true); Filters = method.GetAttributes<OperationFilterAttribute>(true).Distinct().ToArray(); Bindings = method.GetParameters().Select(p => new BindingInfo( p)).ToArray(); var descAttr = Method.GetAttribute<DescriptionAttribute>(true); if (descAttr != null) Description = descAttr.Description; }
/// <inheritdoc /> public IServiceCollection Add([NotNull] IServiceDescriptor descriptor) { _descriptors.Add(descriptor); return(this); }
public Service(IServiceDescriptor descriptor) { _descriptor = descriptor; }
//TODO: public void OnServiceDescriptorResolved(IServiceDescriptor serviceDescriptor) { var errorNavigation = serviceDescriptor.ServiceType.GetAttribute<RedirectToErrorAttribute>(true); if (errorNavigation != null) serviceDescriptor.Extensions[ControllerListener.ErrorNavigation] = errorNavigation; }
public FactoryService(IServiceDescriptor descriptor) { _descriptor = descriptor; }