Esempio n. 1
0
        public async Task UpdateUsers()
        {
            using (var client = new HttpClient())
            {
                var response = await client.GetAsync("https://jsonplaceholder.typicode.com/users");

                var users = JsonConvert.DeserializeObject <List <Contact> >(await response.Content.ReadAsStringAsync());

                await Task.Delay(2000);

                foreach (var item in users)
                {
                    Contacts?.Add(item);
                }
            }
        }
Esempio n. 2
0
    protected void lnkSave_Click(object sender, EventArgs e)
    {
        if (Session["mode"] != null)
        {
            if (Session["mode"] == "add")
            {
                try{
                    Contacts contacts = new Contacts();

                    contacts.FirstName = txtFirstName.Text;
                    contacts.LastName = txtLastName.Text;
                    contacts.Mobile = txtMobile.Text;
                    contacts.Landline = txtLandline.Text;
                    contacts.Email = txtEmail.Text;

                    contacts.Add();
                    Response.Redirect("Default.aspx");
                }
                catch(Exception ex)
                {
                    lblMessage.Text = "Error in adding new contact." + Environment.NewLine + ex.Message;
                }
            }
            else
            {
                try
                {
                    Contacts contacts = new Contacts();
                    Int32 id = Convert.ToInt32(ViewState["id"].ToString());
                    contacts.GetContact(id);

                    contacts.FirstName = txtFirstName.Text;
                    contacts.LastName = txtLastName.Text;
                    contacts.Mobile = txtMobile.Text;
                    contacts.Landline = txtLandline.Text;
                    contacts.Email = txtEmail.Text;

                    contacts.Update();
                    Response.Redirect("Default.aspx");
             }
                catch(Exception ex)
                {
                    lblMessage.Text = "Error in editing new contact." + Environment.NewLine + ex.Message;
                }
            }
        }
    }
Esempio n. 3
0
        //.getMembers
        public Contacts vimeo_groups_getMembers(string group_id, ChannelsSortMethods sortMethod=ChannelsSortMethods.Default, int? page=null, int? per_page=null)
        {
            var parameters = new Dictionary<string, string> { { "group_id", group_id } };
            if (page.HasValue) parameters.Add("page", page.Value.ToString());
            if (per_page.HasValue) parameters.Add("per_page", per_page.Value.ToString());
            var x = ExecuteGetRequest("vimeo.groups.getMembers", parameters);
            if (!IsResponseOK(x)) return null;

            var e = x.Element("rsp").Element("members");
            Contacts cs = new Contacts();
            cs.on_this_page = int.Parse(e.Attribute("on_this_page").Value);
            cs.page = int.Parse(e.Attribute("page").Value);
            cs.perpage = int.Parse(e.Attribute("perpage").Value);
            cs.total = int.Parse(e.Attribute("total").Value);

            foreach (var item in e.Elements("member"))
            {
                cs.Add(Contact.FromElement(item));
            }
            return cs;
        }
Esempio n. 4
0
 public async void UpdateContact(Contact newContact, int contactId, int listboxPosition)
 {
     this.Contacts.RemoveAt(listboxPosition);
     Contacts.Add(await this._contactService.Update(newContact, contactId));
 }
Esempio n. 5
0
 private void AddContact(PersonContact contact)
 {
     contact.PersonId = Id;
     Contacts.Add(contact);
 }
Esempio n. 6
0
        public virtual void AddContact(Contact contact)
        {
            contact.Person = this;

            Contacts.Add(contact);
        }
