Пример #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

                int i = username.IndexOf(@"\");
                if (i != -1)
                {
                    username = username.Substring(i + 1, username.Length - i - 1);
                }
                txtUsername.Text = username;

                AppConfig appConfig = new AppConfig(Constants.GetConfigFilePath());
                contactManagement = new ContactManagement.ActiveDirectory.ContactManagement(Constants.GetADDomain());
                contact           = contactManagement.GetUserProfile(username);
                contact.Username  = username;

                txtHomePhone.Text     = contact.HomePhone;
                txtMobilePhone.Text   = contact.MobilePhone;
                txtBusinessPhone.Text = contact.BusinessPhone;
                txtBusinessFax.Text   = contact.BusinessFax;
                txtEmail.Text         = contact.Email;
                txtAddress.Text       = contact.Address;
                txtIPPhone.Text       = contact.IPPhone;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Search all the contacts
        /// </summary>
        public void SearchAll()
        {
            AppConfig appConfig = new AppConfig(Constants.GetConfigFilePath());


            if (Constants.IsActiveDirectory())
            {
                //Active Directory Contact

                string domainName = Constants.GetADDomain();


                try
                {
                    ContactManagement.ActiveDirectory.ContactManagement contactManagement = new ContactManagement.ActiveDirectory.ContactManagement(domainName);
                    Dictionary <string, Contact> activeDirectoryContacts = contactManagement.RetrieveAllContact("(objectCategory=person)");

                    foreach (var k in activeDirectoryContacts)
                    {
                        string key = k.Key;
                        if (_contacts.ContainsKey(k.Key))
                        {
                            key = HandleDuplicateContact(k.Key, k.Value);
                        }

                        if (key != null)
                        {
                            _contacts.Add(key, k.Value);
                            backgroundWorker.ReportProgress(1, key);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (Constants.IsDebugMode())
                    {
                        MessageBox.Show("Check Domain Name  " + domainName + ";" + ex.Message);
                    }

                    Utilities.Log.Create("Check Domain Name  " + domainName + ";" + ex.Message);
                }
            }

            //Outlook contact
            if (Constants.IsOutlook())
            {
                try
                {
                    bool accessEmail = false;
                    if (appConfig.GetValue("Email").Equals("yes"))
                    {
                        accessEmail = true;
                    }

                    Dictionary <string, Contact> tmp_contacts = ContactManagement.Outlook.ContactManagement.RetreiveAllContact(accessEmail);
                    foreach (var c in tmp_contacts)
                    {
                        string key = c.Key;
                        if (_contacts.ContainsKey(c.Key))
                        {
                            key = HandleDuplicateContact(c.Key, c.Value);
                        }

                        if (key != null)
                        {
                            _contacts.Add(key, c.Value);
                            backgroundWorker.ReportProgress(1, key);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (Constants.IsDebugMode())
                    {
                        MessageBox.Show("Outlook:" + ex.Message);
                    }
                    Utilities.Log.Create("Outlook:" + ex.Message);
                }
            }

            //Outlook Express
            if (Constants.IsOutlookExpress())
            {
                try
                {
                    Dictionary <string, Contact> tmp_contacts = ContactManagement.OutlookExpress.ContactManagement.RetreiveAllContact();
                    foreach (var c in tmp_contacts)
                    {
                        string key = c.Key;
                        if (_contacts.ContainsKey(c.Key))
                        {
                            key = HandleDuplicateContact(c.Key, c.Value);
                        }

                        if (key != null)
                        {
                            _contacts.Add(key, c.Value);
                            backgroundWorker.ReportProgress(1, key);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (Constants.IsDebugMode())
                    {
                        MessageBox.Show("Outlook Express;" + ex.Message);
                    }
                    Utilities.Log.Create("Outlook Express;" + ex.Message);
                }
            }
            //return _contacts;
        }