Example #1
0
        private void TestCm()
        {
            List <Sync.BL.Entities.List> cmList;

            this.Dispatcher.Invoke((Action)(() =>
            {
                cmSettings = new CMSettings()
                {
                    UserName = CMUserName.Text,
                    Password = CMPassword.Password,
                    ApiKey = CMApiKey.Text
                };
            }));

            try
            {
                cmRepo = new CMRepository(cmSettings);
                Client cmClient = cmRepo.GetClients().FirstOrDefault();
                cmList = cmRepo.GetLists(cmClient.ClientId);
                this.Dispatcher.Invoke((Action)(() =>
                {
                    MessageBox.Show(Application.Current.MainWindow, "Connection is OK");
                    TestingScreen.Visibility = System.Windows.Visibility.Hidden;
                }));
            }
            catch
            {
                this.Dispatcher.Invoke((Action)(() =>
                {
                    MessageBox.Show(Application.Current.MainWindow, "Test failed!");
                    TestingScreen.Visibility = System.Windows.Visibility.Hidden;
                }));
            }
        }
Example #2
0
        public void AddSubscribersTest()
        {
            CMSettings settings = new CMSettings();

            settings.ApiKey = "4a087dfc720e09d91e8cb5cae9db51d5"; //Hard Coded
            ICMRepository repo       = new CMRepository(settings);
            List <Client> clientList = repo.GetClients();
            List <List>   list       = repo.GetLists(clientList.Find(x => x.Name == "Hal").ClientId.ToString());
            //Create Test Subscribers
            List <Subscriber> importSubscribers = new List <Subscriber>()
            {
                new Subscriber()
                {
                    E_mail = "*****@*****.**", Name = "Joze"
                },
                new Subscriber()
                {
                    E_mail = "*****@*****.**", Name = "Miha"
                },
                new Subscriber()
                {
                    E_mail = "*****@*****.**", Name = "Mojca"
                }
            };

            //Import Subscribers
            repo.AddSubscribers(list.Find(x => x.Name == "Crm").ListId.ToString(), importSubscribers);
            //Test inported subscribers
            List <Subscriber> subscribers = repo.GetAciveSubscribers(list.Find(x => x.Name == "Crm").ListId.ToString());

            Assert.IsNotNull(subscribers.Find(x => x.E_mail == "*****@*****.**"));
        }
Example #3
0
        private void InitializeComboBox()
        {
            List <Sync.BL.Entities.List> cmList;
            List <Sync.BL.Entities.List> crmList;

            Client cmClient = cmRepo.GetClients().FirstOrDefault();

            cmList  = cmRepo.GetLists(cmClient.ClientId);
            crmList = crmRepo.GetMarketingLists();

            this.Dispatcher.Invoke((Action)(() =>
            {
                Binding cmListBinding = new Binding();
                cmListBinding.Source = cmList;
                CmListComboBox.DisplayMemberPath = "Name";
                CmListComboBox.SelectedValuePath = "ListId";
                CmListComboBox.SetBinding(ComboBox.ItemsSourceProperty, cmListBinding);

                Binding crmListBinding = new Binding();
                crmListBinding.Source = crmList;
                CrmListComboBox.DisplayMemberPath = "Name";
                CrmListComboBox.SelectedValuePath = "ListId";
                CrmListComboBox.SetBinding(ComboBox.ItemsSourceProperty, crmListBinding);
            }));
        }
Example #4
0
        private void InitializeComboBox()
        {
            Client cmClient = cmRepo.GetClients().FirstOrDefault();

            cmList  = cmRepo.GetLists(cmClient.ClientId);
            crmList = crmRepo.GetMarketingLists();
        }
Example #5
0
        public void ClientsTest()
        {
            CMSettings settings = new CMSettings();

            settings.ApiKey = "4a087dfc720e09d91e8cb5cae9db51d5"; //Hard Coded
            ICMRepository repo = new CMRepository(settings);
            List <Client> list = repo.GetClients();

            Assert.IsNotNull(list.Find(x => x.Name == "Hal"));
        }
Example #6
0
        public void UnsubscribedSubscribersTest()
        {
            CMSettings settings = new CMSettings();

            settings.ApiKey = "4a087dfc720e09d91e8cb5cae9db51d5"; //Hard Coded
            ICMRepository     repo        = new CMRepository(settings);
            List <Client>     clientList  = repo.GetClients();
            List <List>       list        = repo.GetLists(clientList.Find(x => x.Name == "Hal").ClientId.ToString());
            List <Subscriber> subscribers = repo.GetUnsubscribedSubscribers(list.Find(x => x.Name == "Crm").ListId.ToString());

            Assert.IsNull(subscribers.Find(x => x.Name == "Xxxxx Yyyyy"));
        }
Example #7
0
        public void ActiveSubscribersByTimeTest()
        {
            CMSettings settings = new CMSettings();

            settings.ApiKey = "4a087dfc720e09d91e8cb5cae9db51d5"; //Hard Coded
            ICMRepository     repo        = new CMRepository(settings);
            List <Client>     clientList  = repo.GetClients();
            List <List>       list        = repo.GetLists(clientList.Find(x => x.Name == "Hal").ClientId.ToString());
            List <Subscriber> subscribers = repo.GetAciveSubscribers(list.Find(x => x.Name == "Crm").ListId.ToString(), DateTime.Now.AddHours(-1));

            repo.GetAciveSubscribers(ListId: "dsds", fromDate: DateTime.Now);
            Assert.IsNotNull(subscribers.Find(x => x.Name == "Xxxxx Yyyyy"));
        }
