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(); }
private static CTCT.Components.Contacts.ContactList GetListByID(string p) { IUserServiceContext userServiceContext = new UserServiceContext("3f09fe65-10ae-44a9-9db6-d9f2d6de1dec", "cvwkqk7ajrm67rcagvfwn9gx"); ConstantContactFactory serviceFactory = new ConstantContactFactory(userServiceContext); IListService listService = serviceFactory.CreateListService(); try { ContactList lists = listService.GetList(p); if (lists != null) { return(lists); } } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); return(null); } return(null); }
public void LiveVerifiedEmailAddressTest() { var cc = new ConstantContactFactory(userServiceContext); var accountService = cc.CreateAccountService(); var list = accountService.GetVerifiedEmailAddress(); Assert.IsNotNull(list); Assert.AreNotEqual(0, list.Count); }
/// <summary> /// Get a contact by email address /// </summary> /// <param name="emailAddress"></param> /// <returns></returns> private static Contact GetContactByEmailAddress(string emailAddress) { //var contactService = _constantContactFactory.CreateContactService(); IUserServiceContext userServiceContext = new UserServiceContext("3f09fe65-10ae-44a9-9db6-d9f2d6de1dec", "cvwkqk7ajrm67rcagvfwn9gx"); ConstantContactFactory serviceFactory = new ConstantContactFactory(userServiceContext); IContactService contactService = serviceFactory.CreateContactService(); ResultSet <Contact> contacts = contactService.GetContacts(emailAddress, 1, null, null); if (contacts != null) { if (contacts.Results != null && contacts.Results.Count > 0) { return(contacts.Results[0]); } } return(null); }
public void LiveGetAllContacts() { var cc = new ConstantContactFactory(userServiceContext); var contactService = cc.CreateContactService(); var result = contactService.GetContacts(DateTime.Now.AddMonths(-1)); Assert.IsNotNull(result); Assert.IsNotNull(result.Results); Assert.AreNotEqual(0, result.Results.Count); }
static void Main(string[] args) { Uri OrganizationUri = new Uri(String.Format("https://netunousa.api.crm.dynamics.com/XRMServices/2011/Organization.svc")); Uri HomeRealmUri = new Uri(String.Format("https://netunousa.api.crm.dynamics.com/XRMServices/2011/Discovery.svc")); Uri serviceUri = new Uri("https://netunousa.api.crm.dynamics.com/XRMServices/2011/Organization.svc"); System.ServiceModel.Description.ClientCredentials clientCredentials = new System.ServiceModel.Description.ClientCredentials(); clientCredentials.UserName.UserName = "******"; clientCredentials.UserName.Password = "******"; OrganizationServiceProxy serviceproxy = new OrganizationServiceProxy(OrganizationUri, null, clientCredentials, null); IOrganizationService orgservice = (IOrganizationService)serviceproxy; //ConditionExpression condition = new ConditionExpression(); //condition.AttributeName = "new_sagecustomerid"; //condition.Operator = ConditionOperator.Equal; //condition.Values.Add("0"); string[] cols = { "listid", "listname", "new_constantcontactid" }; ColumnSet columns = new ColumnSet(cols); QueryExpression expression = new QueryExpression(); expression.EntityName = "list"; //expression.ColumnSet = new AllColumns(); expression.ColumnSet.AllColumns = true; QueryExpression query = new QueryExpression { EntityName = "list", ColumnSet = new ColumnSet("listid", "listname", "new_constantcontactid"), }; expression.ColumnSet = columns; EntityCollection listEntityColl = orgservice.RetrieveMultiple(query); IUserServiceContext userServiceContext = new UserServiceContext("3f09fe65-10ae-44a9-9db6-d9f2d6de1dec", "cvwkqk7ajrm67rcagvfwn9gx"); ConstantContactFactory serviceFactory = new ConstantContactFactory(userServiceContext); IListService listService = serviceFactory.CreateListService(); if (listEntityColl.Entities.Count > 0) { //get contact if exists (by email address) CTCT.Components.Contacts.ContactList list = null; for (int i = 0; i < listEntityColl.Entities.Count; i++) { try { try { list = GetListByID(listEntityColl.Entities[i].Attributes["new_constantcontactid"].ToString(), ref listService); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } bool alreadyExists = list != null ? true : false; try { list = UpdateListFields(list, listEntityColl.Entities[i].Attributes); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } // var contactService = _constantContactFactory.CreateContactService(); CTCT.Components.Contacts.ContactList result = null; // IListService listService = serviceFactory.CreateListService(); if (alreadyExists) { try { result = listService.UpdateList(list); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } } else { try { // IBulkStatusService listService1 = serviceFactory.CreateBulkStatusService(); result = listService.AddList(list); listEntityColl.Entities[i].Attributes["new_constantcontactid"] = result.Id; orgservice.Update((Entity)listEntityColl.Entities[i]); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); alreadyExists = true; } } if (result != null) { if (alreadyExists) { //messageResult = "Changes successfully saved!"; } else { // messageResult = "Contact successfully added!"; } } else { if (alreadyExists) { // messageResult = "Failed to save changes!"; } else { // messageResult = "Failed to add contact!"; } } //MessageBox.Show(messageResult, "Result"); } catch (IllegalArgumentException illegalEx) { CTCTLogger.LogFile(illegalEx.InnerException.ToString(), illegalEx.InnerException.ToString(), illegalEx.Data.ToString(), (int)illegalEx.LineNumber(), illegalEx.Source.ToString()); } catch (CtctException ctcEx) { CTCTLogger.LogFile(ctcEx.InnerException.ToString(), ctcEx.InnerException.ToString(), ctcEx.Data.ToString(), (int)ctcEx.LineNumber(), ctcEx.Source.ToString()); } catch (OAuth2Exception oauthEx) { CTCTLogger.LogFile(oauthEx.InnerException.ToString(), oauthEx.InnerException.ToString(), oauthEx.Data.ToString(), (int)oauthEx.LineNumber(), oauthEx.Source.ToString()); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } } //btnSave.Enabled = true; } if (listEntityColl.Entities.Count > 0) { bool flag = false;; for (int i = 0; i < listEntityColl.Entities.Count; i++) { try { GetAllMembersInaList(listEntityColl.Entities[i].Attributes["listid"].ToString(), listEntityColl.Entities[i].Attributes["new_constantcontactid"].ToString(), flag, ref orgservice, ref listService); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } flag = true; } } }
public void SendCampaign() { if (ValidateFields()) { var confirmResult = MessageBox.Show(CommonConstants.MandatoryFields.Alert, CommonConstants.MandatoryFields.SendCampaign, MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { string campaignId = cmbCampaign.SelectedValue.ToString(); // Loading panel Cursor.Current = Cursors.WaitCursor; try { ApiKey = ConstantContactAPI; AccessToken = ConstantContactToken; IUserServiceContext userServiceContext = new UserServiceContext(AccessToken, ApiKey); var cc = new ConstantContactFactory(userServiceContext); List<SentContactList> SentContactListObj = new List<SentContactList>(); Contact contact = new Contact(); List<Contact> contactList = new List<Contact>(); var emailCampignService = cc.CreateEmailCampaignService(); var result = emailCampignService.GetCampaign(campaignId); int count = 0; foreach (var item in result.Lists) { SentContactList contactObj = new SentContactList(); contactObj.Id = item.Id; SentContactListObj.Add(contactObj); } foreach (var item in SentContactListObj) { try { var getContactDetails = cc.CreateListService(); var contactDetails = getContactDetails.GetContactsFromList(item.Id,null); foreach (var j in contactDetails.Results) { string message = getMessageDetails(txtMessage.Text.Trim(), j); string phone = getPhoneDetails(cmbFieldPhone.Text.Trim(), j); if (!string.IsNullOrEmpty(phone)) { // Send SMS string smsResult = SmsSender.SendSMS(phone, NexmoFromNumber, NexmoAPI, NexmoSecretKey, HttpUtility.UrlEncode(message)); count++; } } } catch (Exception ex) { // Logger.Write(ex); continue; } } if(count>0) { MessageBox.Show(CommonConstants.MandatoryFields.Success); } else { MessageBox.Show(CommonConstants.MandatoryFields.MSGNOTSEND); } this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Cursor.Current = Cursors.Default; } } } }
public void LiveDeleteContactListTest() { var cc = new ConstantContactFactory(userServiceContext); var listService = cc.CreateListService(); var contactList = new ContactList { Name = string.Format("List {0}", Guid.NewGuid()), Status = Status.Active }; var result = listService.AddList(contactList); Assert.IsNotNull(result); Assert.IsTrue(result.Name.Equals(contactList.Name)); result.Name = string.Format("List - {0}", Guid.NewGuid()); var deleted = listService.DeleteList(result.Id.ToString(CultureInfo.InvariantCulture)); Assert.IsTrue(deleted); }
public void LiveGetContactFromListTest() { var cc = new ConstantContactFactory(userServiceContext); var listService = cc.CreateListService(); IList<ContactList> lists = listService.GetLists(DateTime.Now.AddMonths(-1)); Assert.IsNotNull(lists); Assert.AreNotEqual(0, lists.Count); ResultSet<Contact> contacts = listService.GetContactsFromList(lists[0].Id, DateTime.Now.AddMonths(-1)); Assert.IsNotNull(contacts); Assert.IsNotNull(contacts.Results); contacts = listService.GetContactsFromList(lists[0].Id, 3, DateTime.Now.AddMonths(-1)); Assert.IsNotNull(contacts); Assert.IsNotNull(contacts.Meta); Assert.IsNotNull(contacts.Meta.Pagination); Assert.IsNotNull(contacts.Results); //Assert.AreEqual(3, contacts.Results.Count); }
public void LiveGetFilesByFolderTest() { var cc = new ConstantContactFactory(userServiceContext); var myLibraryService = cc.CreateMyLibraryService(); var folders = myLibraryService.GetLibraryFolders(); Assert.IsNotNull(folders); Assert.IsNotNull(folders.Results); Assert.AreNotEqual(0, folders.Results.Count); var files = myLibraryService.GetLibraryFilesByFolder(folders.Results[0].Id); Assert.IsNotNull(files); Assert.IsNotNull(files.Results); }
public void LiveGetTrashTest() { var cc = new ConstantContactFactory(userServiceContext); var myLibraryService = cc.CreateMyLibraryService(); var files = myLibraryService.GetLibraryTrashFiles(); Assert.IsNotNull(files); Assert.IsNotNull(files.Results); //Assert.AreNotEqual(0, files.Results.Count); }
public void LiveActivityAddContactsMultipartTest() { var cc = new ConstantContactFactory(userServiceContext); var activityService = cc.CreateActivityService(); var filename = "add_contacts.txt"; var content = Encoding.UTF8.GetBytes(String.Format("{0}@example.com", Guid.NewGuid())); var lists = new List<string>() { "1" }; Activity activity = activityService.AddContactstMultipartActivity(filename, content, lists); Assert.IsNotNull(activity); Assert.IsNotNull(activity.Id); Assert.AreEqual(activity.ContactCount, 1); Assert.AreEqual(activity.Type, "ADD_CONTACTS"); }
public void LiveContactTrackingUnsubscribesTest() { var cc = new ConstantContactFactory(userServiceContext); var contactService = cc.CreateContactService(); var contactTrackingService = cc.CreateContactTrackingService(); ResultSet<Contact> contacts = contactService.GetContacts(DateTime.Now.AddMonths(-1)); Assert.IsNotNull(contacts); Assert.IsNotNull(contacts.Results); Assert.IsTrue(contacts.Results.Count > 0); ResultSet<OptOutActivity> a = contactTrackingService.GetContactTrackingOptOuts(contacts.Results[0].Id, DateTime.Now.AddMonths(-1)); Assert.IsNotNull(a); }
public void LiveContactTrackingSummaryTest() { var cc = new ConstantContactFactory(userServiceContext); var contactService = cc.CreateContactService(); var contactTrackingService = cc.CreateContactTrackingService(); var emailCampaignService = cc.CreateEmailCampaignService(); ResultSet<Contact> contacts = contactService.GetContacts(DateTime.Now.AddMonths(-1)); Assert.IsNotNull(contacts); Assert.IsNotNull(contacts.Results); Assert.IsTrue(contacts.Results.Count > 0); TrackingSummary summary = contactTrackingService.GetSummary(contacts.Results[0].Id); Assert.IsNotNull(summary); //Assert.AreNotEqual(0, summary.Forwards); //Assert.AreNotEqual(0, summary.Opens); //Assert.AreNotEqual(0, summary.Sends); //ResultSet<EmailCampaign> camps = emailCampaignService.GetCampaigns(DateTime.Now.AddMonths(-1)); //summary = contactTrackingService.GetSummary(camps.Results[1].Id); //Assert.AreNotEqual(0, summary.Forwards); //Assert.AreNotEqual(0, summary.Opens); //Assert.AreNotEqual(0, summary.Sends); //Assert.AreNotEqual(0, summary.Bounces); }
public void LiveContactTrackingEmailCampaignActivitiesTest() { var cc = new ConstantContactFactory(userServiceContext); var contactService = cc.CreateContactService(); var contactTrackingService = cc.CreateContactTrackingService(); ResultSet<Contact> contacts = contactService.GetContacts(DateTime.Now.AddMonths(-1)); Assert.IsNotNull(contacts); Assert.IsNotNull(contacts.Results); Assert.IsTrue(contacts.Results.Count > 0); ResultSet<TrackingSummary> result = contactTrackingService.GetEmailCampaignActivities(contacts.Results[0].Id); Assert.IsNotNull(result); }
public void LiveEmailCampaignTestSendTest() { var cc = new ConstantContactFactory(userServiceContext); var emailCampaignService = cc.CreateEmailCampaignService(); var campaignScheduleService = cc.CreateCampaignScheduleService(); var camp = new EmailCampaign { EmailContent = "<html><body>EMAIL CONTENT.</body></html>", Subject = "campaign subject", FromName = "my company", FromEmail = CustomerEmail, ReplyToEmail = CustomerEmail, Name = "campaign_" + DateTime.Now.ToString("yyMMddHHmmss"), TextContent = "email campaign text content", GreetingString = "Dear ", //TemplateType = TemplateType.CUSTOM, Status = CampaignStatus.DRAFT, EmailContentFormat = CampaignEmailFormat.HTML, StyleSheet = "", MessageFooter = new MessageFooter { OrganizationName = "my organization", AddressLine1 = "123 Mapple Street", AddressLine2 = "Suite 1", AddressLine3 = "", City = "Boston", State = "MA", PostalCode = "02101", Country = "US", IncludeForwardEmail = true, ForwardEmailLinkText = "forward link", IncludeSubscribeLink = true, SubscribeLinkText = "subscribe link" } , Lists = new List<SentContactList> { new SentContactList { Id = "1" } } }; camp = emailCampaignService.AddCampaign(camp); Assert.IsNotNull(camp); Assert.IsNotNull(camp.Id); var test = new TestSend { Format = EmailFormat.HTML_AND_TEXT.ToString(), PersonalMessage = "This is a test send of the email campaign message.", EmailAddresses = new List<string> { CustomerEmail } }; var testSend = campaignScheduleService.SendTest(camp.Id, test); Assert.IsNotNull(testSend); Assert.AreEqual(test.Format, testSend.Format); }
private static void GetAllMembersInaList(string listid, string constantcontactlistid, bool flag, ref IOrganizationService orgservice, ref IListService listService) { ArrayList memberGuids = new ArrayList(); PagingInfo pageInfo = new PagingInfo(); pageInfo.Count = 5000; pageInfo.PageNumber = 1; QueryByAttribute query = new QueryByAttribute("listmember"); // pass the guid of the Static marketing list query.AddAttributeValue("listid", listid); query.ColumnSet = new ColumnSet(true); EntityCollection entityCollection = orgservice.RetrieveMultiple(query); Entity entity1 = null; Contact result = null; IUserServiceContext userServiceContext = new UserServiceContext("3f09fe65-10ae-44a9-9db6-d9f2d6de1dec", "cvwkqk7ajrm67rcagvfwn9gx"); ConstantContactFactory serviceFactory = new ConstantContactFactory(userServiceContext); IContactService contactService = serviceFactory.CreateContactService(); ContactList list = null; try { list = GetListByID(constantcontactlistid, ref listService); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } foreach (Entity entity in entityCollection.Entities) { try { Contact contact = null; entity1 = RetrieveEntityById(orgservice, "contact", Guid.Parse(((EntityReference)entity.Attributes["entityid"]).Id.ToString())); if (entity1.Attributes.Contains("emailaddress1")) { contact = GetContactByEmailAddress(entity1.Attributes["emailaddress1"].ToString(), ref contactService); if (flag == false) { if (contact != null) { contact.Lists.Clear(); } } bool alreadyExists = contact != null ? true : false; try { contact = UpdateContactFields(contact, entity1.Attributes, list); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } // var contactService = _constantContactFactory.CreateContactService(); if (alreadyExists) { try { result = contactService.UpdateContact(contact, false); entity1.Attributes["new_integratectct"] = result.Id; orgservice.Update((Entity)entity1); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } } else { try { result = contactService.AddContact(contact, false); entity1.Attributes["new_integratectct"] = result.Id; orgservice.Update((Entity)entity1); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } } } } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } } // if list contains more than 5000 records while (entityCollection.MoreRecords) { query.PageInfo.PageNumber += 1; query.PageInfo.PagingCookie = entityCollection.PagingCookie; entityCollection = orgservice.RetrieveMultiple(query); foreach (Entity entity in entityCollection.Entities) { try { memberGuids.Add(((EntityReference)entity.Attributes["entityid"]).Id); entity1 = RetrieveEntityById(orgservice, "contact", Guid.Parse(((EntityReference)entity.Attributes["entityid"]).Id.ToString())); } catch (Exception ex) { CTCTLogger.LogFile(ex.InnerException.ToString(), ex.InnerException.ToString(), ex.Data.ToString(), (int)ex.LineNumber(), ex.Source.ToString()); } } } }
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 IUserServiceContext userServiceContext = new UserServiceContext(_accessToken, _apiKey); _constantContactFactory = new ConstantContactFactory(userServiceContext); } 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 void LiveGetFolderTest() { var cc = new ConstantContactFactory(userServiceContext); var myLibraryService = cc.CreateMyLibraryService(); var folder = new MyLibraryFolder(); folder.Id = Guid.NewGuid().ToString(); folder.Name = Guid.NewGuid().ToString(); folder.CreatedDate = Extensions.ToISO8601String(DateTime.Now); folder.ModifiedDate = Extensions.ToISO8601String(DateTime.Now); var newFolder = myLibraryService.AddLibraryFolder(folder); var getFolder = myLibraryService.GetLibraryFolder(newFolder.Id); Assert.IsNotNull(getFolder); Assert.AreEqual(getFolder.Id, newFolder.Id); Assert.AreEqual(getFolder.Name, newFolder.Name); }
public void LiveDeleteFolderTest() { var cc = new ConstantContactFactory(userServiceContext); var myLibraryService = cc.CreateMyLibraryService(); var folder = new MyLibraryFolder(); folder.Id = Guid.NewGuid().ToString(); folder.Name = Guid.NewGuid().ToString(); folder.CreatedDate = Extensions.ToISO8601String(DateTime.Now); folder.ModifiedDate = Extensions.ToISO8601String(DateTime.Now); var newFolder = myLibraryService.AddLibraryFolder(folder); bool result = myLibraryService.DeleteLibraryFolder(newFolder.Id); Assert.IsTrue(result); }
public void LiveActivityRemoveContactsMultipartTest() { var cc = new ConstantContactFactory(userServiceContext); var activityService = cc.CreateActivityService(); var filename = "remove_contacts.csv"; var fileContent = String.Format("{0}@example.com", Guid.NewGuid()); var content = Encoding.UTF8.GetBytes(fileContent); var lists = new List<string>() { "1" }; var add = new AddContacts(new List<AddContactsImportData> { new AddContactsImportData { EmailAddresses = new List<string> { fileContent } } }, lists, null); Activity act = activityService.CreateAddContactsActivity(add); Activity activity = activityService.RemoveContactsMultipartActivity(filename, content, lists); Assert.IsNotNull(activity); Assert.IsNotNull(activity.Id); Assert.AreEqual(activity.ContactCount, 1); Assert.AreEqual(activity.Type, "REMOVE_CONTACTS_FROM_LISTS"); }
public void LiveDeleteTrashFilesTest() { var cc = new ConstantContactFactory(userServiceContext); var myLibraryService = cc.CreateMyLibraryService(); var result = myLibraryService.DeleteLibraryTrashFiles(); Assert.IsTrue(result); }
public void LiveActivityRemoveContactTest() { var cc = new ConstantContactFactory(userServiceContext); var activityService = cc.CreateActivityService(); var emailAddresses = new List<string> { String.Format("{0}@example.com", Guid.NewGuid()) }; var lists = new List<string> { "1" }; var add = new AddContacts( new List<AddContactsImportData>{ new AddContactsImportData{ EmailAddresses = emailAddresses } }, lists, null ); Activity act = activityService.CreateAddContactsActivity(add); Assert.IsNotNull(act); Activity activity = activityService.AddRemoveContactsFromListsActivity(emailAddresses, lists); Assert.IsNotNull(activity); Assert.AreEqual(activity.ContactCount, emailAddresses.Count); }
public void LiveGetContactByEmail() { var cc = new ConstantContactFactory(userServiceContext); var contactService = cc.CreateContactService(); var contact = new Contact(); contact.EmailAddresses.Add(new EmailAddress { EmailAddr = String.Format("{0}@email.com", Guid.NewGuid()), ConfirmStatus = ConfirmStatus.NoConfirmationRequired, Status = Status.Active }); contact.Lists.Add(new ContactList { Id = "1", Status = Status.Active }); Contact nc = contactService.AddContact(contact, false); Assert.IsNotNull(nc); Assert.IsNotNull(nc.Id); var result = contactService.GetContacts(nc.EmailAddresses[0].EmailAddr, 1, DateTime.Now.AddMonths(-1), null); Assert.IsNotNull(result); Assert.IsNotNull(result.Results); Assert.AreEqual(1, result.Results.Count); }
public void LiveCampaignTrackingGetSummaryTest() { var cc = new ConstantContactFactory(userServiceContext); var emailCampaignService = cc.CreateEmailCampaignService(); var campaignTrackingService = cc.CreateCampaignTrackingService(); var camp = new EmailCampaign { EmailContent = "<html><body>EMAIL CONTENT.</body></html>", Subject = "campaign subject", FromName = "my company", FromEmail = CustomerEmail, ReplyToEmail = CustomerEmail, Name = "campaign_" + DateTime.Now.ToString("yyMMddHHmmss"), TextContent = "email campaign text content", GreetingString = "Dear ", //TemplateType = TemplateType.CUSTOM, Status = CampaignStatus.DRAFT, EmailContentFormat = CampaignEmailFormat.HTML, StyleSheet = "", MessageFooter = new MessageFooter { OrganizationName = "my organization", AddressLine1 = "123 Mapple Street", AddressLine2 = "Suite 1", AddressLine3 = "", City = "Boston", State = "MA", PostalCode = "02101", Country = "US", IncludeForwardEmail = true, ForwardEmailLinkText = "forward link", IncludeSubscribeLink = true, SubscribeLinkText = "subscribe link" } , Lists = new List<SentContactList> { new SentContactList { Id = "1" } } }; camp = emailCampaignService.AddCampaign(camp); Assert.IsNotNull(camp); Assert.IsNotNull(camp.Id); TrackingSummary summary = campaignTrackingService.GetSummary(camp.Id); Assert.IsNotNull(summary); }
public void LiveUpdateContactListTest() { var cc = new ConstantContactFactory(userServiceContext); var listService = cc.CreateListService(); var contactList = new ContactList { Name = string.Format("List {0}", Guid.NewGuid()), Status = Status.Active }; var result = listService.AddList(contactList); Assert.IsNotNull(result); Assert.IsTrue(result.Name.Equals(contactList.Name)); result.Name = string.Format("List - {0}", Guid.NewGuid()); var updatedList = listService.UpdateList(result); Assert.IsNotNull(updatedList); Assert.AreEqual(result.Id, updatedList.Id); Assert.AreEqual(result.Name, updatedList.Name); }
public void LiveCampaignTrackingGetClicksTest() { var camp = CreateTestCampaign(); var cc = new ConstantContactFactory(userServiceContext); var campaignTrackingService = cc.CreateCampaignTrackingService(); ResultSet<ClickActivity> result = campaignTrackingService.GetClicks(camp.Id, "1", null, DateTime.Now.AddMonths(-1)); Assert.IsNotNull(result); }
public void LiveActivityClearListTest() { var cc = new ConstantContactFactory(userServiceContext); var activityService = cc.CreateActivityService(); var emailAddresses = new List<string> { String.Format("{0}@example.com", Guid.NewGuid()) }; var lists = new List<string> { "1" }; var add = new AddContacts( new List<AddContactsImportData>{ new AddContactsImportData{ EmailAddresses = emailAddresses } }, lists, null ); Activity act = activityService.CreateAddContactsActivity(add); Assert.IsNotNull(act); Activity activity = activityService.AddClearListsActivity(lists); Assert.IsNotNull(activity); Assert.AreEqual(activity.Type, "CLEAR_CONTACTS_FROM_LISTS"); }
/// <summary> /// Bind Campaign in dropdown /// </summary> public void LoadCampaign() { try { ApiKey = ConstantContactAPI; AccessToken = ConstantContactToken; IUserServiceContext userServiceContext = new UserServiceContext(AccessToken, ApiKey); var cc = new ConstantContactFactory(userServiceContext); var emailCampignService = cc.CreateEmailCampaignService(); ResultSet<EmailCampaign> listsAll = emailCampignService.GetCampaigns(null, null, null); ResultSet<EmailCampaign> filteredList = new ResultSet<EmailCampaign>() ; List<ConstantContactList> mailChimpList = new List<ConstantContactList>(); if (listsAll != null && listsAll.Results.Count > 0) { filteredList.Results = listsAll.Results.Where(p => p.Status.Equals(CampaignStatus.DRAFT)).ToList(); if (!chkDraft.Checked) { var newList = filteredList.Results.ToList(); newList.RemoveAll(p => p.Status == CampaignStatus.DRAFT); filteredList.Results = newList; } else { filteredList.Results = listsAll.Results.Where(p => p.Status == CampaignStatus.DRAFT).ToList(); } if (!chkSchedule.Checked) { filteredList.Results.ToList().RemoveAll(p => p.Status == CampaignStatus.SCHEDULED); } else { var newList = filteredList.Results.ToList(); newList.RemoveAll(p => p.Status == CampaignStatus.SCHEDULED); filteredList.Results = newList; filteredList.Results = filteredList.Results.Concat(listsAll.Results.Where(p => p.Status == CampaignStatus.SCHEDULED)).ToList(); } if (!chkSent.Checked) { var newList = filteredList.Results.ToList(); newList.RemoveAll(p => p.Status == CampaignStatus.SENT); filteredList.Results = newList; } else { if (filteredList.Results != null) { var newList = filteredList.Results.ToList(); newList.RemoveAll(p => p.Status == CampaignStatus.SENT); filteredList.Results = newList; filteredList.Results = filteredList.Results.Concat(listsAll.Results.Where(p => p.Status == CampaignStatus.SENT)).ToList(); } } cmbCampaign.DataSource = null; cmbCampaign.Items.Clear(); mailChimpList.Add(new ConstantContactList("0", CommonConstants.MandatoryFields.SelectCampaign)); foreach (var list in filteredList.Results.OrderBy(p=>p.Name)) { mailChimpList.Add(new ConstantContactList(list.Id.ToString(), list.Name+" "+'(' + list.Status + ')')); } cmbCampaign.DisplayMember = "Name"; cmbCampaign.ValueMember = "Id"; cmbCampaign.DataSource = mailChimpList; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void LiveAddContactTest() { var cc = new ConstantContactFactory(userServiceContext); var contactService = cc.CreateContactService(); var contact = new Contact(); contact.EmailAddresses.Add(new EmailAddress { EmailAddr = String.Format("{0}@email.com", Guid.NewGuid()), ConfirmStatus = ConfirmStatus.NoConfirmationRequired, Status = Status.Active }); contact.Lists.Add(new ContactList { Id = "1", Status = Status.Active }); var nc = contactService.AddContact(contact, false); Assert.IsNotNull(nc); Assert.IsNotNull(nc.Id); }
public void LiveActivityExportContactsTest() { var cc = new ConstantContactFactory(userServiceContext); var activityService = cc.CreateActivityService(); var lists = new List<string>() { "1" }; ExportContacts export = new ExportContacts(); export.Lists = lists; Activity activity = activityService.AddExportContactsActivity(export); Assert.IsNotNull(activity); Assert.IsNotNull(activity.Id); Assert.AreEqual(activity.Type, "EXPORT_CONTACTS"); }
public void LiveCampaignTrackingGetForwardsTest() { var cc = new ConstantContactFactory(userServiceContext); var emailCampaignService = cc.CreateEmailCampaignService(); var campaignScheduleService = cc.CreateCampaignScheduleService(); var campaignTrackingService = cc.CreateCampaignTrackingService(); var camp = new EmailCampaign { EmailContent = "<html><body>EMAIL CONTENT.</body></html>", Subject = "campaign subject", FromName = "my company", FromEmail = CustomerEmail, ReplyToEmail = CustomerEmail, Name = "campaign_" + DateTime.Now.ToString("yyMMddHHmmss"), TextContent = "email campaign text content", GreetingString = "Dear ", Status = CampaignStatus.DRAFT, EmailContentFormat = CampaignEmailFormat.HTML, StyleSheet = "", MessageFooter = new MessageFooter { OrganizationName = "my organization", AddressLine1 = "123 Mapple Street", AddressLine2 = "Suite 1", AddressLine3 = "", City = "Boston", State = "MA", PostalCode = "02101", Country = "US", IncludeForwardEmail = true, ForwardEmailLinkText = "forward link", IncludeSubscribeLink = true, SubscribeLinkText = "subscribe link" } , Lists = new List<SentContactList> { new SentContactList { Id = "1" } } }; camp = emailCampaignService.AddCampaign(camp); Assert.IsNotNull(camp); Assert.IsNotNull(camp.Id); DateTime schDate = DateTime.Now; Schedule schedule = campaignScheduleService.AddSchedule(camp.Id, new Schedule { ScheduledDate = schDate }); Assert.IsNotNull(schedule); Assert.AreNotEqual("", schedule.Id); Assert.IsNotNull(schedule.ScheduledDate); ResultSet<ForwardActivity> result = campaignTrackingService.GetForwards(camp.Id, null, DateTime.Now.AddMonths(-1)); Assert.IsNotNull(result); }
public void LiveActivityGetSummaryReportTest() { var cc = new ConstantContactFactory(userServiceContext); var activityService = cc.CreateActivityService(); var add = new AddContacts( new List<AddContactsImportData>{ new AddContactsImportData{ EmailAddresses = new List<string>{ String.Format("{0}@example.com", Guid.NewGuid()) } } }, new List<string> { "1" }, null ); Activity act = activityService.CreateAddContactsActivity(add); Assert.IsNotNull(act); IList<Activity> list = activityService.GetActivities(); Activity a = activityService.GetActivity(list[0].Id); Assert.IsNotNull(a); }
static void Mainss(string[] args) { Uri OrganizationUri = new Uri(String.Format("https://netunousa.api.crm.dynamics.com/XRMServices/2011/Organization.svc")); Uri HomeRealmUri = new Uri(String.Format("https://netunousa.api.crm.dynamics.com/XRMServices/2011/Discovery.svc")); Uri serviceUri = new Uri("https://netunousa.api.crm.dynamics.com/XRMServices/2011/Organization.svc"); System.ServiceModel.Description.ClientCredentials clientCredentials = new System.ServiceModel.Description.ClientCredentials(); clientCredentials.UserName.UserName = "******"; clientCredentials.UserName.Password = "******"; OrganizationServiceProxy serviceproxy = new OrganizationServiceProxy(OrganizationUri, null, clientCredentials, null); IOrganizationService orgservice = (IOrganizationService)serviceproxy; //ConditionExpression condition = new ConditionExpression(); //condition.AttributeName = "new_integratectct"; //condition.Operator = ConditionOperator.Equal; //condition.Values.Add("0"); string[] cols = { "firstname", "lastname", "middlename", "emailaddress1", "address1_line1", "address1_line2", "address1_city", "address1_county", "address1_postalcode", "mobilephone", "donotbulkemail", "company", "jobtitle", "birthdate", "gendercode", "salutation" }; ColumnSet columns = new ColumnSet(cols); QueryExpression expression = new QueryExpression(); expression.EntityName = "contact"; //expression.ColumnSet = new AllColumns(); expression.ColumnSet.AllColumns = true; //expression.ColumnSet.AllColumns = true; expression.ColumnSet = columns; //expression.Criteria.AddCondition(condition); EntityCollection contactEntityColl = orgservice.RetrieveMultiple(expression); if (contactEntityColl.Entities.Count > 0) { IUserServiceContext userServiceContext = new UserServiceContext("3f09fe65-10ae-44a9-9db6-d9f2d6de1dec", "cvwkqk7ajrm67rcagvfwn9gx"); ConstantContactFactory serviceFactory = new ConstantContactFactory(userServiceContext); IContactService contactService = serviceFactory.CreateContactService(); for (int i = 0; i < contactEntityColl.Entities.Count; i++) { try { //get contact if exists (by email address) Contact contact = null; if (contactEntityColl.Entities[i].Attributes.Contains("emailaddress1")) { try { contact = GetContactByEmailAddress(contactEntityColl.Entities[i].Attributes["emailaddress1"].ToString()); } catch (CtctException ctcEx) { //contact not found } bool alreadyExists = contact != null ? true : false; contact = UpdateContactFields(contact, contactEntityColl.Entities[i].Attributes); Contact result = null; // var contactService = _constantContactFactory.CreateContactService(); if (alreadyExists) { result = contactService.UpdateContact(contact, false); contactEntityColl.Entities[i].Attributes["new_integratectct"] = result.Id; orgservice.Update((Entity)contactEntityColl.Entities[i]); } else { result = contactService.AddContact(contact, false); contactEntityColl.Entities[i].Attributes["new_integratectct"] = result.Id; orgservice.Update((Entity)contactEntityColl.Entities[i]); } if (result != null) { if (alreadyExists) { //messageResult = "Changes successfully saved!"; } else { // messageResult = "Contact successfully added!"; } } else { if (alreadyExists) { // messageResult = "Failed to save changes!"; } else { // messageResult = "Failed to add contact!"; } } //MessageBox.Show(messageResult, "Result"); } } 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; } }
public void GetLibraryInfoTest() { var cc = new ConstantContactFactory(userServiceContext); var myLibraryService = cc.CreateMyLibraryService(); var result = myLibraryService.GetLibraryInfo(); Assert.IsNotNull(result); Assert.IsNotNull(result.UsageSummary); }