Ejemplo n.º 1
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (Convert.ToBoolean(ParentWorkflow.InternalParameters["Monthly"]))
            {
                return(ActivityExecutionStatus.Closed);
            }

            DateTime reportDate = DateTime.Now.AddDays(-1);

            if (ParentWorkflow.InternalParameters.ContainsKey("ReportDate"))
            {
                reportDate = Convert.ToDateTime(ParentWorkflow.InternalParameters["ReportDate"]);
            }


            //Execute the query to get the measured parameters for the OLTP for all accounts.
            string sql = @"SELECT BO.Account_ID, Account_Name AccountName, sum(BOClicks) AS SumOfClicks,
                            SUM(new_leads) AS SumOfLeads, SUM(new_users) AS SumOfNewUsers,
                            SUM(new_active_users) AS SumOfNewActiveUsers, SUM(active_users) AS SumOfActiveUsers,
                            SUM(new_net_deposits_in_dollars) SumOfNewNetDeposits, SUM(total_net_deposits_in_dollars) SumOfTotalNetDeposits,
                            SUM(clientspecific1) AS SumOfClientSpecific1, SUM(clientspecific2) AS SumOfClientSpecific2,
                            SUM(clientspecific3) AS SumOfClientSpecific3, SUM(clientspecific4) AS SumOfClientSpecific4,
                            SUM(clientspecific5) AS SumOfClientSpecific5
                            FROM easynet_oltp.dbo.BackOffice_Client_Gateway BO,easynet_oltp.dbo.User_GUI_Account ";

            sql += "WHERE day_code =  '" + DayCode.ToDayCode(reportDate) + "' ";
            sql += "AND BO.account_id = User_GUI_Account.Account_ID GROUP BY Account_Name,BO.Account_id,day_code ORDER BY 2";

            DataManager.ConnectionString = ParentWorkflow.Parameters["AdminConnectionString"].ToString();
            DataManager.CommandTimeout   = 0;

            using (DataManager.Current.OpenConnection())
            {
                SqlCommand    cmd = DataManager.CreateCommand(sql);
                SqlDataReader dr  = cmd.ExecuteReader();

                //Loop on the results, and build a hash-table per account. We assume that each
                //account only appears ONCE!.
                Hashtable ht = new Hashtable();
                while (dr.Read())
                {
                    AccountAllMeasures aam = new AccountAllMeasures(dr, true);
                    ht.Add(aam.AccountID, aam);
                }

                dr.Close();
                dr.Dispose();

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

            return(ActivityExecutionStatus.Closed);
        }
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            DataManager.ConnectionString = ParentWorkflow.Parameters["ConnectionString"].ToString();
            DataManager.CommandTimeout   = 0;

            //Run the stored procedure, based on the params we have.
            try
            {
                string channelID = ParentWorkflow.Parameters["ChannelID"].ToString();

                //Create the command.
                using (DataManager.Current.OpenConnection())
                {
                    SqlCommand accounts = BuildCommand();
                    accounts.ExecuteNonQuery();

                    Easynet.Edge.Alerts.Core.AlertMeasures measures = AlertMeasures;

                    //Now we need to loop on the table and build the list of campaigns and deltas.
                    SqlDataReader             sdr         = GetMeasuredData(ParentWorkflow.Parameters);
                    string                    accountName = String.Empty;
                    List <AccountAllMeasures> accountList = new List <AccountAllMeasures>();
                    while (sdr.Read())
                    {
                        AccountAllMeasures aam = new AccountAllMeasures(sdr, measures, _alertType);
                        accountList.Add(aam);
                    }

                    sdr.Close();
                    sdr.Dispose();

                    foreach (AccountAllMeasures aams in accountList)
                    {
                        AccountAlertFilters filters = new AccountAlertFilters(aams.AccountID);
                        aams.Filter(measures, filters);
                        accountName          = aams.AccountName;
                        aams.TimeMeasurement = this.TimeMeasurement;
                        aams.MeasurementType = this.MeasurementType;

                        //Only add if we're going to include it in the list (i.e. passed the min)
                        if (aams.Include)
                        {
                            _results.Add(aams);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception at Account Campaigns: " + ex.ToString());
                throw ex;
            }

            return(ActivityExecutionStatus.Closed);
        }
Ejemplo n.º 3
0
        private void sumAccounts(AccountAllMeasures aam, string destAccountName, ref bool isAccntExist)
        {
            foreach (AccountAllMeasures ob in _results)
            {
                if (ob.AccountName.Equals(destAccountName))
                {
                    //temporary until we fix it in db for any account
                    //if (aam.AccountName.Length < ob.AccountName.Length)
                    //    ob.AccountName = aam.AccountName;

                    ob.BONewActivationsCompare   += aam.BONewActivationsCompare;
                    ob.BONewActivationsCurrent   += aam.BONewActivationsCurrent;
                    ob.BONewUsersCompare         += aam.BONewUsersCompare;
                    ob.BONewUsersCurrent         += aam.BONewUsersCurrent;
                    ob.ClicksChangeRatio         += aam.ClicksChangeRatio;
                    ob.ClicksCompare             += aam.ClicksCompare;
                    ob.ClicksCurrent             += aam.ClicksCurrent;
                    ob.ConversionRateCompare     += aam.ConversionRateCompare;
                    ob.ConversionRateCurrent     += aam.ConversionRateCurrent;
                    ob.ConversionsCompare        += aam.ConversionsCompare;
                    ob.ConversionsCurrent        += aam.ConversionsCurrent;
                    ob.CostCompare               += aam.CostCompare;
                    ob.CostCurrent               += aam.CostCurrent;
                    ob.CostPerBONewUsersCompare  += aam.CostPerBONewUsersCompare;
                    ob.CostPerBONewUsersCurrent  += aam.CostPerBONewUsersCurrent;
                    ob.CostPerConversionsCompare += aam.CostPerConversionsCompare;
                    ob.CostPerConversionsCurrent += aam.CostPerConversionsCurrent;
                    ob.CPCCompare       += aam.CPCCompare;
                    ob.CPCCurrent       += aam.CPCCurrent;
                    ob.CTRCompare       += aam.CTRCompare;
                    ob.CTRCurrent       += aam.CTRCurrent;
                    ob.ImpsCompare      += aam.ImpsCompare;
                    ob.ImpsCurrent      += aam.ImpsCurrent;
                    ob.LeadsCompare     += aam.LeadsCompare;
                    ob.LeadsCurrent     += aam.LeadsCurrent;
                    ob.PurcasesCompare  += aam.PurcasesCompare;
                    ob.PurchasesCurrent += aam.PurchasesCurrent;
                    ob.SignupsCompare   += aam.SignupsCompare;
                    ob.SignupsCurrent   += aam.SignupsCurrent;
                    isAccntExist         = true;
                    return;
                }
            }
        }
Ejemplo n.º 4
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            DateTime reportDate = DateTime.Now.AddDays(-1);

            if (ParentWorkflow.InternalParameters.ContainsKey("ReportDate"))
            {
                reportDate = Convert.ToDateTime(ParentWorkflow.InternalParameters["ReportDate"]);
            }


            //Execute the query to get the measured parameters for the OLTP for all accounts.
            string sql = @"SELECT Account_Name AccountName,Paid_API_AllColumns.account_id,
                            SUM(imps) as SumOfImps,SUM(clicks) as SumOfClicks,Avg(cpc) AVGCPC,
                            SUM(cost) SumOfCost,Avg(pos) AvgPos,SUM(conv) SumOfConv,SUM(purchases) SumOfPurchase,
                            SUM(leads) SumOfleads,SUM(signups) SumOfSignups
                           FROM easynet_OLTP.dbo.Paid_API_AllColumns,easynet_OLTP.dbo.User_GUI_Account ";

            if (Convert.ToBoolean(ParentWorkflow.InternalParameters["Monthly"]))
            {
                string time = reportDate.Year.ToString();
                if (reportDate.Month.ToString().Length < 2)
                {
                    time += "0" + reportDate.Month.ToString();
                }
                else
                {
                    time += reportDate.Month.ToString();
                }

                sql += "WHERE left(day_code,6) = '" + time + "' ";
            }
            else
            {
                sql += "WHERE day_code =  '" + DayCode.ToDayCode(reportDate) + "' ";
            }

            sql += "AND Paid_API_AllColumns.account_id= User_GUI_Account.Account_ID " +
                   "AND channel_id = 1 " +
                   "GROUP BY Account_Name,Paid_API_AllColumns.account_id " +
                   "ORDER BY 1";

            DataManager.ConnectionString = ParentWorkflow.Parameters["AdminConnectionString"].ToString();
            DataManager.CommandTimeout   = 0;

            using (DataManager.Current.OpenConnection())
            {
                SqlCommand    cmd = DataManager.CreateCommand(sql);
                SqlDataReader dr  = cmd.ExecuteReader();

                //Loop on the results, and build a hash-table per account. We assume that each
                //account only appears ONCE!.
                Hashtable ht = new Hashtable();
                while (dr.Read())
                {
                    AccountAllMeasures aam = new AccountAllMeasures(dr);
                    ht.Add(aam.AccountID, aam);
                }

                dr.Close();
                dr.Dispose();

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

            return(ActivityExecutionStatus.Closed);
        }
Ejemplo n.º 5
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            //First see if we have a panorama file. We assume the file is in the Panorama folder.
            //..\Panorama (D:\Edge\Alerts\Panorama)
            string sourcePath = String.Empty;

            if (ParentWorkflow.Parameters.ContainsKey("SourceFilePath"))
            {
                sourcePath = ParentWorkflow.Parameters["SourceFilePath"].ToString();
            }

            string path   = Path.GetDirectoryName(sourcePath);
            string parent = Directory.GetParent(path).FullName;

            if (!parent.EndsWith(@"\"))
            {
                parent += @"\";
            }

            parent += @"Panorama\";
            if (!ParentWorkflow.InternalParameters.ContainsKey("ReportDate"))
            {
                throw new Exception("No report date found. Cannot get panorama details.");
            }

            DateTime reportDate = Convert.ToDateTime(ParentWorkflow.InternalParameters["ReportDate"]);
            string   fileName   = reportDate.ToString("d_M_yy") + ".txt";

            parent += fileName;

            //Check if we have this file. If we don't - exit.
            if (!File.Exists(parent))
            {
                parent = parent.Replace(".txt", ".csv");
                if (!File.Exists(parent))
                {
                    return(ActivityExecutionStatus.Closed);
                }
            }

            //Load the file and parse it.
            StreamReader sr    = File.OpenText(parent);
            string       line  = String.Empty;
            int          count = 0;

            Hashtable ht = new Hashtable();

            while (!sr.EndOfStream)
            {
                line = sr.ReadLine();
                if (count >= 1)
                {
                    try
                    {
                        //Actually do the parsing.
                        AccountAllMeasures aam = new AccountAllMeasures(line, true);

                        //Do not add empty accounts.
                        if (aam.AccountName == String.Empty)
                        {
                            continue;
                        }

                        _results.Add(aam);
                        ht.Add(aam.AccountName, aam);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                count++;
            }

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

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

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

            return(ActivityExecutionStatus.Closed);
        }
Ejemplo n.º 6
0
        public void Generate(string templateFileName, DateTime date)
        {
            if (templateFileName == String.Empty ||
                templateFileName == null)
            {
                throw new ArgumentException("Invalid template file name. Cannot be null or empty");
            }

            if (!File.Exists(templateFileName))
            {
                throw new FileNotFoundException("Could not find templat efile: " + templateFileName);
            }

            if (_source == null ||
                _compare == null)
            {
                throw new Exception("Invalid source or compare data. Cannot be null.");
            }

            string reportFilePath = Path.GetDirectoryName(templateFileName);

            if (!reportFilePath.EndsWith("\\"))
            {
                reportFilePath += "\\";
            }

            string reportFileName = "AdminAlert_" + DayCode.ToDayCode(date).ToString() + ".xlsx";

            reportFileName = reportFilePath + reportFileName;

            FileInfo newFile  = new FileInfo(reportFileName);
            FileInfo template = new FileInfo(templateFileName);

            using (ExcelPackage ep = new ExcelPackage(newFile, template))
            {
                ExcelWorkbook ew = ep.Workbook;

                ExcelWorksheet worksheet = ew.Worksheets["AdWords"];

                //Start inserting rows from the begining.
                int row = ADMIN_START_ROW;
                IDictionaryEnumerator ide = _source.GetEnumerator();
                while (ide.MoveNext())
                {
                    AccountAllMeasures csv = (AccountAllMeasures)ide.Value;

                    //First the CSV Row.
                    worksheet.Cell(row, 1).Value  = "Adwords - " + csv.AccountName;
                    worksheet.Cell(row, 2).Value  = csv.ImpsCurrent.ToString();
                    worksheet.Cell(row, 3).Value  = csv.ClicksCurrent.ToString();
                    worksheet.Cell(row, 4).Value  = csv.CPCCurrent.ToString();
                    worksheet.Cell(row, 5).Value  = csv.CostCurrent.ToString();
                    worksheet.Cell(row, 6).Value  = csv.AveragePosition.ToString();
                    worksheet.Cell(row, 7).Value  = csv.ConversionsCurrent.ToString();
                    worksheet.Cell(row, 8).Value  = csv.PurchasesCurrent.ToString();
                    worksheet.Cell(row, 9).Value  = csv.LeadsCurrent.ToString();
                    worksheet.Cell(row, 10).Value = csv.SignupsCurrent.ToString();

                    //Now - OLTP
                    int id = -1;
                    try
                    {
                        id = AccountAllMeasures.FromAccountName(csv.AccountName);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }

                    if (_compare.ContainsKey(id))
                    {
                        AccountAllMeasures oltp = (AccountAllMeasures)_compare[id];
                        worksheet.Cell(row + 1, 1).Value  = "OLTP - " + oltp.AccountName;
                        worksheet.Cell(row + 1, 2).Value  = oltp.ImpsCurrent.ToString();
                        worksheet.Cell(row + 1, 3).Value  = oltp.ClicksCurrent.ToString();
                        worksheet.Cell(row + 1, 4).Value  = oltp.CPCCurrent.ToString();
                        worksheet.Cell(row + 1, 5).Value  = oltp.CostCurrent.ToString();
                        worksheet.Cell(row + 1, 6).Value  = oltp.AveragePosition.ToString();
                        worksheet.Cell(row + 1, 7).Value  = oltp.ConversionsCurrent.ToString();
                        worksheet.Cell(row + 1, 8).Value  = oltp.PurchasesCurrent.ToString();
                        worksheet.Cell(row + 1, 9).Value  = oltp.LeadsCurrent.ToString();
                        worksheet.Cell(row + 1, 10).Value = oltp.SignupsCurrent.ToString();

                        if (csv.ImpsCurrent != oltp.ImpsCurrent)
                        {
                            worksheet.Cell(row + 1, 2).Style = "Bad";
                        }

                        if (csv.ClicksCurrent != oltp.ClicksCurrent)
                        {
                            worksheet.Cell(row + 1, 3).Style = "Bad";
                        }

                        if (csv.CPCCurrent != oltp.CPCCurrent)
                        {
                            worksheet.Cell(row + 1, 4).Style = "Bad";
                        }

                        if (csv.CostCurrent != oltp.CostCurrent)
                        {
                            worksheet.Cell(row + 1, 5).Style = "Bad";
                        }

                        if (csv.AveragePosition != oltp.AveragePosition)
                        {
                            worksheet.Cell(row + 1, 6).Style = "Bad";
                        }

                        if (csv.ConversionsCurrent != oltp.ConversionsCurrent)
                        {
                            worksheet.Cell(row + 1, 7).Style = "Bad";
                        }

                        if (csv.PurchasesCurrent != oltp.PurchasesCurrent)
                        {
                            worksheet.Cell(row + 1, 8).Style = "Bad";
                        }

                        if (csv.LeadsCurrent != oltp.LeadsCurrent)
                        {
                            worksheet.Cell(row + 1, 9).Style = "Bad";
                        }

                        if (csv.SignupsCurrent != oltp.SignupsCurrent)
                        {
                            worksheet.Cell(row + 1, 10).Style = "Bad";
                        }
                    }
                    else
                    {
                        //Couldn't find it. Put 0 in everyone, and mark them all as "Bad".
                        worksheet.Cell(row + 1, 1).Value  = "OLTP - " + csv.AccountName;
                        worksheet.Cell(row + 1, 2).Value  = "0";
                        worksheet.Cell(row + 1, 2).Style  = "Bad";
                        worksheet.Cell(row + 1, 3).Value  = "0";
                        worksheet.Cell(row + 1, 3).Style  = "Bad";
                        worksheet.Cell(row + 1, 4).Value  = "0";
                        worksheet.Cell(row + 1, 4).Style  = "Bad";
                        worksheet.Cell(row + 1, 5).Value  = "0";
                        worksheet.Cell(row + 1, 5).Style  = "Bad";
                        worksheet.Cell(row + 1, 6).Value  = "0";
                        worksheet.Cell(row + 1, 6).Style  = "Bad";
                        worksheet.Cell(row + 1, 7).Value  = "0";
                        worksheet.Cell(row + 1, 7).Style  = "Bad";
                        worksheet.Cell(row + 1, 8).Value  = "0";
                        worksheet.Cell(row + 1, 8).Style  = "Bad";
                        worksheet.Cell(row + 1, 9).Value  = "0";
                        worksheet.Cell(row + 1, 9).Style  = "Bad";
                        worksheet.Cell(row + 1, 10).Value = "0";
                        worksheet.Cell(row + 1, 10).Style = "Bad";
                    }

                    //Now panorama
                    string accountName = AccountAllMeasures.FromGoogleAccountName(csv.AccountName);
                    if (_bi != null && _bi.ContainsKey(accountName))
                    {
                        AccountAllMeasures panorama = (AccountAllMeasures)_bi[accountName];
                        worksheet.Cell(row + 2, 1).Value  = "PANORAMA - " + panorama.AccountName;
                        worksheet.Cell(row + 2, 2).Value  = panorama.ImpsCurrent.ToString();
                        worksheet.Cell(row + 2, 3).Value  = panorama.ClicksCurrent.ToString();
                        worksheet.Cell(row + 2, 4).Value  = panorama.CPCCurrent.ToString();
                        worksheet.Cell(row + 2, 5).Value  = panorama.CostCurrent.ToString();
                        worksheet.Cell(row + 2, 6).Value  = panorama.AveragePosition.ToString();
                        worksheet.Cell(row + 2, 7).Value  = panorama.ConversionsCurrent.ToString();
                        worksheet.Cell(row + 2, 8).Value  = panorama.PurchasesCurrent.ToString();
                        worksheet.Cell(row + 2, 9).Value  = panorama.LeadsCurrent.ToString();
                        worksheet.Cell(row + 2, 10).Value = panorama.SignupsCurrent.ToString();

                        if (csv.ImpsCurrent != panorama.ImpsCurrent)
                        {
                            worksheet.Cell(row + 1, 2).Style = "Bad";
                        }

                        if (csv.ClicksCurrent != panorama.ClicksCurrent)
                        {
                            worksheet.Cell(row + 1, 3).Style = "Bad";
                        }

                        if (csv.CPCCurrent != panorama.CPCCurrent)
                        {
                            worksheet.Cell(row + 1, 4).Style = "Bad";
                        }

                        if (csv.CostCurrent != panorama.CostCurrent)
                        {
                            worksheet.Cell(row + 1, 5).Style = "Bad";
                        }

                        if (csv.AveragePosition != panorama.AveragePosition)
                        {
                            worksheet.Cell(row + 1, 6).Style = "Bad";
                        }

                        if (csv.ConversionsCurrent != panorama.ConversionsCurrent)
                        {
                            worksheet.Cell(row + 1, 7).Style = "Bad";
                        }

                        if (csv.PurchasesCurrent != panorama.PurchasesCurrent)
                        {
                            worksheet.Cell(row + 1, 8).Style = "Bad";
                        }

                        if (csv.LeadsCurrent != panorama.LeadsCurrent)
                        {
                            worksheet.Cell(row + 1, 9).Style = "Bad";
                        }

                        if (csv.SignupsCurrent != panorama.SignupsCurrent)
                        {
                            worksheet.Cell(row + 1, 10).Style = "Bad";
                        }
                    }
                    else
                    {
                        //Couldn't find it. Put 0 in everyone, and mark them all as "Bad".
                        worksheet.Cell(row + 2, 1).Value  = "PANORAMA - " + csv.AccountName;
                        worksheet.Cell(row + 2, 2).Value  = "0";
                        worksheet.Cell(row + 2, 2).Style  = "Bad";
                        worksheet.Cell(row + 2, 3).Value  = "0";
                        worksheet.Cell(row + 2, 3).Style  = "Bad";
                        worksheet.Cell(row + 2, 4).Value  = "0";
                        worksheet.Cell(row + 2, 4).Style  = "Bad";
                        worksheet.Cell(row + 2, 5).Value  = "0";
                        worksheet.Cell(row + 2, 5).Style  = "Bad";
                        worksheet.Cell(row + 2, 6).Value  = "0";
                        worksheet.Cell(row + 2, 6).Style  = "Bad";
                        worksheet.Cell(row + 2, 7).Value  = "0";
                        worksheet.Cell(row + 2, 7).Style  = "Bad";
                        worksheet.Cell(row + 2, 8).Value  = "0";
                        worksheet.Cell(row + 2, 8).Style  = "Bad";
                        worksheet.Cell(row + 2, 9).Value  = "0";
                        worksheet.Cell(row + 2, 9).Style  = "Bad";
                        worksheet.Cell(row + 2, 10).Value = "0";
                        worksheet.Cell(row + 2, 10).Style = "Bad";
                    }

                    //Advance 3 rows.

                    row += 3;
                }

                worksheet.Cell(ADMIN_START_ROW + 1, 16).Value = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
                worksheet.Cell(ADMIN_START_ROW + 2, 16).Value = date.ToString("dd/MM/yyyy HH:mm:ss");

                ExcelWorksheet boHistory = ew.Worksheets["BOHistory"];
                ExcelWorksheet bo_ef     = ew.Worksheets["BO_EF"];

                if (_bo != null)
                {
                    //Add the BO sheet.
                    int boRow = ADMIN_START_ROW;
                    IDictionaryEnumerator boe = _bo.GetEnumerator();

                    if (boHistory != null)
                    {
                        while (boe.MoveNext())
                        {
                            AccountAllMeasures boData = (AccountAllMeasures)boe.Value;

                            boHistory.Cell(boRow, 1).Value  = boData.AccountName;
                            boHistory.Cell(boRow, 2).Value  = boData.ClicksCurrent.ToString();
                            boHistory.Cell(boRow, 3).Value  = boData.LeadsCurrent.ToString();
                            boHistory.Cell(boRow, 4).Value  = boData.BONewUsersCurrent.ToString();
                            boHistory.Cell(boRow, 5).Value  = boData.BONewActivationsCurrent.ToString();
                            boHistory.Cell(boRow, 6).Value  = boData.SumOfActiveUsers.ToString();
                            boHistory.Cell(boRow, 7).Value  = boData.SumOfNewNetDeposits.ToString();
                            boHistory.Cell(boRow, 8).Value  = boData.SumOfTotalNetDeposits.ToString();
                            boHistory.Cell(boRow, 9).Value  = boData.SumOfClientSpecific1.ToString();
                            boHistory.Cell(boRow, 10).Value = boData.SumOfClientSpecific2.ToString();
                            boHistory.Cell(boRow, 11).Value = boData.SumOfClientSpecific3.ToString();
                            boHistory.Cell(boRow, 12).Value = boData.SumOfClientSpecific4.ToString();
                            boHistory.Cell(boRow, 13).Value = boData.SumOfClientSpecific5.ToString();

                            boRow++;
                        }
                    }

                    boe.Reset();

                    boRow = ADMIN_START_ROW;

                    if (bo_ef != null)
                    {
                        while (boe.MoveNext())
                        {
                            AccountAllMeasures boef = (AccountAllMeasures)boe.Value;

                            //Hack for easy forex only!
                            if (boef.AccountID == 7)
                            {
                                bo_ef.Cell(boRow, 2).Value = boef.LeadsCurrent.ToString();
                                bo_ef.Cell(boRow, 3).Value = boef.BONewUsersCurrent.ToString();
                                bo_ef.Cell(boRow, 4).Value = boef.BONewActivationsCurrent.ToString();
                                bo_ef.Cell(boRow, 5).Value = boef.SumOfActiveUsers.ToString();
                                bo_ef.Cell(boRow, 6).Value = boef.SumOfNewNetDeposits.ToString();
                                bo_ef.Cell(boRow, 7).Value = boef.SumOfTotalNetDeposits.ToString();
                            }
                        }
                    }
                }
                else
                {
                    boHistory.Cell(100, 1).Value = "1";
                    bo_ef.Cell(100, 1).Value     = "1";
                }

                ep.Save();

                _generatedFileName = reportFileName;
            }
        }
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            //Compare the results per account, and see if there is a difference
            if (!ParentWorkflow.InternalParameters.ContainsKey("CSVResults"))
            {
                throw new Exception("Could not find the results from the CSV file.");
            }

            if (!ParentWorkflow.InternalParameters.ContainsKey("OLTPResults"))
            {
                throw new Exception("Could not find the results from the OLTP database.");
            }

            Hashtable csv       = (Hashtable)ParentWorkflow.InternalParameters["CSVResults"];
            Hashtable oltp      = (Hashtable)ParentWorkflow.InternalParameters["OLTPResults"];
            Hashtable panorama  = null;
            Hashtable boResults = null;

            if (ParentWorkflow.InternalParameters.ContainsKey("PanoramaCSVResults"))
            {
                panorama = (Hashtable)ParentWorkflow.InternalParameters["PanoramaCSVResults"];
            }

            if (ParentWorkflow.InternalParameters.ContainsKey("BOResults"))
            {
                boResults = (Hashtable)ParentWorkflow.InternalParameters["BOResults"];
            }

            IDictionaryEnumerator ide = csv.GetEnumerator();

            while (ide.MoveNext())
            {
                AccountAllMeasures csvRecord = (AccountAllMeasures)ide.Value;

                //Get the account ID based on the name of the account from the CSV.
                int accountID = -1;
                try
                {
                    accountID = AccountAllMeasures.FromAccountName(ide.Key.ToString());
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }

                if (accountID <= 0)
                {
                    continue;
                }

                if (!oltp.ContainsKey(accountID))
                {
                    //If we couldn't find this account in the OLTP, this means
                    //we have no data about it.
                    DifferenceFound = true;
                }
                else
                {
                    AccountAllMeasures oltpRecord = (AccountAllMeasures)oltp[accountID];

                    //Check if we have a difference. Since we generate the report anyway,
                    //it means that this repoert will be sent to more people.
                    try
                    {
                        if (csvRecord.Different(oltpRecord))
                        {
                            DifferenceFound = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                        continue;
                    }
                }
            }

            if (DifferenceFound)
            {
                string rndEmail = "*****@*****.**";
                if (ParentWorkflow.Parameters.ContainsKey("RNDEmail"))
                {
                    rndEmail = ParentWorkflow.Parameters["RNDEmail"].ToString();
                }
                ParentWorkflow.InternalParameters.Add("Emails", rndEmail);
            }
            else
            {
                string itEmail = "*****@*****.**";
                if (ParentWorkflow.Parameters.ContainsKey("ITEmail"))
                {
                    itEmail = ParentWorkflow.Parameters["ITEmail"].ToString();
                }
                ParentWorkflow.InternalParameters.Add("Emails", itEmail);
            }

            if (!ParentWorkflow.Parameters.ContainsKey("AdminAlertTemplate"))
            {
                throw new Exception("Could not find alert template file.");
            }

            string templateFile = ParentWorkflow.Parameters["AdminAlertTemplate"].ToString();

            try
            {
                DateTime reportDate = DateTime.Now.AddDays(-1);
                if (ParentWorkflow.InternalParameters.ContainsKey("ReportDate"))
                {
                    reportDate = Convert.ToDateTime(ParentWorkflow.InternalParameters["ReportDate"]);
                }

                //Generate the excel report.
                AdminReport ar = new AdminReport(csv, oltp, panorama);
                if (boResults != null)
                {
                    ar.BOResults = boResults;
                }

                ar.Generate(templateFile, reportDate);

                ParentWorkflow.InternalParameters.Add("AccountName", "Edge Administration");
                ParentWorkflow.InternalParameters.Add("MessageFileName", ar.GeneratedReportFile);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception while trying to generate report. Exception: " + ex.ToString());
            }

            return(ActivityExecutionStatus.Closed);
        }
Ejemplo n.º 8
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);
        }