private void GatherDataForOneHour()

in SamplesV1/HttpDataDownloaderSample/CustomDotNetActivity/DataDownloader.cs [57:105]


        private void GatherDataForOneHour(string sliceStartTime, string urlFormat)
        {
            Uri storageAccountUri = new Uri("http://" + _dataStorageAccountName + ".blob.core.windows.net/");
            string year = sliceStartTime.Substring(0, 4);
            string month = sliceStartTime.Substring(4, 2);
            string day = sliceStartTime.Substring(6, 2);
            string hour = sliceStartTime.Substring(8, 2);
            string minute = sliceStartTime.Substring(10, 2);
            DateTime dataSlotGathered = new DateTime(int.Parse(year), int.Parse(month), int.Parse(day), int.Parse(hour), int.Parse(minute), 0);

            _logger.Write("Current data slot gathered : {0}.......", dataSlotGathered);

            // Temporary staging folder
            string dataStagingFolder = string.Format(@"{0}\{1}\{1}-{2}", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), year, month);
            Directory.CreateDirectory(dataStagingFolder);

            // Temporary staging file
            string hourlyFileName = string.Format("data-{0}{1}{2}-{3}0000.txt", year, month, day, hour);
            string decompressedFile = Path.Combine(dataStagingFolder, hourlyFileName);

            try
            {
                _logger.Write("Gathering hourly data: ..");
                TriggerRequest(urlFormat, year, month, day, hour, decompressedFile);

                _logger.Write("Uploading to Blob: ..");
                CloudBlobClient blobClient = new CloudBlobClient(storageAccountUri, new StorageCredentials(_dataStorageAccountName, _dataStorageAccountKey));
                string blobPath = string.Format(CultureInfo.InvariantCulture, "httpdownloaddatain/{0}-{1}-{2}-{3}/{4}",
                    year, month, day, hour, hourlyFileName);

                CloudBlobContainer container = blobClient.GetContainerReference(_dataStorageContainer);
                container.CreateIfNotExists();

                var blob = container.GetBlockBlobReference(blobPath);
                blob.UploadFromFile(decompressedFile, FileMode.OpenOrCreate);
            }
            catch (Exception ex)
            {
                _logger.Write("Error occurred : {0}", ex);
                throw;
            }
            finally
            {
                if (File.Exists(decompressedFile))
                {
                    File.Delete(decompressedFile);
                }
            }
        }