コード例 #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;

                CommonLibrary.AppConfig appConfig = new CommonLibrary.AppConfig(Constants.GetConfigFilePath());
                contactManagement = new CommonLibrary.ActiveDirectory.ContactManagement("LDAP://" + appConfig.GetValue("DomainName"));
                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 Dictionary <string, Contact> SearchAll()
        {
            CommonLibrary.AppConfig appConfig = new CommonLibrary.AppConfig(Constants.CONGIF_FILE);

            //Outlook contact
            if (appConfig.GetValue("Outlook").Equals("yes"))
            {
                try
                {
                    _contacts = CommonLibrary.OutlookContact.ContactManagement.RetreiveAllContact();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Outlook not available " + ex.Message);
                }
            }


            if (appConfig.GetValue("ActiveDirectory").Equals("yes"))
            {
                //Active Directory Contact
                string domainName = appConfig.GetValue("DomainName");
                try
                {
                    CommonLibrary.ActiveDirectory.ContactManagement contactManagement = new CommonLibrary.ActiveDirectory.ContactManagement(domainName);
                    Dictionary <string, Contact> activeDirectoryContacts = contactManagement.RetrieveAllContact("(objectCategory=person)");

                    foreach (var k in activeDirectoryContacts)
                    {
                        if (_contacts.ContainsKey(k.Key))
                        {
                            _contacts.Add(k.Key + " (AD)", k.Value);
                        }
                        else
                        {
                            _contacts.Add(k.Key, k.Value);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Wrong Domain Name  " + domainName);
                }
            }

            return(_contacts);
        }
コード例 #3
0
ファイル: Searcher.cs プロジェクト: anhvaut/phone-directory
        /// <summary>
        /// Search all the contacts
        /// </summary>
        public void SearchAll()
        {
            CommonLibrary.AppConfig appConfig = new CommonLibrary.AppConfig(CommonLibrary.Constants.GetConfigFilePath());


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

                string domainName = CommonLibrary.Constants.GetADDomain();


                try
                {
                    CommonLibrary.ActiveDirectory.ContactManagement contactManagement = new CommonLibrary.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 (CommonLibrary.Constants.IsDebugMode())
                    {
                        MessageBox.Show("Check Domain Name  " + domainName + ";" + ex.Message);
                    }

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

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

                    Dictionary <string, Contact> tmp_contacts = CommonLibrary.OutlookContact.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 (CommonLibrary.Constants.IsDebugMode())
                    {
                        MessageBox.Show("Outlook:" + ex.Message);
                    }
                    CommonLibrary.Utilities.Log.Create("Outlook:" + ex.Message);
                }
            }

            //Outlook Express
            if (CommonLibrary.Constants.IsOutlookExpress())
            {
                try
                {
                    Dictionary <string, Contact> tmp_contacts = CommonLibrary.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 (CommonLibrary.Constants.IsDebugMode())
                    {
                        MessageBox.Show("Outlook Express;" + ex.Message);
                    }
                    CommonLibrary.Utilities.Log.Create("Outlook Express;" + ex.Message);
                }
            }
            //return _contacts;
        }