public StatusDialog UpdateApplication(EventWaitHandle asyncHandle) { var feedManager = new FeedManager(this.publicKey); var newVersions = feedManager.GetNewVersions(feedUrl, this.context.ApplicationVersion); if (dialog == null) { this.dialog = new StatusDialog(); this.dialog.AppTitle = this.context.ApplicationTitle; this.dialogAdapter = new StatusDialogAdapter(dialog); } worker = new UpdateWorker( () => { var downloadManager = new DownloadManager(this.context, dialogAdapter); var files = downloadManager.DownloadFiles(newVersions); var installer = new InstallationManager(this.context, new TraceLogger()); foreach (var file in files.OrderBy(f => f.Key)) { installer.Install(file.Value, file.Key); } }); worker.WorkCompleted += (object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) => { if (dialog != null) { dialog.Close(); dialog.Dispose(); dialogAdapter = null; dialog = null; } if (asyncHandle != null) { asyncHandle.Set(); } }; worker.Start(); return(this.dialog); }
public void RestartListeners() { if (listeners == null) { return; } StatusDialog d = new StatusDialog(); new Thread(delegate() { d.SetStatus("Restarting listeners..."); EventLogger.LogEvent("Restarting", "Listeners are restarting"); foreach (Listener l in listeners) { l.Stop(); } listeners.Clear(); for (int i = 0; i < Settings.Ports.Count; i++) { Listener l = new Listener(); int port = Settings.Ports[i]; if (l.Listen(port)) { l.SocketAccepted += listener_SocketAccepted; EventLogger.LogEvent("Listening", "Successfully listening on port " + port.ToString()); } else { EventLogger.LogEvent("Listening Failed", "Unable to listen on port " + port.ToString()); } if (l.Running) { listeners.Add(l); } } Invoke((MethodInvoker) delegate { d.Close(); }); }).Start(); d.ShowDialog(); }
void listen() { if (listeners == null) { listeners = new List <Listener>(); Clients = new List <Client>(); foreach (int port in Settings.Ports) { Listener l = new Listener(); if (l.Listen(port)) { l.SocketAccepted += listener_SocketAccepted; EventLogger.LogEvent("Listening", "Successfully listening on port " + port.ToString()); } else { EventLogger.LogEvent("Listening Failed", "Unable to listen on port " + port.ToString()); } if (l.Running) { listeners.Add(l); } } EventLogger.LogEvent("Started", "Net-Weave R has been started"); startToolStripMenuItem.Text = startToolStripMenuItem.Text.Replace("Listen", "Stop"); Pinger.Start(ref Clients); } else { Pinger.Stop(); StatusDialog d = new StatusDialog(); d.SetStatus("Stopping Listeners..."); new Thread(delegate() { foreach (Listener l in listeners) { if (l.Running) { l.SocketAccepted -= listener_SocketAccepted; l.Stop(); EventLogger.LogEvent("Listening Stopped", "The listener for port " + l.Port + " has been stopped"); } } Restart(); d.SetStatus("Disconnecting Clients..."); if (Clients.Count > 0) { for (int i = 0; i < Clients.Count; i++) { Clients[i].DataReceived -= client_DataReceived; Clients[i].DataSent -= client_DataSent; Clients[i].Disconnected -= client_Disconnected; Clients[i].Close(); } } listeners.Clear(); listeners = null; Clients.Clear(); Clients = null; Invoke((MethodInvoker) delegate { EventLogger.LogEvent("Stopped", "Net-Weave R has been stopped"); startToolStripMenuItem.Text = startToolStripMenuItem.Text.Replace("Stop", "Listen"); lstClients.Items.Clear(); d.Close(); }); }).Start(); d.ShowDialog(); } }