コード例 #1
0
 protected virtual void HandleRow(bool hasBackOffice, FieldElementSection rawDataFields, FieldElementSection metaDataFields, SqlCommand insertCommand, Dictionary <string, string> gatewayNameFields, XmlTextReader xmlReader)
 {
     InitalizeNullValues(insertCommand, rawDataFields, metaDataFields);
     InitalizeRawDataFromXml(rawDataFields, metaDataFields, insertCommand, xmlReader);
     InitalizeMetaDataParameters(insertCommand, xmlReader, hasBackOffice, gatewayNameFields);
     InsertRowToDB(insertCommand);
 }
 /// <summary>
 /// Initalize the relevent field (fieldName) with fieldValue.
 /// </summary>
 /// <param name="fieldName">The name of the field to initalize.</param>
 /// <param name="fieldValue">The value of to set in the required field.</param>
 /// <param name="rawDataFields">FieldElementSection that contain all the required raw data fields from the DB.</param>
 /// <param name="insertCommand"></param>
 private void HandleNode(string fieldName, string fieldValue, FieldElementSection rawDataFields, SqlCommand insertCommand)
 {
     if (rawDataFields.Fields[fieldName] != null &&
         rawDataFields.Fields[fieldName].InsertToDB &&
         rawDataFields.Fields[fieldName].Enabled)
     {
         if (fieldValue != AnanlyticsNullValue)
         {
             insertCommand.Parameters["@" + rawDataFields.Fields[fieldName].DBFieldName].Value =
                 Convert.ChangeType(fieldValue, Type.GetType(_tableTypeMappings[rawDataFields.Fields[fieldName].DBFieldType.ToLower()]));
         }
         else
         {
             // Initalize null value.
             if (rawDataFields.Fields[fieldName].DBDefaultValue == null)
             {
                 insertCommand.Parameters["@" + rawDataFields.Fields[fieldName].DBFieldName].Value = DBNull.Value;
             }
             else
             {
                 insertCommand.Parameters["@" + rawDataFields.Fields[fieldName].DBFieldName].Value =
                     Convert.ChangeType(rawDataFields.Fields[fieldName].DBDefaultValue, Type.GetType(_tableTypeMappings[rawDataFields.Fields[fieldName].DBFieldType.ToLower()]));
             }
         }
     }
 }
        /// <summary>
        /// Get all the fields from the xml row. when we get to the end of the row
        /// we initalzie null values and all the required meta data fields.s
        /// </summary>
        /// <remarks>
        /// Analytics works in nodes format and not attribute format like adwords.
        /// That mean that each row contain nodes which are the fields of the row.
        /// Each node that is dimension or metric is being handled.
        /// </remarks>
        /// <param name="hasBackOffice"></param>
        /// <param name="rawDataFields"></param>
        /// <param name="metaDataFields"></param>
        /// <param name="insertCommand"></param>
        /// <param name="gatewayNameFields"></param>
        /// <param name="xmlReader"></param>
        /// <param name="retriveredDate">Required date.</param>
        protected override void HandleRow(bool hasBackOffice, FieldElementSection rawDataFields, FieldElementSection metaDataFields, SqlCommand insertCommand, Dictionary <string, string> gatewayNameFields, XmlTextReader xmlReader)
        {
            switch (xmlReader.NodeType)
            {
            case XmlNodeType.Element:
                if (xmlReader.Name == "dxp:dimension" || xmlReader.Name == "dxp:metric")
                {
                    HandleNode(xmlReader.GetAttribute("name"), xmlReader.GetAttribute("value"), rawDataFields, insertCommand);
                }
                break;

            case XmlNodeType.EndElement:
                // Arrived to end of row.
                if (xmlReader.Name.ToLower().Contains(XmlRowName.ToLower()))
                {
                    //InitalizeNullValues(metaDataFields, insertCommand, xmlReader);
                    InitalizeMetaDataParameters(insertCommand, xmlReader, hasBackOffice, gatewayNameFields);

                    // Execute command.
                    InsertRowToDB(insertCommand);
                }
                break;

            default:
                break;
            }
        }
