private List <PingItem> FetchMessages(int maximumMessagesToFetch) { string queueName = RoleEnvironment.GetConfigurationSettingValue("ProcessQueueName"); CloudQueue queue = storageAccount.CreateCloudQueueClient().GetQueueReference(queueName); var messages = queue.GetMessages(maximumMessagesToFetch); List <PingItem> itemsToBeProcessed = new List <PingItem>(); foreach (var message in messages) { itemsToBeProcessed.Add(PingItem.ParseFromString(message.AsString)); queue.DeleteMessage(message); } return(itemsToBeProcessed); }
private PingResult FetchUrl(PingItem item) { DateTime startDateTime = DateTime.UtcNow; TimeSpan elapsedTime = TimeSpan.FromSeconds(0); string statusCode = ""; long contentLength = 0; try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(item.Url); req.Timeout = 30 * 1000;//Let's timeout the request in 30 seconds. req.Method = "GET"; using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse()) { DateTime endDateTime = DateTime.UtcNow; elapsedTime = new TimeSpan(endDateTime.Ticks - startDateTime.Ticks); statusCode = resp.StatusCode.ToString(); contentLength = resp.ContentLength; } } catch (WebException webEx) { DateTime endDateTime = DateTime.UtcNow; elapsedTime = new TimeSpan(endDateTime.Ticks - startDateTime.Ticks); statusCode = webEx.Status.ToString(); } return(new PingResult() { PartitionKey = DateTime.UtcNow.Ticks.ToString("d19"), RowKey = item.RowKey, Url = item.Url, StatusCode = statusCode, ContentLength = contentLength, TimeTaken = elapsedTime.TotalMilliseconds, }); }