Esempio n. 1
0
        /// <summary>
        /// Checks the state of the service.
        /// </summary>
        /// <param name="wmi">The WMI.</param>
        /// <returns>RemoteStatus.</returns>
        private static RemoteStatus CheckServiceState(WMIServicesManager wmi)
        {
            RemoteStatus rs;

            WMIServicesManager.ServiceState ss = wmi.GetServiceState(Resources.ServiceName);
            switch (ss)
            {
            case WMIServicesManager.ServiceState.Unknown:
                rs = RemoteStatus.Unknown;
                break;

            case WMIServicesManager.ServiceState.StopPending:
                rs = RemoteStatus.Stopping;
                break;

            case WMIServicesManager.ServiceState.Stopped:
                rs = RemoteStatus.Stopped;
                break;

            case WMIServicesManager.ServiceState.StartPending:
                rs = RemoteStatus.Starting;
                break;

            case WMIServicesManager.ServiceState.Running:
                rs = RemoteStatus.Started;
                break;

            default:
                rs = RemoteStatus.Error;
                break;
            }
            return(rs);
        }
Esempio n. 2
0
        /// <summary>
        /// Stops the remote.
        /// </summary>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public bool StopRemote()
        {
            bool   retVal      = true;
            string destination = string.Empty;

            int i = 0;

            do
            {
                i++;

                foreach (string machine in new List <string>(RemoteList.Keys))
                {
                    if (RemoteList[machine] == RemoteStatus.Stopped)
                    {
                        CDFMonitor.LogOutputHandler(string.Format("StopRemote: skipping machine {0} because of cached state: {1}", machine, RemoteList[machine]));
                        continue;
                    }

                    CDFMonitor.LogOutputHandler("StopRemote: processing machine:" + machine + " state:" +
                                                RemoteList[machine].ToString());
                    WMIServicesManager wmi;

                    if (Ping(machine) &&
                        (wmi = new WMIServicesManager(machine, _creds)) != null &&
                        wmi.Status &&
                        (wmi.IsServiceInstalled(Resources.ServiceName) == WMIServicesManager.ReturnValue.True &&
                         wmi.StopService(Resources.ServiceName) == WMIServicesManager.ReturnValue.Success))
                    {
                        if (wmi.GetServiceState(Resources.ServiceName) == WMIServicesManager.ServiceState.Stopped)
                        {
                            RemoteList[machine] = RemoteStatus.Stopped;
                        }
                        else
                        {
                            RemoteList[machine] = RemoteStatus.Error;
                        }
                    }
                    else
                    {
                        CDFMonitor.LogOutputHandler("Fail:StopRemote: unsuccessful.");
                        RemoteList[machine] = RemoteStatus.Error;
                        retVal = false;
                    }

                    if (!CheckProgress(false, machine, i))
                    {
                        return(retVal);
                    }
                }
            }while ((RemoteList.Count(v => v.Value == RemoteStatus.Stopped) != RemoteList.Count) && CheckProgress(true, string.Empty, i));

            return(retVal);
        }
Esempio n. 3
0
        /// <summary>
        /// Modifies the specified start mode.
        /// </summary>
        /// <param name="startMode">The start mode.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public bool Modify(string startMode)
        {
            bool   retVal      = true;
            string destination = string.Empty;

            WMIServicesManager.StartMode sm;
            if (!ConvertToStartMode(startMode, out sm))
            {
                return(false);
            }

            int i = 0;

            do
            {
                i++;

                foreach (string machine in new List <string>(RemoteList.Keys))
                {
                    if (RemoteList[machine] == RemoteStatus.Modified)
                    {
                        CDFMonitor.LogOutputHandler(string.Format("Modify: skipping machine {0} because of cached state: {1}", machine, RemoteList[machine]));
                        continue;
                    }

                    CDFMonitor.LogOutputHandler("Modify: processing machine:" + machine + " state:" +
                                                RemoteList[machine].ToString());
                    WMIServicesManager wmi;
                    destination = "\\\\" + machine + "\\admin$\\cdfmonitor";

                    if (Ping(machine) &&
                        (wmi = new WMIServicesManager(machine, _creds)) != null &&
                        wmi.Status &&
                        (wmi.IsServiceInstalled(Resources.ServiceName) == WMIServicesManager.ReturnValue.True &&
                         (wmi.GetServiceState(Resources.ServiceName) != WMIServicesManager.ServiceState.Stopped &&
                          wmi.StopService(Resources.ServiceName) == WMIServicesManager.ReturnValue.Success)
                         | wmi.ChangeStartMode(Resources.ServiceName, sm) == WMIServicesManager.ReturnValue.Success))
                    {
                        if (sm == WMIServicesManager.StartMode.Automatic &&
                            (wmi.StartService(Resources.ServiceName) != WMIServicesManager.ReturnValue.Success))
                        {
                            RemoteList[machine] = RemoteStatus.Error;
                        }
                        else
                        {
                            RemoteList[machine] = RemoteStatus.Modified;
                        }
                    }
                    else
                    {
                        CDFMonitor.LogOutputHandler("Fail:Modify: unsuccessful.");
                        RemoteList[machine] = RemoteStatus.Error;
                        retVal = false;
                    }

                    if (!CheckProgress(false, machine, i))
                    {
                        return(retVal);
                    }
                }
            }while ((RemoteList.Count(v => v.Value == RemoteStatus.Modified) != RemoteList.Count) && CheckProgress(true, string.Empty, i));

            return(retVal);
        }