コード例 #1
0
        public static string GetIisVersion(IScriptExecutionEnvironment environment, bool failIfNotExist)
        {
            string major;

            if (environment.IsConfigSettingDefined(IisMajorVersion))
            {
                major = environment.GetConfigSetting(IisMajorVersion);
            }
            else
            {
                ExecuteTask(environment);
                major = environment.GetConfigSetting(IisMajorVersion);
            }

            if (string.IsNullOrEmpty(major))
            {
                const string Msg = "IIS not installed or IIS access denied!";
                if (failIfNotExist)
                {
                    throw new RunnerFailedException(Msg);
                }
                environment.LogMessage(Msg);

                return("0.0");
            }

            string minor = environment.GetConfigSetting(IisMinorVersion);

            return(major + "." + minor);
        }
コード例 #2
0
        //internal static int GetMinorVersion(string version)
        //{
        //    if (string.IsNullOrEmpty(version))
        //        return 0;
        //    string[] split = version.Split('.');
        //    return split.Length != 2 ? 0 : Convert.ToInt32(split[1], CultureInfo.InvariantCulture);
        //}

        protected override void DoExecute(IScriptExecutionEnvironment environment)
        {
            GetRegistryValueTask innerTask = new GetRegistryValueTask(
                Microsoft.Win32.Registry.LocalMachine,
                @"SOFTWARE\Microsoft\InetStp",
                "MajorVersion",
                IisMajorVersion);

            innerTask.Execute(environment);

            innerTask = new GetRegistryValueTask(
                Microsoft.Win32.Registry.LocalMachine,
                @"SOFTWARE\Microsoft\InetStp",
                "MinorVersion",
                IisMinorVersion);
            innerTask.Execute(environment);

            environment.LogMessage(
                "Local IIS has version {0}.{1}",
                environment.GetConfigSetting("IIS/MajorVersion"),
                environment.GetConfigSetting("IIS/MinorVersion"));
        }
コード例 #3
0
        /// <summary>
        /// Method defining the actual work for a task.
        /// </summary>
        /// <param name="environment">The script execution environment.</param>
        protected override void DoExecute(IScriptExecutionEnvironment environment)
        {
            string configSettingName = String.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                "ServicesExist/{0}",
                serviceName);

            CheckIfServiceExistsTask.Execute(environment, serviceName, configSettingName);
            if (bool.Parse(environment.GetConfigSetting(configSettingName)) == true)
            {
                ControlWindowsServiceTask.Execute(
                    environment,
                    serviceName,
                    ControlWindowsServiceMode.Stop,
                    TimeSpan.FromSeconds(30));
            }
        }
コード例 #4
0
ファイル: NCoverTask.cs プロジェクト: mohanak12/projectpilot
        private static bool ShouldRegisterNCover(IScriptExecutionEnvironment environment)
        {
            GetRegistryValueTask task = new GetRegistryValueTask(
                Microsoft.Win32.Registry.ClassesRoot,
                "TypeLib\\{3FB1CC1E-1C17-4A37-9C18-BF3DB8F10E46}\\1.0",
                string.Empty,
                "NCoverRegistered");

            try
            {
                task.Execute(environment);
            }
            catch (RunnerFailedException)
            {
                return(true);
            }

            string val = environment.GetConfigSetting("NCoverRegistered");

            return(string.IsNullOrEmpty(val));
        }
コード例 #5
0
        /// <summary>
        /// Internal task execution code.
        /// </summary>
        /// <param name="environment">The script execution environment.</param>
        protected override void DoExecute(IScriptExecutionEnvironment environment)
        {
            string configSettingName = String.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                "ServicesExist/{0}",
                serviceName);

            CheckIfServiceExistsTask checkIfServiceExistsTask = new CheckIfServiceExistsTask(serviceName, configSettingName);

            checkIfServiceExistsTask.Execute(environment);

            if (bool.Parse(environment.GetConfigSetting(configSettingName)) == true)
            {
                switch (mode)
                {
                case InstallWindowsServiceMode.DoNothingIfExists:
                    return;

                case InstallWindowsServiceMode.FailIfAlreadyInstalled:
                    throw new RunnerFailedException(
                              String.Format(
                                  System.Globalization.CultureInfo.InvariantCulture,
                                  "The Windows service '{0}' already exists.",
                                  serviceName));

                case InstallWindowsServiceMode.ReinstallIfExists:
                    UninstallWindowsServiceTask uninstallWindowsServiceTask = new UninstallWindowsServiceTask(executablePath);
                    uninstallWindowsServiceTask.Execute(environment);

                    // wait for a while to ensure the service is really deleted
                    SleepTask.Execute(environment, serviceUninstallationWaitTime);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }

            IDictionary savedState = new Hashtable();

            string[] commandLine = new string[0];

            using (System.Configuration.Install.AssemblyInstaller assemblyInstaller
                       = new System.Configuration.Install.AssemblyInstaller(executablePath, commandLine))
            {
                try
                {
                    assemblyInstaller.UseNewContext = true;

                    assemblyInstaller.Install(savedState);
                    assemblyInstaller.Commit(savedState);
                }
                catch (System.ComponentModel.Win32Exception ex)
                {
                    // 1073
                    environment.LogMessage(
                        "ex.ErrorCode = {0}",
                        ex.NativeErrorCode);
                    throw;
                }
            }
        }
コード例 #6
0
        protected override void DoExecute(IScriptExecutionEnvironment environment)
        {
            string configSettingName = String.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                "ServicesExist/{0}",
                serviceName);

            CheckIfServiceExistsTask.Execute(environment, serviceName, configSettingName);
            if (bool.Parse(environment.GetConfigSetting(configSettingName)) == false)
            {
                if (FailIfNotExist)
                {
                    throw new RunnerFailedException("Service {0} does not exist.", serviceName);
                }

                environment.LogMessage("Service '{0}' does not exist, doing nothing.", serviceName);
                return;
            }

            using (ServiceController serviceController = new ServiceController(serviceName, MachineName))
            {
                ServiceControllerStatus status = ServiceControllerStatus.Running;
                switch (mode)
                {
                case ControlWindowsServiceMode.Start:
                    status = ServiceControllerStatus.Running;
                    break;

                case ControlWindowsServiceMode.Stop:
                    status = ServiceControllerStatus.Stopped;
                    break;
                }

                switch (status)
                {
                case ServiceControllerStatus.Running:
                    if (serviceController.Status != ServiceControllerStatus.Running)
                    {
                        serviceController.Start();
                    }
                    break;

                case ServiceControllerStatus.Stopped:
                    if (serviceController.Status != ServiceControllerStatus.Stopped)
                    {
                        serviceController.Stop();
                    }
                    break;
                }

                int timeSoFar = 0;
                for (serviceController.Refresh(); serviceController.Status != status; serviceController.Refresh())
                {
                    System.Threading.Thread.Sleep(500);
                    timeSoFar += 500;

                    if (timeSoFar >= timeout.TotalMilliseconds)
                    {
                        throw new RunnerFailedException(
                                  String.Format(
                                      System.Globalization.CultureInfo.InvariantCulture,
                                      "Timeout waiting for '{0}' service to reach status {1}.",
                                      serviceName,
                                      status));
                    }
                }
            }
        }