private void _monitorHandel(Object o) { MonitorModel model = (MonitorModel)o; try { DateTime dt = DateTime.Now; //toLog("------------------------------------------"); //toLog(""); toLog("请求:" + model.host); Uri uri = new Uri(model.host); WebClient webClient = new WebClient(); byte[] byt = webClient.DownloadData(uri); String content = System.Text.Encoding.UTF8.GetString(byt); TimeSpan tm = DateTime.Now - dt; toLog(" 耗时:" + tm.Milliseconds, false); if (content.Contains(model.key)) { return; } showError("未返回指定的内容:" + model.key, model); } catch (Exception ex) { showError("访问异常," + ex.Message, model); } }
private void showError(String msg, MonitorModel model) { toLog(msg); try { Uri uri = new Uri(ConfigModel.getMsgHost() + model.host + msg); WebClient webClient = new WebClient(); byte[] byt = webClient.DownloadData(uri); String content = System.Text.Encoding.UTF8.GetString(byt); LogHelper.Log("发送消息"); } catch (Exception ex) { LogHelper.Log("消息发送异常:" + ex); } /* * msgForm = new MsgForm(model.host + "异常", msg); * msgForm.ShowDialog();//正常 */ showErrorThread = new Thread(new ParameterizedThreadStart(showMsgForm)); MsgModel msgModel = new MsgModel(); msgModel.Name = model.host + "异常"; msgModel.Remark = msg; showErrorThread.Start(msgModel); }
private void monitorHandel() { while (true) { for (int i = 0; i < monitorList.Count; i++) { if (showErrorThread != null && showErrorThread.IsAlive) { //toLog("等待处理中,请稍后..."); i--; continue; } MonitorModel model = monitorList[i]; try { _monitorHandel(model); Thread.Sleep(500); } catch (Exception ex) { } } //toLog("------------------------------------------"); LogHelper.Log("休眠" + ConfigModel.getSleep()); Thread.Sleep(ConfigModel.getSleep()); } }
private async Task ApplyCommandAsync() { MonitorModel model = new MonitorModel { Id = _model.Id, Name = Name, UserId = Settings.UserId, URL = URL, SMSAlert = SMS, PushAlert = Push, }; try { await _monitorService.EditMonitorAsync(model); await DialogService.ShowAlertAsync(AppResources.ChangesApplied, "", AppResources.OK); await NavigationService.PopAsync(); } catch (ServiceAuthenticationException e) { await DialogService.ShowAlertAsync(AppResources.GenericError, AppResources.Error, AppResources.OK); } catch (HttpRequestExceptionEx e) { await DialogService.ShowAlertAsync(AppResources.GenericError, AppResources.Error, AppResources.OK); } catch (Exception e) { await DialogService.ShowAlertAsync(AppResources.GenericError, AppResources.Error, AppResources.OK); } }
async Task addMonitorRequestAsync() { if (!Validate()) { return; } MonitorModel addMonitor = new MonitorModel { Name = Name.Value.Trim(), URL = URL.Value.Trim(), UserId = Settings.UserId, }; try { await _monitorService.AddMonitorAsync(addMonitor); await DialogService.ShowAlertAsync(AppResources.MonitorAdded, AppResources.Added , AppResources.OK); await NavigationService.PopAsync(); } catch (ServiceAuthenticationException e) { await DialogService.ShowAlertAsync(AppResources.GenericError, AppResources.Error, AppResources.OK); } catch (HttpRequestExceptionEx e) { await DialogService.ShowAlertAsync(AppResources.GenericError, AppResources.Error, AppResources.OK); } catch (Exception e) { await DialogService.ShowAlertAsync(AppResources.GenericError, AppResources.Error, AppResources.OK); } }
public async Task <MonitorModel> DeleteMonitorAsync(MonitorModel model) { UriBuilder builder = new UriBuilder(GlobalRoutingSettings.Instance.DeleteMonitor); string uri = builder.ToString(); MonitorModel monitorModel = await _request.PostAsync <MonitorModel>(uri, model); return(monitorModel); }
public async Task <MonitorModel> GetMonitorAsync(MonitorModel model) { UriBuilder builder = new UriBuilder($"{GlobalRoutingSettings.Instance.GetMonitor}/{model.Id}/{model.UserId}"); string uri = builder.ToString(); MonitorModel monitorModel = await _request.GetAsync <MonitorModel>(uri); return(monitorModel); }
public async Task <MonitorModel> AddMonitorAsync(MonitorModel monitor) { UriBuilder builder = new UriBuilder(GlobalRoutingSettings.Instance.AddMonitor); string uri = builder.ToString(); MonitorModel monitorContainer = await _request.PostAsync(uri, monitor); return(monitorContainer); }
private async Task AlertTapCommandAsync(object sender) { MonitorModel monitor = new MonitorModel() { }; MonitorModel editMonitor = await _monitorService.EditMonitorAsync(monitor); await DialogService.ShowAlertAsync(AppResources.Successful, AppResources.Save, AppResources.OK); }
private void getStatus(MonitorModel monitor) { _model = monitor; Name = monitor.Name; URL = monitor.URL; StatusCode = monitor.StatusCode; Description = monitor.Description; SMS = monitor.SMSAlert; Email = monitor.EmailAlert; Push = monitor.PushAlert; }