예제 #1
0
        private void frmEmailCampaign_Load(object sender, EventArgs e)
        {
            try
            {
                string state = "ok";
                _accessToken = OAuth.AuthenticateFromWinProgram(ref state);

                if (string.IsNullOrEmpty(_accessToken))
                {
                    Application.Exit();
                }

                //initialize ConstantContact members
                IUserServiceContext    userServiceContext      = new UserServiceContext(_accessToken, _apiKey);
                ConstantContactFactory _constantContactFactory = new ConstantContactFactory(userServiceContext);
                _emailCampaignService         = _constantContactFactory.CreateEmailCampaignService();
                _emailCampaginScheduleService = _constantContactFactory.CreateCampaignScheduleService();
                _listService    = _constantContactFactory.CreateListService();
                _accountService = _constantContactFactory.CreateAccountService();
            }
            catch (OAuth2Exception oauthEx)
            {
                MessageBox.Show(string.Format("Authentication failure: {0}", oauthEx.Message), "Warning");
            }

            PopulateCampaignTypeList();
            PopulateListOfCountries();
            PopulateUSAndCanadaListOfStates();

            GetListOfContacts();
            PopulateEmailLists();
        }
예제 #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            _apiKey             = ConfigurationManager.AppSettings["APIKey"];
            Session["campaign"] = TextBox1.Text;
            try
            {
                string state = "ok";
                OAuth.AuthorizeFromWebApplication(HttpContext.Current
                                                  , state);


                //initialize ConstantContact members
                IUserServiceContext    userServiceContext      = new UserServiceContext(_accessToken, _apiKey);
                ConstantContactFactory _constantContactFactory = new ConstantContactFactory(userServiceContext);
                _emailCampaignService         = _constantContactFactory.CreateEmailCampaignService();
                _emailCampaginScheduleService = _constantContactFactory.CreateCampaignScheduleService();
                _listService    = _constantContactFactory.CreateListService();
                _accountService = _constantContactFactory.CreateAccountService();
            }
            catch (OAuth2Exception oauthEx)
            {
                //  MessageBox.Show(string.Format("Authentication failure: {0}", oauthEx.Message), "Warning");
            }


            //PopulateListOfCountries();
            //PopulateUSAndCanadaListOfStates();

            //GetListOfContacts();
            //PopulateEmailLists();
        }
예제 #3
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)
            {
            }
        }
예제 #4
0
        private void Initialize()
        {
            try
            {
                string state = "ok";
                if (String.IsNullOrEmpty(_emailTemplateTransformUrl))
                {
                    throw new Exception("Missing email campaign template location from configuration");
                }

                if ((String.IsNullOrEmpty(_apiKey) || String.IsNullOrEmpty(_accessToken)) && !String.IsNullOrEmpty(_emailConnectionTransformUrl))
                {
                    XDocument emailConnection = new XDocument();
                    using (System.Xml.XmlWriter writer = emailConnection.CreateWriter())
                    {
                        XslCompiledTransform emailConnectionTransform = new XslCompiledTransform();
                        emailConnectionTransform.Load(_emailConnectionTransformUrl);
                        emailConnectionTransform.Transform(XDocument.Parse("<dummy />").CreateReader(), writer);
                    }
                }

                if (String.IsNullOrEmpty(_accessToken))
                {
                    _accessToken = OAuth.AuthenticateFromWinProgram(ref state);
                }
                if (string.IsNullOrEmpty(_accessToken))
                {
                    throw new Exception("Unable to authenticate & retrieve access token");
                }

                //initialize ConstantContact members
                IUserServiceContext    userServiceContext      = new UserServiceContext(_accessToken, _apiKey);
                ConstantContactFactory _constantContactFactory = new ConstantContactFactory(userServiceContext);
                _emailCampaignService         = _constantContactFactory.CreateEmailCampaignService();
                _emailCampaginScheduleService = _constantContactFactory.CreateCampaignScheduleService();
                _listService = _constantContactFactory.CreateListService();
            }
            catch (OAuth2Exception oauthEx)
            {
                GlobalFunctions.WarnLog(string.Format("Authentication failure: {0}", oauthEx.Message));
            }
        }