Esempio n. 1
0
        public AESFile()
        {
            InitializeComponent();
            usageCheck = new DataUsageCheck();
            config     = new VConfig();

            usage = usageCheck.initData();

            DataContextChanged            += AESFile_DataContextChanged;
            SaltTitle.MouseLeftButtonDown += new MouseButtonEventHandler(SaltTitle_MouseLeftButtonDown);
        }
Esempio n. 2
0
        public void setDataUsage()
        {
            AESUsage hashme;

            usage = usageCheck.initData();

            AESStringUsage = usage.string_usage;
            AESFileUsage   = usage.file_usage;
            hashme         = new AESUsage(usage);
            encryptUsage   = new encryptUsageViewModel(hashme).dataUsage;
            DescText       = "Bạn đã mã hóa " + usage.string_usage + " chuỗi và " + usage.file_usage + " file";
            AESStringDesc  = "Bạn đã mã hóa " + usage.string_usage + " chuỗi trong " + usage.total_usage + " lần";
            AESFileDesc    = "Bạn đã mã hóa " + usage.file_usage + " file trong " + usage.total_usage + " lần";
            AESStringPerc  = Math.Round(((double)usage.string_usage / usage.total_usage * 100), 2) + "%";
            AESFilePerc    = Math.Round(((double)usage.file_usage / usage.total_usage * 100), 2) + "%";
            OnPropertyChanged(nameof(AESStringUsage));
            OnPropertyChanged(nameof(AESFileUsage));
            OnPropertyChanged(nameof(encryptUsage));
            OnPropertyChanged(nameof(DescText));
        }
Esempio n. 3
0
        /// <summary>
        /// Method that process usage pages and places them into a generic list and dictionary by instanceId
        /// </summary>
        /// <param name="usagePage">The usage page</param>
        static void ProcessUsagePage(IPage <UsageDetail> usagePage)
        {
            IEnumerator enumerator = usagePage.GetEnumerator();

            StreamWriter writer = new StreamWriter(@"./cost.csv", false);


            while (enumerator.MoveNext())
            {
                UsageDetail currentDetail = (UsageDetail)enumerator.Current;

                string ConsumedService = currentDetail.ConsumedService.ToString();
                string InstanceName    = currentDetail.InstanceName.ToString();
                string UsageStart      = currentDetail.UsageStart.ToString();
                string UsageEnd        = currentDetail.UsageEnd.ToString();
                string UsageQuantity   = currentDetail.UsageQuantity.ToString();
                string PretaxCost      = currentDetail.PretaxCost.ToString();

                string line1 = ConsumedService + "," + InstanceName + "," + UsageStart + "," + UsageEnd + "," + UsageQuantity + "," + PretaxCost;

                writer.WriteLine(line1);
                Console.WriteLine(line1);

                //Add the usage detail to the list
                usageDetails.Add(currentDetail);

                //Add the usage detail to the dictionary
                if (usageDetailsByInstance.ContainsKey(currentDetail.InstanceId))
                {
                    usageDetailsByInstance[currentDetail.InstanceId].Add(currentDetail);
                }
                else
                {
                    List <UsageDetail> usageDetailsListForResource = new List <UsageDetail>();
                    usageDetailsListForResource.Add(currentDetail);
                    usageDetailsByInstance.Add(currentDetail.InstanceId, usageDetailsListForResource);
                }
            }

            writer.Close();
        }
