Example #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 member
                _constantContact = new ConstantContact(_apiKey, _accessToken);
            }
            catch (OAuth2Exception oauthEx)
            {
                MessageBox.Show(string.Format("Authentication failure: {0}", oauthEx.Message), "Warning");
            }

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

            GetListOfContacts();
            PopulateEmailLists();
        }
        /// <summary>
        /// Create or Update A Constant Contact List
        /// </summary>
        /// <param name="members">List to Export </param>
        /// <param name="listName">Name Of List</param>
        /// <returns></returns>

        public async Task <ServiceResponse> ExportConstantContactList(IList <PaaMember> members, string listName)
        {
            // find existing list or create new one
            ContactList requestedList = await ConstantContactService.GetListByListName(listName, true);

            // build the export structure
            ContactImport import = BuildContactImport(members, new List <string> {
                requestedList.Id
            });


            var bulkActivitiesService = ConstantContact.BulkListsService();

            try
            {
                // clear any existing list
                ConstantContactBulkResponse clearResponse = await ClearConstantContactList(requestedList.Id);


                if (import.ImportData.Count() < 1)  // nothing to add
                {
                    return(new ServiceResponse
                    {
                        Name = listName,
                        Success = true,
                        SuccessCount = 0,
                        ErrorCount = 0,
                        Message = "Success"
                    });
                }

                else
                {
                    BulkActivityResponse response = await bulkActivitiesService.ImportContactsAsync(import);

                    return(new ServiceResponse
                    {
                        Name = listName,
                        Success = true,
                        SuccessCount = int.Parse(response.ContactCount),
                        ErrorCount = int.Parse(response.ErrorCount),
                        Message = "Success"
                    });
                }
            }

            catch (Exception ex)
            {
                return(new ServiceResponse
                {
                    Name = listName,
                    Success = false,
                    Message = "Failed",
                    ExceptionMessage = ex.Message
                });
            }
        }
        private static async Task <ConstantContactBulkResponse> ClearConstantContactList(string listId)
        {
            var work = new ContactLists {
                Lists = new string[] { listId }
            };

            var bulkActivitiesService     = ConstantContact.BulkListsService();
            BulkActivityResponse response = await bulkActivitiesService.ClearContactListsAsync(work);

            return(new ConstantContactBulkResponse
            {
                Id = response.Id,
                ContactCount = int.Parse(response.ContactCount),
                ErrorCount = int.Parse(response.ErrorCount)
            });
        }
Example #4
0
        private void frmEmailCampaign_Load(object sender, EventArgs e)
        {
            try
            {
                //initialize ConstantContact member
                ConstantContact = new ConstantContact();
            }
            catch (OAuth2Exception oauthEx)
            {
                MessageBox.Show(string.Format("Authentication failure: {0}", oauthEx.Message), "Warning");
            }

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

            GetListOfContacts();
            PopulateEmailLists();
        }
        private static async Task <List <ConstantContactModel> > Create(List <string> ccLists)
        {
            List <ConstantContactModel> model = new List <ConstantContactModel>();

            IEnumerable <ContactList> allLists = await ConstantContact.GetAllLists();


            foreach (string ccList in ccLists)
            {
                ContactList existingList = IdentifyList(ccList);

                // found in constant contact ?
                if (existingList == null)

                {
                    // no create it !!
                    var newList = new ContactList {
                        Name = ccList, Status = ContactListsStatus.Hidden
                    };
                    ContactListsService service = ConstantContact.ListsService();
                    existingList = await service.CreateContactListAsync(newList);
                }


                if (existingList != null)
                {
                    var l = new ConstantContactModel
                    {
                        ListName     = existingList.Name,
                        ListId       = existingList.Id,
                        Status       = existingList.Status,
                        CreatedDate  = existingList.CreatedDate,
                        ModifiedDate = existingList.ModifiedDate,
                        ContactCount = existingList.ContactCount
                    };

                    model.Add(l);
                }
            }

            return(model);
        }
        public static async Task <ContactList> GetListByListName(string name, bool create = false)
        {
            IEnumerable <ContactList> allLists = await ConstantContact.GetAllLists();

            var rtnval = (from list in allLists
                          where string.Equals(list.Name.ToLower(), name.ToLower(), StringComparison.Ordinal)
                          select list).FirstOrDefault();


            if (rtnval == null && create)
            {
                ContactList newList = new ContactList {
                    Name = name, Status = ContactListsStatus.Hidden
                };
                ContactListsService service = ConstantContactHelper.ListsService();
                ContactList         y       = await service.CreateContactListAsync(newList);

                return(y);
            }

            return(rtnval);
        }
Example #7
0
        private void frmContact_Load(object sender, EventArgs e)
        {
            try
            {
                string state = "ok";
                _accessToken = OAuth.AuthenticateFromWinProgram(ref state);

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

                //initialize ConstantContact member
                _constantContact = new ConstantContact(_apiKey, _accessToken);
            }
            catch (OAuth2Exception oauthEx)
            {
                MessageBox.Show(string.Format("Authentication failure: {0}", oauthEx.Message), "Warning");
            }

            toolTipClose.SetToolTip(lblClose, "Close");
            lblErrorMsg.Visible = false;

            #region Populate list of countries

            var           countries = new List <RegionInfo>();
            CultureInfo[] cinfo     = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
            foreach (CultureInfo cul in cinfo)
            {
                var country = new RegionInfo(cul.LCID);

                if (country != null && !countries.Contains(country))
                {
                    countries.Add(country);
                }
            }

            countries = countries.OrderBy(c => c.EnglishName).ToList();
            cbCountry.Items.Add(new CountryInfo(string.Empty, string.Empty));

            var US     = countries.Where(c => c.EnglishName.Equals("United States")).FirstOrDefault();
            var Canada = countries.Where(c => c.EnglishName.Equals("Canada")).FirstOrDefault();

            if (US != null)
            {
                countries.Remove(US);
            }

            if (Canada != null)
            {
                countries.Remove(Canada);
            }

            var lstCountries = countries.Select(c => new CountryInfo(c.EnglishName, c.TwoLetterISORegionName)).ToArray();

            if (US != null)
            {
                cbCountry.Items.Add(new CountryInfo(US.EnglishName, US.TwoLetterISORegionName));
            }

            if (Canada != null)
            {
                cbCountry.Items.Add(new CountryInfo(Canada.EnglishName, Canada.TwoLetterISORegionName));
            }

            cbCountry.Items.AddRange(lstCountries);
            cbCountry.ValueMember   = "TwoLetterCountryName";
            cbCountry.DisplayMember = "Name";

            #endregion Populate list of countries
        }
        public async Task <ContactList> FindExistingContactList(string contactListName)
        {
            IEnumerable <ContactList> allLists = await ConstantContact.GetAllLists();

            return((from cx in allLists where cx.Name == contactListName select cx).FirstOrDefault());
        }