コード例 #1
0
        public OtherLocalService2(IMyLocalService localService, IOtherLocalService otherLocalService)
        {
            InstanceCount++;

            this.localService       = localService;
            this.otherLocalService1 = otherLocalService;
        }
コード例 #2
0
        /// <summary>
        /// Implementation of the function that will call a method of the local service.
        /// Notice that this class will access the local service using as service provider the one
        /// implemented by ServicesPackage.
        /// </summary>
        public int CallLocalService()
        {
            // Query the service provider for the local service.
            // This object is supposed to be build by ServicesPackage and it pass its service provider
            // to the constructor, so the local service should be found.
            IMyLocalService localService = serviceProvider.GetService(typeof(SMyLocalService)) as IMyLocalService;

            if (null == localService)
            {
                // The local service was not found; write a message on the debug output and exit.
                Debug.WriteLine("Can not get the local service from the global one.");
                return(-1);
            }

            // Now call the method of the local service. This will write a message on the output window.
            return(localService.LocalServiceFunction());
        }
コード例 #3
0
        public void GetLocalServiceSimple()
        {
            ServicesPackage packageObject = new ServicesPackage();
            IVsPackage      package       = (IVsPackage)packageObject;

            using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices())
            {
                int result = package.SetSite(provider);
                Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded(result), "SetSite failed.");
                IServiceProvider serviceProvider = package as IServiceProvider;
                object           o = serviceProvider.GetService(typeof(SMyLocalService));
                Assert.IsNotNull(o, "GetService returned null for the local service.");
                IMyLocalService service = o as IMyLocalService;
                Assert.IsNotNull(service, "The service SMyLocalService does not implements IMyLocalService.");
                service.LocalServiceFunction();
            }
            package.SetSite(null);
            package.Close();
        }
コード例 #4
0
        private void GetLocalServiceCallback(object sender, EventArgs args)
        {
            // Try to get the service. Notice that GetService will use the service provider
            // implemented by the base class and, in case of service not found, it will query
            // the service provider used during SetSite to get the service. Because the
            // service provider implemented by ServicesPackage is not inside this chain of
            // providers, this query must fail.
            IMyLocalService service = GetService(typeof(SMyLocalService)) as IMyLocalService;

            if (null != service)
            {
                // Something strange happened, write a message on the debug output and exit.
                Debug.WriteLine("GetService for the local service succeeded, but it should fail.");
                return;
            }

            // Now write on the output window that the call failed and the test succeeded.
            string outputText = " ======================================\n" +
                                "\tGetLocalServiceCallback test succeeded.\n" +
                                " ======================================\n";

            // Write a message on the debug output.
            HelperFunctions.WriteOnOutputWindow(this, outputText);
        }
コード例 #5
0
        public OtherLocalService(IMyLocalService localService)
        {
            InstanceCount++;

            this.localService = localService;
        }