public async Task Execute(IJobExecutionContext context) { var response = new Response { Date = DateTime.Now, OrderId = context.JobDetail.JobDataMap.GetInt("Id"), Type = "server" }; try { var ping = new Ping(); var pingReply = await ping.SendPingAsync(context.JobDetail.JobDataMap.GetString("TargetAddress")); response.Content = "{" + System.Environment.NewLine + "\"Status\": " + "\"" + pingReply.Status.ToString() + "\"" + "," + System.Environment.NewLine + "\"Latency\": " + pingReply.RoundtripTime.ToString() + Environment.NewLine + "}"; } catch (PingException e) { response.Content = "{" + System.Environment.NewLine + "\"Status\": " + "\"" + "Failure" + "\"" + "," + System.Environment.NewLine + "\"Latency\": " + "0" + Environment.NewLine + "}"; } finally { Debug.WriteLine(response.Content); await responseService.AddResponseToDb(response); } }
public async Task Execute(IJobExecutionContext context) { var response = new Response { Date = DateTime.Now, OrderId = context.JobDetail.JobDataMap.GetInt("Id"), Type = "html" }; try { using (WebClient client = new WebClient()) { string url = context.JobDetail.JobDataMap.GetString("TargetAddress"); string content = await client.DownloadStringTaskAsync(url); if (content.Contains(context.JobDetail.JobDataMap.GetString("Content"))) { response.Content = "{" + Environment.NewLine + "\"Status\":" + "\"Not changed\"" + Environment.NewLine + "}"; } else { response.Content = "{" + Environment.NewLine + "\"Status\":" + "\"Changed\"" + Environment.NewLine + "}"; } } } catch (WebException e) { response.Content = "{" + Environment.NewLine + "\"Status\":" + "\"Failure\"" + Environment.NewLine + "}"; } finally { Debug.WriteLine(response.Content); await responseService.AddResponseToDb(response); } }