public SampleDesignerHost(IServiceProvider parentProvider) { this.serviceContainer = new ServiceContainer(parentProvider); this.designerTable = new Hashtable(); this.sites = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default); this.loadingDesigner = false; this.transactionCount = 0; this.reloading = false; this.serviceContainer.AddService(typeof(IDesignerHost), this); this.serviceContainer.AddService(typeof(IContainer), this); this.serviceContainer.AddService(typeof(IComponentChangeService), this); this.serviceContainer.AddService(typeof(IExtenderProviderService), this); this.serviceContainer.AddService(typeof(IDesignerEventService), this); CodeDomComponentSerializationService codeDomComponentSerializationService = new CodeDomComponentSerializationService(this.serviceContainer); if (codeDomComponentSerializationService != null) { this.serviceContainer.RemoveService(typeof(ComponentSerializationService), false); this.serviceContainer.AddService(typeof(ComponentSerializationService), codeDomComponentSerializationService); } ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService); this.serviceContainer.AddService(typeof(IToolboxService), callback); this.serviceContainer.AddService(typeof(ISelectionService), callback); this.serviceContainer.AddService(typeof(ITypeDescriptorFilterService), callback); this.serviceContainer.AddService(typeof(IMenuCommandService), callback); this.serviceContainer.AddService(typeof(IDesignerSerializationService), callback); ((IExtenderProviderService) this).AddExtenderProvider(new SampleNameExtenderProvider(this)); ((IExtenderProviderService) this).AddExtenderProvider(new SampleInheritedNameExtenderProvider(this)); }
/// <summary> /// Adds the specified service to the service container. /// </summary> /// <param name="serviceType">The type of service to add.</param> /// <param name="callback">A callback object that is used to create the service. This allows a service to be declared as available, but delays the creation of the object until the service is requested.</param> public void AddService(Type serviceType, ServiceCreatorCallback callback) { Guard.NotNull(() => serviceType, serviceType); Guard.NotNull(() => callback, callback); this.services.Add(serviceType, callback); }
internal CommonPackage() { IServiceContainer container = this as IServiceContainer; ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateService); //container.AddService(GetLanguageServiceType(), callback, true); container.AddService(GetLibraryManagerType(), callback, true); }
public void AddService (Type serviceType, ServiceCreatorCallback callback, bool promote) { // Validate the parameters. if(serviceType == null) { throw new ArgumentNullException("serviceType"); } if(callback == null) { throw new ArgumentNullException("callback"); } // Promote the service to the parent if necessary. if(promote && parentProvider != null) { IServiceContainer parent; parent = (IServiceContainer)(parentProvider.GetService (typeof(IServiceContainer))); if(parent != null) { parent.AddService(serviceType, callback, promote); return; } } // Add the service to this container. table[serviceType] = callback; }
/// <summary> /// Default constructor of the package. /// The package is not yet sited inside Visual Studio, so this is the place /// for any setup that doesn't need the VS environment. /// Here we register our service, so that it will be available to any other /// packages by the time their Initialize is called. /// </summary> public PlotterServicePackage() { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString())); var serviceContainer = this as IServiceContainer; var serviceCreator = new ServiceCreatorCallback(CreatePlotterService); serviceContainer.AddService(typeof(SPlotter2DService), serviceCreator, true); }
/// <summary> /// Default constructor of the package. /// Inside this method you can place any initialization code that does not require /// any Visual Studio service because at this point the package object is created but /// not sited yet inside Visual Studio environment. The place to do all the other /// initialization is the Initialize method. /// </summary> public VsExtAutoShelvePackage() { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this)); IServiceContainer serviceContainer = this as IServiceContainer; ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateService); serviceContainer.AddService(typeof(SAutoShelveService), callback, true); //serviceContainer.AddService(typeof(SMyLocalService), callback); }
public void AddService(Type serviceType, ServiceCreatorCallback callback, bool shouldDisposeServiceInstance) { // Create the description of this service. Note that we don't do any validation // of the parameter here because the constructor of ServiceData will do it for us. ServiceData service = new ServiceData(serviceType, null, callback, shouldDisposeServiceInstance); // Now add the service desctription to the dictionary. AddService(service); }
/// <summary> /// Default constructor of the package. /// Inside this method you can place any initialization code that does not require /// any Visual Studio service, because at this point the package object is created but /// not sited yet inside the Visual Studio environment. The place to do all the other /// initialization is the Initialize method. /// </summary> public PythonConsolePackage() { // This package has to proffer the IronPython engine provider as a Visual Studio // service. Note that for performance reasons we don't actually create any object here, // but instead we register a callback function that will create the object the first // time this package will receive a request for the service. IServiceContainer container = this as IServiceContainer; ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateService); container.AddService(typeof(IPythonEngineProvider), callback, true); }
void IPackage.Initialize(IServiceProvider serviceProvider) { this._serviceProvider = serviceProvider; IServiceContainer service = (IServiceContainer) this._serviceProvider.GetService(typeof(IServiceContainer)); if (service != null) { ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService); service.AddService(typeof(IClassViewService), callback); } }
/// <summary> /// Default constructor of the package. /// Inside this method you can place any initialization code that does not require /// any Visual Studio service, because at this point the package object is created but /// not sited yet inside the Visual Studio environment. The place to do all the other /// initialization is the Initialize method. /// </summary> public PythonConsolePackage() { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString())); // This package has to proffer the IronPython engine provider as a Visual Studio // service. Note that for performance reasons we don't actually create any object here, // but instead we register a callback function that will create the object the first // time this package will receive a request for the service. IServiceContainer container = this as IServiceContainer; ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateService); container.AddService(typeof(IPythonEngineProvider), callback, true); }
public void Dispose() { if ((shouldDispose) && (null != instance)) { IDisposable disp = instance as IDisposable; if (null != disp) { disp.Dispose(); } instance = null; } creator = null; GC.SuppressFinalize(this); }
public ServiceData(Type serviceType, object instance, ServiceCreatorCallback callback, bool shouldDispose) { Utilities.ArgumentNotNull("serviceType", serviceType); if ((null == instance) && (null == callback)) { throw new ArgumentNullException("instance"); } this.serviceType = serviceType; this.instance = instance; this.creator = callback; this.shouldDispose = shouldDispose; }
public void Dispose() { if ((shouldDispose) && (null != instance)) { IDisposable disp = instance as IDisposable; if (null != disp) { disp.Dispose(); } instance = null; } creator = null; }
public DesignSurface(IServiceProvider parentProvider) { this._parentProvider = parentProvider; this._serviceContainer = new DesignSurfaceServiceContainer(this._parentProvider); ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService); this.ServiceContainer.AddService(typeof(ISelectionService), callback); this.ServiceContainer.AddService(typeof(IExtenderProviderService), callback); this.ServiceContainer.AddService(typeof(IExtenderListService), callback); this.ServiceContainer.AddService(typeof(ITypeDescriptorFilterService), callback); this.ServiceContainer.AddService(typeof(IReferenceService), callback); this.ServiceContainer.AddService(typeof(DesignSurface), this); this._host = new DesignerHost(this); }
/// <summary> /// Adds the specified service to the service container. /// </summary> /// <param name="serviceType">The type of service to add.</param> /// <param name="callback">A callback object that is used to create the service. This allows a service to be declared as available, but delays the creation of the object until the service is requested.</param> public void AddService(Type serviceType, ServiceCreatorCallback callback) { if (serviceType == null) throw new ArgumentNullException("serviceType"); if (callback == null) throw new ArgumentNullException("callback"); if (_services.Contains(serviceType)) throw new ArgumentException("Service already exists.", "serviceType"); _services[serviceType] = callback; }
/// <summary> /// Default constructor of the package. /// Inside this method you can place any initialization code that does not require /// any Visual Studio service because at this point the package object is created but /// not sited yet inside Visual Studio environment. The place to do all the other /// initialization is the Initialize method. /// </summary> public SharpOnlyPkgPackage() { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString())); // Init service... IServiceContainer serviceContainer = this as IServiceContainer; ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateService); serviceContainer.AddService(typeof(MSBuildTaskService), callback, true); serviceContainer.AddService(typeof(SharpBuildService), callback, true); serviceContainer.AddService(typeof(SharpBuildDeployService), callback, true); }
private static void InitializeServices(IServiceProvider serviceProvider) { IServiceContainer container = (IServiceContainer)serviceProvider; ServiceCreatorCallback callback = new ServiceCreatorCallback(OnCreateService); if (GetService <ICodeGenerationService>(serviceProvider) == null) { container.AddService(typeof(ICodeGenerationService), callback, true); } if (GetService <IExtensionProviderService>(serviceProvider) == null) { container.AddService(typeof(IExtensionProviderService), callback, true); } }
public void AddServiceCreatorCallback() { ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateCalculatorService); container.AddService(typeof(ICalcService), callback); ICalcService service = (ICalcService)container.GetService(typeof(ICalcService)); Assert.IsNotNull(service); Assert.AreSame(service, container.Container[typeof(ICalcService)]); service = (ICalcService)container.GetService(typeof(ICalcService)); Assert.AreEqual(1, calledCount); }
public static IEnumerable <object[]> AddService_TypeServiceCreatorCallbackBool_TestData() { var nullServiceProvider = new MockServiceProvider(); nullServiceProvider.Setup(typeof(IServiceContainer), null); nullServiceProvider.Setup(typeof(object), null); nullServiceProvider.Setup(typeof(int), null); var invalidServiceProvider = new MockServiceProvider(); invalidServiceProvider.Setup(typeof(IServiceContainer), new object()); invalidServiceProvider.Setup(typeof(object), null); invalidServiceProvider.Setup(typeof(int), null); var validServiceProvider = new MockServiceProvider(); validServiceProvider.Setup(typeof(IServiceContainer), new ServiceContainer()); validServiceProvider.Setup(typeof(object), null); validServiceProvider.Setup(typeof(int), null); var o = new object(); ServiceCreatorCallback callback = (container, serviceType) => "abc"; ServiceCreatorCallback nullCallback = (container, serviceType) => null; foreach (bool promote in new bool[] { true, false }) { foreach (IServiceProvider parentProvider in new object[] { null, nullServiceProvider, invalidServiceProvider, validServiceProvider }) { if (promote && parentProvider == validServiceProvider) { continue; } yield return(new object[] { parentProvider, typeof(object), callback, promote, "abc" }); yield return(new object[] { parentProvider, typeof(string), callback, promote, "abc" }); yield return(new object[] { parentProvider, typeof(int), callback, promote, null }); yield return(new object[] { parentProvider, typeof(object), nullCallback, promote, null }); yield return(new object[] { parentProvider, typeof(int), nullCallback, promote, null }); } var customServiceProvider = new MockServiceProvider(); customServiceProvider.Setup(typeof(IServiceContainer), null); customServiceProvider.Setup(typeof(int), o); yield return(new object[] { customServiceProvider, typeof(int), callback, promote, o }); } }
// -------------------------------------------------------------------------------------------- /// <summary> /// Disposes the service instance /// </summary> // -------------------------------------------------------------------------------------------- public void Dispose() { if ((_ShouldDispose) && (null != _Instance)) { var disp = _Instance as IDisposable; if (null != disp) { disp.Dispose(); } _Instance = null; } _Creator = null; GC.SuppressFinalize(this); }
public void AddService_PromoteCallbackWithNoParentProvider_AddsToCurrent() { var serviceInstance = new object(); var container = new ServiceContainer(); ServiceCreatorCallback callback = (c, serviceType) => { Assert.Same(container, c); Assert.Equal(typeof(object), serviceType); return(serviceInstance); }; container.AddService(typeof(object), callback, promote: true); Assert.Same(serviceInstance, container.GetService(typeof(object))); }
public void AddService_AlreadyAddedServiceInstance_ThrowsArgumentException() { var container = new ServiceContainer(); var serviceInstance = new object(); ServiceCreatorCallback callback = (container, serviceType) => "abc"; container.AddService(typeof(object), serviceInstance); Assert.Throws <ArgumentException>("serviceType", () => container.AddService(typeof(object), new object())); Assert.Throws <ArgumentException>("serviceType", () => container.AddService(typeof(object), new object(), true)); Assert.Throws <ArgumentException>("serviceType", () => container.AddService(typeof(object), new object(), false)); Assert.Throws <ArgumentException>("serviceType", () => container.AddService(typeof(object), callback)); Assert.Throws <ArgumentException>("serviceType", () => container.AddService(typeof(object), callback, true)); Assert.Throws <ArgumentException>("serviceType", () => container.AddService(typeof(object), callback, false)); }
public void SampleMethod() { ServiceContainer serviceContainer = new ServiceContainer(); // <Snippet1> // The following code shows how to publish a service using a callback function. // Creates a service creator callback. ServiceCreatorCallback callback1 = new ServiceCreatorCallback(myCallBackMethod); // Adds the service using its type and the service creator callback. serviceContainer.AddService(typeof(myService), callback1); // </Snippet1> }
public void AddService(string serviceName, ServiceCreatorCallback creatorCallback, bool promote) { Require.NotNullOrEmptyString("serviceName", serviceName); // $NON-NLS-1 if (this.servicesByName.ContainsKey(serviceName)) throw RuntimeFailure.ServiceAlreadyExists("serviceName", serviceName); this.servicesByName.Add(serviceName, creatorCallback); if (promote) { IServiceContainerExtension ice = this.ParentContainer as IServiceContainerExtension; if (ice != null) ice.AddService(serviceName, creatorCallback, true); } }
/// <summary> /// Default constructor of the package. /// Inside this method you can place any initialization code that does not require /// any Visual Studio service because at this point the package object is created but /// not sited yet inside Visual Studio environment. The place to do all the other /// initialization is the Initialize method. /// </summary> public RemarkerPackage() { try { var container = (IServiceContainer)this; var callback = new ServiceCreatorCallback(this.CreateService); container.AddService(typeof(IRemarkerService), callback, true); } // ReSharper disable once RedundantCatchClause // ReSharper disable once UnusedVariable catch (Exception) { throw; } }
[Test] // AddService (Type, ServiceCreatorCallback) public void AddService2_Callback_Null() { ServiceContainer sc = new ServiceContainer(); ServiceCreatorCallback callback = null; try { sc.AddService(typeof(IList), callback); Assert.Fail("#1"); } catch (ArgumentNullException ex) { Assert.AreEqual(typeof(ArgumentNullException), ex.GetType(), "#2"); Assert.IsNull(ex.InnerException, "#3"); Assert.IsNotNull(ex.Message, "#4"); Assert.AreEqual("callback", ex.ParamName, "#5"); } }
protected override void Initialize() { base.Initialize(); Reporter = Reporter ?? new ReAttachTraceReporter(); History = History ?? new ReAttachHistory(new ReAttachRegistryRepository(this)); Ui = Ui ?? new ReAttachUi(this); Debugger = Debugger ?? new ReAttachDebugger(this); History.Load(); Ui.Update(); var callback = new ServiceCreatorCallback(CreateBusService); ((IServiceContainer)this).AddService(typeof(IReAttachBusService), callback); }
public static IEnumerable <object[]> AddService_TypeServiceCreatorCallback_TestData() { var nullServiceProvider = new MockServiceProvider(); nullServiceProvider.Setup(typeof(IServiceContainer), null); nullServiceProvider.Setup(typeof(object), null); nullServiceProvider.Setup(typeof(int), null); var invalidServiceProvider = new MockServiceProvider(); invalidServiceProvider.Setup(typeof(IServiceContainer), new object()); invalidServiceProvider.Setup(typeof(object), null); invalidServiceProvider.Setup(typeof(int), null); var validServiceProvider = new MockServiceProvider(); validServiceProvider.Setup(typeof(IServiceContainer), new ServiceContainer()); validServiceProvider.Setup(typeof(object), null); validServiceProvider.Setup(typeof(int), null); var o = new object(); ServiceCreatorCallback callback = (container, serviceType) => "abc"; ServiceCreatorCallback nullCallback = (container, serviceType) => null; foreach (IServiceProvider parentProvider in new object[] { null, nullServiceProvider, invalidServiceProvider, validServiceProvider }) { // .NET Core fixes an InvalidCastException bug. if (PlatformDetection.IsFullFramework && parentProvider == invalidServiceProvider) { continue; } yield return(new object[] { parentProvider, typeof(object), callback, "abc" }); yield return(new object[] { parentProvider, typeof(string), callback, "abc" }); yield return(new object[] { parentProvider, typeof(int), callback, null }); yield return(new object[] { parentProvider, typeof(object), nullCallback, null }); yield return(new object[] { parentProvider, typeof(int), nullCallback, null }); } var customServiceProvider = new MockServiceProvider(); customServiceProvider.Setup(typeof(int), o); yield return(new object[] { customServiceProvider, typeof(int), callback, o }); }
/// <summary> /// Gets the requested service instance. /// </summary> /// <typeparam name="T">The type of the service to return</typeparam> /// <returns>The service implementation.</returns> public T Get <T>() { Type t = typeof(T); object o = null; if (services.TryGetValue(t, out o)) { ServiceCreatorCallback <T> s = o as ServiceCreatorCallback <T>; if (s != null) { return(s(this)); } return((T)services[t]); } return(default(T)); }
protected override void Initialize() { // Long running synchronous method call that blocks the UI thread Thread.Sleep(5000); // Adds a service synchronosly on the UI thread var callback = new ServiceCreatorCallback(CreateMyService); ((IServiceContainer)this).AddService(typeof(MyService), callback); // Synchronously requesting a service on the UI thread var dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; // Initializes the command synchronously on the UI thread MyCommand.Initialize(this, dte); }
/// <summary> /// Standard constructor for the package. /// </summary> public ServicesPackage() { // Here we update the list of the provided services with the ones specific for this package. // Notice that we set to true the boolean flag about the service promotion for the global: // to promote the service is actually to proffer it globally using the SProfferService service. // For performance reasons we don’t want to instantiate the services now, but only when and // if some client asks for them, so we here define only the type of the service and a function // that will be called the first time the package will receive a request for the service. // This callback function is the one responsible for creating the instance of the service // object. IServiceContainer serviceContainer = this as IServiceContainer; ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateService); serviceContainer.AddService(typeof(SMyGlobalService), callback, true); serviceContainer.AddService(typeof(SMyLocalService), callback); }
/// <summary> /// Creates a new DesignSurface given a parent service provider. /// </summary> /// <param name="parentProvider"> The parent service provider. If there is no parent used to resolve services this can be null. </param> public DesignSurface(IServiceProvider parentProvider) { _parentProvider = parentProvider; _serviceContainer = new DesignSurfaceServiceContainer(_parentProvider); // Configure our default services ServiceCreatorCallback callback = new ServiceCreatorCallback(OnCreateService); ServiceContainer.AddService(typeof(ISelectionService), callback); ServiceContainer.AddService(typeof(IExtenderProviderService), callback); ServiceContainer.AddService(typeof(IExtenderListService), callback); ServiceContainer.AddService(typeof(ITypeDescriptorFilterService), callback); ServiceContainer.AddService(typeof(IReferenceService), callback); ServiceContainer.AddService(typeof(DesignSurface), this); _host = new DesignerHost(this); }
// -------------------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ServiceData"/> class. /// </summary> /// <param name="serviceType">Type of the service.</param> /// <param name="instance">The instance.</param> /// <param name="callback">The callback.</param> /// <param name="shouldDispose"> /// If set to <c>true</c> the service instance should be disposed. /// </param> // -------------------------------------------------------------------------------------------- public ServiceData(Type serviceType, object instance, ServiceCreatorCallback callback, bool shouldDispose) { if (null == serviceType) { throw new ArgumentNullException("serviceType"); } if ((null == instance) && (null == callback)) { throw new ArgumentNullException("instance"); } _ServiceType = serviceType; _Instance = instance; _Creator = callback; _ShouldDispose = shouldDispose; }
public void AddService1() { object service; ServiceContainer parent; ServiceContainer sc; object serviceInstance1 = new ArrayList(); object serviceInstance2 = new Hashtable(); object callback1 = new ServiceCreatorCallback( Svc.ServiceCreator); sc = new ServiceContainer(); sc.AddService(typeof(ICollection), serviceInstance1); sc.AddService(typeof(IEnumerable), serviceInstance2); sc.AddService(typeof(Svc), callback1); service = sc.GetService(typeof(ICollection)); Assert.IsNotNull(service, "#A1"); Assert.AreSame(serviceInstance1, service, "#A2"); service = sc.GetService(typeof(IEnumerable)); Assert.IsNotNull(service, "#B1"); Assert.AreSame(serviceInstance2, service, "#B2"); service = sc.GetService(typeof(ArrayList)); Assert.IsNull(service, "#C1"); service = sc.GetService(typeof(ICloneable)); Assert.IsNull(service, "#D1"); Assert.AreEqual(0, Svc.TotalObjectsCreatedByCallback, "#E1"); service = sc.GetService(typeof(Svc)); Assert.IsNotNull(service, "#E2"); Assert.IsTrue(service is Svc, "#E3"); Assert.AreEqual(1, Svc.TotalObjectsCreatedByCallback, "#E4"); Assert.AreSame(service, sc.GetService(typeof(Svc)), "#E5"); Assert.AreEqual(1, Svc.TotalObjectsCreatedByCallback, "#E6"); parent = new ServiceContainer(); sc = new ServiceContainer(parent); sc.AddService(typeof(ICollection), serviceInstance1); Assert.AreSame(serviceInstance1, sc.GetService(typeof(ICollection)), "#F1"); Assert.IsNull(parent.GetService(typeof(ICollection)), "#F2"); }
/// <summary> /// Adds the specified service to the service container. /// </summary> /// <param name="serviceType">The type of service to add.</param> /// <param name="callback">A callback object that is used to create the service. This allows a service to be declared as available, but delays the creation of the object until the service is requested.</param> /// <exception cref="ArgumentNullException"> /// Either <paramref name="serviceType"/> or <paramref name="callback"/> /// is a <see langword="null"/> reference. /// </exception> public void AddService(Type serviceType, ServiceCreatorCallback callback) { //CheckDisposed(); // See ContainerComponent.cs (180) if (null == serviceType) { throw new ArgumentNullException("serviceType"); } if (null == callback) { throw new ArgumentNullException("callback"); } if (services.Contains(serviceType)) { throw new ArgumentException(Properties.Resources.ServiceContainer_ServiceExists, "serviceType"); } services[serviceType] = callback; }
public void AddService1 () { object service; ServiceContainer parent; ServiceContainer sc; object serviceInstance1 = new ArrayList (); object serviceInstance2 = new Hashtable (); object callback1 = new ServiceCreatorCallback ( Svc.ServiceCreator); sc = new ServiceContainer (); sc.AddService (typeof (ICollection), serviceInstance1); sc.AddService (typeof (IEnumerable), serviceInstance2); sc.AddService (typeof (Svc), callback1); service = sc.GetService (typeof (ICollection)); Assert.IsNotNull (service, "#A1"); Assert.AreSame (serviceInstance1, service, "#A2"); service = sc.GetService (typeof (IEnumerable)); Assert.IsNotNull (service, "#B1"); Assert.AreSame (serviceInstance2, service, "#B2"); service = sc.GetService (typeof (ArrayList)); Assert.IsNull (service, "#C1"); service = sc.GetService (typeof (ICloneable)); Assert.IsNull (service, "#D1"); Assert.AreEqual (0, Svc.TotalObjectsCreatedByCallback, "#E1"); service = sc.GetService (typeof (Svc)); Assert.IsNotNull (service, "#E2"); Assert.IsTrue (service is Svc, "#E3"); Assert.AreEqual (1, Svc.TotalObjectsCreatedByCallback, "#E4"); Assert.AreSame (service, sc.GetService (typeof (Svc)), "#E5"); Assert.AreEqual (1, Svc.TotalObjectsCreatedByCallback, "#E6"); parent = new ServiceContainer (); sc = new ServiceContainer (parent); sc.AddService (typeof (ICollection), serviceInstance1); Assert.AreSame (serviceInstance1, sc.GetService (typeof (ICollection)), "#F1"); Assert.IsNull (parent.GetService (typeof (ICollection)), "#F2"); }
/// <summary> /// Default constructor of the package. /// Inside this method you can place any initialization code that does not require /// any Visual Studio service because at this point the package object is created but /// not sited yet inside Visual Studio environment. The place to do all the other /// initialization is the Initialize method. /// </summary> public GitHubExtensionPackage() { Factory.AddAssembly(Assembly.GetExecutingAssembly()); Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this)); var container = this as IServiceContainer; var callback = new ServiceCreatorCallback(CreateIssueViewer); container.AddService(typeof(IIssueToolWindow), callback, true); var tfsCallback = new ServiceCreatorCallback(CreateTfsIssueViewer); container.AddService(typeof(ITfsIssueToolWindow), tfsCallback, true); var issueListcallback = new ServiceCreatorCallback(CreateIssueListViewer); container.AddService(typeof(IssueListToolWindow), callback, true); }
/// <summary> /// <para>Adds the specified service to the service container.</para> /// </summary> /// <param name="serviceType"><para>The type of service to add.</para></param> /// <param name="callback"><para>A callback object that is used to create the service. This allows a service to be declared as available, but delays the creation of the object until the service is requested.</para></param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="serviceType"/> is a null reference (Nothing in Visual Basic).</para> /// <para>- or -</para> /// <para><paramref name="callback"/> is a null reference (Nothing in Visual Basic).</para> /// </exception> /// <exception cref="InvalidOperationException"> /// <para><paramref name="serviceType"/> already exists.</para> /// </exception> public void AddService(Type serviceType, ServiceCreatorCallback callback) { if (null == serviceType) { throw new ArgumentNullException("serviceType"); } if (null == callback) { throw new ArgumentNullException("callback"); } if (services.Contains(serviceType)) { throw new InvalidOperationException(SR.ExceptionServiceExists(serviceType.Name)); } services[serviceType] = callback; }
protected override void Initialize() { base.Initialize(); Type type = Type.GetType("System.Workflow.Activities.InvokeWorkflowActivity, System.Workflow.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); if (type != null) { TypeDescriptor.AddAttributes(type, new Attribute[] { new DesignerAttribute(typeof(InvokeWorkflowDesigner), typeof(IDesigner)) }); } base.LoaderHost.AddService(typeof(WorkflowDesignerLoader), this); ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService); if (base.LoaderHost.GetService(typeof(IWorkflowCompilerOptionsService)) == null) { base.LoaderHost.AddService(typeof(IWorkflowCompilerOptionsService), callback); } if (base.LoaderHost.GetService(typeof(IIdentifierCreationService)) == null) { base.LoaderHost.AddService(typeof(IIdentifierCreationService), callback); } if (base.LoaderHost.GetService(typeof(ComponentSerializationService)) == null) { base.LoaderHost.AddService(typeof(ComponentSerializationService), callback); } base.LoaderHost.RemoveService(typeof(IReferenceService)); if (base.LoaderHost.GetService(typeof(IReferenceService)) == null) { base.LoaderHost.AddService(typeof(IReferenceService), callback); } if (base.LoaderHost.GetService(typeof(IDesignerVerbProviderService)) == null) { base.LoaderHost.AddService(typeof(IDesignerVerbProviderService), callback); } IExtenderProviderService service = base.GetService(typeof(IExtenderProviderService)) as IExtenderProviderService; if (service != null) { foreach (IExtenderProvider provider in ComponentDispenser.Extenders) { service.AddExtenderProvider(provider); } } this.customActivityDesignerAdapter = new CustomActivityDesignerAdapter(base.LoaderHost); }
protected override void Initialize() { base.Initialize(); new OrchestratorCommandSet(this); this.optionsAutomation = new OrchestratorOptionsAutomation(this); ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService); ((IServiceContainer)this).AddService(typeof(STextTemplating), callback, true); DTE dTE = this.GetDTE(); if (dTE != null) { this.solutionEvents = dTE.Events.SolutionEvents; if (this.solutionEvents != null) { this.solutionEvents.add_AfterClosing(new _dispSolutionEvents_AfterClosingEventHandler(this.OnSolutionClose)); } } }
public object GetService(Type serviceType) { if (serviceType == null) { throw new ArgumentNullException("serviceType"); } object service = null; this._services.TryGetValue(serviceType, out service); if ((service == null) && (this._parentContainer != null)) { service = this._parentContainer.GetService(serviceType); } ServiceCreatorCallback callback = service as ServiceCreatorCallback; if (callback != null) { service = callback(this, serviceType); } return service; }
/// <summary> /// Adds the specified service to the service container. /// </summary> /// <param name="serviceType">The type of service to add.</param> /// <param name="callback">A callback object that is used to create the service. This allows a service to be declared as available, but delays the creation of the object until the service is requested.</param> public void AddService(Type serviceType, ServiceCreatorCallback callback) { if (serviceType == null) { throw new ArgumentNullException("serviceType"); } if (callback == null) { throw new ArgumentNullException("callback"); } if (_services.Contains(serviceType)) { throw new ArgumentException("Service already exists.", "serviceType"); } _services[serviceType] = callback; }
protected override object InternalCreate() { IServiceContainer container = (IServiceContainer) Model.ExtendedProperties[ServiceContainerKey]; ServiceCreatorCallback callback = (ServiceCreatorCallback) Model.ExtendedProperties[ServiceCreatorCallbackKey]; Type serviceType = Model.Service; object service = callback(container, serviceType); if (!(service == null || service.GetType().IsCOMObject || serviceType.IsAssignableFrom(service.GetType()))) { service = null; } return(service); }
public void AddService( Type serviceType, ServiceCreatorCallback callback, bool promote ) { if ( promote && parentContainer != null ) { parentContainer.AddService( serviceType, callback, promote ); return; } lock ( syncRoot ) { if ( services.ContainsKey( serviceType ) ) { var message = DataAnnotationsResources.ServiceAlreadyExists.FormatDefault( serviceType ); throw new ArgumentException( message, "serviceType" ); } services.Add( serviceType, callback ); } }
public void AddService(Type serviceType, ServiceCreatorCallback callback, bool promote) { if (promote && this._parentContainer != null) { this._parentContainer.AddService(serviceType, callback, promote); } else { lock (this._lock) { if (this._services.ContainsKey(serviceType)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.ValidationContextServiceContainer_ItemAlreadyExists, serviceType), "serviceType"); } this._services.Add(serviceType, callback); } } }
protected override async Task InitializeAsync(System.Threading.CancellationToken cancellationToken, IProgress <VS.ServiceProgressData> progress) { await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); await base.InitializeAsync(cancellationToken, progress); Reporter = Reporter ?? new ReAttachTraceReporter(); History = History ?? new ReAttachHistory(new ReAttachRegistryRepository(this)); Ui = Ui ?? await ReAttachUi.InitAsync(this); Debugger = Debugger ?? await ReAttachDebugger.InitAsync(this); History.Load(); Ui.Update(); var callback = new ServiceCreatorCallback(CreateBusService); ((IServiceContainer)this).AddService(typeof(IReAttachBusService), callback); }
protected override void Initialize() { base.Initialize(); //PLEASE NOTE THE FOLLOWING CODE IS ADDED TO MAKE THE SPECIFIC DESIGNER TYPE INTERNAL //This is a work around for invoke workflow so that the ActivityHostDesignerType does not become public //Please refer to file WorkflowInlining.cs Type invokeWorkflowType = Type.GetType(InvokeWorkflowDesigner.InvokeWorkflowRef); if (invokeWorkflowType != null) TypeDescriptor.AddAttributes(invokeWorkflowType, new DesignerAttribute(typeof(InvokeWorkflowDesigner), typeof(IDesigner))); //Add all the services, it is important to make sure that if user pushes the services then we honor //those services LoaderHost.AddService(typeof(WorkflowDesignerLoader), this); ServiceCreatorCallback callback = new ServiceCreatorCallback(OnCreateService); if (LoaderHost.GetService(typeof(IWorkflowCompilerOptionsService)) == null) LoaderHost.AddService(typeof(IWorkflowCompilerOptionsService), callback); if (LoaderHost.GetService(typeof(IIdentifierCreationService)) == null) LoaderHost.AddService(typeof(IIdentifierCreationService), callback); if (LoaderHost.GetService(typeof(ComponentSerializationService)) == null) LoaderHost.AddService(typeof(ComponentSerializationService), callback); LoaderHost.RemoveService(typeof(IReferenceService)); if (LoaderHost.GetService(typeof(IReferenceService)) == null) LoaderHost.AddService(typeof(IReferenceService), callback); if (LoaderHost.GetService(typeof(IDesignerVerbProviderService)) == null) LoaderHost.AddService(typeof(IDesignerVerbProviderService), callback); //Add all the extenders, the extenders are responsible to add the extended properties which are not //actual properties on activity IExtenderProviderService extenderProviderService = GetService(typeof(IExtenderProviderService)) as IExtenderProviderService; if (extenderProviderService != null) { foreach (IExtenderProvider extender in ComponentDispenser.Extenders) extenderProviderService.AddExtenderProvider(extender); } this.customActivityDesignerAdapter = new CustomActivityDesignerAdapter(LoaderHost); }
protected BabelPackage() { ServiceCreatorCallback callback = new ServiceCreatorCallback( delegate(IServiceContainer container, Type serviceType) { if (typeof(BlenXLanguageService) == serviceType) { BlenXLanguageService language = new BlenXLanguageService(this); language.SetSite(this); // register for idle time callbacks IOleComponentManager mgr = GetService(typeof(SOleComponentManager)) as IOleComponentManager; if (componentID == 0 && mgr != null) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime; crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 1000; int hr = mgr.FRegisterComponent(this, crinfo, out componentID); } return language; } else { return null; } }); // proffer the LanguageService (this as IServiceContainer).AddService(typeof(BlenXLanguageService), callback, true); }
void IServiceContainer.AddService(Type serviceType, ServiceCreatorCallback callback, bool promote) { Services.AddService(serviceType, callback, promote); }
void IServiceContainer.AddService(Type serviceType, ServiceCreatorCallback callback) { Services.AddService(serviceType, callback); }
public void AddService (Type serviceType, ServiceCreatorCallback callback) { AddService (serviceType, callback, false); }
public void AddService (Type serviceType, ServiceCreatorCallback callback, bool promote) { AddService (serviceType, (object)callback, promote); }
/// <summary> /// Default constructor of the package. /// Inside this method you can place any initialization code that does not require /// any Visual Studio service because at this point the package object is created but /// not sited yet inside Visual Studio environment. The place to do all the other /// initialization is the Initialize method. /// </summary> public SrcMLServicePackage() { //WriteActivityLog("SrcMLServicePackage.SrcMLServicePackage()"); // Leave this here as an example of how to use Activity Log SrcMLFileLogger.DefaultLogger.Info(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString())); // Step 2: Add callback methods to the service container to create the services. // Here we update the list of the provided services with the ones specific for this package. // Notice that we set to true the boolean flag about the service promotion for the global: // to promote the service is actually to proffer it globally using the SProfferService service. // For performance reasons we don’t want to instantiate the services now, but only when and // if some client asks for them, so we here define only the type of the service and a function // that will be called the first time the package will receive a request for the service. // This callback function is the one responsible for creating the instance of the service // object. // The SrcML local service has not been used so far. IServiceContainer serviceContainer = this as IServiceContainer; ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateService); serviceContainer.AddService(typeof(SSrcMLGlobalService), callback, true); serviceContainer.AddService(typeof(SSrcMLLocalService), callback); }
/// <summary> /// Adds the specified service to the service container, and optionally /// promotes the service to parent service containers. /// </summary> /// <param name="serviceType">The type of service to add.</param> /// <param name="callback">A callback object that is used to create the service.</param> /// <param name="promote">true to promote this request to any parent service containers.</param> public virtual void AddService(Type serviceType, ServiceCreatorCallback callback, bool promote) { if (promote) { IServiceContainer parentServices = ParentServices; if (parentServices != null) { parentServices.AddService(serviceType, callback, promote); return; } } if (serviceType == null) { throw new ArgumentNullException("serviceType"); } if (callback == null) { throw new ArgumentNullException("callback"); } if (HasService(serviceType)) { throw new ArgumentException(String.Format( "A service for type '{0}' already exists", serviceType.FullName), "serviceType"); } String serviceName = GetServiceName(serviceType); ComponentModel model = new ComponentModel(serviceName, serviceType, null); model.ExtendedProperties.Add(ServiceCreatorCallbackActivator.ServiceContainerKey, GetService(typeof(IServiceContainer))); model.ExtendedProperties.Add(ServiceCreatorCallbackActivator.ServiceCreatorCallbackKey, callback); model.LifestyleType = LifestyleType.Singleton; model.CustomComponentActivator = typeof(ServiceCreatorCallbackActivator); Kernel.AddCustomComponent(model); }
public void AddService (Type serviceType, ServiceCreatorCallback callback, bool promote) { _serviceContainer.AddService (serviceType, callback, promote); }
public void AddService (Type serviceType, ServiceCreatorCallback callback) { _serviceContainer.AddService (serviceType, callback); }
public override void Initialize(IComponent component) { this.initializing = true; base.Initialize(component); this.initializing = false; PropertyDescriptor descriptor = TypeDescriptor.GetProperties(base.Component.GetType())["BackColor"]; if (((descriptor != null) && (descriptor.PropertyType == typeof(System.Drawing.Color))) && !descriptor.ShouldSerializeValue(base.Component)) { this.Control.BackColor = SystemColors.Control; } IDesignerHost serviceProvider = (IDesignerHost) this.GetService(typeof(IDesignerHost)); IExtenderProviderService ex = (IExtenderProviderService) this.GetService(typeof(IExtenderProviderService)); if (ex != null) { this.designerExtenders = new DesignerExtenders(ex); } if (serviceProvider != null) { serviceProvider.Activated += new EventHandler(this.OnDesignerActivate); serviceProvider.Deactivated += new EventHandler(this.OnDesignerDeactivate); ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService); serviceProvider.AddService(typeof(IEventHandlerService), callback); this.frame = new DesignerFrame(component.Site); IOverlayService frame = this.frame; serviceProvider.AddService(typeof(IOverlayService), frame); serviceProvider.AddService(typeof(ISplitWindowService), this.frame); this.behaviorService = new BehaviorService(base.Component.Site, this.frame); serviceProvider.AddService(typeof(BehaviorService), this.behaviorService); this.selectionManager = new SelectionManager(serviceProvider, this.behaviorService); serviceProvider.AddService(typeof(SelectionManager), this.selectionManager); serviceProvider.AddService(typeof(ToolStripAdornerWindowService), callback); IComponentChangeService service = (IComponentChangeService) this.GetService(typeof(IComponentChangeService)); if (service != null) { service.ComponentAdded += new ComponentEventHandler(this.OnComponentAdded); service.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged); service.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemoved); } this.inheritanceUI = new InheritanceUI(); serviceProvider.AddService(typeof(InheritanceUI), this.inheritanceUI); InheritanceService serviceInstance = new DocumentInheritanceService(this); serviceProvider.AddService(typeof(IInheritanceService), serviceInstance); manager = serviceProvider.GetService(typeof(IDesignerSerializationManager)) as IDesignerSerializationManager; serviceInstance.AddInheritedComponents(component, component.Site.Container); manager = null; this.inheritanceService = serviceInstance; if (this.Control.IsHandleCreated) { this.OnCreateHandle(); } IPropertyValueUIService service5 = (IPropertyValueUIService) component.Site.GetService(typeof(IPropertyValueUIService)); if (service5 != null) { this.designBindingValueUIHandler = new DesignBindingValueUIHandler(); service5.AddPropertyValueUIHandler(new PropertyValueUIHandler(this.designBindingValueUIHandler.OnGetUIValueItem)); } IToolboxService service6 = (IToolboxService) serviceProvider.GetService(typeof(IToolboxService)); if (service6 != null) { this.toolboxCreator = new ToolboxItemCreatorCallback(this.OnCreateToolboxItem); service6.AddCreator(this.toolboxCreator, axClipFormat, serviceProvider); service6.AddCreator(this.toolboxCreator, OleDragDropHandler.DataFormat, serviceProvider); service6.AddCreator(this.toolboxCreator, OleDragDropHandler.NestedToolboxItemFormat, serviceProvider); } serviceProvider.LoadComplete += new EventHandler(this.OnLoadComplete); } this.commandSet = new ControlCommandSet(component.Site); this.frame.Initialize(this.Control); this.pbrsFwd = new PbrsForward(this.frame, component.Site); this.Location = new Point(0, 0); }