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; } }
protected void InitalizeCreativeGK(SqlCommand insertCommand, int accountID) { int gkManagerCallsCounter = 0; bool callSuccess = false; // Creative_gk if ((insertCommand.Parameters["@headline"].Value == DBNull.Value) && (insertCommand.Parameters["@desc1"].Value == DBNull.Value) && (insertCommand.Parameters["@desc2"].Value == DBNull.Value)) { // Yaniv: report to log. insertCommand.Parameters["@headline"].Value = StringFieldNullValue; insertCommand.Parameters["@desc1"].Value = StringFieldNullValue; insertCommand.Parameters["@desc2"].Value = StringFieldNullValue; insertCommand.Parameters["@Creative_gk"].Value = 0; return; } // Convert DBNull to null if (insertCommand.Parameters["@headline"].Value == DBNull.Value) { insertCommand.Parameters["@headline"].Value = string.Empty; } if (insertCommand.Parameters["@desc1"].Value == DBNull.Value) { insertCommand.Parameters["@desc1"].Value = string.Empty; } if (insertCommand.Parameters["@desc2"].Value == DBNull.Value) { insertCommand.Parameters["@desc2"].Value = string.Empty; } // try 3 time to get campaignGK from GKManager, if failed the trow Exception while (!callSuccess) { try { insertCommand.Parameters["@Creative_gk"].Value = GkManager.GetCreativeGK(accountID, insertCommand.Parameters["@headline"].Value.ToString(), insertCommand.Parameters["@desc1"].Value.ToString(), insertCommand.Parameters["@desc2"].Value.ToString()); callSuccess = true; } catch (TimeoutException ex) { ++gkManagerCallsCounter; if (gkManagerCallsCounter > MaxNumOFGkManagerCallsTries) { throw ex; } } catch (Exception ex) { throw ex; } } }