/// <summary> /// Uns the deploy. /// </summary> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> public bool UnDeploy() { 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.UnDeployed) { CDFMonitor.LogOutputHandler(string.Format("UnDeploy: skipping machine {0} because of cached state: {1}", machine, RemoteList[machine])); continue; } CDFMonitor.LogOutputHandler("UnDeploy: processing machine:" + machine + " state:" + RemoteList[machine].ToString()); WMIServicesManager wmi; destination = "\\\\" + machine + "\\admin$\\cdfmonitor"; int pid = 0; 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 && wmi.UninstallService(Resources.ServiceName) == WMIServicesManager.ReturnValue.Success) | (FileManager.CheckPath(destination, true) && ((pid = wmi.RunProcess(string.Format("{0}\\cdfmonitor\\cdfmonitor.exe /clean", wmi.GetSYSTEMROOT()))) != 0 & wmi.CheckProcess(_processName, pid, true) == 0) && FileManager.DeleteFolder(destination, false))) { RemoteList[machine] = RemoteStatus.UnDeployed; } else { CDFMonitor.LogOutputHandler("Fail:UnDeploy: unsuccessful."); RemoteList[machine] = RemoteStatus.Error; retVal = false; } if (!CheckProgress(false, machine, i)) { return(retVal); } } }while ((RemoteList.Count(v => v.Value == RemoteStatus.UnDeployed)) != RemoteList.Count && CheckProgress(true, string.Empty, i)); return(retVal); }
/// <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); }
/// <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); }
/// <summary> /// Gathers this instance. /// </summary> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> public bool Gather() { bool retVal = true; string source = string.Empty; string destination = string.Empty; if (!FileManager.CheckPath(_path, true)) { return(false); } int i = 0; do { i++; foreach (string machine in new List <string>(RemoteList.Keys)) { if (RemoteList[machine] == RemoteStatus.Gathered) { CDFMonitor.LogOutputHandler(string.Format("Gather: skipping machine {0} because of cached state: {1}", machine, RemoteList[machine])); continue; } CDFMonitor.LogOutputHandler("Gather: processing machine:" + machine + " state:" + RemoteList[machine].ToString()); WMIServicesManager wmi; source = "\\\\" + machine + "\\admin$\\cdfmonitor"; destination = _path + "\\" + machine; int pid = 0; RemoteStatus rs = RemoteStatus.Unknown; if (Ping(machine) && (wmi = new WMIServicesManager(machine, _creds)) != null && wmi.Status && (wmi.IsServiceInstalled(Resources.ServiceName) == WMIServicesManager.ReturnValue.True && ((rs = CheckServiceState(wmi)) != RemoteStatus.Started || wmi.StopService(Resources.ServiceName) == WMIServicesManager.ReturnValue.Success)) | (FileManager.CheckPath(source, false) && (pid = wmi.RunProcess(wmi.GetSYSTEMROOT() + "\\cdfmonitor\\cdfmonitor.exe /zip")) != 0 && wmi.CheckProcess(_processName, pid, true) == 0 && FileManager.CopyFiles(FileManager.GetFiles(source, "*.zip", SearchOption.TopDirectoryOnly), destination, true) && (FileManager.DeleteFiles(FileManager.GetFiles(source, "*.zip", SearchOption.TopDirectoryOnly), true) == FileManager.Results.Success) && (rs != RemoteStatus.Started || wmi.StartService(Resources.ServiceName) == WMIServicesManager.ReturnValue.Success))) { RemoteList[machine] = RemoteStatus.Gathered; } else { CDFMonitor.LogOutputHandler("Fail:Gather: unsuccessful."); RemoteList[machine] = RemoteStatus.Error; retVal = false; } if (!CheckProgress(false, machine, i, destination)) { return(retVal); } } }while ((RemoteList.Count(v => v.Value == RemoteStatus.Gathered) != RemoteList.Count) && CheckProgress(true, string.Empty, i)); return(retVal); }
/// <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); }
/// <summary> /// Checks remote machine for existence of utility. Returns true if successful. /// </summary> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> public bool Check() { bool retVal = true; string source = string.Empty; int i = 0; do { i++; foreach (string machine in new List <string>(RemoteList.Keys)) { if (RemoteList[machine] != RemoteStatus.Unknown && RemoteList[machine] != RemoteStatus.Error) { CDFMonitor.LogOutputHandler(string.Format("Check: skipping machine {0} because of cached state: {1}", machine, RemoteList[machine])); continue; } source = "\\\\" + machine + "\\admin$\\cdfmonitor"; CDFMonitor.LogOutputHandler("Check: processing machine:" + machine + " state:" + RemoteList[machine].ToString()); WMIServicesManager wmi; RemoteStatus rs = RemoteStatus.Error; if (Ping(machine) && (wmi = new WMIServicesManager(machine, _creds)) != null && wmi.Status ) { if (wmi.IsServiceInstalled(Resources.ServiceName) == WMIServicesManager.ReturnValue.False) { rs = RemoteStatus.UnDeployed; } else { wmi.ShowProperties(Resources.ServiceName); rs = CheckServiceState(wmi); } RemoteList[machine] = rs; } else { CDFMonitor.LogOutputHandler("Fail:Check: unsuccessful."); RemoteList[machine] = RemoteStatus.Error; retVal = false; } if (!CheckProgress(false, machine, i)) { return(retVal); } } }while ((RemoteList.Count(v => (v.Value == RemoteStatus.Unknown | v.Value == RemoteStatus.Error)) != 0) && CheckProgress(true, string.Empty, i)); CDFMonitor.LogOutputHandler("Check: exit:" + retVal); return(retVal); }