コード例 #1
0
        private PgStageDetailsForm GetStageDetails(bool isAipe, string budgetRegion, string targetBudget, CostType costType, string agencyCurrency)
        {
            var stageDetails = new PgStageDetailsForm
            {
                BudgetRegion = new AbstractTypeValue {
                    Key = budgetRegion
                },
                InitialBudget  = decimal.Parse(targetBudget),
                IsAIPE         = isAipe,
                CostType       = costType.ToString(),
                AgencyCurrency = agencyCurrency
            };

            if (costType == CostType.Production)
            {
                stageDetails.ContentType = new DictionaryValue {
                    Key = _contentType
                };
                stageDetails.ProductionType = new DictionaryValue {
                    Key = _productionType
                };
            }
            else
            {
                stageDetails.UsageBuyoutType = new DictionaryValue {
                    Key = _contentType
                };
            }

            return(stageDetails);
        }
コード例 #2
0
        public static TECMisc TestMisc(TECCatalogs catalogs, Random rand, CostType type)
        {
            TECMisc misc = new TECMisc(type);

            misc.Description = string.Format("Test Misc {0}", type.ToString());
            misc.Quantity    = rand.Next(1, 10);
            misc.AssignRandomCostProperties(catalogs, rand);
            return(misc);
        }
コード例 #3
0
ファイル: Cost.cs プロジェクト: jpbruyere/MagicCrow
        public override string ToString()
        {
            string tmp = CostType.ToString() + Count;

            if (validTargets != null)
            {
                tmp += validTargets.ToString();
            }
            return(tmp);
        }
コード例 #4
0
        public async Task <List <SupportingDocumentModel> > BuildSupportingDocuments(IStageDetails stageDetails, CostType costType, IEnumerable <string> stageKeys,
                                                                                     Guid costStageRevisionId, bool totalCostIncreased = false)
        {
            var stageDetailsForm = stageDetails.Data.ToModel <PgStageDetailsForm>();

            var rules            = (await _ruleService.GetCompiledByRuleType <SupportingDocumentRule>(RuleType.SupportingDocument)).ToArray();
            var supportingDocs   = new List <SupportingDocumentModel>();
            var previousRevision = await _costStageRevisionService.GetPreviousRevision(costStageRevisionId);

            foreach (var stage in stageKeys)
            {
                var supportingDocRule = new SupportingDocumentRule
                {
                    BudgetRegion       = stageDetailsForm.BudgetRegion?.Key,
                    ContentType        = stageDetailsForm.ContentType?.Key,
                    CostStage          = stage,
                    ProductionType     = stageDetailsForm.ProductionType?.Key,
                    CostType           = costType.ToString(),
                    TotalCostIncreased = totalCostIncreased,
                    PreviousCostStage  = previousRevision != null ? previousRevision?.Name : string.Empty
                };
                List <SupportingDocumentModel> output;
                Func <SupportingDocumentRule, Rule, List <SupportingDocumentModel> > matched = (supportingDocumentRule, rule) =>
                {
                    var ruleDefinition = JsonConvert.DeserializeObject <SupportingDocumentRuleDefinition>(rule.Definition);
                    return(new List <SupportingDocumentModel>
                    {
                        new SupportingDocumentModel
                        {
                            CanManuallyUpload = ruleDefinition.CanManuallyUpload,
                            Name = ruleDefinition.Name,
                            Key = ruleDefinition.Key ?? string.Empty,
                            Generated = true,
                            Required = ruleDefinition.Mandatory
                        }
                    });
                };

                Func <List <SupportingDocumentModel>, List <SupportingDocumentModel>, List <SupportingDocumentModel> > aggregator = (total, result) =>
                {
                    total.AddRange(result);
                    return(total);
                };

                _ruleService.TryMatchRule(rules, supportingDocRule, matched, aggregator, out output);

                if (output != null)
                {
                    supportingDocs.AddRange(output);
                }
            }

            return(supportingDocs);
        }
コード例 #5
0
 public TechnicalFee GetFee(CostType costType, string contentType, string productionType, string budgetRegion, decimal fee, string currencyCode)
 {
     return(new TechnicalFee
     {
         CostType = costType.ToString(),
         ConsultantRate = fee,
         ContentType = contentType,
         CurrencyCode = currencyCode,
         ProductionType = productionType,
         RegionName = budgetRegion
     });
 }
コード例 #6
0
        public static ILossOperator GetCostFunction(CostType costType)
        {
            switch (costType)
            {
            case CostType.Abs:
                return(new Abs());

            case CostType.Square:
                return(new SquareError());

            default:
                throw new InvalidEnumArgumentException(costType.ToString());
            }
        }
コード例 #7
0
        private async Task <Dictionary <string, StageModel> > GetStages(PgStageDetailsForm stageDetailsForm, CostType costType)
        {
            var testStageRule = new PgStageRule
            {
                BudgetRegion       = stageDetailsForm.BudgetRegion?.Key,
                ContentType        = stageDetailsForm.ContentType?.Key,
                ProductionType     = stageDetailsForm.ProductionType?.Key,
                CostType           = costType.ToString(),
                TargetBudgetAmount = stageDetailsForm.InitialBudget.GetValueOrDefault()
            };
            var stages = await _pgStageBuilder.GetStages(testStageRule);

            return(stages);
        }
