protected void InitalizeCampaignGK(SqlCommand insertCommand, int channelID, int accountID) { int gkManagerCallsCounter = 0; bool callSuccess = false; if (insertCommand.Parameters["@campaign"].Value == DBNull.Value) { // Yaniv: add gatway to the log message //Log.Write(String.Format("campaign have no name.", insertCommand.Parameters["@campaignGK"].Value) // , LogMessageType.Warning); insertCommand.Parameters["@campaign"].Value = StringFieldNullValue; } else { long lVal = FetchCampaignID(insertCommand); // try 3 time to get campaignGK from GKManager, if failed the trow Exception while (!callSuccess) { try { // Have campaignid if (lVal != 0) { insertCommand.Parameters["@Campaign_GK"].Value = GkManager.GetCampaignGK(accountID, channelID, insertCommand.Parameters["@campaign"].Value.ToString(), lVal); } else // Don't have campaignid { insertCommand.Parameters["@Campaign_GK"].Value = GkManager.GetCampaignGK(accountID, channelID, insertCommand.Parameters["@campaign"].Value.ToString(), null); } callSuccess = true; } catch (TimeoutException ex) { ++gkManagerCallsCounter; if (gkManagerCallsCounter > MaxNumOFGkManagerCallsTries) { throw ex; } } catch (Exception ex) { throw ex; } } } }
protected override PpcDataUnit NextRow() { while (_innerReader.Read()) { if (_innerReader.Name == "Row") { string row = _innerReader.ReadOuterXml(); XmlDocument xd = new XmlDocument(); xd.LoadXml(row); PpcDataUnit objPpcData = new PpcDataUnit(); objPpcData.AccountID = GetAccountIDFromName(xd.DocumentElement["AccountName"].GetAttribute("value")); objPpcData.AdDistribution = xd.DocumentElement["AdDistribution"].GetAttribute("value"); objPpcData.AdId = Convert.ToInt32(xd.DocumentElement["AdId"].GetAttribute("value")); objPpcData.AdGroupName = xd.DocumentElement["AdGroupName"].GetAttribute("value"); objPpcData.AdType = Convert.ToInt32(xd.DocumentElement["AdType"].GetAttribute("value")); objPpcData.CampaignName = xd.DocumentElement["CampaignName"].GetAttribute("value"); //p.DestinationUrl =xd.DocumentElement["DestinationUrl"].GetAttribute("value"); objPpcData.Impressions = Convert.ToInt32(xd.DocumentElement["Impressions"].GetAttribute("value")); objPpcData.Clicks = Convert.ToInt32(xd.DocumentElement["Clicks"].GetAttribute("value")); objPpcData.Ctr = decimal.Parse(xd.DocumentElement["Ctr"].GetAttribute("value")); objPpcData.AverageCpc = decimal.Parse(xd.DocumentElement["AverageCpc"].GetAttribute("value")); objPpcData.Spend = decimal.Parse(xd.DocumentElement["Spend"].GetAttribute("value")); objPpcData.AveragePosition = decimal.Parse(xd.DocumentElement["AveragePosition"].GetAttribute("value")); objPpcData.Conversions = decimal.Parse(xd.DocumentElement["Conversions"].GetAttribute("value")); objPpcData.ConversionRate = decimal.Parse(xd.DocumentElement["ConversionRate"].GetAttribute("value")); //p.Keyword = xd.DocumentElement["Keyword"].GetAttribute("value"); string d = xd.DocumentElement["GregorianDate"].GetAttribute("value"); // +" 00:00:01"; objPpcData.GregorianDate = DateTime.ParseExact(d, "MM/dd/yyyy", null); //xd.DocumentElement["GregorianDate"].GetAttribute("value")); //p.Matchtype = xd.DocumentElement["MatchType"].GetAttribute("value"); objPpcData.AdGroupId = Convert.ToInt32(xd.DocumentElement["AdGroupId"].GetAttribute("value")); objPpcData.Channel_id = 14; objPpcData.Downloaded_date = DateTime.Now; objPpcData.Day_code = Core.Utilities.DayCode.ToDayCode(DateTime.Now); objPpcData.GatewayId = Convert.ToInt32(BusinessObjects.Tracker.ExtractTracker(_innerReader.ReadElementString("Gateway"), BusinessObjects.Tracker.GetAccountTrackerPattern(objPpcData.AccountID)));// GetGateway(_innerReader.ReadElementString("Gateway")); objPpcData.CampaignGk = GkManager.GetCampaignGK(objPpcData.AccountID, objPpcData.Channel_id, objPpcData.CampaignName, null); objPpcData.AdgroupGk = GkManager.GetAdgroupGK(objPpcData.AccountID, objPpcData.Channel_id, objPpcData.CampaignGk, objPpcData.AdGroupName, objPpcData.AdGroupId); //p.CreativeGk = GkManager.GetCreativeGK (p.AccountID,); //objPpcData.GatewayGk = GkManager.GetGatewayGK(objPpcData.AccountID,objPpcData.GatewayId,objPpcData.Channel_id,objPpcData.CampaignGK,objPpcData.Adgroup_Gk,null,); //p.PPC_CreativeGk = GkManager.GetAdgroupCreativeGK(p.AccountID,p.Channel_id,p.CampaignGk,p.AdgroupGk,p.CreativeGk,p.DestinationUrl,p.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); return(objPpcData); } } return(new PpcDataUnit()); }
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; } }