Example #8
0
        public void Sync()
        {
            Initialization();
            List <List> cmList;
            List <List> crmList;
            Client      cmClient = cmRepo.GetClients().FirstOrDefault();

            try
            {
                cmList  = cmRepo.GetLists(cmClient.ClientId);
                crmList = crmRepo.GetMarketingLists();
            }
            catch (Exception e)
            {
                EventLogManager.WriteMessage(new Message()
                {
                    Description = e.Message.ToString(), Type = "Error", Time = DateTime.Now
                }, EventType.Error);
                return;
            }
            string   CmListID;
            string   CmrListID;
            DateTime lastSync;


            List <CrmCmConnection> mapTable = ManageMapTable.LoadMapTable();


            foreach (CrmCmConnection connection in mapTable)
            {
                CmListID  = connection.CmListId;
                CmrListID = connection.CrmListId;
                lastSync  = connection.LastSync;

                List <Subscriber> cmSubscribers;
                List <Subscriber> crmSubscribers;

                try
                {
                    cmSubscribers  = cmRepo.GetAciveSubscribers(CmListID);
                    crmSubscribers = crmRepo.GetSubscribers(CmrListID);
                }
                catch (Exception e)
                {
                    EventLogManager.WriteMessage(new Message()
                    {
                        Description = e.Message.ToString(), Type = "Error", Time = DateTime.Now
                    }, EventType.Error);
                    break;
                }

                //Left Excluding JOIN using
                //A:CM B:CRM
                List <Subscriber> subscribersToCRM = (from a in cmSubscribers
                                                      join b in crmSubscribers on a.E_mail equals b.E_mail into j
                                                      from b in j.DefaultIfEmpty()
                                                      where b == null
                                                      select new Subscriber {
                    Name = a.Name, E_mail = a.E_mail
                }).ToList();


                //A:CRM B:CM
                List <Subscriber> subscribersToCM = (from a in crmSubscribers
                                                     join b in cmSubscribers on a.E_mail equals b.E_mail into j
                                                     from b in j.DefaultIfEmpty()
                                                     where b == null
                                                     select new Subscriber {
                    Name = a.Name, E_mail = a.E_mail
                }).ToList();
                //Delete or insert
                //new Subscribers from last sync
                List <Subscriber> newCmSubscribeers;
                List <Subscriber> newCrmSubscribers;

                try
                {
                    newCmSubscribeers = cmRepo.GetAciveSubscribers(CmListID, lastSync);
                    newCrmSubscribers = crmRepo.GetSubscribers(CmrListID, lastSync.AddHours(-2));
                    //newCrmSubscribers = crmRepo.GetSubscribers(CmrListID, lastSync.AddHours(-2));
                }
                catch (Exception e)
                {
                    EventLogManager.WriteMessage(new Message()
                    {
                        Description = e.Message.ToString(), Type = "Error", Time = DateTime.Now
                    }, EventType.Error);
                    return;
                }


                //Delete
                List <Subscriber> subscribersDeleteToCM = (from a in subscribersToCM
                                                           join b in newCrmSubscribers on a.E_mail equals b.E_mail into j
                                                           from b in j.DefaultIfEmpty()
                                                           where b == null
                                                           select new Subscriber {
                    Name = a.Name, E_mail = a.E_mail
                }).ToList();

                List <Subscriber> subscribersDeleteToCMR = (from a in subscribersToCRM
                                                            join b in newCmSubscribeers on a.E_mail equals b.E_mail into j
                                                            from b in j.DefaultIfEmpty()
                                                            where b == null
                                                            select new Subscriber {
                    Name = a.Name, E_mail = a.E_mail
                }).ToList();
                try
                {
                    //Insert Delete
                    //CM
                    //ADD
                    if (newCrmSubscribers.Count > 0)
                    {
                        cmRepo.AddSubscribers(CmListID, newCrmSubscribers);
                        EventLogManager.WriteMessage(new Message()
                        {
                            Description = "Added", SubscribersNumber = newCrmSubscribers.Count, ListName = connection.CmListName, System = "CM", Time = DateTime.Now, Type = "Sync"
                        }, EventType.Sync);
                    }
                    //DELETE
                    if (subscribersDeleteToCMR.Count > 0)
                    {
                        cmRepo.UnsubscribeSubscribers(CmListID, subscribersDeleteToCMR);
                        EventLogManager.WriteMessage(new Message()
                        {
                            Description = "Deleted", SubscribersNumber = subscribersDeleteToCMR.Count, ListName = connection.CmListName, System = "CM", Time = DateTime.Now, Type = "Sync"
                        }, EventType.Sync);
                    }
                    //CRM
                    //ADD
                    if (newCmSubscribeers.Count > 0)
                    {
                        crmRepo.AddSubscribers(CmrListID, newCmSubscribeers);
                        EventLogManager.WriteMessage(new Message()
                        {
                            Description = "Added", SubscribersNumber = newCmSubscribeers.Count, ListName = connection.CrmListName, System = "CRM", Time = DateTime.Now, Type = "Sync"
                        }, EventType.Sync);
                    }
                    //DELETE
                    if (subscribersDeleteToCM.Count > 0)
                    {
                        crmRepo.UnsubscribeSubscribers(CmrListID, subscribersDeleteToCM);
                        EventLogManager.WriteMessage(new Message()
                        {
                            Description = "Deleted", SubscribersNumber = subscribersDeleteToCM.Count, ListName = connection.CrmListName, System = "CRM", Time = DateTime.Now, Type = "Sync"
                        }, EventType.Sync);
                    }
                }
                catch (Exception e)
                {
                    EventLogManager.WriteMessage(new Message()
                    {
                        Description = e.Message.ToString(), Type = "Error", Time = DateTime.Now
                    }, EventType.Error);
                    return;
                }

                //Save sync date
                connection.LastSync = DateTime.Now;
                ManageMapTable.SaveMapTable(mapTable);
            }
        }