void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            Timer.Stop();

            using (var db = new SiteMonitRContext())
            {
                var sites = db.MonitoredSites;

                foreach (var site in sites)
                {
                    var result = new SiteStatusResult
                    {
                        SiteId = site.Id,
                        Url = site.Url,
                        Status = "Checking"
                    };

                    Clients.All.receiveSiteStatus(result);

                    try
                    {
                        new WebClient().DownloadString(site.Url);
                        result.Status = SiteStatus.Up.ToString();
                    }
                    catch
                    {
                        result.Status = SiteStatus.Down.ToString();
                    }

                    Clients.All.receiveSiteStatus(result);
                }
            }

            Timer.Start();
        }
        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;
        }
        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;
        }
        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;
        }