Ejemplo n.º 1
0
        /// <summary>
        ///     Get Users Attributes From Phone Number
        /// </summary>
        /// <param name="phoneNumber">Business Phone Number</param>
        /// <returns>ADUserInfo Object</returns>
        public AdUserInfo GetUsersAttributesFromPhone(string phoneNumber)
        {
            var userInfo = new AdUserInfo();

            var searchFilter   = "(&(objectClass=user)(objectCategory=person)(msrtcsip-line=Tel:{0}))";
            var resourceFilter = string.Format(searchFilter, phoneNumber);

            _resourceSearcher.Filter = resourceFilter;

            try
            {
                var resourceForestResult = _resourceSearcher.FindOne();

                if (resourceForestResult != null)
                {
                    userInfo.Title       = (string)resourceForestResult.Properties["title"][0];
                    userInfo.FirstName   = (string)resourceForestResult.Properties["givenName"][0];
                    userInfo.LastName    = (string)resourceForestResult.Properties["sn"][0];
                    userInfo.DisplayName = (string)resourceForestResult.Properties["cn"][0];
                    userInfo.Telephone   = (string)resourceForestResult.Properties["msrtcsip-line"][0];
                }
                return(userInfo);
            }
            catch (Exception ex)
            {
                var argEx = new ArgumentException("Exception", "ex", ex);
                throw argEx;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Get Lync Server Pools FQDN
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public AdUserInfo SetLyncPool(AdUserInfo userInfo)
        {
            var poolFilter = string.Format(@"(distinguishedName={0})", userInfo.PrimaryHomeServerDn);

            _resourceSearcher.Filter = poolFilter;
            var resourceForestPoolResult = _resourceSearcher.FindOne();

            if ((string)resourceForestPoolResult.Properties["dnshostname"][0] != null)
            {
                userInfo.PoolName = (string)resourceForestPoolResult.Properties["dnshostname"][0];
            }

            return(userInfo);
        }
Ejemplo n.º 3
0
        public List <AdUserInfo> GetSipAccounts(string fullName)
        {
            var resourceFilter = string.Format("(&(objectClass=user)(objectCategory=person)(cn={0}))", fullName);

            _resourceSearcher.Filter = resourceFilter;

            var        listOfUsers = new List <AdUserInfo>();
            AdUserInfo userInfo;

            try
            {
                var resourceForestResult = _resourceSearcher.FindAll();

                foreach (SearchResult result in resourceForestResult)
                {
                    userInfo = new AdUserInfo();

                    if (result.Properties.Contains("mail"))
                    {
                        userInfo.EmailAddress = (string)result.Properties["mail"][0];
                    }

                    if (result.Properties.Contains("cn"))
                    {
                        userInfo.DisplayName = (string)result.Properties["cn"][0];
                    }

                    if (result.Properties.Contains("employeeid"))
                    {
                        userInfo.EmployeeId = (string)result.Properties["employeeid"][0];
                    }

                    listOfUsers.Add(userInfo);
                }

                return(listOfUsers);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Get All Users Related Attributes from Active Directory by Quering two forests
        ///     1. for Users Related Information
        ///     2. Sip Related Information
        /// </summary>
        /// <param name="mailAddress"></param>
        /// <returns></returns>
        public AdUserInfo GetUserAttributes(string mailAddress)
        {
            var userInfo = new AdUserInfo();

            var resourceFilter = string.Format(AdSearchFilter, mailAddress);

            _resourceSearcher.Filter = resourceFilter;

            try
            {
                var resourceForestResult = _resourceSearcher.FindOne();

                if (resourceForestResult != null)
                {
                    if (resourceForestResult.Properties.Contains("title"))
                    {
                        userInfo.Title = (string)resourceForestResult.Properties["title"][0];
                    }

                    if (resourceForestResult.Properties.Contains("givenName"))
                    {
                        userInfo.FirstName = (string)resourceForestResult.Properties["givenName"][0];
                    }

                    if (resourceForestResult.Properties.Contains("sn"))
                    {
                        userInfo.LastName = (string)resourceForestResult.Properties["sn"][0];
                    }

                    if (resourceForestResult.Properties.Contains("cn"))
                    {
                        userInfo.DisplayName = (string)resourceForestResult.Properties["cn"][0];
                    }

                    if (resourceForestResult.Properties.Contains("samaccountname"))
                    {
                        userInfo.SamAccountName = (string)resourceForestResult.Properties["samaccountname"][0];
                    }

                    if (resourceForestResult.Properties.Contains("department"))
                    {
                        userInfo.department = (string)resourceForestResult.Properties["department"][0];
                    }

                    if (resourceForestResult.Properties.Contains("mail"))
                    {
                        userInfo.EmailAddress = (string)resourceForestResult.Properties["mail"][0];
                    }

                    if (resourceForestResult.Properties.Contains("employeeid"))
                    {
                        userInfo.EmployeeId = (string)resourceForestResult.Properties["employeeid"][0];
                    }

                    if (resourceForestResult.Properties.Contains("telephonenumber"))
                    {
                        userInfo.BusinessPhone = (string)resourceForestResult.Properties["telephonenumber"][0];
                    }

                    if (resourceForestResult.Properties.Contains("physicalDeliveryOfficeName"))
                    {
                        userInfo.PhysicalDeliveryOfficeName =
                            (string)resourceForestResult.Properties["physicalDeliveryOfficeName"][0];
                    }

                    if (resourceForestResult.Properties.Contains("msrtcsip-primaryuseraddress"))
                    {
                        userInfo.SipAccount = (string)resourceForestResult.Properties["msrtcsip-primaryuseraddress"][0];
                    }

                    if (resourceForestResult.Properties.Contains("msrtcsip-line"))
                    {
                        userInfo.Telephone = (string)resourceForestResult.Properties["msrtcsip-line"][0];
                    }

                    if (resourceForestResult.Properties.Contains("msrtcsip-primaryhomeserver"))
                    {
                        userInfo.PrimaryHomeServerDn =
                            ((string)resourceForestResult.Properties["msrtcsip-primaryhomeserver"][0]).Replace(
                                "CN=Lc Services,CN=Microsoft,", "");
                    }

                    //AUTHENTICATION
                    if (resourceForestResult.Properties.Contains("extensionAttribute3"))
                    {
                        userInfo.Upn = (string)resourceForestResult.Properties["extensionAttribute3"][0];
                    }
                    else if (resourceForestResult.Properties.Contains("userprincipalname"))
                    {
                        userInfo.Upn = (string)resourceForestResult.Properties["userprincipalname"][0];
                    }

                    //Get the IP Dialing Code and extensionfor projects
                    if (resourceForestResult.Properties.Contains("extensionAttribute1") &&
                        resourceForestResult.Properties.Contains("extensionAttribute2"))
                    {
                        userInfo.OtherTelphone = (string)resourceForestResult.Properties["extensionAttribute2"][0] +
                                                 resourceForestResult.Properties["extensionAttribute1"][0];
                    }

                    return(userInfo);
                }
                return(null);
            }
            catch (Exception ex)
            {
                var argEx = new ArgumentException("Exception", "ex", ex);
                throw argEx;
            }
        }