コード例 #4
0
        protected virtual void InitalizeRawDataFromXml(FieldElementSection rawDataFields, FieldElementSection metaDataFields, SqlCommand insertCommand, XmlTextReader xmlReader)
        {
            // Initalize the insertCommand with the values from the xmlReader.
            foreach (FieldElement fe in rawDataFields.Fields)
            {
                if (!fe.InsertToDB || !fe.Enabled)
                {
                    continue;
                }

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

                    InitalizeGatewayGK(insertCommand, xmlReader, fe);
                }
                else
                {
                    InsertNullValue(insertCommand, fe);
                }
            }

            // Initalize Meta Data fields with null values.
            foreach (FieldElement fe in metaDataFields.Fields)
            {
                if (!fe.InsertToDB || !fe.Enabled)
                {
                    continue;
                }

                InsertNullValue(insertCommand, fe);
            }
        }
        private bool GetReport(FieldElementSection fieldsMapping, DateTime retrievedDay, string profileID, Dictionary <string, string> headers)
        {
            Log.Write(string.Format("run GAnalytics Retriever for account {0}, for date {1}.", Instance.AccountID.ToString(), retrievedDay.ToShortDateString()), LogMessageType.Information);

            string url      = CreateGAnalyticsUrl(profileID, fieldsMapping, retrievedDay);
            string fileName = WriteResultToFile(url, retrievedDay, string.Empty, false, headers);

            return(SaveFilePathToDB(AnalyticsServiceType, fileName, retrievedDay, _adwordsFile));
        }
