Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        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 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;
                    }
                }
            }
        }
        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;
                }
            }
        }