static int GetSnapshotCount(ref DateTimeOffset?mostRecentlyUpdatedAt)
        {
            var valetKeyUrl    = ConfigurationManager.AppSettings["BlobValetKeyUrl"];
            var destinationUrl = ConfigurationManager.AppSettings["BlobDestinationUrl"];
            var blob           = BlobContainerValet.GetCloudBlockBlob(valetKeyUrl, new Uri(destinationUrl));

            var blobRequestOptions = new BlobRequestOptions();
            var snapCount          = 0;

            mostRecentlyUpdatedAt = null;
            foreach (CloudBlockBlob b in blob.Container.ListBlobs(useFlatBlobListing: true, blobListingDetails: BlobListingDetails.Snapshots))
            {
                snapCount++;
                if (mostRecentlyUpdatedAt.HasValue)
                {
                    if (mostRecentlyUpdatedAt.Value < b.SnapshotTime)
                    {
                        mostRecentlyUpdatedAt = b.SnapshotTime;
                    }
                }
                else
                {
                    mostRecentlyUpdatedAt = b.SnapshotTime;
                }
            }

            return(snapCount);
        }
        static bool WriteToBlobIfChanged(Uri blobUri, string thumbprint, byte[] contents)
        {
            Console.Write("[thumbprint = {0} ... ", thumbprint);

            var valetKeyUrl    = ConfigurationManager.AppSettings["BlobValetKeyUrl"];
            var destinationUrl = ConfigurationManager.AppSettings["BlobDestinationUrl"];


            var blob = BlobContainerValet.GetCloudBlockBlob(valetKeyUrl, new Uri(destinationUrl));

            try
            {
                blob.FetchAttributes();
            }
            catch (Microsoft.WindowsAzure.Storage.StorageException ex)
            {
                // if (Enum.GetName(typeof(RequestResult), ex.RequestInformation.HttpStatusCode) == HttpStatusCode.NotFound))
                if (ex.RequestInformation.HttpStatusCode == Convert.ToInt32(HttpStatusCode.NotFound))
                {
                    // write it the first time
                    WriteBlob(blobUri, thumbprint, contents);
                    Console.WriteLine(" (created)");
                    return(true);
                }
                else
                {
                    throw;
                }
            }
            var oldthumbprint = blob.Metadata["thumbprint"];

            if (oldthumbprint != thumbprint)
            {
                Console.Write("Change detected: {0}... ", DateTime.Now.ToLongTimeString()); // TODO: DateTimeOffset

                var snapshot = blob.CreateSnapshot();
                WriteBlob(blobUri, thumbprint, contents);

                Console.WriteLine("updated.");
                return(true);
            }
            else
            {
                Console.WriteLine("No change at {0}...", DateTime.Now.ToLongTimeString());
                return(false);
            }
        }