示例#1
0
        public Campaign CreateCampaign(string code, string name, MailFrequency frequency, Newsletter fixedNewsletter,
                                       string dynamicCode, DateTime?startDate, DateTime?endDate, CampaignStatus status,
                                       CampaignType type)
        {
            CampaignDao cd = new CampaignDao(sessionFactoryConfigPath);

            if (cd.GetByCode(applicationName, code) != null)
            {
                throw new ApplicationException(
                          string.Format("There is already a campaign with the code {{{0}}} on the application {{{1}}}", code, applicationName));
            }

            Campaign c = new Campaign();

            c.ApplicationName = applicationName;
            c.Code            = code;
            c.Name            = name;
            c.StartDate       = startDate;
            c.EndDate         = endDate;
            c.DynamicCode     = dynamicCode;
            c.Frequency       = frequency;
            c.FixedNewsletter = fixedNewsletter;
            c.Status          = status;
            c.Type            = type;

            cd.Save(c);

            return(c);
        }
示例#2
0
        public void ChangeCampaignStatus(Campaign campaign, CampaignStatus campaignStatus)
        {
            campaign.Status = campaignStatus;

            CampaignDao cd = new CampaignDao(sessionFactoryConfigPath);

            cd.Save(campaign);
        }
示例#3
0
        /// <summary>
        /// Get all active or inactive campaigns
        /// </summary>
        /// <param name="active"></param>
        /// <returns></returns>
        public IList <Campaign> GetFixedCampaigns(bool active)
        {
            CampaignDao cd = new CampaignDao(sessionFactoryConfigPath);

            if (!active)
            {
                return(cd.GetAll(applicationName, true));
            }
            else
            {
                return(cd.GetActive(applicationName, true));
            }
        }
示例#4
0
        public Campaign UpdateCampaign(string code, string name, MailFrequency frequency, Newsletter fixedNewsletter,
                                       string dynamicCode, DateTime?startDate, DateTime?endDate, CampaignStatus status,
                                       CampaignType type)
        {
            CampaignDao cd = new CampaignDao(sessionFactoryConfigPath);
            Campaign    c  = cd.GetByCode(applicationName, code);

            if (c != null)
            {
                c.Name            = name;
                c.StartDate       = startDate;
                c.EndDate         = endDate;
                c.DynamicCode     = dynamicCode;
                c.Frequency       = frequency;
                c.FixedNewsletter = fixedNewsletter;
                c.Status          = status;
                c.Type            = type;
                cd.Save(c);
            }

            return(c);
        }
示例#5
0
        /// <summary>
        /// Process all the campaigns in the system and send the mails to the user subscribed.
        /// If dynamic campaigns are defined, the corresponding component must be located in the bin folder to be loaded dynamically.
        /// </summary>
        /// <returns>Any error occured during processing.</returns>
        /// <remarks>To be executed once a day.</remarks>
        public bool ExecuteAll(out string errors, bool testExecution)
        {
            errors = string.Empty;

            // Check if should be executed today
            bool execute = false;

            foreach (DayOfWeek day in DaysToExecute)
            {
                if (day == DateTime.Today.DayOfWeek)
                {
                    execute = true;
                    break;
                }
            }

            if (!execute)
            {
                return(true);
            }

            ProcessExecutionDao ped = new ProcessExecutionDao(SessionFactoryConfigPath);
            CampaignDao         cd  = new CampaignDao(SessionFactoryConfigPath);

            ArrayList arr = new ArrayList(4);

            arr.Add(MailFrequency.TimeSpan);
            arr.Add(MailFrequency.Daily);
            if (DateTime.Today.DayOfWeek == WeekDay)
            {
                arr.Add(MailFrequency.Weekly);
            }
            if (DateTime.Today.Day == MonthDay)
            {
                arr.Add(MailFrequency.Monthly);
            }

            IList <Campaign> campaigns = cd.GetPendingAutomatic(applicationName, false, arr.ToArray());

            foreach (Campaign c in campaigns)
            {
                if (c.Frequency == MailFrequency.TimeSpan || ped.ExecutedToday(applicationName, c) == null)
                {
                    int position = ((int)c.Frequency) - 1;

                    bool run = false;

                    // Ejecuto el proceso si paso el tiempo desde la ultima vez
                    if (c.Frequency == MailFrequency.TimeSpan)
                    {
                        ProcessExecution pe = ped.ExecutedLast(applicationName, c);
                        if (pe != null)
                        {
                            TimeSpan diff = DateTime.Now - pe.RunDate;
                            if (diff.Hours > TimeSpan.Parse(TimesToExecute[position]).Hours ||
                                (diff.Hours == TimeSpan.Parse(TimesToExecute[position]).Hours&& diff.Minutes >= TimeSpan.Parse(TimesToExecute[position]).Minutes))
                            {
                                run = true;
                            }
                        }
                        else
                        {
                            run = true;
                        }
                    }
                    // Ejecuto el proceso diario luego de la hora establecida
                    else if (
                        (
                            DateTime.Now.Hour == Convert.ToInt32(TimeSpan.Parse(TimesToExecute[position]).Hours) &&
                            DateTime.Now.Minute >= Convert.ToInt32(TimeSpan.Parse(TimesToExecute[position]).Minutes)
                        ) ||
                        DateTime.Now.Hour > Convert.ToInt32(TimeSpan.Parse(TimesToExecute[position]).Hours)
                        )
                    {
                        run = true;
                    }

                    if (run)
                    {
                        ExecuteCampaign(ref errors, c, testExecution);

                        ProcessExecution pe = new ProcessExecution( );
                        pe.ApplicationName = applicationName;
                        pe.Campaign        = c;
                        pe.RunDate         = DateTime.Now;
                        ped.Save(pe);
                    }
                }
            }

            // Ejecuto las campañas scheduleadas manualmente
            ExecutionDao ced = new ExecutionDao(SessionFactoryConfigPath);

            foreach (Execution ce in ced.GetPendings(applicationName))
            {
                // Ejecuto el proceso diario luego de la hora establecida
                if ((DateTime.Now - ce.RunDate).Ticks >= 0)
                {
                    ExecuteCampaign(ref errors, ce.Campaign, ce.TestExecution);
                    ced.Delete(ce);
                }
            }

            return(errors == string.Empty);
        }
示例#6
0
        public Campaign GetCampaign(string code)
        {
            CampaignDao cd = new CampaignDao(sessionFactoryConfigPath);

            return(cd.GetByCode(applicationName, code));
        }
示例#7
0
        /// <summary>
        /// Get all campaigns
        /// </summary>
        /// <returns></returns>
        public IList <Campaign> GetCampaigns()
        {
            CampaignDao cd = new CampaignDao(sessionFactoryConfigPath);

            return(cd.GetAll(applicationName));
        }