FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 70368ab9 authored by Dr Adam Thorn's avatar Dr Adam Thorn
Browse files

Add WpkgInstaller.RunWpkgSync() method

parent 0047227b
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
using System.ServiceProcess;
using System.Diagnostics;
using System;
using System.Threading;
namespace WpkgInstaller
{
......@@ -81,6 +82,56 @@ namespace WpkgInstaller
eventLog.WriteEntry("Service stopped", EventLogEntryType.Information);
}
private void RunWpkgSync()
{
eventLog.WriteEntry("Starting sync", EventLogEntryType.Information);
Thread thWorker = new Thread(new ThreadStart(delegate
{
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo()
{
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
FileName = Environment.GetEnvironmentVariable("comspec"),
Arguments = "/C \\\\wpkg.ch.cam.ac.uk\\wpkg\\wpkg.cmd /synchronize",
WorkingDirectory = Environment.GetEnvironmentVariable("temp"),
UseShellExecute = false,
};
process.StartInfo = startInfo;
process.EnableRaisingEvents = true;
process.OutputDataReceived += WriteDataToLog;
process.ErrorDataReceived += WriteDataToLog;
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
String msg = String.Format("sync done with exit code {0}", process.ExitCode);
eventLog.WriteEntry(msg, EventLogEntryType.Information);
}));
thWorker.Start();
}
private void WriteDataToLog(object sendingProcess, DataReceivedEventArgs e)
{
if (e != null)
{
eventLog.WriteEntry(e.Data, EventLogEntryType.Information);
}
}
private void eventLog_EntryWritten(object sender, System.Diagnostics.EntryWrittenEventArgs e)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment