private static void BiddingSchemeToCsv(BulkCampaign c, RowValues values)
        {
            var biddingScheme = c.Campaign.BiddingScheme;

            if (biddingScheme == null)
            {
                return;
            }

            values[StringTable.BidStrategyType] = biddingScheme.ToBiddingSchemeBulkString();

            var maxClicksBiddingScheme = biddingScheme as MaxClicksBiddingScheme;

            if (maxClicksBiddingScheme != null)
            {
                values[StringTable.BidStrategyMaxCpc] = maxClicksBiddingScheme.MaxCpc.ToBidBulkString();
            }
            else
            {
                var maxConversionsBiddingScheme = c.Campaign.BiddingScheme as MaxConversionsBiddingScheme;
                if (maxConversionsBiddingScheme != null)
                {
                    values[StringTable.BidStrategyMaxCpc] = maxConversionsBiddingScheme.MaxCpc.ToBidBulkString();
                }
                else
                {
                    var targetCpaBiddingScheme = c.Campaign.BiddingScheme as TargetCpaBiddingScheme;
                    if (targetCpaBiddingScheme != null)
                    {
                        values[StringTable.BidStrategyMaxCpc]    = targetCpaBiddingScheme.MaxCpc.ToBidBulkString();
                        values[StringTable.BidStrategyTargetCpa] = targetCpaBiddingScheme.TargetCpa.ToBulkString();
                    }
                }
            }
        }
        private static void CsvToBudget(RowValues values, BulkCampaign c)
        {
            string budgetTypeRowValue;

            BudgetLimitType?budgetType;

            if (!values.TryGetValue(StringTable.BudgetType, out budgetTypeRowValue) || (budgetType = budgetTypeRowValue.ParseOptional <BudgetLimitType>()) == null)
            {
                return;
            }

            string budgetRowValue;

            if (!values.TryGetValue(StringTable.Budget, out budgetRowValue))
            {
                return;
            }

            var budgetValue = budgetRowValue.ParseOptional <double>();

            c.Campaign.BudgetType = budgetType;

            if (budgetType == BudgetLimitType.DailyBudgetAccelerated || budgetType == BudgetLimitType.DailyBudgetStandard)
            {
                c.Campaign.DailyBudget = budgetValue;
            }
        }
Пример #3
0
        private static void CsvToBiddingScheme(RowValues values, BulkCampaign c)
        {
            string bidStrategyTypeRowValue;

            BiddingScheme biddingScheme;

            if (!values.TryGetValue(StringTable.BidStrategyType, out bidStrategyTypeRowValue) || (biddingScheme = bidStrategyTypeRowValue.ParseBiddingScheme()) == null)
            {
                return;
            }

            string maxCpcRowValue;
            string targetCpaRowValue;

            values.TryGetValue(StringTable.BidStrategyMaxCpc, out maxCpcRowValue);
            values.TryGetValue(StringTable.BidStrategyTargetCpa, out targetCpaRowValue);

            var maxCpcValue    = maxCpcRowValue.ParseBid();
            var targetCpaValue = targetCpaRowValue.ParseOptional <double>();

            var maxClicksBiddingScheme = biddingScheme as MaxClicksBiddingScheme;

            if (maxClicksBiddingScheme != null)
            {
                c.Campaign.BiddingScheme = new MaxClicksBiddingScheme
                {
                    MaxCpc = maxCpcValue,
                    Type   = "MaxClicks",
                };
            }
            else
            {
                var maxConversionsBiddingScheme = biddingScheme as MaxConversionsBiddingScheme;
                if (maxConversionsBiddingScheme != null)
                {
                    c.Campaign.BiddingScheme = new MaxConversionsBiddingScheme
                    {
                        MaxCpc = maxCpcValue,
                        Type   = "MaxConversions",
                    };
                }
                else
                {
                    var targetCpaBiddingScheme = biddingScheme as TargetCpaBiddingScheme;
                    if (targetCpaBiddingScheme != null)
                    {
                        c.Campaign.BiddingScheme = new TargetCpaBiddingScheme
                        {
                            MaxCpc    = maxCpcValue,
                            TargetCpa = targetCpaValue,
                            Type      = "TargetCpa",
                        };
                    }
                    else
                    {
                        c.Campaign.BiddingScheme = biddingScheme;
                    }
                }
            }
        }
        private static void BudgetToCsv(BulkCampaign c, RowValues values)
        {
            var budgetType = c.Campaign.BudgetType;

            if (budgetType == null)
            {
                return;
            }

            values[StringTable.Budget] = c.Campaign.DailyBudget.ToBulkString();
        }