Esempio n. 1
0
        /// <summary>
        /// Create EA backup data in Azure Blob Storage.
        /// </summary>
        /// <param name="filteredRecords">List of billing records of EA.</param>
        /// <param name="filename">File name for blob storage.</param>
        /// <returns>Uri of the blob.</returns>
        private static string UpdateEaRecordsInAzureStorage(List <BillingDetailLineItem> filteredRecords, string filename)
        {
            Console.WriteLine("Taking backup on Azure..");

            // connect to the storage account:
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                ConfigurationManager.AppSettings["StorageConnectionString"]);

            // Retrieve storage account from connection string.

            // Create the blob client.
            CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container  = blobClient.GetContainerReference("billingdata");

            container.CreateIfNotExists();

            container.SetPermissions(new BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            int    idstarter = 0;
            string resp      = Path.GetTempPath() + "csvtep.txt";

            //// TODO: change naming convention once web api is converted to accepted params
            //// string cont = subscription.Id + "\\" + stdate.Year.ToString() + "\\" + stdate.ToString("MM");
            //// string flname = cont + "\\" + stdate.ToString("MMMM") + "From" + stdate.AddDays(-stdate.Day + 1).ToString("dd") + "To" + stdate.ToString("dd") + ".csv";

            string idval;

            // Create the container if it doesn't already exist.
            using (CsvFileWriter writer = new CsvFileWriter(resp))
            {
                foreach (var rcd in filteredRecords)
                {
                    CsvRow row = new CsvRow();

                    if (rcd != null)
                    {
                        idstarter = idstarter + 1;
                        idval     = idstarter.ToString(CultureInfo.InvariantCulture);
                        row.Add(string.Format(CultureInfo.InvariantCulture, "CultureInfo.InvariantCulture, {0}", idval));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.AccountName));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.AccountOwnerId));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.AdditionalInfo));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.Component));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.CostCenter));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.Date.ToString()));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.Day.ToString()));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.DepartmentName));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.DownloadUrl));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ExtendedCost));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "CultureInfo.InvariantCulture, {0}", rcd.Key));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.Month.ToString()));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.Product));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ResourceGUID));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ResourceKey));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ResourceQtyConsumed));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ResourceRate));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.Service));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ServiceAdministratorId));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ServiceInfo));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ServiceInfo1));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ServiceInfo2));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ServiceRegion));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ServiceResource));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ServiceSubRegion));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.ServiceType));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.StoreServiceIdentifier));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.SubscriptionGuid));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.SubscriptionId));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.SubscriptionName));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.Tags));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", rcd.Year.ToString()));

                        writer.WriteRow(row);
                    }
                }
            }

            CloudBlockBlob blockBlob = container.GetBlockBlobReference(filename);

            //// using (var fileStream = System.IO.File.OpenRead(@"WriteTest.csv"))

            using (var fileStream = System.IO.File.OpenRead(resp))
            {
                blockBlob.UploadFromStream(fileStream);
            }

            return(blockBlob.SnapshotQualifiedUri.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Create user backup data in Azure Blob Storage
        /// </summary>
        /// <param name="billingRecordsFromApi">records returned from API</param>
        /// <returns>Uri of the blob</returns>
        internal static string UpdateRecordsInAzureStorage(IList <UsageInfoModel> billingRecordsFromApi)
        {
            // connect to the storage account:
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                ConfigurationManager.AppSettings["StorageConnectionString"]);
            // Retrieve storage account from connection string.
            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();


            CloudBlobContainer container = blobClient.GetContainerReference("billingdata");

            container.CreateIfNotExists();

            container.SetPermissions(new BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            int    idstarter = 0;
            string resp      = Path.GetTempPath() + "csvtep.txt";

            string flname = "UsageData_" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" +
                            DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + ".csv";

            // TODO: change naming convention once web api is converted to accepted params
            // string cont = subscription.Id + "\\" + stdate.Year.ToString() + "\\" + stdate.ToString("MM");
            // string flname = cont + "\\" + stdate.ToString("MMMM") + "From" + stdate.AddDays(-stdate.Day + 1).ToString("dd") + "To" + stdate.ToString("dd") + ".csv";

            string idval;

            // Create the container if it doesn't already exist.
            using (CsvFileWriter writer = new CsvFileWriter(resp))
            {
                foreach (var usg in billingRecordsFromApi)
                {
                    CsvRow row = new CsvRow();

                    if (usg != null)
                    {
                        idstarter = idstarter + 1;
                        idval     = idstarter.ToString(CultureInfo.InvariantCulture);
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", idval));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.SubceriptionId));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.MeterName));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.MeteredRegion));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.MeterCategory));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.MeterSubCategory));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.UsageStartTime));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.UsageEndTime));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.MeteredService));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.MeteredServiceType));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.UserProject));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.Quantity.ToString()));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ItemTotal.ToString()));

                        writer.WriteRow(row);
                    }
                }
            }
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(flname);

            // using (var fileStream = System.IO.File.OpenRead(@"WriteTest.csv"))

            using (var fileStream = System.IO.File.OpenRead(resp))
            {
                blockBlob.UploadFromStream(fileStream);
            }

            return(blockBlob.SnapshotQualifiedUri.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// Creating backup of data collected in azure storage blob.
        /// </summary>
        /// <param name="billingRecords">Records of CSP billing.</param>
        /// <param name="blobFilename">Name of blob file.</param>
        /// <returns>Uri of the blob written data to.</returns>
        internal static string UpdateCspSummaryRecordsInAzureStorage(List <UsageBasedLineItem> billingRecords, string blobFilename)
        {
            //// connect to the storage account:
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                ConfigurationManager.AppSettings["StorageConnectionString"]);
            //// Retrieve storage account from connection string.
            //// Create the blob client.
            CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container  = blobClient.GetContainerReference("billingcspdata");

            container.CreateIfNotExists();

            container.SetPermissions(new BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            int    idstarter = 0;
            string resp      = Path.GetTempPath() + "csvtep.txt";

            //// TODO: change naming convention once web api is converted to accepted params
            //// string cont = subscription.Id + "\\" + stdate.Year.ToString() + "\\" + stdate.ToString("MM");
            //// string blobFilename = cont + "\\" + stdate.ToString("MMMM") + "From" + stdate.AddDays(-stdate.Day + 1).ToString("dd") + "To" + stdate.ToString("dd") + ".csv";

            string idval;

            // Create the container if it doesn't already exist.
            using (CsvFileWriter writer = new CsvFileWriter(resp))
            {
                foreach (var usg in billingRecords)
                {
                    CsvRow row = new CsvRow();
                    if (usg != null)
                    {
                        idstarter = idstarter + 1;
                        idval     = idstarter.ToString(CultureInfo.InvariantCulture);
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", idval));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.Attributes));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.BillingProvider));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ChargeEndDate));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ChargeStartDate));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ChargeType));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ConsumedQuantity));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ConsumptionDiscount));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ConsumptionPrice));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.Currency));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.CustomerCompanyName));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.DetailLineItemId));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.IncludedQuantity));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.InvoiceLineItemType));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.InvoiceNumber));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ListPrice));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.MpnId));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.OrderId));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.OverageQuantity));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.PartnerBillableAccountId));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.PartnerId));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.PartnerName));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.PostTaxEffectiveRate));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.PostTaxTotal));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.PretaxCharges));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.PretaxEffectiveRate));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.Region));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ResourceGuid));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ResourceName));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ServiceName));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.ServiceType));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.Sku));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.SubscriptionDescription));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.SubscriptionId));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.SubscriptionName));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.TaxAmount));
                        row.Add(string.Format(CultureInfo.InvariantCulture, "{0}", usg.Tier2MpnId));

                        writer.WriteRow(row);
                    }
                }
            }

            CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobFilename);

            //// using (var fileStream = System.IO.File.OpenRead(@"WriteTest.csv"))
            using (var fileStream = System.IO.File.OpenRead(resp))
            {
                blockBlob.UploadFromStream(fileStream);
            }

            return(blockBlob.SnapshotQualifiedUri.ToString());
        }