private void btnSelfTesting_Click(object sender, RoutedEventArgs e) { try { RMS.Agent.BSL.Monitoring.MonitoringService ms = new RMS.Agent.BSL.Monitoring.MonitoringService(); var deviceStatuses = ms.SelfMonitoring(txtSelfTesting_ClientCode.Text); dtgSelfTestingResult.ItemsSource = deviceStatuses; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
private void dispatcherTimer_Tick(object sender, EventArgs e) { try { #region Try to Check Watchdog Process if (watchdogWakeUp) { try { string watchdogProcessName = ConfigurationManager.AppSettings["RMS.WatchdogProcessName"] ?? "RMS.Agent.Watchdog"; if (!IsProcessRunning(watchdogProcessName)) { Process.Start(ConfigurationManager.AppSettings["RMS.WatchdogFilePath"] ?? @"D:\App\RMS.Agent.Watchdog\RMS.Agent.Watchdog.exe"); } } catch (Exception ex) { new RMSAppException(this, "500", "Check Watchdog Process failed. " + ex.Message, ex, true); } } #endregion if (File.Exists(maFilePath)) { if (currentStateOnServer != "Maintenance") { ReloadLocalConfiguration(); MonitoringService ms = new MonitoringService(); if (ms.SetMonitoringState(clientCode, ClientState.Maintenance)) { currentStateOnServer = "Maintenance"; } else { currentStateOnServer = "N/A"; } } lblState.Content = "Maintenance"; } else { if (currentStateOnServer != "Normal") { ReloadLocalConfiguration(); MonitoringService ms = new MonitoringService(); if (ms.SetMonitoringState(clientCode, ClientState.Normal)) { currentStateOnServer = "Normal"; } else { currentStateOnServer = "N/A"; } } lblState.Content = "Normal"; } if (processingTempEvent) { return; } try { processingTempEvent = true; lock (AgentService._lock) { if (File.Exists(tempEventFile)) { string strResultList = string.Empty; using (FileStream fs = File.OpenRead(tempEventFile)) { using (TextReader tr = new StreamReader(fs)) { strResultList = tr.ReadToEnd(); tr.Close(); } fs.Close(); } if (!string.IsNullOrEmpty(strResultList)) { try { logs.AddRange(Serializer.XML.DeserializeObject <ListEventLogs>(strResultList)); } catch { } finally { File.Delete(tempEventFile); dgLogs.ItemsSource = null; dgLogs.ItemsSource = logs; } } } } } catch (Exception ex) { throw new RMSAppException(this, "0500", "Import tempEventFile failed. " + ex.Message, ex, false); } finally { processingTempEvent = false; } } catch (Exception ex) { new RMSAppException(this, "0500", "dispatcherTimer_Tick failed. " + ex.Message, ex, true); } finally { try { string strResultList = Serializer.XML.SerializeObject(logs); using (TextWriter tw = new StreamWriter(historyFile, false)) // Create & open the file { tw.Write(strResultList); tw.Close(); } } catch (Exception ex) { new RMSAppException(this, "0500", "Saving History Log failed. " + ex.Message, ex, true); } } }