public async Task AddNewContact(string newContactEmail, string newContactDisplayName = "")
        {
            if (newContactEmail == "")
            {
                throw new ArgumentNullException("Contact email is empty");
            }
            if (newContactDisplayName == "")
            {
                newContactDisplayName = newContactEmail;
            }
            await Task.Run(() =>
            {
                switch (MsnpVersion)
                {
                case "MSNP12":
                    TransactionId++;
                    nsSocket.SendCommand($"ADC {TransactionId} FL N={newContactEmail} F={newContactDisplayName}\r\n");
                    Windows.Foundation.IAsyncAction adcTask = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Contact newContact = new Contact((int)ListNumbers.Forward + (int)ListNumbers.Allow)
                        {
                            DisplayName = newContactDisplayName,
                            Email       = newContactEmail
                        };
                        ContactList.Add(newContact);
                        ContactsInForwardList.Add(newContact);
                    });
                    break;

                case "MSNP15":
                    TransactionId++;
                    soapRequests.AbContactAdd(newContactEmail);
                    string contactPayload = ReturnXMLNewContactPayload(newContactEmail);
                    int payloadLength     = Encoding.UTF8.GetBytes(contactPayload).Length;
                    nsSocket.SendCommand($"ADL {TransactionId} {payloadLength}\r\n{contactPayload}");
                    Windows.Foundation.IAsyncAction adlTask = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Contact newContact = new Contact((int)ListNumbers.Forward + (int)ListNumbers.Allow)
                        {
                            DisplayName = newContactDisplayName,
                            Email       = newContactEmail
                        };
                        ContactList.Add(newContact);
                        ContactsInForwardList.Add(newContact);
                    });
                    break;

                default:
                    throw new Exceptions.VersionNotSelectedException();
                }
            });
        }
 public void FillForwardListCollection()
 {
     foreach (Contact contact in ContactList)
     {
         if (contact.OnForward)
         {
             Windows.Foundation.IAsyncAction task = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 ContactsInForwardList.Add(contact);
             });
         }
     }
 }
        public async Task AcceptNewContact(Contact contactToAccept)
        {
            if (contactToAccept == null)
            {
                throw new ArgumentNullException("Contact is null");
            }
            if (contactToAccept.OnForward)
            {
                return;
            }
            await Task.Run(() =>
            {
                switch (MsnpVersion)
                {
                case "MSNP12":
                    TransactionId++;
                    nsSocket.SendCommand($"ADC {TransactionId} FL N={contactToAccept.Email} F={contactToAccept.DisplayName}\r\n");
                    contactToAccept.OnForward = true;
                    Windows.Foundation.IAsyncAction adc_task = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        ContactsInForwardList.Add(contactToAccept);
                        ContactsInPendingOrReverseList.Remove(contactToAccept);
                    });
                    break;

                case "MSNP15":
                    TransactionId++;
                    soapRequests.AbContactAdd(contactToAccept.Email);
                    string contactPayload = ReturnXMLNewContactPayload(contactToAccept.Email);
                    int payloadLength     = Encoding.UTF8.GetBytes(contactPayload).Length;
                    nsSocket.SendCommand($"ADL {TransactionId} {payloadLength}\r\n{contactPayload}");
                    TransactionId++;
                    contactPayload = ReturnXMLNewContactPayload(contactToAccept.Email, 2);
                    payloadLength  = Encoding.UTF8.GetBytes(contactPayload).Length;
                    nsSocket.SendCommand($"ADL {TransactionId} {payloadLength}\r\n{contactPayload}");
                    contactToAccept.OnForward = true;
                    Windows.Foundation.IAsyncAction adl_task = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        contactToAccept.DisplayName = contactToAccept.Email;
                        ContactsInForwardList.Add(contactToAccept);
                        ContactsInPendingOrReverseList.Remove(contactToAccept);
                    });
                    break;

                default:
                    throw new Exceptions.VersionNotSelectedException();
                }
            });
        }
예제 #4
0
        public void HandleLst()
        {
            string[] lstParameters = currentResponse.Split(" ");
            string   email, displayName, guid;
            int      listNumber = 0;

            email       = lstParameters[1].Replace("N=", "");
            displayName = lstParameters[2].Replace("F=", "");
            try
            {
                guid = lstParameters[3].Replace("C=", "");
            }
            catch (IndexOutOfRangeException)
            {
                guid = null;
            }
            int.TryParse(lstParameters[4], out listNumber);
            displayName = plusCharactersRegex.Replace(displayName, "");
            var contactsInList = from contactInList in ContactList
                                 where contactInList.Email == email
                                 select contactInList;

            if (!contactsInList.Any())
            {
                Contact newContact = new Contact(listNumber)
                {
                    DisplayName = displayName,
                    Email       = email,
                    GUID        = guid
                };
                ContactList.Add(newContact);
                DatabaseAccess.AddContactToTable(UserInfo.Email, newContact);
                if (newContact.OnForward)
                {
                    Windows.Foundation.IAsyncAction task = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        ContactsInForwardList.Add(newContact);
                    });
                }
                if (newContact.OnReverse || newContact.Pending)
                {
                    Windows.Foundation.IAsyncAction task = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        ContactsInPendingOrReverseList.Add(newContact);
                    });
                }
            }
            else
            {
                foreach (Contact contactInList in contactsInList)
                {
                    contactInList.SetListsFromListNumber(listNumber);
                    contactInList.DisplayName = displayName;
                    contactInList.GUID        = guid;
                    if (contactInList.OnForward)
                    {
                        Windows.Foundation.IAsyncAction task = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            ContactsInForwardList.Add(contactInList);
                        });
                    }
                    if (contactInList.OnReverse || contactInList.Pending)
                    {
                        Windows.Foundation.IAsyncAction task = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            ContactsInPendingOrReverseList.Add(contactInList);
                        });
                    }
                }
            }
        }