Example #1
0
        protected void InitalizeAdgroupKeywordGK(SqlCommand insertCommand, int accountID, int channelID, bool hasBackOffice)
        {
            int  gkManagerCallsCounter = 0;
            bool callSuccess           = false;

            // try 3 time to get campaignGK from GKManager, if failed the trow Exception
            while (!callSuccess)
            {
                try
                {
                    if (insertCommand.Parameters["@Keyword_GK"].Value.ToString() == string.Empty ||
                        insertCommand.Parameters["@Keyword_gk"].Value == DBNull.Value)
                    {
                        return;
                    }

                    // Convert DBNull to null
                    if (insertCommand.Parameters["@MatchType"].Value == DBNull.Value)
                    {
                        insertCommand.Parameters["@MatchType"].Value = MatchType.Unidentified;
                    }

                    insertCommand.Parameters["@PPC_Keyword_GK"].Value =
                        GkManager.GetAdgroupKeywordGK(accountID,
                                                      channelID,
                                                      (long)Convert.ToInt32(insertCommand.Parameters["@Campaign_GK"].Value),
                                                      (long)Convert.ToInt32(insertCommand.Parameters["@AdGroup_GK"].Value),
                                                      (long)Convert.ToInt32(insertCommand.Parameters["@Keyword_GK"].Value),
                                                      (MatchType)(insertCommand.Parameters["@MatchType"].Value),
                                                      insertCommand.Parameters["@destUrl"].Value.ToString(),
                                                      hasBackOffice ? (long?)Convert.ToInt32(insertCommand.Parameters["@Gateway_gk"].Value): null);

                    //insertCommand.Parameters["@PPC_Keyword_GK"].Value =
                    //    GkManager.GetAdgroupKeywordGK(accountID,
                    //        channelID,
                    //        (long)Convert.ToInt32(insertCommand.Parameters["@Campaign_GK"].Value),
                    //        (long)Convert.ToInt32(insertCommand.Parameters["@AdGroup_GK"].Value),
                    //        (long)Convert.ToInt32(insertCommand.Parameters["@Keyword_GK"].Value),
                    //        (MatchType)(insertCommand.Parameters["@MatchType"].Value),
                    //        insertCommand.Parameters["@kwDestUrl"].Value.ToString() == "defult url" ?
                    //        null : insertCommand.Parameters["@kwDestUrl"].Value.ToString(),
                    //        null);

                    callSuccess = true;
                }
                catch (TimeoutException ex)
                {
                    ++gkManagerCallsCounter;

                    if (gkManagerCallsCounter > MaxNumOFGkManagerCallsTries)
                    {
                        throw ex;
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        protected override PpcDataUnit NextRow()
        {
            try
            {
                if (_xd.ChildNodes[0].ChildNodes.Count > _RowNumber)
                {
                    PpcDataUnit         objPpcData = new PpcDataUnit();
                    AdPerformanceValues ad         = new AdPerformanceValues();
                    for (int i = 0; i < _Columns; i++)
                    {
                        string nameNode  = _xd.ChildNodes[0].ChildNodes[_RowNumber].ChildNodes[i].Name;
                        string valueNode = _xd.ChildNodes[0].ChildNodes[_RowNumber].ChildNodes[i].Attributes[0].Value;
                        switch (nameNode)
                        {
                        case "AccountName":
                            objPpcData.AccountID = GetAccountIDByName(valueNode);
                            break;

                        case "AdDistribution":
                            objPpcData.AdDistribution = valueNode;
                            break;

                        case "AdId":
                            objPpcData.AdId = valueNode != string.Empty ? Convert.ToInt32(valueNode) : 0;
                            break;

                        case "AdGroupName":
                            objPpcData.AdGroupName = valueNode;
                            break;

                        case "AdType":
                            objPpcData.AdType = (int)Enum.Parse(typeof(AdVariation), valueNode.Substring(0, valueNode.IndexOf(" ad")), true);
                            break;

                        case "CampaignName":
                            objPpcData.CampaignName = valueNode;
                            break;

                        case "DestinationUrl":
                            objPpcData.DestinationUrl = valueNode;
                            break;

                        case "Impressions":
                            objPpcData.Impressions = valueNode != string.Empty ? Convert.ToInt32(valueNode) : 0;
                            break;

                        case "Clicks":
                            objPpcData.Clicks = valueNode != string.Empty ? Convert.ToInt32(valueNode) : 0;
                            break;

                        case "Ctr":
                            objPpcData.Ctr = valueNode != string.Empty ? decimal.Parse(valueNode) : 0;
                            break;

                        case "AverageCpc":
                            objPpcData.AverageCpc = valueNode != string.Empty ? decimal.Parse(valueNode) : 0;
                            break;

                        case "Spend":
                            objPpcData.Spend = valueNode != string.Empty ? decimal.Parse(valueNode) : 0;
                            break;

                        case "AveragePosition":
                            objPpcData.AveragePosition = valueNode != string.Empty ? decimal.Parse(valueNode) : 0;
                            break;

                        case "Conversions":
                            objPpcData.Conversions = valueNode != string.Empty ? decimal.Parse(valueNode) : 0;
                            break;

                        case "ConversionRate":
                            objPpcData.ConversionRate = valueNode != string.Empty ?  decimal.Parse(valueNode):0;
                            break;

                        case "Keyword":
                            objPpcData.Keyword = valueNode;
                            break;

                        case "GregorianDate":
                            string d = valueNode;
                            objPpcData.GregorianDate = DateTime.ParseExact(d, "M/d/yyyy", null);
                            break;

                        case "MatchType":
                            objPpcData.Matchtype = (MatchType)Enum.Parse(typeof(MatchType), valueNode, true);
                            break;

                        default:
                            break;
                        }
                    }
                    objPpcData.AdDistribution  = Ads[objPpcData.AdId].AdDescription;
                    objPpcData.AdTitle         = Ads[objPpcData.AdId].AdTitle;
                    objPpcData.Channel_id      = 14;
                    objPpcData.Downloaded_date = DateTime.Now;
                    objPpcData.Day_code        = Core.Utilities.DayCode.ToDayCode(DateTime.Now);
                    objPpcData.CampaignGk      = GkManager.GetCampaignGK(objPpcData.AccountID, objPpcData.Channel_id, objPpcData.CampaignName, null);
                    objPpcData.GatewayGk       = GkManager.GetGatewayGK(objPpcData.AccountID, objPpcData.GatewayId, objPpcData.Channel_id, objPpcData.CampaignGk, objPpcData.AdgroupGk, null, objPpcData.DestinationUrl, GatewayReferenceType.Keyword, objPpcData.KeywordGk);
                    objPpcData.AdgroupGk       = GkManager.GetAdgroupGK(objPpcData.AccountID, objPpcData.Channel_id, objPpcData.CampaignGk, objPpcData.AdGroupName, objPpcData.AdGroupId);
                    objPpcData.CreativeGk      = GkManager.GetCreativeGK(objPpcData.AccountID, objPpcData.AdTitle, objPpcData.AdDistribution, string.Empty);
                    objPpcData.PPC_CreativeGk  = GkManager.GetAdgroupCreativeGK(objPpcData.AccountID, objPpcData.Channel_id, objPpcData.CampaignGk, objPpcData.AdgroupGk, objPpcData.CreativeGk, objPpcData.DestinationUrl, string.Empty, objPpcData.GatewayGk);
                    objPpcData.KeywordGk       = GkManager.GetKeywordGK(objPpcData.AccountID, objPpcData.Keyword);
                    objPpcData.PPC_KeywordGk   = GkManager.GetAdgroupKeywordGK(objPpcData.AccountID, objPpcData.Channel_id, objPpcData.CampaignGk, objPpcData.AdgroupGk, objPpcData.KeywordId, objPpcData.Matchtype, objPpcData.DestinationUrl, objPpcData.GatewayGk);
                    _RowNumber += 1;
                    return(objPpcData);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }