Пример #1
0
        protected void btnCreateCampaign_Click(object sender, EventArgs e)
        {
            try
            {
                string _accessToken = GetListService();// OAuth.GetAccessTokenByCode(HttpContext.Current, Request.QueryString["code"].ToString());
                string _apiKey      = ConfigurationManager.AppSettings["APIKey"];
                IUserServiceContext    userServiceContext      = new UserServiceContext(_accessToken, _apiKey);
                ConstantContactFactory _constantContactFactory = new ConstantContactFactory(userServiceContext);
                _emailCampaignService         = _constantContactFactory.CreateEmailCampaignService();
                _emailCampaginScheduleService = _constantContactFactory.CreateCampaignScheduleService();
                //  EmailCampaign campaign = CreateCampaignFromInputs();
                EmailCampaign campaign = CreateCampaignFromInputs();

                var savedCampaign = _emailCampaignService.AddCampaign(campaign);

                if (savedCampaign != null)
                {
                    //campaign was saved, but need to schedule it, if the case
                    Schedule schedule = null;


                    {
                        schedule = new Schedule()
                        {
                            ScheduledDate = Convert.ToDateTime(DateTime.Now.AddMinutes(1).ToShortTimeString().Trim()).ToUniversalTime()
                        };
                    }

                    Schedule savedSchedule = _emailCampaginScheduleService.AddSchedule(savedCampaign.Id, schedule);
                }
            }
            catch (Exception ex)
            {
            }
        }
Пример #2
0
        /** Creates a list of campaigns, and sends it, with content based on the campaignTemplate transform */
        public int SendEmails(Dictionary <string, string> parameters)
        {
            int status = 0;

            try
            {
                IEnumerable <EmailCampaign> campaigns = CreateCampaigns(parameters);
                GlobalFunctions.InfoLog($"{0} campaigns has been created. Scheduling campaigns.");
                if (campaigns.Count() == 0)
                {
                    status = -1;
                }
                foreach (EmailCampaign campaign in campaigns)
                {
                    EmailCampaign campaign_ = _emailCampaignService.AddCampaign(campaign);
                    Schedule      schedule;
                    schedule = new Schedule()
                    {
                        ScheduledDate = DateTime.Now.AddMinutes(20).ToUniversalTime()
                    };
                    schedule = _emailCampaginScheduleService.AddSchedule(campaign_.Id, schedule);
                    if (schedule == null)
                    {
                        GlobalFunctions.WarnLog("Campaign was saved, but failed to schedule it!");
                        status = -1;
                    }
                }
            }
            catch (IllegalArgumentException illegalEx)
            {
                GlobalFunctions.ErrorLog(GetExceptionsDetails(illegalEx, "IllegalArgumentException"));
                status = -1;
            }
            catch (CtctException ctcEx)
            {
                GlobalFunctions.ErrorLog(GetExceptionsDetails(ctcEx, "CtctException"));
                status = -1;
            }
            catch (OAuth2Exception oauthEx)
            {
                GlobalFunctions.ErrorLog(GetExceptionsDetails(oauthEx, "OAuth2Exception"));
                status = -1;
            }
            catch (Exception ex)
            {
                GlobalFunctions.ErrorLog(GetExceptionsDetails(ex, "Exception"));
                status = -1;
            }
            return(status);
        }
Пример #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            btnSave.Enabled = false;

            try
            {
                EmailCampaign campaign = CreateCampaignFromInputs();

                EmailCampaign savedCampaign = _emailCampaignService.AddCampaign(campaign);

                if (savedCampaign != null)
                {
                    //campaign was saved, but need to schedule it, if the case
                    Schedule schedule = null;

                    if (rbnSendNow.Checked || rbnScheduled.Checked)
                    {
                        if (rbnSendNow.Checked)
                        {
                            schedule = new Schedule()
                            {
                                ScheduledDate = DateTime.Now.AddMinutes(20).ToUniversalTime()
                            };
                        }
                        else
                        {
                            schedule = new Schedule()
                            {
                                ScheduledDate = Convert.ToDateTime(txtScheduleDate.Text.Trim()).ToUniversalTime()
                            };
                        }

                        Schedule savedSchedule = _emailCampaginScheduleService.AddSchedule(savedCampaign.Id, schedule);

                        if (savedSchedule != null)
                        {
                            MessageBox.Show("Campaign successfully saved and scheduled!", "Success");
                        }
                        else
                        {
                            MessageBox.Show("Campaign was saved, but failed to schedule it!", "Failure");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Campaign successfully saved!", "Success");
                    }
                }
                else
                {
                    MessageBox.Show("Failed to save campaign!", "Failure");
                }
            }
            catch (IllegalArgumentException illegalEx)
            {
                MessageBox.Show(GetExceptionsDetails(illegalEx, "IllegalArgumentException"), "Exception");
            }
            catch (CtctException ctcEx)
            {
                MessageBox.Show(GetExceptionsDetails(ctcEx, "CtctException"), "Exception");
            }
            catch (OAuth2Exception oauthEx)
            {
                MessageBox.Show(GetExceptionsDetails(oauthEx, "OAuth2Exception"), "Exception");
            }
            catch (Exception ex)
            {
                MessageBox.Show(GetExceptionsDetails(ex, "Exception"), "Exception");
            }

            btnSave.Enabled = true;
        }