コード例 #8
0
        /// <summary>
        /// Build Stage and its rules
        /// <para>Required: Cost revision must have data of Cost Line Item / Stage Details / Production Details</para>
        /// </summary>
        public async Task <Dictionary <string, StageModel> > GetStages(CostType costType, CostStageRevision costStageRevision)
        {
            var stageDetails      = _costStageRevisionService.GetStageDetails <PgStageDetailsForm>(costStageRevision);
            var productionDetails = _costStageRevisionService.GetProductionDetails <PgProductionDetailsForm>(costStageRevision);
            var revisionTotals    = costStageRevision.CostLineItems.Sum(cli => cli.ValueInDefaultCurrency);

            var stageRule = new PgStageRule
            {
                ProductionType     = stageDetails.ProductionType?.Key,
                ContentType        = stageDetails.ContentType?.Key,
                BudgetRegion       = stageDetails.BudgetRegion?.Key,
                CostType           = costType.ToString(),
                TargetBudgetAmount = stageDetails.InitialBudget.GetValueOrDefault(),
                IsAIPE             = stageDetails.IsAIPE,
                TotalCostAmount    = revisionTotals
            };

            return(await GetStages(stageRule, productionDetails?.DirectPaymentVendor?.Id));
        }
コード例 #9
0
        private string CreateAppListUrl(SearchBy searchBy,
                                        CostType costType,
                                        bool includeGames = false,
                                        //int maxNumberOfAppsToReturn = 20,
                                        int pageNumber    = 1,
                                        string locale     = null,
                                        string categoryId = null)
        {
            var storeFormat = WindowsPhoneStore == Store.WindowsPhone8 ? Constants.AppListUrlFormat : Constants.AppListUrlFormat7;

            var url = string.Format(storeFormat,
                                    pageNumber * 10,
                                    locale,
                                    includeGames ? "" : "windowsphone.games",
                                    searchBy.ToString(),
                                    costType.ToString());

            if (!string.IsNullOrEmpty(categoryId))
            {
                url += string.Format("&category={0}", categoryId);
            }

            return(url);
        }
コード例 #10
0
        // Token: 0x060073F5 RID: 29685 RVA: 0x0017E74C File Offset: 0x0017C94C
        internal bool TryCheckOverBudget(CostType costType, out OverBudgetException exception)
        {
            exception = null;
            this.Update();
            if (base.CasTokenBucket.Locked)
            {
                int num = (int)(base.CasTokenBucket.LockedUntilUtc.Value - TimeProvider.UtcNow).TotalMilliseconds;
                if (num > 0)
                {
                    exception = base.CreateOverBudgetException("LocalTime", base.ThrottlingPolicy.CutoffBalance.ToString(), num);
                    return(true);
                }
            }
            switch (costType)
            {
            case CostType.CMDLET:
            {
                int    num2        = 0;
                string text        = null;
                string policyValue = null;
                if (this.IsDestructiveCmdletPerTimePeriodEnabled() && this.destructiveCmdletsRemaining < 0L)
                {
                    int backoffTime = this.GetBackoffTime(this.powerShellMaxDestructiveCmdletsTimePeriodPolicyValue.Value, this.lastTimeFrameDestructiveCmdlets);
                    if (backoffTime > num2)
                    {
                        num2        = backoffTime;
                        text        = "MaxDestructiveCmdletsTimePeriod";
                        policyValue = string.Format("{0}/{1}s", this.powerShellMaxDestructiveCmdletsPolicyValue, this.powerShellMaxDestructiveCmdletsTimePeriodPolicyValue);
                    }
                }
                bool flag  = this.IsCmdletPerTimePeriodEnabled() && this.cmdletsRemaining < 0L;
                bool flag2 = this.IsExchangeCmdletPerTimePeriodEnabled() && this.exchangeCmdletsRemaining < 0L;
                if (flag || flag2)
                {
                    int backoffTime = this.GetBackoffTime(this.powerShellMaxCmdletsTimePeriodPolicyValue.Value, this.lastTimeFrame);
                    if (backoffTime > num2)
                    {
                        num2        = backoffTime;
                        text        = (flag ? "PowerShellMaxCmdlets" : "ExchangeMaxCmdlets");
                        policyValue = string.Format("{0}/{1}s", flag ? this.powerShellMaxCmdletsPolicyValue : this.exchangeMaxCmdletsPolicyValue, this.powerShellMaxCmdletsTimePeriodPolicyValue);
                    }
                }
                if (!string.IsNullOrEmpty(text))
                {
                    exception = base.CreateOverBudgetException(text, policyValue, num2);
                }
                return(exception != null);
            }

            case CostType.ActiveRunspace:
                if (this.IsMaxConcurrencyEnabled() && (long)this.activeRunspaces >= (long)((ulong)this.activeRunspacesPolicyValue.Value))
                {
                    exception = base.CreateOverBudgetException(this.MaxConcurrencyOverBudgetReason, this.activeRunspacesPolicyValue.Value.ToString(), int.MaxValue);
                }
                else if (this.IsMaxRunspacesPerTimePeriodEnabled() && this.runspacesRemaining <= 0L)
                {
                    int backoffTime2 = this.GetBackoffTime(this.powerShellMaxRunspacesTimePeriodPolicyValue.Value, this.lastTimeFrameRunspaces);
                    exception = base.CreateOverBudgetException(this.MaxRunspacesTimePeriodOverBudgetReason, string.Format("{0}/{1}s", this.powerShellMaxRunspacesPolicyValue, this.powerShellMaxRunspacesTimePeriodPolicyValue), backoffTime2);
                }
                return(exception != null);

            default:
                throw new ArgumentException("[PowerShellBudget.TryCheckOverBudget] Unsupported CostType: " + costType.ToString(), "costType");
            }
        }
