Ejemplo n.º 1
0
        static void NewMain(string[] args)
        {
            string singlecampaignname = "";
            bool   usesinglecampaign  = false;
            bool   runqueue           = false;

            try
            {
                //check for an argument that starts with "CAMPAIGNNAME"
                foreach (string s in args)
                {
                    if (s.ToUpper().Trim().StartsWith("/CAMPAIGNNAME:"))
                    {
                        singlecampaignname = s.ToUpper().Trim().Replace("/CAMPAIGNNAME:", "");
                        usesinglecampaign  = true;
                    }
                    else if (s.ToUpper().StartsWith("/TIMEOVERRIDE:"))
                    {
                        overridestarttimecheck = true;
                    }
                    else if (s.ToUpper().StartsWith("/QUEUE:"))
                    {
                        runqueue = true;
                    }
                }

                int campaignsthatrancount = 0;

                string htmlOutput = string.Empty;

                if (!runqueue)
                {
                    //run if override is on OR the time is before 7 AM (call center hours)
                    if ((overridestarttimecheck == true) || (overridestarttimecheck == false && (DateTime.Now.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.DayOfWeek == DayOfWeek.Sunday)) || (overridestarttimecheck == false && DateTime.Now.Hour < 7 && (DateTime.Now.DayOfWeek == DayOfWeek.Monday || DateTime.Now.DayOfWeek == DayOfWeek.Tuesday || DateTime.Now.DayOfWeek == DayOfWeek.Wednesday || DateTime.Now.DayOfWeek == DayOfWeek.Thursday || DateTime.Now.DayOfWeek == DayOfWeek.Friday)))
                    {
                        Console.Out.WriteLine("Starting rollup updates...");

                        CampaignHelper.ExecuteRollupUpdates();

                        //run all campaigns from master base table

                        DataTable dt = CheckRunAdHocCampaignsHelper.GetCampaignNamesList();

                        foreach (DataRow dr in dt.Rows)
                        {
                            bool   isactive      = Convert.ToBoolean(dr["isactive"].ToString());
                            string campaignname  = dr["campaignname"].ToString();
                            string daystorun     = dr["skipdays"].ToString();
                            string dialertable   = dr["dialertable"].ToString();
                            string dialertablehx = dr["dialertablehx"].ToString();
                            bool   donotrun      = Convert.ToBoolean(dr["donotrun"].ToString());

                            if (donotrun)
                            {
                                //what are you dumb? this variable says DO NOT RUN!
                            }
                            else
                            {
                                //only run if active campaign (or it's a single use campaign from the parameter)
                                if (isactive || usesinglecampaign)
                                {
                                    //check the table configuration skip days from the C# enumerator (1-7  versus 0-6 cause I was lazy about it)
                                    //Sunday(1) to Saturday(7)
                                    int dayofweektoday = (int)DateTime.Now.DayOfWeek + 1;

                                    if (usesinglecampaign)
                                    {
                                        if (campaignname.ToLower().Trim() == singlecampaignname.ToLower().Trim())
                                        {
                                            htmlOutput = CampaignHelper.RunCampaign(campaignname, dialertable, dialertablehx);
                                            CampaignHelper.SaveHTMLOutput(htmlOutput);
                                            campaignsthatrancount++;
                                        }
                                    }
                                    else
                                    {
                                        if (daystorun.Contains(dayofweektoday.ToString()))
                                        {
                                            htmlOutput = CampaignHelper.RunCampaign(campaignname, dialertable, dialertablehx);
                                            CampaignHelper.SaveHTMLOutput(htmlOutput);
                                            campaignsthatrancount++;
                                        }
                                    }
                                }
                            }
                        }

                        //htmlOutput = CampaignHelper.RunCampaign(args[0]);
                        //CampaignHelper.SaveHTMLOutput(htmlOutput);

#if RELEASE
                        if (campaignsthatrancount > 0)
                        {
                            CampaignHelper.RunPostDeployActions();
                        }
#elif Release
                        if (campaignsthatrancount > 0)
                        {
                            CampaignHelper.RunPostDeployActions();
                        }
#endif

                        //attach this to this section
                        Console.Out.WriteLine("Starting email transmission...");

                        //CampaignHelper.SendEmail();
                    }
                    else
                    {
                        Console.Out.WriteLine("Start Time is too late (post 7 AM): " + DateTime.Now.ToString());
                    }
                }
                else
                {
                    //run only the queued campaigns....
                    Console.Out.WriteLine("Starting rollup updates...");

                    CampaignHelper.ExecuteRollupUpdates();

                    DataTable dt = CheckRunAdHocCampaignsHelper.GetQueuedCampaignNamesList();

                    //do some more stuff
                    foreach (DataRow dr in dt.Rows)
                    {
                        string campaignname  = dr["campaignname"].ToString();
                        string dialertable   = dr["dialertable"].ToString();
                        string dialertablehx = dr["dialertablehx"].ToString();
                        int    campaignid    = Convert.ToInt32(dr["campaignid"].ToString());
                        int    id            = Convert.ToInt32(dr["id"].ToString());

                        //mark campaign as processing...
                        CheckRunAdHocCampaignsHelper.UpdateCampaignQueueStatus(id, processingstatusid);

                        htmlOutput = CampaignHelper.RunCampaign(campaignname, dialertable, dialertablehx);
                        CampaignHelper.SaveHTMLOutput(htmlOutput);

                        //mark campaign as completed
                        CheckRunAdHocCampaignsHelper.UpdateCampaignQueueStatus(id, completedstatusid);

                        campaignsthatrancount++;
                    }

                    if (campaignsthatrancount > 0)
                    {
                        CampaignHelper.RunPostDeployActions();
                    }

                    //attach this to this section
                    Console.Out.WriteLine("Starting email transmission...");

                    CampaignHelper.SendEmail();
                }
                Console.WriteLine();
                Console.WriteLine();

                //Console.Write("Press any key to exit...");
                //Console.ReadKey();

                Console.Out.WriteLine(goodexitcode);
                System.Environment.Exit(goodexitcode);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine("An error has occurred. Please check the message below.");
                Console.Out.WriteLine("");

                Console.Out.WriteLine(ex.Message + " - " + ex.StackTrace);
                Console.Out.WriteLine("");
                Console.Out.WriteLine("");


                //display some help text
                HelpText();

                Console.Out.WriteLine("The application will exit in 30 seconds....");

                System.Threading.Thread.Sleep(30000);

                Console.Out.WriteLine(badexitcode);
                System.Environment.Exit(badexitcode);
            }
        }