예제 #1
0
        /// <summary>
        /// Add a new list.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="list">Contact list.</param>
        /// <returns>Returns the newly created list.</returns>
        public ContactList AddList(string accessToken, string apiKey, ContactList list)
        {
            ContactList newList = null;
            string url = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.Lists);
            string json = list.ToJSON();
            CUrlResponse response = RestClient.Post(url, accessToken, apiKey, json);

            if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }

            if (response.HasData)
            {
                newList = Component.FromJSON<ContactList>(response.Body);
            }

            return newList;
        }
예제 #2
0
        /// <summary>
        /// Add a new list.
        /// </summary>
        /// <param name="list">Contact list.</param>
        /// <returns>Returns the newly created list.</returns>
        public ContactList AddList(ContactList list)
        {
            if (list == null)
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.ListOrId);
            }

            string url = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.Lists);
            string json = list.ToJSON();
            RawApiResponse response = RestClient.Post(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json);
            try
            {
                var newList = response.Get<ContactList>();
                return newList;
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
예제 #3
0
 /// <summary>
 /// Get contact that belong to a specific list.
 /// </summary>
 /// <param name="list">Contact list object.</param>
 /// <param name="limit">Specifies the number of results per page in the output, from 1 - 500, default = 500.</param>
 /// <param name="modifiedSince">limit contacts retrieved to contacts modified since the supplied date</param>
 /// <returns>Returns the list of contacts.</returns>
 /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
 public ResultSet<Contact> GetContactsFromList(ContactList list, int? limit, DateTime? modifiedSince)
 {
     return this.GetContactsFromList(list.Id, limit, modifiedSince, null);
 }
예제 #4
0
        /// <summary>
        /// Add a new list to an account.
        /// </summary>
        /// <param name="list">List to add.</param>
        /// <returns>Returns the newly created list.</returns>
        public ContactList AddList(ContactList list)
        {
			if (list == null)
            {
                throw new IllegalArgumentException(Config.Errors.ListOrId);
            }

            return ListService.AddList(AccessToken, APIKey, list);
        }
예제 #5
0
        /// <summary>
        /// Delete a contact from all contact lists.
        /// </summary>
        /// <param name="contact">Contact object.</param>
        /// <param name="list">List object.</param>
        /// <returns>Returns true if operation succeeded.</returns>
        /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
        public bool DeleteContactFromList(Contact contact, ContactList list)
        {
            if (contact == null)
            {
                throw new IllegalArgumentException(Config.Errors.ContactOrId);
            }
            if (list == null)
            {
                throw new IllegalArgumentException(Config.Errors.ListOrId);
            }

            return this.DeleteContactFromList(contact.Id, list.Id);
        }
예제 #6
0
        public void LiveDeleteContactListTest()
        {
            var cc = new ConstantContact(ApiKey, AccessToken);

            var contactList = new ContactList
            {
                Name = string.Format("List {0}", Guid.NewGuid()),
                Status = Status.Active
            };

            var result = cc.AddList(contactList);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Name.Equals(contactList.Name));

            result.Name = string.Format("List - {0}", Guid.NewGuid());

            var deleted = cc.DeleteList(result.Id.ToString(CultureInfo.InvariantCulture));
            Assert.IsTrue(deleted);
        }
예제 #7
0
        public void LiveUpdateContactListTest()
        {
            var cc = new ConstantContact(ApiKey, AccessToken);

            var contactList = new ContactList
                {
                Name = string.Format("List {0}", Guid.NewGuid()),
                Status = Status.Active
            };

            var result = cc.AddList(contactList);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Name.Equals(contactList.Name));

            result.Name = string.Format("List - {0}", Guid.NewGuid());

            var updatedList = cc.UpdateList(result);
            Assert.IsNotNull(updatedList);
            Assert.AreEqual(result.Id, updatedList.Id);
            Assert.AreEqual(result.Name, updatedList.Name);
        }
예제 #8
0
        public void LiveAddContactListTest()
        {
            var cc = new ConstantContact(ApiKey, AccessToken);

            ContactList contactList = new ContactList { 
                Name = string.Format("List {0}", Guid.NewGuid()),
                Status = Status.Active
            };

            var result = cc.AddList(contactList);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Name.Equals(contactList.Name));
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
 /// <summary>
 /// Get contact that belong to a specific list.
 /// </summary>
 /// <param name="list">Contact list object.</param>
 /// <param name="modifiedSince">limit contacts retrieved to contacts modified since the supplied date</param>
 /// <returns>Returns the list of contacts.</returns>
 /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
 public ResultSet<Contact> GetContactsFromList(ContactList list, DateTime? modifiedSince)
 {
     return GetContactsFromList(list.Id, null, modifiedSince, null);
 }
예제 #12
0
        /// <summary>
        /// Get contact that belong to a specific list.
        /// </summary>
        /// <param name="list">Contact list object.</param>
        /// <param name="limit">Specifies the number of results per page in the output, from 1 - 500, default = 500.</param>
        /// <param name="modifiedSince">limit contacts retrieved to contacts modified since the supplied date</param>
        /// <returns>Returns the list of contacts.</returns>
        /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
        public ResultSet<Contact> GetContactsFromList(ContactList list, int? limit, DateTime? modifiedSince)
        {
            if (list == null)
            {
                throw new IllegalArgumentException(Config.Errors.ListOrId);
            }

            return ListService.GetContactsFromList(AccessToken, APIKey, list.Id, limit, modifiedSince);
        }
예제 #13
0
 /// <summary>
 /// Add a new list to an account.
 /// </summary>
 /// <param name="list">List to add.</param>
 /// <returns>Returns the newly created list.</returns>
 public ContactList AddList(ContactList list)
 {
     return ListService.AddList(AccessToken, APIKey, list);
 }
예제 #14
0
        /// <summary>
        /// Delete a contact from all contact lists.
        /// </summary>
        /// <param name="contact">Contact object.</param>
        /// <param name="list">List object.</param>
        /// <returns>Returns true if operation succeeded.</returns>
        /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
        public bool DeleteContactFromList(Contact contact, ContactList list)
        {
            if (contact == null)
            {
                throw new IllegalArgumentException(Config.Errors.ContactOrId);
            }
            if (list == null)
            {
                throw new IllegalArgumentException(Config.Errors.ListOrId);
            }

            return ContactService.DeleteContactFromList(AccessToken, APIKey, contact.Id, list.Id);
        }
        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;
                }
            }
        }