Esempio n. 7
0
 public void AddContact(Contact newContact)
 {
     Contacts.Add(newContact);
 }
        private async Task <bool> ImportExchangeContactsAsync()
        {
            try
            {
                if (CurrentContactsFolder.TotalCount == 0)
                {
                    Console.WriteLine($"Ordner '{CurrentContactsFolder.DisplayName}' enthält keine Elemente.");
                    return(false);
                }

                FindItemsResults <Item> foundItems = await System.Threading.Tasks.Task.Run(() => {
                    Console.WriteLine($"Ordner '{CurrentContactsFolder.DisplayName}' wird durchsucht.");
                    ItemView itemView = new ItemView(CurrentContactsFolder.TotalCount);
                    return(exService.FindItems(CurrentContactsFolder.Id, itemView));
                });


                Console.WriteLine("Es wurde{0} {1} Objekt{2} im ausgewählten Ordner gefunden.",
                                  foundItems.TotalCount == 1 ? "" : "n",
                                  foundItems.TotalCount,
                                  foundItems.TotalCount == 1 ? "" : "e");

                foreach (Item item in foundItems)
                {
                    if (item is Contact)
                    {
                        Contact exContact = item as Contact;
                        Console.WriteLine("");
                        Console.WriteLine("Kontakt: " + exContact.DisplayName);

                        ContactModel contact = new ContactModel
                        {
                            Title       = exContact.JobTitle,
                            GivenName   = exContact.GivenName,
                            Surname     = exContact.Surname,
                            CompanyName = exContact.CompanyName
                        };

                        if (exContact.EmailAddresses.TryGetValue(EmailAddressKey.EmailAddress1, out EmailAddress emailAdress))
                        {
                            if (IsValidEmailAddress(emailAdress.Address))
                            {
                                contact.EMailAddress = emailAdress.Address;
                            }
                        }

                        string phoneNumber;

                        phoneNumber = string.Empty;
                        exContact.PhoneNumbers.TryGetValue(PhoneNumberKey.MobilePhone, out phoneNumber);
                        if (!string.IsNullOrEmpty(phoneNumber) && !IsValidPhoneNumber(phoneNumber))
                        {
                            continue;
                        }
                        contact.CellBusiness = ReFormatPhoneNumber(phoneNumber);

                        phoneNumber = string.Empty;
                        exContact.PhoneNumbers.TryGetValue(PhoneNumberKey.BusinessPhone, out phoneNumber);
                        if (!string.IsNullOrEmpty(phoneNumber) && !IsValidPhoneNumber(phoneNumber))
                        {
                            continue;
                        }
                        contact.Work = ReFormatPhoneNumber(phoneNumber);

                        phoneNumber = string.Empty;
                        exContact.PhoneNumbers.TryGetValue(PhoneNumberKey.BusinessFax, out phoneNumber);
                        if (!string.IsNullOrEmpty(phoneNumber) && !IsValidPhoneNumber(phoneNumber))
                        {
                            continue;
                        }
                        contact.Fax = ReFormatPhoneNumber(phoneNumber);

                        phoneNumber = string.Empty;
                        exContact.PhoneNumbers.TryGetValue(PhoneNumberKey.OtherTelephone, out phoneNumber);
                        if (!string.IsNullOrEmpty(phoneNumber) && !IsValidPhoneNumber(phoneNumber))
                        {
                            continue;
                        }
                        contact.CellPersonal = ReFormatPhoneNumber(phoneNumber);

                        phoneNumber = string.Empty;
                        exContact.PhoneNumbers.TryGetValue(PhoneNumberKey.HomePhone, out phoneNumber);
                        if (!string.IsNullOrEmpty(phoneNumber) && !IsValidPhoneNumber(phoneNumber))
                        {
                            continue;
                        }
                        contact.Home = ReFormatPhoneNumber(phoneNumber);

                        phoneNumber = string.Empty;
                        exContact.PhoneNumbers.TryGetValue(PhoneNumberKey.BusinessPhone2, out phoneNumber);
                        if (!string.IsNullOrEmpty(phoneNumber) && !IsValidPhoneNumber(phoneNumber))
                        {
                            continue;
                        }
                        contact.Work2 = ReFormatPhoneNumber(phoneNumber);

                        phoneNumber = string.Empty;
                        exContact.PhoneNumbers.TryGetValue(PhoneNumberKey.HomePhone2, out phoneNumber);
                        if (!string.IsNullOrEmpty(phoneNumber) && !IsValidPhoneNumber(phoneNumber))
                        {
                            continue;
                        }
                        contact.Home2 = ReFormatPhoneNumber(phoneNumber);

                        Contacts.Add(contact);
                    }
                }
                Console.WriteLine("Es wurde{0} {1} Kontakt{2} erfolgreich importiert.",
                                  Contacts.Count == 1 ? "" : "n",
                                  Contacts.Count,
                                  Contacts.Count == 1?"":"e");
            }
            catch (ServiceRequestException ex)
            {
                Console.WriteLine("Exchange Fehler: " + ex.Message);
                if (DebugMode)
                {
                    Console.WriteLine(ex.ToString());
                }

                LoggedIn = false;
                return(false);
            }
            catch (ServiceResponseException ex)
            {
                Console.WriteLine("Exchange Fehler: " + ex.Message);
                if (DebugMode)
                {
                    Console.WriteLine(ex.ToString());
                }

                LoggedIn = false;
                return(false);
            }
            return(true);
        }
