コード例 #1
0
        /// <summary>
        /// Deploys 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 Deploy(string startMode)
        {
            bool   retVal      = true;
            string destination = string.Empty;

            if (!CheckSource(_path))
            {
                return(false);
            }

            WMIServicesManager.StartMode sm;
            if (string.IsNullOrEmpty(startMode))
            {
                sm = WMIServicesManager.StartMode.Automatic;
            }
            else if (!ConvertToStartMode(startMode, out sm))
            {
                return(false);
            }

            int i = 0;

            // Add current running exe to list so it doesnt have to be in staged dir
            List <string> fileList = FileManager.GetFiles(_path, "*.*", SearchOption.AllDirectories).ToList();

            fileList.Add(AppDomain.CurrentDomain.FriendlyName);

            do
            {
                i++;

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

                    CDFMonitor.LogOutputHandler("Deploy: 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.StopService(Resources.ServiceName) == WMIServicesManager.ReturnValue.Success))
                        | (FileManager.CheckPath(destination, true) &&
                           FileManager.CopyFiles(fileList.ToArray(), destination, true) &&
                           SetSeServiceLogonRight(wmi) &&
                           wmi.InstallService(Resources.ServiceName,
                                              Resources.FriendlyName,
                                              wmi.GetSYSTEMROOT() + "\\cdfmonitor\\cdfmonitor.exe /runningasservice",
                                              WMIServicesManager.ServiceType.OwnProcess,
                                              WMIServicesManager.OnError.UserIsNotNotified,
                                              sm,
                                              false,
                                              _creds,
                                              null,
                                              null,
                                              null) == WMIServicesManager.ReturnValue.Success))
                    {
                        if (sm == WMIServicesManager.StartMode.Automatic
                            &&
                            (wmi.ChangeStartMode(Resources.ServiceName, sm)) != WMIServicesManager.ReturnValue.Success ||
                            (wmi.StartService(Resources.ServiceName) != WMIServicesManager.ReturnValue.Success))
                        {
                            RemoteList[machine] = RemoteStatus.Error;
                        }
                        else
                        {
                            RemoteList[machine] = RemoteStatus.Deployed;
                        }

                        wmi.ShowProperties(Resources.ServiceName);
                    }
                    else
                    {
                        CDFMonitor.LogOutputHandler("Fail:Deploy: unsuccessful.");
                        RemoteList[machine] = RemoteStatus.Error;
                        retVal = false;
                    }

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

            return(retVal);
        }