Beispiel #1
0
        private async Task <SiteStatusResult> CheckSite(MonitoredSite site)
        {
            var status = new SiteStatusResult {
                SiteId = site.Id, Url = site.Url
            };

            var client = new WebClient();

            var response = await client.DownloadStringTaskAsync(site.Url).ContinueWith(async(t) =>
            {
                status.Status = t.IsFaulted
                    ? SiteStatus.Down.ToString()
                    : SiteStatus.Up.ToString();

                // put the URL onto the queue if the site is online
                if (!t.IsFaulted)
                {
                    var account = CloudStorageAccount.DevelopmentStorageAccount;
                    var queue   = account.CreateCloudQueueClient().GetQueueReference("incoming");
                    queue.CreateIfNotExists();
                    queue.AddMessage(new CloudQueueMessage(status.Url));
                }
            });

            return(status);
        }
Beispiel #2
0
        private async Task <SiteStatusResult> CheckSite(MonitoredSite site)
        {
            var status = new SiteStatusResult {
                SiteId = site.Id, Url = site.Url
            };

            var client = new WebClient();

            var response = await client.DownloadStringTaskAsync(site.Url).ContinueWith(async(t) =>
            {
                status.Status = t.IsFaulted
                    ? SiteStatus.Down.ToString()
                    : SiteStatus.Up.ToString();
            });

            return(status);
        }
Beispiel #3
0
        private async Task <SiteStatusResult> CheckSite(MonitoredSite site)
        {
            var status = new SiteStatusResult {
                SiteId = site.Id, Url = site.Url
            };

            var client = new WebClient();

            var response = await client.DownloadStringTaskAsync(site.Url).ContinueWith(async(t) =>
            {
                status.Status = t.IsFaulted
                    ? SiteStatus.Down.ToString()
                    : SiteStatus.Up.ToString();

                // put the URL onto the queue if the site is online
                //if (!t.IsFaulted)
                //{
                //    var account = CloudStorageAccount.DevelopmentStorageAccount;
                //    var queue = account.CreateCloudQueueClient().GetQueueReference("incoming");
                //    queue.CreateIfNotExists();
                //    queue.AddMessage(new CloudQueueMessage(status.Url));
                //}

                // send the results to the service bus
                var connectionString =
                    ConfigurationManager
                    .AppSettings["serviceBusConnectionString"];

                ServiceBusHelper.ServiceBus
                .Setup(connectionString, "sitemonitr")
                .Publish <SitePingResult>(new SitePingResult
                {
                    Id        = site.Id,
                    Url       = site.Url,
                    Status    = status.Status,
                    TimeStamp = DateTime.Now
                });
            });

            return(status);
        }