From 2f2b58e130194b2e42ef9f2b13d1fa164fa4d48b Mon Sep 17 00:00:00 2001 From: Virtuworks Date: Sun, 8 Jun 2014 17:44:26 -0400 Subject: [PATCH] Add Execute Commands for HandheldCleanup --- .../BlackBerry5Provider.cs | 18 +----- .../BlackBerryProvider.cs | 56 ++++++++++++++++++- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/BlackBerry5Provider.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/BlackBerry5Provider.cs index 667e7dc3..4e0b947f 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/BlackBerry5Provider.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/BlackBerry5Provider.cs @@ -47,20 +47,6 @@ namespace WebsitePanel.Providers.HostedSolution return ProviderSettings[Constants.UserName]; } } - public string HandheldcleanupPath - { - get - { - return ProviderSettings[Constants.HandheldcleanupPath]; - } - } - public string MAPIProfile - { - get - { - return ProviderSettings[Constants.MAPIProfile]; - } - } public override string[] Install() { @@ -124,7 +110,7 @@ namespace WebsitePanel.Providers.HostedSolution //run handheldcleanup.exe if (File.Exists(file2)) { - string serverfilename = Path.Combine(HandheldcleanupPath, "servername.txt"); + string serverfilename = "servername.txt"; string arguments2 = string.Format("-u -p {0} < {1}", MAPIProfile, @@ -133,7 +119,7 @@ namespace WebsitePanel.Providers.HostedSolution { string output; - int exitCode = Execute(file2, arguments2, out output); + int exitCode = Execute2(file2, arguments2, out output); if (exitCode == 0) { Log.WriteInfo(output); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/BlackBerryProvider.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/BlackBerryProvider.cs index 44ba70f4..cc0d37d9 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/BlackBerryProvider.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/BlackBerryProvider.cs @@ -50,7 +50,20 @@ namespace WebsitePanel.Providers.HostedSolution return ProviderSettings[Constants.UtilityPath]; } } - + public string HandheldcleanupPath + { + get + { + return ProviderSettings[Constants.HandheldcleanupPath]; + } + } + public string MAPIProfile + { + get + { + return ProviderSettings[Constants.MAPIProfile]; + } + } public string Password { get @@ -172,6 +185,47 @@ namespace WebsitePanel.Providers.HostedSolution return res; } + protected int Execute2(string file, string arguments, out string output, out string error) + { + string oldDir = Directory.GetCurrentDirectory(); + Directory.SetCurrentDirectory(HandheldcleanupPath); + ProcessStartInfo startInfo = new ProcessStartInfo(file, arguments); + + startInfo.RedirectStandardError = true; + startInfo.RedirectStandardOutput = true; + startInfo.UseShellExecute = false; + startInfo.CreateNoWindow = true; + startInfo.WindowStyle = ProcessWindowStyle.Hidden; + + Process proc = Process.Start(startInfo); + + if (proc == null) + throw new ApplicationException("Proc is null."); + + StreamReader outputReader = proc.StandardOutput; + output = outputReader.ReadToEnd(); + + StreamReader errorReader = proc.StandardError; + error = errorReader.ReadToEnd(); + + Directory.SetCurrentDirectory(oldDir); + return proc.ExitCode; + } + + protected int Execute2(string file, string arguments, out string output) + { + Log.WriteInfo(file); + Log.WriteInfo(arguments); + + string outputData; + string errorData; + int res = Execute2(file, arguments, out outputData, out errorData); + + output = outputData.Length > 0 ? "Output stream:" + outputData : string.Empty; + output += errorData.Length > 0 ? "Error stream:" + errorData : string.Empty; + + return res; + } public ResultObject DeleteBlackBerryUser(string primaryEmailAddress) {