/// <summary>
        /// GetUserRegistration method implementation
        /// </summary>
        public Registration GetUserRegistration(string upn)
        {
            Registration reg = null;

            try
            {
                using (DirectoryEntry rootdir = GetDirectoryEntry())
                {
                    string qryldap = string.Empty;
                    qryldap = "(&(objectCategory=user)(objectClass=user)(userprincipalname=" + upn + ")(!(userAccountControl:1.2.840.113556.1.4.803:=2)))";

                    using (DirectorySearcher dsusr = new DirectorySearcher(rootdir, qryldap))
                    {
                        dsusr.PropertiesToLoad.Clear();
                        dsusr.PropertiesToLoad.Add("objectGUID");
                        dsusr.PropertiesToLoad.Add("userPrincipalName");
                        dsusr.PropertiesToLoad.Add("whenCreated");
                        dsusr.PropertiesToLoad.Add(_host.mailAttribute);
                        dsusr.PropertiesToLoad.Add(_host.phoneAttribute);
                        dsusr.PropertiesToLoad.Add(_host.methodAttribute);
                        dsusr.PropertiesToLoad.Add(_host.totpEnabledAttribute);

                        SearchResult sr = dsusr.FindOne();
                        if (sr != null)
                        {
                            reg = new Registration();
                            using (DirectoryEntry DirEntry = GetDirectoryEntry(sr))
                            {
                                if (DirEntry.Properties["objectGUID"].Value != null)
                                {
                                    reg.ID  = new Guid((byte[])DirEntry.Properties["objectGUID"].Value).ToString();
                                    reg.UPN = DirEntry.Properties["userPrincipalName"].Value.ToString();
                                    if (DirEntry.Properties["whenCreated"].Value != null)
                                    {
                                        reg.CreationDate = Convert.ToDateTime(DirEntry.Properties["whenCreated"].Value);
                                    }
                                    if (DirEntry.Properties[_host.mailAttribute].Value != null)
                                    {
                                        reg.MailAddress  = DirEntry.Properties[_host.mailAttribute].Value.ToString();
                                        reg.IsRegistered = true;
                                    }
                                    if (DirEntry.Properties[_host.phoneAttribute].Value != null)
                                    {
                                        reg.PhoneNumber  = DirEntry.Properties[_host.phoneAttribute].Value.ToString();
                                        reg.IsRegistered = true;
                                    }
                                    if (DirEntry.Properties[_host.methodAttribute].Value != null)
                                    {
                                        reg.PreferredMethod = (RegistrationPreferredMethod)Enum.Parse(typeof(RegistrationPreferredMethod), DirEntry.Properties[_host.methodAttribute].Value.ToString(), true);
                                        if (reg.PreferredMethod != RegistrationPreferredMethod.Choose)
                                        {
                                            reg.IsRegistered = true;
                                        }
                                    }
                                    if (DirEntry.Properties[_host.totpEnabledAttribute].Value != null)
                                    {
                                        reg.Enabled      = bool.Parse(DirEntry.Properties[_host.totpEnabledAttribute].Value.ToString());
                                        reg.IsRegistered = true;
                                    }
                                    if (reg.IsRegistered)
                                    {
                                        return(reg);
                                    }
                                    else
                                    {
                                        return(null);
                                    }
                                }
                                else
                                {
                                    return(null);
                                }
                            };
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error, 5000);
                throw new FaultException(ex.Message);
            }
            return(null);
        }
        /// <summary>
        /// SetUserRegistration method implementation
        /// </summary>
        public void SetUserRegistration(Registration reg)
        {
            try
            {
                using (DirectoryEntry rootdir = GetDirectoryEntry())
                {
                    string qryldap = "(&(objectCategory=user)(objectClass=user)(userprincipalname=" + reg.UPN + ")(!(userAccountControl:1.2.840.113556.1.4.803:=2)))";

                    using (DirectorySearcher dsusr = new DirectorySearcher(rootdir, qryldap))
                    {
                        dsusr.PropertiesToLoad.Clear();
                        dsusr.PropertiesToLoad.Add("userPrincipalName");

                        SearchResult sr = dsusr.FindOne();
                        if (sr != null)
                        {
                            bool mustcommit = false;
                            using (DirectoryEntry DirEntry = GetDirectoryEntry(sr))
                            {
                                if (!string.IsNullOrEmpty(reg.MailAddress))
                                {
                                    DirEntry.Properties[_host.mailAttribute].Value = reg.MailAddress;
                                    mustcommit = true;
                                }
                                else
                                {
                                    DirEntry.Properties[_host.mailAttribute].Clear();
                                }
                                if (!string.IsNullOrEmpty(reg.PhoneNumber))
                                {
                                    DirEntry.Properties[_host.phoneAttribute].Value = reg.PhoneNumber;
                                    mustcommit = true;
                                }
                                else
                                {
                                    DirEntry.Properties[_host.phoneAttribute].Clear();
                                }

                                if (reg.Enabled)
                                {
                                    DirEntry.Properties[_host.totpEnabledAttribute].Value = true;
                                }
                                else
                                {
                                    DirEntry.Properties[_host.totpEnabledAttribute].Value = false;
                                }
                                if (mustcommit)
                                {
                                    DirEntry.Properties[_host.methodAttribute].Value = ((int)reg.PreferredMethod).ToString();
                                }
                                DirEntry.CommitChanges();
                            };
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error, 5000);
                throw new FaultException(ex.Message);
            }
        }