Esempio n. 9
0
        public async void ImportContactsAsync()
        {
            Telegram.Logs.Log.Write("Contacts start search 2");

            _stopwatch = Stopwatch.StartNew();
            var contactStore = await ContactManager.RequestStoreAsync();

            if (contactStore == null)
            {
                Telegram.Logs.Log.Write("ContactsStore is null");
                IsWorking = false;
                Status    = Items.Count == 0 && LazyItems.Count == 0
                    ? AppResources.NoContactsHere
                    : string.Empty;

                return;
            }

            var contacts = await contactStore.FindContactsAsync();

            Telegram.Logs.Log.Write("Contacts search completed count=" + contacts.Count);

            TLUtils.WritePerformance("::Search contacts time: " + _stopwatch.Elapsed);
            _stopwatch = Stopwatch.StartNew();

            var phonesCache           = new Dictionary <string, Contact>();
            var notRegisteredContacts = new List <TLUserBase>();

            foreach (var contact in contacts)
            {
                foreach (var phoneNumber in contact.Phones)
                {
                    phonesCache[phoneNumber.Number] = contact;
                }

                var notRegisteredUser = GetNotRegisteredUser(contact);
                if (notRegisteredUser != null)
                {
                    notRegisteredContacts.Add(notRegisteredUser);
                }
            }

            Telegram.Logs.Log.Write("Contacts skip empty count=" + notRegisteredContacts.Count);

            TLUtils.WritePerformance("::Get not registered phones time: " + _stopwatch.Elapsed);

            _stopwatch = Stopwatch.StartNew();

            var groups = AlphaKeyGroup <TLUserBase> .CreateGroups(
                notRegisteredContacts,
                Thread.CurrentThread.CurrentUICulture,
                x => x.FullName,
                false);

            TLUtils.WritePerformance("::Get groups time: " + _stopwatch.Elapsed);

            var contactKeys = new Dictionary <string, string>();

            foreach (var contact in Contacts)
            {
                contactKeys[contact.Key] = contact.Key;
            }
            BeginOnThreadPool(() =>
            {
                foreach (var @group in groups)
                {
                    var gr = new AlphaKeyGroup <TLUserBase>(@group.Key);
                    foreach (var u in @group.OrderBy(x => x.FullName))
                    {
                        gr.Add(u);
                    }

                    if (!contactKeys.ContainsKey(gr.Key))
                    {
                        BeginOnUIThread(() => Contacts.Add(gr));
                    }
                }
            });

            var importedPhonesCache = GetImportedPhones();

            Telegram.Logs.Log.Write("Contacts load imported count=" + importedPhonesCache.Count);

            var phones            = phonesCache.Keys.Take(Constants.MaxImportingContactsCount).ToList();
            var importingContacts = new TLVector <TLInputContactBase>();
            var importingPhones   = new List <string>();

            foreach (var phone in phones)
            {
                if (importedPhonesCache.ContainsKey(phone))
                {
                    continue;
                }

                var firstLastName = GetFirstLastName(phonesCache[phone]);

                var contact = new TLInputContact
                {
                    Phone     = new TLString(phone),
                    FirstName = new TLString(firstLastName.Item1),
                    LastName  = new TLString(firstLastName.Item2),
                    ClientId  = new TLLong(phonesCache[phone].GetHashCode())
                };

                importingContacts.Add(contact);
                importingPhones.Add(phone);
            }

            Telegram.Logs.Log.Write("Contacts skip imported count=" + importingContacts.Count);

            if (importingContacts.Count > 0)
            {
                System.Diagnostics.Debug.WriteLine("contacts.importContacts id={0}", string.Join(",", importingContacts.Select(x => ((TLInputContact)x).Phone)));

                IsWorking = true;
                MTProtoService.ImportContactsAsync(importingContacts,
                                                   result => Execute.BeginOnUIThread(() =>
                {
                    Telegram.Logs.Log.Write("Contacts contacts.importContacts result=" + result);

                    IsWorking = false;
                    Status    = Items.Count == 0 && LazyItems.Count == 0 && result.Users.Count == 0
                            ? AppResources.NoContactsHere
                            : string.Empty;

                    var retryContactsCount = result.RetryContacts.Count;
                    if (retryContactsCount > 0)
                    {
                        Execute.ShowDebugMessage("contacts.importContacts retry_contacts_count=" + retryContactsCount);
                    }

                    InsertContacts(result.Users);

                    SaveImportedPhones(importedPhonesCache, importingPhones);
                }),
                                                   error => Execute.BeginOnUIThread(() =>
                {
                    Telegram.Logs.Log.Write("Contacts contacts.importContacts error=" + error);

                    IsWorking = false;
                    Status    = string.Empty;

                    Execute.ShowDebugMessage("contacts.importContacts error=" + error);
                }));
            }
            else
            {
                Status = Items.Count == 0 && LazyItems.Count == 0
                    ? AppResources.NoContactsHere
                    : string.Empty;
            }
        }
Esempio n. 10
0
 public void AddContact(string contact)
 {
     _contacts.Add(contact);
 }