コード例 #1
0
        public void AddCompositeDailyValue(DateTime InputDate, decimal Value, int FrequencyID, DateTime date, int MetricFrequencyID)
        {
            try
            {
                if (DailyValues == null)
                {
                    DailyValues = new Dictionary <DateTime, CompositeInfo>();
                }

                DateTime BeginPeriod = Frequency.GetNormalizedDate(FrequencyID, date);
                DateTime EndPeripd   = Frequency.AddPeriod(BeginPeriod, FrequencyID, 1);
                decimal  v           = Value / (EndPeripd - BeginPeriod).Days;
                for (DateTime Date = BeginPeriod; Date < EndPeripd; Date = Date.AddDays(1))
                {
                    CompositeInfo ci;
                    if (FrequencyID == MetricFrequencyID || !DailyValues.Keys.Contains(Date))
                    {
                        ci = new CompositeInfo();
                        DailyValues[Date] = ci;
                    }
                    else
                    {
                        ci = DailyValues[Date];
                    }

                    ci.FrequencyID = FrequencyID;
                    ci.Value       = v;
                    ci.InputDate   = InputDate;
                }
            }
            catch { }
        }
コード例 #2
0
        /// <inheritdoc/>
        public async Task <IResourceGroupResource> CreateAsync(string resourceGroup,
                                                               bool deleteOnDispose, ISubscriptionInfo subscription)
        {
            subscription = CompositeInfo.Create(subscription, _subscription);

            // Create resource group
            var client = await CreateClientAsync(subscription);

            if (string.IsNullOrEmpty(resourceGroup))
            {
                // Create group name
                while (true)
                {
                    resourceGroup = StringEx.CreateUnique(8, "rg");
                    var exists = await client.ResourceGroups.ContainAsync(
                        resourceGroup);

                    if (!exists)
                    {
                        break;
                    }
                }
            }
            else
            {
                var exists = await client.ResourceGroups.ContainAsync(
                    resourceGroup);

                if (exists)
                {
                    throw new ExternalDependencyException("resource group already exists");
                }
            }

            var region = await subscription.GetRegionAsync();

            _logger.Information("Creating simulation group {resourceGroup} in {region}...",
                                resourceGroup, region);
            var rg = await client.ResourceGroups.Define(resourceGroup)
                     .WithRegion(region)
                     .CreateAsync();

            _logger.Information("Created resource group {resourceGroup}.", rg.Name);
            return(new ResourceGroupResource(this, rg, deleteOnDispose, subscription, _logger));
        }
コード例 #3
0
        /// <inheritdoc/>
        public async Task <IResourceGroupResource> GetAsync(string resourceGroup,
                                                            bool deleteOnDispose, ISubscriptionInfo subscription)
        {
            if (string.IsNullOrEmpty(resourceGroup))
            {
                throw new ArgumentNullException(nameof(resourceGroup));
            }
            subscription = CompositeInfo.Create(subscription, _subscription);
            var client = await CreateClientAsync(subscription);

            var rg = await client.ResourceGroups.GetByNameAsync(resourceGroup);

            if (rg == null)
            {
                return(null);
            }
            return(new ResourceGroupResource(this, rg, deleteOnDispose,
                                             subscription, _logger));
        }
コード例 #4
0
        public decimal?GetCompositeValue(DateTime BeginPeriod, DateTime EndPeripd, bool InterpolateMissingDays)
        {
            try
            {
                if (DailyValues == null)
                {
                    return(null);
                }
                int     MissCount  = 0;
                decimal TotalValue = 0;
                decimal LastValue  = 0;
                bool    IsExist    = false;

                for (DateTime Date = BeginPeriod; Date < EndPeripd; Date = Date.AddDays(1))
                {
                    if (!DailyValues.Keys.Contains(Date))
                    {
                        MissCount++;
                        continue;
                    }
                    CompositeInfo ci = DailyValues[Date];

                    LastValue   = ci.Value;
                    TotalValue += (InterpolateMissingDays ? (MissCount + 1) : 1) * LastValue;
                    MissCount   = 0;
                    IsExist     = true;
                }
                if (!IsExist)
                {
                    return(null);
                }
                if (InterpolateMissingDays)
                {
                    TotalValue += MissCount * LastValue;
                }
                return(TotalValue);
            }
            catch
            {
                return(null);
            }
        }