Esempio n. 4
0
        /// <summary>
        /// Method that process usage pages and places them into a generic list and dictionary by instanceId
        /// </summary>
        /// <param name="usagePage">The usage page</param>
        static void ProcessUsagePage(IPage <UsageDetail> usagePage)
        {
            IEnumerator enumerator = usagePage.GetEnumerator();

            while (enumerator.MoveNext())
            {
                UsageDetail currentDetail = (UsageDetail)enumerator.Current;

                //Add the usage detail to the list
                usageDetails.Add(currentDetail);

                //Add the usage detail to the dictionary
                if (usageDetailsByInstance.ContainsKey(currentDetail.InstanceId))
                {
                    usageDetailsByInstance[currentDetail.InstanceId].Add(currentDetail);
                }
                else
                {
                    List <UsageDetail> usageDetailsListForResource = new List <UsageDetail>();
                    usageDetailsListForResource.Add(currentDetail);
                    usageDetailsByInstance.Add(currentDetail.InstanceId, usageDetailsListForResource);
                }
            }
        }
        private static void ValidateProperties(
            UsageDetail item,
            bool includeMeterDetails         = false,
            bool includeAdditionalProperties = false,
            string expectedBillingPeriodId   = null,
            DateTime?usageStart = null,
            DateTime?usageEnd   = null,
            string instanceName = null)
        {
            Assert.NotNull(item.Name);
            Assert.NotNull(item.Id);
            Assert.NotNull(item.InstanceId);
            Assert.NotNull(item.InstanceName);
            Assert.NotNull(item.InstanceLocation);
            Assert.EndsWith(item.Name, item.Id);
            Assert.NotNull(item.Type);
            Assert.NotNull(item.BillingPeriodId);
            Assert.NotNull(item.Currency);
            Assert.True(item.UsageStart.Value < item.UsageEnd.Value);
            Assert.NotNull(item.MeterId);
            Assert.NotNull(item.IsEstimated);
            Assert.True(item.PretaxCost.Value >= 0);


            if (expectedBillingPeriodId != null)
            {
                Assert.Contains(expectedBillingPeriodId.ToLowerInvariant(), item.BillingPeriodId.ToLowerInvariant());
            }
            else
            {
                Assert.NotNull(item.BillingPeriodId);
            }

            if (usageStart != null && usageEnd != null)
            {
                Assert.True(item.UsageStart.Value >= usageStart);
                Assert.True(item.UsageEnd.Value <= usageEnd);
            }

            if (includeMeterDetails)
            {
                Assert.NotNull(item.MeterDetails);
                Assert.NotNull(item.MeterDetails.MeterName);
                Assert.NotNull(item.MeterDetails.MeterCategory);
                Assert.NotNull(item.MeterDetails.Unit);
            }
            else
            {
                Assert.Null(item.MeterDetails);
            }

            if (!includeAdditionalProperties)
            {
                Assert.Null(item.AdditionalProperties);
            }

            if (instanceName != null)
            {
                Assert.Equal(instanceName, item.InstanceName, ignoreCase: true);
            }
        }
 public static UserHomeViewModel GetUsageDetailsBySubscriptionId(string subscriptionId,
     string subName, string orgId, string accessToken, string currency)
 {
     try
     {
         UserHomeViewModel vm = null;
         List<UsageDetail> usageDetails = null;
         var usagePayLoad = GetUsage(subscriptionId, orgId, accessToken);
         if (usagePayLoad != null && usagePayLoad.value != null && usagePayLoad.value.Count > 0)
         {
             vm = new UserHomeViewModel();
             vm.SubscriptionId = subscriptionId;
             vm.SubscriptionName = subName;
             vm.Currency = currency;
             var rateCard = AzureResourceManagerUtil.GetRatesForSubscription(subscriptionId, accessToken, vm.Currency);
             if (usagePayLoad != null && usagePayLoad.value != null && usagePayLoad.value.Any())
             {
                 usageDetails = new List<UsageDetail>();
                 foreach (var usageAggregate in usagePayLoad.value)
                 {
                     var usageDetail = new UsageDetail();
                     usageDetail.UsageDetailId = usageAggregate.id;
                     usageDetail.SubscriptionId = usageAggregate.properties.subscriptionId;
                     usageDetail.UsageStartTime = usageAggregate.properties.usageStartTime;
                     usageDetail.UsageEndTime = usageAggregate.properties.usageEndTime;
                     usageDetail.MeterId = usageAggregate.properties.meterId;
                     usageDetail.MeterName = usageAggregate.properties.meterName;
                     usageDetail.MeterRegion = usageAggregate.properties.meterRegion;
                     usageDetail.MeterCategory = usageAggregate.properties.meterCategory;
                     usageDetail.Unit = usageAggregate.properties.unit;
                     usageDetail.Region = usageAggregate.properties.infoFields.meteredRegion;
                     usageDetail.Service = usageAggregate.properties.infoFields.meteredService;
                     usageDetail.ResourceName = usageAggregate.properties.infoFields.project;
                     usageDetail.Quantity = (decimal)usageAggregate.properties.quantity;
                     var meter = rateCard.Meters.FirstOrDefault(m => m.MeterId == usageDetail.MeterId);
                     if (meter != null && meter.MeterRates[0] != 0)
                     {
                         usageDetail.Cost = RoundTo2Digits(usageDetail.Quantity * meter.MeterRates[0]);
                         if (usageDetail.Cost > 0)
                         {
                             usageDetail.CostPerUnit = meter.MeterRates[0];
                             usageDetails.Add(usageDetail);
                         }
                     }
                 }
                 vm.UsageDetails = usageDetails;
             }
             vm.UsageByResource = usageDetails.GroupBy(x => x.MeterCategory)
                       .Select(g => new UsageDetail { MeterId = g.Key, Cost = g.Sum(x => x.Cost) })
                       .OrderByDescending(m => m.Cost).ToList();
         }
         return vm;
     }
     catch (Exception ex) { throw ex; }
 }