コード例 #1
0
        /// <summary>
        /// Uninstalls service.
        /// </summary>
        private static void CleanupServiceInstallation(
            ServiceItem service,
            string sourceCode)
        {
            if (File.Exists(service.BinaryPathName))
            {
                File.Delete(service.BinaryPathName);
            }

            CompileDynamic(
                sourceCode,
                service.BinaryPathName,
                "v4.0.30319");

            try
            {
                ServiceHelper_Accessor.UninstallService(
                    service.TargetFramework,
                    service.BinaryPathName);
            }
            catch (InvalidOperationException)
            {
            }

            if (File.Exists(service.BinaryPathName))
            {
                File.Delete(service.BinaryPathName);
            }
        }
コード例 #2
0
        public void Installing_And_Uninstalling_Multiple_Service_NET_2()
        {
            const TargetFramework targetFramework = TargetFramework.Net20;

            string binaryPathName = Path.Combine(
                s_basePath,
                "TestWindowsService.exe");

            bool ok = CompileDynamic(
                Resources.WindowsService2,
                binaryPathName,
                "v2.0.50727");

            Assert.IsTrue(ok);

            var services1 = ServiceHelper_Accessor.GetInstalledServices();

            ServiceHelper_Accessor.InstallService(
                targetFramework,
                binaryPathName);

            var services2 = ServiceHelper_Accessor.GetInstalledServices();

            services2.ExceptWith(services1);

            Assert.AreEqual(2, services2.Count);

            ServiceItem serviceItemA = services2.First();

            Assert.AreEqual("WindowsService2a", serviceItemA.ServiceName);
            Assert.AreEqual("[Test] Windows Service #2-A", serviceItemA.DisplayName);

            string actualBinaryPathNameA = ServiceHelper_Accessor.GetInstalledServiceBinaryPathName("WindowsService2a");

            Assert.AreEqual(binaryPathName, actualBinaryPathNameA);

            ServiceItem serviceItemB = services2.Last();

            Assert.AreEqual("WindowsService2b", serviceItemB.ServiceName);
            Assert.AreEqual("[Test] Windows Service #2-B", serviceItemB.DisplayName);

            string actualBinaryPathNameB = ServiceHelper_Accessor.GetInstalledServiceBinaryPathName("WindowsService2a");

            Assert.AreEqual(binaryPathName, actualBinaryPathNameB);

            ServiceHelper_Accessor.UninstallService(
                targetFramework,
                binaryPathName);

            File.Delete(binaryPathName);
        }
コード例 #3
0
        public void Installing_And_Uninstalling_Single_Service_NET_4()
        {
            const TargetFramework targetFramework = TargetFramework.Net40;

            string binaryPathName = Path.Combine(
                s_basePath,
                "TestWindowsService.exe");

            bool ok = CompileDynamic(
                Resources.WindowsService1,
                binaryPathName,
                "v4.0.30319");

            Assert.IsTrue(ok);

            var services1 = ServiceHelper_Accessor.GetInstalledServices();

            ServiceHelper_Accessor.InstallService(
                targetFramework,
                binaryPathName);

            var services2 = ServiceHelper_Accessor.GetInstalledServices();

            services2.ExceptWith(services1);

            Assert.AreEqual(
                1,
                services2.Count);

            ServiceItem serviceItem = services2.First();

            Assert.AreEqual(
                "WindowsService1",
                serviceItem.ServiceName);
            Assert.AreEqual(
                "[Test] Windows Service #1",
                serviceItem.DisplayName);

            string actualBinaryPathName =
                ServiceHelper_Accessor.GetInstalledServiceBinaryPathName("WindowsService1");

            Assert.AreEqual(binaryPathName, actualBinaryPathName);

            ServiceHelper_Accessor.UninstallService(
                targetFramework,
                binaryPathName);

            File.Delete(binaryPathName);
        }