public static void Start(string serviceFilePath) { if (String.IsNullOrEmpty(serviceFilePath)) { throw new NullReferenceException("invalid filename"); } if (!File.Exists(serviceFilePath)) { throw new FileNotFoundException(serviceFilePath + " not found"); } string serviceFileName = IO.GetFilename(serviceFilePath); string serviceName = StringHelper.TrimEnd(serviceFileName, IO.GetFileExtension(serviceFilePath).Length + 1); ShellResults results = Shell.Run(IO.System32 + @"net.exe", "START " + serviceName); if (results.ExitCode != Shell.EXIT_OK) { if (!String.IsNullOrEmpty(results.Output)) { ConsoleHelper.DebugWriteLine("output: " + results.Output); } if (!String.IsNullOrEmpty(results.Error)) { ConsoleHelper.DebugWriteLine("output: " + results.Error); } throw new Exception("Failed to start " + serviceName); } }
public static bool SetProperty(svnInfo repo, string name, int revision, string newValue) { if (String.IsNullOrEmpty(name)) { throw new NullReferenceException("property name not specified"); } if (revision <= 0 || revision > repo.Revision) { throw new ArgumentOutOfRangeException("invalid revision"); } ShellResults result = Subversion.Run("propset " + name + " -r " + revision.ToString() + " " + newValue + " " + repo.RepositoryRoot); return(result.ExitCode == Shell.EXIT_OK); }
public static List <SubversionLog> GetLog(svnInfo repo) { List <SubversionLog> list = new List <SubversionLog>(); ShellResults result = Shell.Run(singleton.svnPath, "log " + repo.RepositoryRoot); foreach (string logEntry in Regex.Split(result.Output, new String('-', 72))) { string entry = logEntry.TrimWhiteSpace(); if (!String.IsNullOrEmpty(entry)) { list.Add(new SubversionLog(repo, entry)); } } list.Sort(); return(list); }
public static svnInfo ReadURL(string RepositoryURL) { ShellResults result = Subversion.Run("info " + RepositoryURL); svnInfo info = new svnInfo(); if (result.ExitCode == Shell.EXIT_OK) { info.NodeFound = true; info.WorkingCopyPath = null; info.WorkingCopyRootPath = null; info.Repository = StringHelper.RegexFindString(result.Output, "URL:(.+)\n"); info.RepositoryRoot = StringHelper.RegexFindString(result.Output, "Repository Root:(.+)\n"); info.Revision = int.Parse(StringHelper.RegexFindString(result.Output, "Revision:(.+)\n")); } else { info.NodeFound = false; } return(info); }
public static void Uninstall(string dotNetVersion, string serviceFilePath) { if (String.IsNullOrEmpty(serviceFilePath)) { throw new NullReferenceException("invalid filename"); } if (!File.Exists(serviceFilePath)) { throw new FileNotFoundException(serviceFilePath + " not found"); } string serviceFileName = IO.GetFilename(serviceFilePath); string serviceName = StringHelper.TrimEnd(serviceFileName, IO.GetFileExtension(serviceFilePath).Length + 1); string dotNetFolder = IO.FindDotNetFolder(dotNetVersion); string installUtil = IO.FindFile(dotNetFolder, "Installutil.exe"); ShellResults results = Shell.Run(installUtil, "/u " + IO.GetFilename(serviceFilePath), IO.GetRoot(serviceFilePath)); if (results.ExitCode != Shell.EXIT_OK) { throw new Exception("Failed to uninstall " + serviceName); } }
public static ShellResults Run(string applicationFilePath, string arguments, string workingDirectory, bool elevatedRights) { if (String.IsNullOrEmpty(applicationFilePath)) { throw new NullReferenceException("application filename was not specified"); } if (String.IsNullOrEmpty(arguments)) { arguments = ""; } if (string.IsNullOrEmpty(workingDirectory)) { throw new NullReferenceException("working directory was not specified"); } if (!File.Exists(applicationFilePath)) { throw new FileNotFoundException("application filename not found"); } if (!Directory.Exists(workingDirectory)) { throw new DirectoryNotFoundException("working directory not found"); } Stopwatch applicationExecutionTime = new Stopwatch(); applicationExecutionTime.Start(); ShellResults results = new ShellResults(); results.Filename = applicationFilePath; results.Arguments = arguments; results.WorkingPath = workingDirectory; Process shell = new Process(); shell.StartInfo.FileName = applicationFilePath; if (elevatedRights) { shell.StartInfo.Verb = "runas"; } shell.StartInfo.Arguments = arguments; shell.StartInfo.UseShellExecute = false; shell.StartInfo.RedirectStandardOutput = true; shell.StartInfo.RedirectStandardError = true; shell.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; shell.StartInfo.CreateNoWindow = true; shell.StartInfo.WorkingDirectory = workingDirectory; try { shell.Start(); } catch (Win32Exception) { //Do nothing. the user canceled the UAC window } results.Output = shell.StandardOutput.ReadToEnd(); results.Error = shell.StandardError.ReadToEnd(); shell.WaitForExit(); results.ExitCode = shell.ExitCode; applicationExecutionTime.Stop(); results.ElapsedMilliseconds = applicationExecutionTime.ElapsedMilliseconds; return(results); }
public static ShellResults Run(string applicationFilePath, string arguments, string workingDirectory, bool elevatedRights) { if (String.IsNullOrEmpty(applicationFilePath)) { throw new NullReferenceException("application filename was not specified"); } if (String.IsNullOrEmpty(arguments)) { arguments = ""; } if (string.IsNullOrEmpty(workingDirectory)) { throw new NullReferenceException("working directory was not specified"); } if (!File.Exists(applicationFilePath)) { throw new FileNotFoundException("application filename not found"); } if (!Directory.Exists(workingDirectory)) { throw new DirectoryNotFoundException("working directory not found"); } Stopwatch applicationExecutionTime = new Stopwatch(); applicationExecutionTime.Start(); ShellResults results = new ShellResults(); results.Filename = applicationFilePath; results.Arguments = arguments; results.WorkingPath = workingDirectory; Process shell = new Process(); shell.StartInfo.FileName = applicationFilePath; if (elevatedRights) shell.StartInfo.Verb = "runas"; shell.StartInfo.Arguments = arguments; shell.StartInfo.UseShellExecute = false; shell.StartInfo.RedirectStandardOutput = true; shell.StartInfo.RedirectStandardError = true; shell.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; shell.StartInfo.CreateNoWindow = true; shell.StartInfo.WorkingDirectory = workingDirectory; try { shell.Start(); } catch (Win32Exception) { //Do nothing. the user canceled the UAC window } results.Output = shell.StandardOutput.ReadToEnd(); results.Error = shell.StandardError.ReadToEnd(); shell.WaitForExit(); results.ExitCode = shell.ExitCode; applicationExecutionTime.Stop(); results.ElapsedMilliseconds = applicationExecutionTime.ElapsedMilliseconds; return results; }