コード例 #11
0
        public async Task <List <ApprovalModel> > GetApprovals(CostType costType, IStageDetails stageDetails, Guid userId, Guid costStageRevisionId, Guid costId)
        {
            var costStageKey = await _efContext.CostStageRevision
                               .Where(csr => csr.Id == costStageRevisionId)
                               .Select(c => c.CostStage.Key)
                               .FirstAsync();

            var stageDetailsForm = stageDetails.Data.ToModel <PgStageDetailsForm>();
            var currentTotals    = await GetTotals(costStageRevisionId);

            var costTotalIncreased = true;
            var previousRevision   = await _costStageRevisionService.GetPreviousRevision(costStageRevisionId);

            // Always need brand approval if prvious stage is aipe  https://jira.adstream.com/browse/ADC-1585
            if (previousRevision != null && previousRevision.Name != CostStages.Aipe.ToString())
            {
                var previousTotals = await GetTotals(previousRevision.Id);

                // rounding to account for decimal precision differences during currency conversion
                if (Math.Round(currentTotals.TotalCostAmountTotal, 2) <= Math.Round(previousTotals.TotalCostAmountTotal, 2))
                {
                    costTotalIncreased = false;
                }
            }

            // we only perform a "soft" calculation, withput saving it to the DB
            //var totalPayments = await _paymentService.GetPaymentAmount(costStageRevisionId, false);
            var brandApprovalEnabled = costTotalIncreased;

            var agency = await _agencyService.GetAgencyByCostId(costId);

            var agencyIsCyclone = agency?.IsCyclone() ?? false;

            var approvalRule = new PgApprovalRule
            {
                ProductionType  = stageDetailsForm.ProductionType?.Key,
                CostType        = costType.ToString(),
                BudgetRegion    = stageDetailsForm.BudgetRegion?.Key,
                ContentType     = stageDetailsForm.ContentType?.Key,
                TotalCostAmount = currentTotals.TotalCostAmountTotal,
                IsCyclone       = agencyIsCyclone
            };

            var rules = await _ruleService.GetCompiledByRuleType <PgApprovalRule>(RuleType.ApprovalRule);

            var costStage          = (CostStages)Enum.Parse(typeof(CostStages), costStageKey);
            var isContractCostOnNa = stageDetailsForm?.UsageBuyoutType?.Key == Constants.UsageBuyoutType.Contract &&
                                     stageDetailsForm.BudgetRegion?.Key == Constants.BudgetRegion.NorthAmerica;
            Func <PgApprovalRule, Rule, ApprovalRule> matchFunc = (t, r) =>
            {
                var ruleFlags = JsonConvert.DeserializeObject <PgApprovalRuleDefinition>(r.Definition);

                // https://jira.adstream.com/browse/ADC-1152
                var ipmEnabled = false;
                var ccEnabled  = false;
                if (costStage != CostStages.Aipe && !isContractCostOnNa)
                {
                    ipmEnabled = ruleFlags.IpmApprovalEnabled;
                    ccEnabled  = ruleFlags.CostConsultantIpmAllowed;
                }

                // https://jira.adstream.com/browse/ADC-812
                var brandApprovalRequired = false;
                if (brandApprovalEnabled)
                {
                    brandApprovalRequired = ruleFlags.BrandApprovalEnabled;
                }

                var res = new ApprovalRule
                {
                    CostType                 = costType,
                    ContentType              = t.ContentType,
                    BudgetRegion             = t.BudgetRegion,
                    TotalCostAmount          = t.TotalCostAmount,
                    BrandApprovalEnabled     = brandApprovalRequired,
                    CostConsultantIpmAllowed = ccEnabled,
                    IpmApprovalEnabled       = ipmEnabled,
                    HasExternalIntegration   = ruleFlags.HasExternalIntegration
                };

                return(res);
            };

            _ruleService.TryMatchRule(rules, approvalRule, matchFunc, out var fResult);

            return(fResult != null?fResult.Approvals() : new List <ApprovalModel>());
        }
コード例 #12
0
 public Task <string> CreateCostNumber(Guid projectId, CostType costType, string contentType)
 {
     return(_costNumberGeneratorService.Generate(projectId, costType.ToString(), contentType));
 }