protected void InitalizeGatewayGK(SqlCommand insertCommand, int accountID, GatewayReferenceType gatewayReferenceType, int channelID) { 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["@Gateway_id"].Value == DBNull.Value) { return; } // Convert DBNull to null if (insertCommand.Parameters["@destUrl"].Value == DBNull.Value) { insertCommand.Parameters["@destUrl"].Value = string.Empty; } if (insertCommand.Parameters["@headline"].Value == DBNull.Value) { insertCommand.Parameters["@headline"].Value = string.Empty; } insertCommand.Parameters["@Gateway_gk"].Value = GkManager.GetGatewayGK(accountID, (long)Convert.ToInt32(insertCommand.Parameters["@Gateway_id"].Value), channelID, (long)Convert.ToInt32(insertCommand.Parameters["@Campaign_GK"].Value), (long)Convert.ToInt32(insertCommand.Parameters["@AdGroup_GK"].Value), gatewayReferenceType == GatewayReferenceType.Keyword ? "KW: " + insertCommand.Parameters["@kwSite"].Value.ToString() : insertCommand.Parameters["@headline"].Value.ToString(), insertCommand.Parameters["@destUrl"].Value.ToString(), gatewayReferenceType, gatewayReferenceType == GatewayReferenceType.Keyword ? (long)Convert.ToInt32(insertCommand.Parameters["@Keyword_GK"].Value) : (long)Convert.ToInt32(insertCommand.Parameters["@Creative_gk"].Value)); callSuccess = true; } catch (TimeoutException ex) { ++gkManagerCallsCounter; if (gkManagerCallsCounter > MaxNumOFGkManagerCallsTries) { throw ex; } } catch (Exception ex) { //Log.Write(String.Format("GkManager.GetGatewayGK failed."), ex, LogMessageType.Error); throw ex; } } }
protected void InitalizeCreativeGKFields(SqlCommand insertCommand, int channelID, bool hasBackOffice, int accountID) { InitalizeCampaignGK(insertCommand, channelID, accountID); InitalizeAdGroupGK(insertCommand, channelID, accountID, (long)Convert.ToInt32(insertCommand.Parameters["@Campaign_GK"].Value)); InitalizeKeywordGK(insertCommand, accountID); InitalizeCreativeGK(insertCommand, accountID); // Initalize backoffice fields. if (hasBackOffice) { if (insertCommand.Parameters["@kwDestUrl"].Value == DBNull.Value) { insertCommand.Parameters["@kwDestUrl"].Value = string.Empty; } // Initalzie Gateway Reference Type by the kwDestUrl parameter. GatewayReferenceType gatewayReferenceType = Uri.IsWellFormedUriString(insertCommand.Parameters["@kwDestUrl"].Value.ToString(), UriKind.Absolute) ? GatewayReferenceType.Keyword : GatewayReferenceType.Creative; // Gateway_gk if ((insertCommand.Parameters["@Keyword_GK"].Value == DBNull.Value) || (insertCommand.Parameters["@Creative_gk"].Value == DBNull.Value)) { return; } InitalizeGatewayGK(insertCommand, accountID, gatewayReferenceType, channelID); } InitalizeAdgroupCreativeGK(insertCommand, accountID, channelID, hasBackOffice); InitalizeAdgroupKeywordGK(insertCommand, accountID, channelID, hasBackOffice); }