예제 #1
0
        public UsageRecord(UsageAggregate ua)
        {
            this.uid            = Guid.NewGuid();
            this.tags           = new Dictionary <string, string>();
            this.additionalInfo = new Dictionary <string, string>();

            this.id                 = "";
            this.name               = "";
            this.type               = "";
            this.subscriptionId     = "";
            this.usageStartTime     = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("s", System.Globalization.CultureInfo.InvariantCulture);
            this.usageEndTime       = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("s", System.Globalization.CultureInfo.InvariantCulture);
            this.meterId            = "";
            this.meterName          = "";
            this.meterCategory      = "";
            this.meterSubCategory   = "";
            this.meterRegion        = "";
            this.quantity           = 0.0;
            this.unit               = "";
            this.instanceDataRaw    = "";
            this.meteredRegion      = "";
            this.meteredService     = "";
            this.meteredServiceType = "";
            this.project            = "";
            this.serviceInfo1       = "";
            this.location           = "";
            this.orderNumber        = "";
            this.partNumber         = "";
            this.resourceUri        = "";
            this.cost               = 0.0M;

            bool notNull = true;

            if (notNull)
            {
                try
                {
                    this.id   = ua.id;
                    this.name = ua.name;
                    this.type = ua.type;
                }
                catch (Exception)
                {
                    notNull = false;
                }
            }

            if (!notNull)
            {
                return;
            }

            if (notNull)
            {
                try
                {
                    this.subscriptionId   = ua.properties.subscriptionId;
                    this.usageStartTime   = ua.properties.usageStartTime;
                    this.usageEndTime     = ua.properties.usageEndTime;
                    this.meterId          = ua.properties.meterId;
                    this.meterName        = ua.properties.meterName;
                    this.meterCategory    = ua.properties.meterCategory;
                    this.meterSubCategory = ua.properties.meterSubCategory;
                    this.meterRegion      = ua.properties.meterRegion;
                    this.quantity         = ua.properties.quantity;
                    this.unit             = ua.properties.unit;
                    this.instanceDataRaw  = ua.properties.instanceDataRaw;
                }
                catch (Exception)
                {
                    notNull = false;
                }
            }

            if (notNull)
            {
                try
                {
                    this.meteredRegion      = ua.properties.infoFields.meteredRegion;
                    this.meteredService     = ua.properties.infoFields.meteredService;
                    this.meteredServiceType = ua.properties.infoFields.meteredServiceType;
                    this.project            = ua.properties.infoFields.project;
                    this.serviceInfo1       = ua.properties.infoFields.serviceInfo1;
                }
                catch (Exception)
                {
                    notNull = false;
                }
            }

            try
            {
                this.location       = ua.properties.InstanceData.MicrosoftResources.location;
                this.orderNumber    = ua.properties.InstanceData.MicrosoftResources.orderNumber;
                this.partNumber     = ua.properties.InstanceData.MicrosoftResources.partNumber;
                this.resourceUri    = ua.properties.InstanceData.MicrosoftResources.resourceUri;
                this.tags           = ua.properties.InstanceData.MicrosoftResources.tags;
                this.additionalInfo = ua.properties.InstanceData.MicrosoftResources.additionalInfo;
            }
            catch (Exception)
            {
                notNull = false;
            }
        }
예제 #2
0
        public UsageRecord(UsageAggregate ua)
        {
            this.Uid                = Guid.NewGuid();
            this.Id                 = "";
            this.Name               = "";
            this.Type               = "";
            this.SubscriptionId     = Guid.Empty;
            this.UsageStartTime     = DateTime.MinValue;
            this.UsageEndTime       = DateTime.MinValue;
            this.MeterId            = "";
            this.MeterName          = "";
            this.MeterCategory      = "";
            this.MeterSubCategory   = "";
            this.MeterRegion        = "";
            this.Quantity           = 0.0;
            this.Unit               = "";
            this.InstanceDataRaw    = "";
            this.MeteredRegion      = "";
            this.MeteredService     = "";
            this.MeteredServiceType = "";
            this.Project            = "";
            this.ServiceInfo1       = "";
            this.Location           = "";
            this.OrderNumber        = null;
            this.PartNumber         = "";
            this.ResourceUri        = "";
            this.Cost               = 0.0;

            this.Id   = ua.Id;
            this.Name = ua.Name;
            this.Type = ua.Type;

            if (ua.Properties != null)
            {
                this.SubscriptionId   = new Guid(ua.Properties.SubscriptionId);
                this.UsageStartTime   = Convert.ToDateTime(ua.Properties.UsageStartTime).ToUniversalTime();
                this.UsageEndTime     = Convert.ToDateTime(ua.Properties.UsageEndTime).ToUniversalTime();
                this.MeterId          = ua.Properties.MeterId ?? "";
                this.MeterName        = ua.Properties.MeterName ?? "";
                this.MeterCategory    = ua.Properties.MeterCategory ?? "";
                this.MeterSubCategory = ua.Properties.MeterSubCategory ?? "";
                this.MeterRegion      = ua.Properties.MeterRegion ?? "";
                this.Quantity         = ua.Properties.Quantity;
                this.Unit             = ua.Properties.Unit ?? "";
                this.InstanceDataRaw  = ua.Properties.InstanceDataRaw;
            }

            if (ua.Properties?.InfoFields != null)
            {
                this.MeteredRegion      = ua.Properties.InfoFields.MeteredRegion ?? "";
                this.MeteredService     = ua.Properties.InfoFields.MeteredService ?? "";
                this.MeteredServiceType = ua.Properties.InfoFields.MeteredServiceType ?? "";
                this.Project            = ua.Properties.InfoFields.Project ?? "";
                this.ServiceInfo1       = ua.Properties.InfoFields.ServiceInfo1 ?? "";
            }

            if (ua.Properties?.InstanceData?.MicrosoftResources != null)
            {
                this.Location       = ua.Properties.InstanceData.MicrosoftResources.Location ?? "";
                this.OrderNumber    = ua.Properties.InstanceData.MicrosoftResources.OrderNumber;
                this.PartNumber     = ua.Properties.InstanceData.MicrosoftResources.PartNumber ?? "";
                this.ResourceUri    = ua.Properties.InstanceData.MicrosoftResources.ResourceUri ?? "";
                this.Tags           = ua.Properties.InstanceData.MicrosoftResources.Tags;
                this.AdditionalInfo = ua.Properties.InstanceData.MicrosoftResources.AdditionalInfo;
            }
        }