コード例 #6
0
        /// <summary>
        /// New function for google adwords V13 that also use the app.config.
        /// The function get the report name and fetch the proper report type
        /// section from app.config with his info and his columns.
        /// </summary>
        /// <param name="type">The report name that exist in the app.config</param>
        /// <returns>A report with the relevent parameters</returns>
        private DefinedReportJob CreateReport(string name, string[] aggregationTypes)
        {
            Hashtable        fields = new Hashtable();
            DefinedReportJob job    = new DefinedReportJob();

            try
            {
                ReportTypesElementSection rtes = (ReportTypesElementSection)ConfigurationManager.GetSection("ReportTypes");

                // Scan all the reports types till we find the chosen report.
                foreach (ReportTypesElement rte in rtes.Fields)
                {
                    if (rte.Enabled && rte.Name == name)
                    {
                        // Load the proper report paramters by the report name.
                        FieldElementSection fes = (FieldElementSection)ConfigurationManager.GetSection(rte.Name);

                        // Initalize the hash table with the fields of the the report.
                        foreach (FieldElement fe in fes.Fields)
                        {
                            if (fe.Enabled)
                            {
                                fields.Add(fe.Key, fe.Key);
                            }
                        }

                        // Add the fields report to and string array useing IDictionaryEnumerator
                        string[] columns          = new string[fields.Count];
                        int      count            = 0;
                        IDictionaryEnumerator dic = fields.GetEnumerator();
                        while (dic.MoveNext())
                        {
                            columns[count] = dic.Value.ToString();
                            count++;
                        }

                        // Initalize the report with his info.
                        job.selectedReportType = rte.Type;
                        job.name = rte.Name;
                        //job.aggregationTypes = new String[] { rte.Aggregation };
                        job.aggregationTypes               = aggregationTypes;
                        job.includeZeroImpression          = true;
                        job.includeZeroImpressionSpecified = true;
                        job.selectedColumns = columns;

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write("Error get configuration Data for the report.", ex);
            }
            return(job);
        }
コード例 #7
0
        /*=========================*/
        #endregion

        #region protected override Methods
        /*================================*/

        protected override bool InitalizeServiceData()
        {
            _fieldsMapping = (FieldElementSection)ConfigurationManager.GetSection
                                 (GetConfigurationOptionsField("FieldsMapping"));

            // Create Authentication Token
            string authToken = FetchAutoToken();

            _headers.Add("Authorization", "GoogleLogin auth=" + authToken);

            return(base.InitalizeServiceData());
        }
コード例 #8
0
        /// <summary>
        /// Initalize the Insert command with null values and than Initalize
        /// all his fields in the CSV file.
        /// </summary>
        /// <param name="filePath">CSV file path (used for errors logging).</param>
        /// <param name="headersDB"> A dictionary with table Fields and there
        /// types of AdWords table.</param>
        /// <param name="commonHeaders">A dictionary of the headers that exist
        /// in the DB and in CSV file with header name as key and numbering as value.</param>
        /// <param name="headersCSV">A dictionary of the headers in the CSV file
        /// with header name as key and numbering as value.</param>
        /// <param name="insertCommand">Insert command to initalize his field.</param>
        /// <param name="csvTextLine"> The current text line from the
        /// CSV file to insert to the DB.</param>
        /// <returns> True for success, False for failure.</returns>
        private void InitalizeInsertCommandFields(FieldElementSection rawDataFields, FieldElementSection metaDataFields, string filePath,
                                                  Dictionary <string, int> headersCSV, SqlCommand insertCommand, string csvTextLine)
        {
            string[] FieldsValues = csvTextLine.Split('\t');
            int      accountID;
            int      dayCode;

            int channelID = InitalizeMandatoryFields(filePath, headersCSV, insertCommand, FieldsValues, out accountID, out dayCode);

            // Delete old data for the DB for the same accountID, dayCode and channelID.
            DeleteOldData(accountID, channelID, dayCode);

            InitalizeRawDataFromXml(rawDataFields, metaDataFields, insertCommand, headersCSV, FieldsValues);
            InitalizeMandatoryFields(filePath, headersCSV, insertCommand, FieldsValues, out accountID, out dayCode);

            // Initalize GK fields
            InitalizeParametersGK(headersCSV, insertCommand, accountID, channelID, FieldsValues);
        }
コード例 #9
0
        protected virtual void InitalizeProcessData(out FieldElementSection rawDataFields, out FieldElementSection metaDataFields, out SqlCommand insertCommand, out Dictionary <string, string> gatewayNameFields)
        {
            // Get the sections with the fields for the insert command.
            rawDataFields = (FieldElementSection)ConfigurationManager.GetSection
                                (GetConfigurationOptionsField("FieldsMapping"));
            metaDataFields = (FieldElementSection)ConfigurationManager.GetSection
                                 (GetConfigurationOptionsField("TableMapping"));

            // Initalize Insert command
            string sqlCmd = CreateInsertCmdString(_tableName, rawDataFields, metaDataFields);

            insertCommand = DataManager.CreateCommand(sqlCmd, CommandType.Text);
            insertCommand.CommandTimeout = 120;

            // Initalize a Dictionary with report fields & gateway Name Fields.
            gatewayNameFields = new Dictionary <string, string>();
            InitalizeGatewayNameMapping(gatewayNameFields, "GatewayName");
        }
コード例 #10
0
        /// <summary>
        /// Initalize the row raw data fields with values from the xml.
        /// And initalize Meta Data fields with null values.
        /// </summary>
        /// <param name="rawDataFields">Dictionary that contain all the required raw data fields from the DB.</param>
        /// <param name="metaDataFields">Dictionary that contain all the required Meta data fields from the DB.</param>
        /// <param name="insertCommand"></param>
        /// <param name="xmlReader"></param>
        protected void InitalizeRawDataFromXml(FieldElementSection rawDataFields, FieldElementSection metaDataFields, SqlCommand insertCommand, Dictionary <string, int> headersCSV, string[] FieldsValues)
        {
            try
            {
                // Initalize the insertCommand with the values from the xmlReader.
                foreach (FieldElement fe in rawDataFields.Fields)
                {
                    if (!fe.InsertToDB || !fe.Enabled)
                    {
                        continue;
                    }

                    string dbFieldName = fe.DBFieldName.ToLower();

                    if ((headersCSV.ContainsKey(dbFieldName) &&
                         !String.IsNullOrEmpty(FieldsValues[headersCSV[dbFieldName]])) &&
                        dbFieldName != "matchtype")
                    {
                        insertCommand.Parameters["@" + fe.DBFieldName].Value =
                            Convert.ChangeType(FieldsValues[headersCSV[dbFieldName]], Type.GetType(_tableTypeMappings[fe.DBFieldType.ToLower()]));
                    }
                    else
                    {
                        InsertNullValue(insertCommand, fe);
                    }
                }

                // Initalize Meta Data fields with null values.
                foreach (FieldElement fe in metaDataFields.Fields)
                {
                    if (!fe.InsertToDB || !fe.Enabled)
                    {
                        continue;
                    }

                    InsertNullValue(insertCommand, fe);
                }
            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
        }
コード例 #11
0
        //protected virtual void InitalizeNullValues(SqlCommand insertCommand, FieldElementSection rawDataFields, FieldElementSection metaDataFields)
        //{
        //}

        protected virtual void InitalizeNullValues(SqlCommand insertCommand, FieldElementSection rawDataFields, FieldElementSection metaDataFields)
        {
            // Initalize the insertCommand null values for the fields in rawDataFields.
            foreach (FieldElement fe in rawDataFields.Fields)
            {
                if (!fe.InsertToDB || !fe.Enabled)
                {
                    continue;
                }

                // 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()]));
                }
            }

            // Initalize the insertCommand null values for the fields in metaDataFields.
            foreach (FieldElement fe in metaDataFields.Fields)
            {
                if (!fe.InsertToDB || !fe.Enabled)
                {
                    continue;
                }

                // 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()]));
                }
            }
        }
        /// <summary>
        /// Get all the fields from the xml row. when we get to the end of the row
        /// we initalzie null values and all the required meta data fields.
        /// </summary>
        /// <remarks>
        /// Analytics works in nodes format and not attribute format like adwords.
        /// That mean that each row contain nodes which are the fields of the row.
        /// Each node that is dimension or metric is being handled.
        /// </remarks>
        /// <param name="hasBackOffice"></param>
        /// <param name="rawDataFields"></param>
        /// <param name="metaDataFields"></param>
        /// <param name="insertCommand"></param>
        /// <param name="gatewayNameFields"></param>
        /// <param name="xmlReader"></param>
        /// <param name="retriveredDate">Required date.</param>
        protected override void HandleRow(bool hasBackOffice, FieldElementSection rawDataFields, FieldElementSection metaDataFields, SqlCommand insertCommand, Dictionary <string, string> gatewayNameFields, XmlTextReader xmlReader)
        {
            string nodeName = string.Empty;

            // Loop on all the rows in the xml report file.
            switch (xmlReader.NodeType)
            {
            case XmlNodeType.Element:
                nodeName = xmlReader.Name;
                //Virtual function to handle the actual node value. If some processing is needed on this
                //value, inherit from this class, and override the HandleBackOfficeNode function.
                if (!xmlReader.Name.ToLower().Contains(_rowName))
                {
                    xmlReader.Read();
                    HandleBackOfficeNode(nodeName, xmlReader.Value, rawDataFields, insertCommand);
                }
                break;

            //case XmlNodeType.Text:
            //	break;
            case XmlNodeType.EndElement:
                // Arrived to end of row.
                if (xmlReader.Name.ToLower().Contains(_rowName.ToLower()))
                {
                    InitalizeMetaDataParameters(insertCommand, xmlReader, hasBackOffice, gatewayNameFields);

                    // Execute command.
                    insertCommand.ExecuteNonQuery();

                    InitalizeNullValues(insertCommand, rawDataFields, metaDataFields);
                }

                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Create GAnalytics url using the dimesnions (the nodes with attribute
        /// IsDimension="True") and metrics in the fieldsMapping and the date retrievedDay.
        /// </summary>
        /// <param name="profileID">The required profile id to get his data from Ganalytics.</param>
        /// <param name="fieldsMapping">Contain a section with the metrics and dimesions to insert to the url.</param>
        /// <param name="retrievedDay">The date to fetch the data added to the end of the url.</param>
        /// <returns></returns>
        private string CreateGAnalyticsUrl(string profileID, FieldElementSection fieldsMapping, DateTime retrievedDay)
        {
            try
            {
                char[] charsToTrim = { ',' };
                string url         = @"https://www.google.com/analytics/feeds/data?ids=ga:" + profileID + @"&dimensions=";

                // Add dimensions' fields
                foreach (FieldElement fe in fieldsMapping.Fields)
                {
                    if (fe.Enabled && fe.IsDimension)
                    {
                        url += fe.Key + ",";
                    }
                }

                // Remove last ,
                url  = url.TrimEnd(charsToTrim);
                url += @"&metrics=";

                // Add metrics fields
                foreach (FieldElement fe in fieldsMapping.Fields)
                {
                    if (fe.Enabled && !fe.IsDimension)
                    {
                        url += fe.Key + ",";
                    }
                }

                url  = url.TrimEnd(charsToTrim);
                url += @"&sort=ga:date&start-date=" + ConvetDateTimeToString(retrievedDay) + "&end-date=" + ConvetDateTimeToString(retrievedDay);
                return(url);
            }
            catch (Exception ex)
            {
                throw new Exception("Error fetch data from the configuration.", ex);
            }
        }
コード例 #14
0
        private bool InitalizeReportMapping(ArrayList fields)
        {
            try
            {
                // Load the proper report paramters by the report name.
                FieldElementSection fes = (FieldElementSection)ConfigurationManager.GetSection("PanamaDailyReport");

                // Initalize the hash table with the fields of the the report.
                foreach (FieldElement fe in fes.Fields)
                {
                    if (fe.Enabled && fe.InsertToDB)
                    {
                        //fields.Add(fe.Key, fe.DBFieldName);
                        fields.Add(fe.DBFieldName.ToString().ToLower());
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write("Error get configuration Data for the report.", ex, Instance.AccountID);
                return(false);
            }
            return(true);
        }
コード例 #15
0
        protected override void ReadFile(string filePath, string defaultErrorSubDirPath, bool hasBackOffice, ref bool xmlFileEmpty, FieldElementSection rawDataFields, FieldElementSection metaDataFields, SqlCommand insertCommand, Dictionary <string, string> gatewayNameFields)
        {
            // Initalzie headers Dictionaries.
            Dictionary <string, int> headersCSV = new Dictionary <string, int>();

            accountList = new Dictionary <int, List <int> >();

            using (StreamReader textReader = new StreamReader(filePath, Encoding.Unicode))
            {
                // Read the headers of the CSV file and DB fields and return
                // a dictionary with the common headers.
                ReadHeaders(headersCSV, textReader);

                // Read first line in the CSV file.
                string csvTextLine = textReader.ReadLine();

                if (csvTextLine == null)
                {
                    Log.Write(string.Format("The file {0} is empty or not format in unicode txt.", filePath), LogMessageType.Error);
                    Exception ex = new Exception(string.Format("The file {0} is empty or not format in unicode txt.", filePath));
                    WriteErrorMesageToFile(filePath, string.Empty, ex, DefaultErrorSubDirPath);
                    throw ex;
                }

                // Read the CSV lines and insert them to the DB.
                while (!textReader.EndOfStream || !string.IsNullOrEmpty(csvTextLine))
                {
                    // Contiune if we have empty line in the csv file.
                    if (csvTextLine == null || csvTextLine == string.Empty)
                    {
                        continue;
                    }

                    try
                    {
                        // Initalize the insert command with values from Csv text line.
                        // InitalizeInsertCommandFields(filePath, headersDB, commonHeaders, headersCSV, insertCommand, csvTextLine, reportType);
                        InitalizeInsertCommandFields(rawDataFields, metaDataFields, filePath, headersCSV, insertCommand, csvTextLine);

                        insertCommand.ExecuteNonQuery();
                        InitalizeNullValues(insertCommand, rawDataFields, metaDataFields);
                    }
                    catch (Exception ex)
                    {
                        WriteErrorMesageToFile(filePath, csvTextLine, ex, DefaultErrorSubDirPath);
                    }
                    // Read the next line in the CSV file.
                    csvTextLine = textReader.ReadLine();
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Create a string which represents insert command from the configuration.
        /// The command created from 2 sections: mappingSection & tableSection.
        /// First we add the fields names and then we add there parmeters with their field type.
        /// </summary>
        /// <param name="tableName">The table name for the insert command.</param>
        /// <param name="rawDataFields"> This section in the configuration contain all the
        /// fields we get from the xmland map each field in the xml to a field in the db.</param>
        /// <param name="metaDataFields"> This section in the configuration contain all the
        /// fields of meta data like account_id, date, gk fields and etc.</param>
        /// <returns>insert command string.</returns>
        protected virtual string CreateInsertCmdString(string tableName, FieldElementSection rawDataFields, FieldElementSection metaDataFields)
        {
            try
            {
                char[] charsToTrim = { ',' };
                string sqlCmd      = "INSERT INTO " + tableName + "(";

                // Add fields' names
                // =============

                // Add fields' names from mapping Section
                foreach (FieldElement fe in rawDataFields.Fields)
                {
                    if (fe.Enabled && fe.InsertToDB)
                    {
                        sqlCmd += " " + fe.DBFieldName + ",";
                    }
                }

                // Add the field names from table Section
                foreach (FieldElement fe in metaDataFields.Fields)
                {
                    if (fe.Enabled && fe.InsertToDB)
                    {
                        sqlCmd += " " + fe.DBFieldName + ",";
                    }
                }

                // Remove last ,
                sqlCmd  = sqlCmd.TrimEnd(charsToTrim);
                sqlCmd += ") VALUES ( ";

                // Add fields' values and types
                // ==============================

                // Add fields' values and types from mapping Section
                foreach (FieldElement fe in rawDataFields.Fields)
                {
                    if (fe.Enabled && fe.InsertToDB)
                    {
                        sqlCmd += " @" + fe.DBFieldName + ":" + fe.DBFieldType + ",";
                    }
                }

                // Add the field values from table Section
                foreach (FieldElement fe in metaDataFields.Fields)
                {
                    if (fe.Enabled && fe.InsertToDB)
                    {
                        sqlCmd += " @" + fe.DBFieldName + ":" + fe.DBFieldType + ",";
                    }
                }

                sqlCmd  = sqlCmd.TrimEnd(charsToTrim);
                sqlCmd += ")";
                return(sqlCmd);
            }
            catch (Exception ex)
            {
                throw new Exception("Error fetch data from the configuration.", ex);
            }
        }
コード例 #17
0
        /// <summary>
        /// Hi M8, This function create a Dictionary with the fields from the required
        /// section in the configuration.
        /// </summary>
        /// <param name="fields">A Dictionary that contain the fields from the required
        /// section in the configuration.</param>
        /// <param name="sectionName">The section name from the configuration to load.</param>
        protected virtual void InitalizeGatewayNameMapping(Dictionary <string, string> fields, string sectionName)
        {
            //***************************
            // ANTI-YANIV HACK
            ServiceInstanceInfo targetInstance = Instance;
            string trackerParamsRaw            = string.Empty;

            if (sectionName == "GatewayName")
            {
                while (targetInstance != null)
                {
                    trackerParamsRaw = targetInstance.Configuration.Options["TrackingParameters"];
                    if (string.IsNullOrEmpty(trackerParamsRaw))
                    {
                        targetInstance = targetInstance.ParentInstance;
                    }
                    else
                    {
                        break;
                    }
                }

                if (trackerParamsRaw != null)
                {
                    string[] trackerParamPairs = trackerParamsRaw.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string trackerParamPair in trackerParamPairs)
                    {
                        string[] pair = trackerParamPair.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        if (pair.Length < 2)
                        {
                            continue;
                        }
                        else
                        {
                            fields.Add(pair[0], pair[1]);
                        }
                    }

                    // If we found anything ignore the rest of this horrible function
                    if (fields.Count >= 1) //fix by alon changed from >1 to >=1 we need at least 1 25/11
                    {
                        return;
                    }
                }
            }
            // ANTI-YANIV HACK
            //***************************

            try
            {
                // Load the proper report paramters by the report name.
                FieldElementSection fes = (FieldElementSection)ConfigurationManager.GetSection(sectionName);

                // Initalize the hash table with the fields of the the report.
                foreach (FieldElement fe in fes.Fields)
                {
                    fields.Add(fe.Key, fe.Value);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Error get configuration Data from {0} section.", sectionName), ex);
            }
        }
コード例 #18
0
 /// <summary>
 /// Initalize row with raw data from the xml and meta
 /// data (like gk fields) and insert the row to the DB.
 /// </summary>
 /// <param name="hasBackOffice">Indicate if the account have backoffice.</param>
 /// <param name="rawDataFields">Dictionary that contain all the required raw data fields from the DB.</param>
 /// <param name="metaDataFields">Dictionary that contain all the required Meta data fields from the DB.</param>
 /// <param name="insertCommand"></param>
 /// <param name="gatewayNameFields"></param>
 /// <param name="xmlReader"></param>
 /// <param name="retriveredDate">Required date.</param>
 protected virtual void HandleRow(bool hasBackOffice, FieldElementSection rawDataFields, FieldElementSection metaDataFields, SqlCommand insertCommand, Dictionary <string, string> gatewayNameFields, SourceDataRowReader <RetrieverDataRow> reader)
 {
     InitalizeRawDataFromXml(rawDataFields, metaDataFields, insertCommand, reader);
     InitalizeMetaDataParameters(insertCommand, reader, hasBackOffice, gatewayNameFields);
     InsertRowToDB(insertCommand);
 }
コード例 #19
0
        // original ReadFile function
        protected virtual void ReadFile(string xmlPath, string defaultErrorSubDirPath, bool hasBackOffice, ref bool xmlFileEmpty, FieldElementSection rawDataFields, FieldElementSection metaDataFields, SqlCommand insertCommand, Dictionary <string, string> gatewayNameFields)
        {
            bool firstRowInXml = true;

            using (XmlTextReader xmlReader = new XmlTextReader(xmlPath))
            {
                xmlReader.WhitespaceHandling = WhitespaceHandling.None;

                // Read root node
                xmlReader.Read();
                xmlFileEmpty = true;

                // Loop on all the rows in the xml report file.
                while (xmlReader.Read())
                {
                    if (!GetToRowsSection(xmlReader))
                    {
                        continue;
                    }

                    // Initalize dayCode.
                    if (firstRowInXml)
                    {
                        xmlFileEmpty  = false;
                        firstRowInXml = false;
                        // ASAF: raise log error if we have diffrent date in the file and in _requiredDay.
                        _requiredDay = DayCode.GenerateDateTime(GetDate(xmlReader));

                        if (_accountID == SystemAccountID)
                        {
                            GetAccountID(xmlReader.GetAttribute("acctname").ToString(), out _accountID, _accountFieldName);
                            _accountName = xmlReader.GetAttribute("acctname").ToString();
                        }

                        // Delete old data in the DB for the same data we fetch the new data.
                        DataIdentifier dataIdentifier = new DataIdentifier(_accountID, GetDayCode(_requiredDay), _channelID);
                        _dataIdentifiers.Add(dataIdentifier);
                        HandleDeleteDay();
                        InitalizeNullValues(insertCommand, rawDataFields, metaDataFields);
                    }

                    CheckRowData(xmlReader);

                    try
                    {
                        HandleRow(hasBackOffice, rawDataFields, metaDataFields, insertCommand, gatewayNameFields, xmlReader);
                    }
                    catch (Exception ex)
                    {
                        WriteErrorMesageToFile(xmlPath, xmlReader.ReadOuterXml(), ex, defaultErrorSubDirPath);
                    }
                }
            }
        }
        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;
            }
        }
        /*=========================*/
        #endregion

        #region protected override Methods
        /*================================*/

        /// <summary>
        /// Main entry point of the service.
        /// </summary>
        /// <returns></returns>
        protected override ServiceOutcome DoWork()
        {
            FieldElementSection fieldsMapping = (FieldElementSection)ConfigurationManager.GetSection
                                                    (GetConfigurationOptionsField("FieldsMapping"));

            string profileID = GetConfigurationOptionsField("profileID");

            // Create Authentication Token
            string authToken = FetchAutoToken();
            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Authorization", "GoogleLogin auth=" + authToken);

            ArrayList dates = new ArrayList();

            if (CheckRangeDate(ref dates))
            {
                int i;
                if (dates == null || dates.Count == 0)
                {
                    return(ServiceOutcome.Failure);
                }

                for (i = 0; i < dates.Count && i < _maxInstancesReRuns; ++i)
                {
                    GetReport(fieldsMapping, (DateTime)dates[i], profileID, headers);
                }

                // Write to the log all the dates that din;t eun because max instances ReRuns.
                if (i < dates.Count)
                {
                    string errorMsg = "Can't write the following dates: ";
                    for (int j = i; j < dates.Count; ++j)
                    {
                        errorMsg += ((DateTime)dates[j]).ToShortDateString() + ", ";
                    }

                    errorMsg += " because the service exceed the max instances ReRuns.";
                    Log.Write(errorMsg, LogMessageType.Error);
                }

                if (_errorDates.Count > 0)
                {
                    for (i = 0; i < _errorDates.Count; ++i)
                    {
                        GetReport(fieldsMapping, (DateTime)dates[i], profileID, headers);
                    }
                }
            }
            else
            {
                DateTime retrievedDay = DateTime.Now.AddDays(-1);
                // Check if we need to get manual date.
                CheckManualDate(ref retrievedDay);
                if (!GetReport(fieldsMapping, retrievedDay, profileID, headers))
                {
                    return(ServiceOutcome.Failure);
                }
            }

            return(ServiceOutcome.Success);
        }
        protected override void HandleBackOfficeNode(string nodeName, string nodeValue, FieldElementSection rawDataFields, SqlCommand insertCommand)
        {
            //If the node name is CODE, then we need to do some processing on the value.
            string boValue = nodeValue;

            if (nodeName.ToLower() == "code")
            {
                if (nodeValue.ToLower().Contains("esgn") && nodeValue.StartsWith("5137"))
                {
                    //now build the new node value.
                    boValue = "1";
                    int    idx   = nodeValue.IndexOf("esgn");
                    string value = nodeValue.Substring(idx + 4);
                    boValue += value;
                }
                else
                {
                    int val = -1;
                    if (!Int32.TryParse(nodeValue, out val))
                    {
                        boValue = "-1";
                    }
                }
            }

            if (nodeName.ToLower() == "refund")
            {
                if (nodeValue.Contains("."))
                {
                    double val  = Convert.ToDouble(nodeValue);
                    int    iVal = Convert.ToInt32(val);
                    boValue = iVal.ToString();
                }
            }

            base.HandleBackOfficeNode(nodeName, boValue, rawDataFields, insertCommand);
        }
コード例 #23
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            //ParentWorkflow.Parameters.Add("SourceFilePath", @"c:\temp\alerts\admin\report062009Monthly.csv");

            //Parse the CSV file, and create the data structure for it.
            if (!ParentWorkflow.Parameters.ContainsKey("SourceFilePath"))
            {
                throw new Exception("Could not find the path of the CSV file.");
            }

            string fileName = ParentWorkflow.Parameters["SourceFilePath"].ToString();

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("Could not find the CSV file at: " + fileName);
            }

            //creating list of accounts names to be reunite


            StreamReader sr    = File.OpenText(fileName);
            string       line  = String.Empty;
            int          count = 1;
            bool         month = false;
            //Loop on the file, and build a hash-table per account. We assume that each
            //account only appears ONCE!.
            Hashtable ht = new Hashtable();
            Dictionary <string, string> aggregatedAccountsProperties = new Dictionary <string, string>();

            //getting aggregation information from configuration
            FieldElementSection fes = (FieldElementSection)ConfigurationManager.GetSection("AggregatedAccountsProperties");
            bool isAccntExist       = false;

            while (!sr.EndOfStream)
            {
                line = sr.ReadLine();

                if (count == AccountAllMeasures.DATE_RANGE_ROW)
                {
                    //Based on what's written in the line, see if we're a daily report
                    //or a monthly report.
                    if (line.ToLower().Contains("last month"))
                    {
                        month = true;
                    }

                    ParentWorkflow.InternalParameters.Add("Monthly", month);
                }

                if (count >= AccountAllMeasures.ADWORDS_CSV_START_ROW)
                {
                    //We have reached the actual data... start parsing.
                    AccountAllMeasures aam = new AccountAllMeasures(line);
                    //Do not add empty accounts.
                    if (aam.AccountName == String.Empty)
                    {
                        continue;
                    }

                    if (!ParentWorkflow.InternalParameters.ContainsKey("ReportDate"))
                    {
                        ParentWorkflow.InternalParameters.Add("ReportDate", aam.CompareDate);
                    }

                    if (aam.AccountName != String.Empty)
                    {
                        isAccntExist = false;
                        //object section = ConfigurationManager.GetSection("AggregatedAccountsProperties");
                        //if configuration hasn't been already read
                        if (aggregatedAccountsProperties.Count == 0)
                        {
                            // Initalize the dictionary with the properties of the accounts.
                            foreach (FieldElement fe in fes.Fields)
                            {
                                string[] parsed = fe.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                foreach (string st in parsed)
                                {
                                    aggregatedAccountsProperties.Add(st, fe.Key);
                                }
                            }
                        }
                        if (aggregatedAccountsProperties.ContainsKey(aam.AccountName))
                        {
                            sumAccounts(aam, aggregatedAccountsProperties[aam.AccountName], ref isAccntExist);
                        }
                        else
                        {
                            sumAccounts(aam, aam.AccountName, ref isAccntExist);
                        }


                        if (!isAccntExist)
                        {
                            //if destination account is not in _results we'll add the account that should be aggregated with destination name
                            if (aggregatedAccountsProperties.ContainsKey(aam.AccountName))
                            {
                                aam.AccountName = aggregatedAccountsProperties[aam.AccountName];
                            }
                            _results.Add(aam);
                            ht.Add(aam.AccountName, aam);
                        }
                    }
                }
                count++;
            }

            sr.Close();
            sr.Dispose();

            if (!ParentWorkflow.InternalParameters.ContainsKey("CSVResults"))
            {
                ParentWorkflow.InternalParameters.Add("CSVResults", ht);
            }

            try
            {
                File.Delete(fileName);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not delete file: " + fileName + ". Exception: " + ex.ToString());
                throw ex;
            }

            return(ActivityExecutionStatus.Closed);
        }