Example #1
0
        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;
                }
            }
        }
Example #2
0
 protected override void InitalizeGatewayGK(SqlCommand insertCommand, SourceDataRowReader <RetrieverDataRow> reader, FieldElement fe)
 {
     if (fe.DBFieldName.ToLower() == "gateway_id")
     {
         insertCommand.Parameters["@Gateway_GK"].Value =
             GkManager.GetGatewayGK(_accountID, Convert.ToInt64(reader.CurrentRow.Fields[fe.Value]));
     }
 }
Example #3
0
 /// <summary>
 /// Initalize GatewayGK by the gateway_id fields for data from backoffice.
 /// </summary>
 /// <param name="insertCommand">The field GatewayGK in the insert command will be initalized.</param>
 /// <param name="xmlReader">The xml reader that contain the gateway_id value.</param>
 /// <param name="fe">The current field we fetach from xml reader.</param>
 protected override void InitalizeGatewayGK(SqlCommand insertCommand, XmlTextReader xmlReader, FieldElement fe)
 {
     if (fe.DBFieldName.ToLower() == "gateway_id")
     {
         insertCommand.Parameters["@Gateway_GK"].Value =
             GkManager.GetGatewayGK(_accountID, Convert.ToInt64(xmlReader.GetAttribute(fe.Value)));
     }
 }
        protected virtual void HandleBackOfficeNode(string nodeName, string nodeValue, FieldElementSection rawDataFields, SqlCommand insertCommand)
        {
            try
            {
                if (nodeName == String.Empty ||
                    nodeName == null)
                {
                    throw new ArgumentException("Invalid node name. Cannot be null or empty.");
                }

                FieldElement fe = rawDataFields.Fields[nodeName];
                //if (fe != null)
                //    insertCommand.Parameters["@" + fe.DBFieldName].Value =
                //        Convert.ChangeType(nodeValue, Type.GetType(_tableTypeMappings[fe.DBFieldType.ToLower()]));


                if (fe == null || !fe.InsertToDB || !fe.Enabled)
                {
                    return;
                }

                if (!String.IsNullOrEmpty(nodeValue))
                {
                    insertCommand.Parameters["@" + fe.DBFieldName].Value =
                        Convert.ChangeType(nodeValue, Type.GetType(_tableTypeMappings[fe.DBFieldType.ToLower()]));

                    // Initalize Gateway_GK
                    if (rawDataFields.Fields[nodeName].DBFieldName.ToLower() == "gateway_id")
                    {
                        insertCommand.Parameters["@Gateway_GK"].Value =
                            GkManager.GetGatewayGK(_accountID, Convert.ToInt64(nodeValue));
                    }
                }
                else
                {
                    // Initalize field with null value.
                    if (fe.DBDefaultValue == null)
                    {
                        insertCommand.Parameters["@" + fe.DBFieldName].Value = DBNull.Value;
                    }
                    else
                    {
                        insertCommand.Parameters["@" + fe.DBFieldName].Value =
                            Convert.ChangeType(fe.DBDefaultValue, Type.GetType(_tableTypeMappings[fe.DBFieldType.ToLower()]));
                    }
                }
            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
        }
Example #5
0
        private void InitalizeParametersGK(Dictionary <string, int> headersCSV, SqlCommand insertCommand, int accountID, int channelID, string[] Fields)
        {
            //bool hasBackOffice = false;
            //int accountID;

            //if (Int32.TryParse( insertCommand.Parameters["@Account_ID"].ToString(), out accountID))
            //    hasBackOffice = HasBackOffice(accountID);
            bool hasBackOffice = HasBackOffice(accountID);

            if (_tableName == "Paid_API_AllColumns")
            {
                Dictionary <string, string> gatewayNameFields = new Dictionary <string, string>();
                // Initalize a Dictionary with report fields & gateway Name Fields.
                InitalizeGatewayNameMapping(gatewayNameFields, "GatewayName");

                InitalizeCreativeFields(headersCSV, insertCommand, Fields);
                // Initalize Gateway ID
                if (hasBackOffice)
                {
                    InitalizeGatewayID(insertCommand, channelID, gatewayNameFields);
                }

                InitalizeCreativeGKFields(insertCommand, channelID, hasBackOffice, accountID);
            }
            else if (_tableName == "Paid_API_Content")
            {
                InitalizeContentGKFields(insertCommand, channelID, hasBackOffice, accountID);
            }
            else if (_tableName == "BackOffice_Client_Gateway")
            {
                //Dictionary<string, string> babylonGatewayNameFields = new Dictionary<string, string>();
                //// Initalize a Dictionary with report fields & gateway Name Fields.
                //InitalizeGatewayNameMapping(babylonGatewayNameFields, "BabylonGatewayName");

                //string gatewayID = Fields[headersCSV["gateway_id"]].ToString();

                //foreach (string gatewayName in babylonGatewayNameFields.Keys)
                //{
                //    if (gatewayID.Contains(gatewayName))
                //    {
                //        insertCommand.Parameters["@gateway_ID"].Value = Convert.ToInt32(babylonGatewayNameFields[gatewayName]) + gatewayID.Substring(gatewayID.IndexOf(gatewayName) + gatewayName.Length);
                //        break;
                //    }
                //}

                // Initalize gateway_GK
                insertCommand.Parameters["@gateway_GK"].Value = GkManager.GetGatewayGK(
                    Convert.ToInt32(insertCommand.Parameters["@Account_ID"].Value),
                    Convert.ToInt64(insertCommand.Parameters["@gateway_ID"].Value));
            }
        }
        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;
            }
        }
        /*=========================*/
        #endregion

        #region Private Methods
        /*=========================*/

        /// <summary>
        /// Fills DB with data that retrieved by EasyForex BackOffice
        /// </summary>
        /// <param name="dataFromBO">Data from BackOffice to write to DB.</param>
        private void ProcessData(string xmlPath, DateTime _requiredDay)
        {
            SqlCommand insertCommand = InitalizeInsertCommand();

            using (ConnectionKey key = DataManager.Current.OpenConnection())
            {
                // Init insertCommand with the data manger connection
                DataManager.ApplyConnection(insertCommand);

                // Yaniv: add Exception
                /////////////////////
                Type t = Type.GetType(Instance.Configuration.Options["BackOfficeXmlReader"]);
                System.Reflection.ConstructorInfo constructor = t.GetConstructor(new Type[] { typeof(string) });
                //if (constructor == null)
                //	throw new blahl
                //BackOfficeXmlReader reader = (BackOfficeXmlReader) constructor.Invoke(new object[] { xmlPath });

                ////////////////////

                //EasyForexReader reader = new EasyForexReader(xmlPath);

                // Initalize const parmaters.
                insertCommand.Parameters["@Downloaded_Date"].Value = DateTime.Now;
                insertCommand.Parameters["@day_Code"].Value        = DayCode(_requiredDay);
                insertCommand.Parameters["@hour_Code"].Value       = DayCode(_requiredDay) == DayCode(DateTime.Today) ? DateTime.Now.Hour : 0;
                insertCommand.Parameters["@account_ID"].Value      = Instance.AccountID;
                //insertCommand.Parameters["@channel_ID"].Value = ChannelID;

                using (EasyForexReader reader = (EasyForexReader)constructor.Invoke(new object[] { xmlPath }))
                {
                    // Read all rows in the BackOffice XML and insert them to the DB.
                    while (reader.Read())
                    {
                        if (reader.CurrentRow.GatewayID == 0)
                        {
                            Log.Write("Error parsing BackOffice row, Can't insert row to DB.", LogMessageType.Error);
                            continue;
                        }

                        InitalizeParametersWithNull(insertCommand);

                        // Initalize command parmaters.
                        insertCommand.Parameters["@gateway_id"].Value                    = reader.CurrentRow.GatewayID;
                        insertCommand.Parameters["@total_Hits"].Value                    = reader.CurrentRow.TotalHits;
                        insertCommand.Parameters["@new_Leads"].Value                     = reader.CurrentRow.NewLeads;
                        insertCommand.Parameters["@new_Users"].Value                     = reader.CurrentRow.NewUsers;
                        insertCommand.Parameters["@new_Active_Users"].Value              = reader.CurrentRow.NewActiveUsers;
                        insertCommand.Parameters["@new_Net_Deposits_in_dollars"].Value   = reader.CurrentRow.NewNetDepostit;
                        insertCommand.Parameters["@active_Users"].Value                  = reader.CurrentRow.ActiveUsers;
                        insertCommand.Parameters["@total_Net_Deposits_in_dollars"].Value = reader.CurrentRow.TotalNetDeposit;
                        insertCommand.Parameters["@Gateway_GK"].Value                    = GkManager.GetGatewayGK(Instance.AccountID, reader.CurrentRow.GatewayID);

                        try
                        {
                            // Execute command.
                            insertCommand.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            Log.Write(string.Format("Error in Inserting data to BackOffice_Client_Gateway table in easynet_Oltp DB."), ex);
                        }
                    }
                }
            }
        }