private static void add(ref AppointmentItem ai, MetadataId key, OlUserPropertyType keyType, object keyValue)
        {
            String addkeyName = metadataIdKeyName(key);

            UserProperties ups = null;

            try {
                if (!Exists(ai, key))
                {
                    int newSet;
                    int?keySet = getKeySet(ai, out newSet);
                    keySet = keySet ?? newSet + 1;
                    if (keySet.HasValue && keySet.Value != 0)
                    {
                        addkeyName += "-" + keySet.Value.ToString("D2");
                    }

                    try {
                        ups = ai.UserProperties;
                        ups.Add(addkeyName, keyType);
                    } catch (System.Exception ex) {
                        OGCSexception.Analyse(ex);
                        ups.Add(addkeyName, keyType, false);
                    } finally {
                        ups = (UserProperties)Calendar.ReleaseObject(ups);
                    }
                }
                ups = ai.UserProperties;
                ups[addkeyName].Value = keyValue;
                log.Fine("Set userproperty " + addkeyName + "=" + keyValue.ToString());
            } finally {
                ups = (UserProperties)Calendar.ReleaseObject(ups);
            }
        }
예제 #2
0
        private static void add(ref AppointmentItem ai, MetadataId key, OlUserPropertyType keyType, object keyValue)
        {
            String addkeyName = metadataIdKeyName(key);

            UserProperties ups = null;

            try {
                int    maxSet;
                int?   keySet         = null;
                String currentKeyName = null;
                if (!Exists(ai, key, out currentKeyName))
                {
                    keySet = getKeySet(ai, out maxSet);
                    if (key == MetadataId.gCalendarId && (keySet ?? 0) == 0)  //Couldn't find key set for calendar
                    {
                        keySet = maxSet + 1;                                  //So start a new one
                    }
                    else if (key != MetadataId.gCalendarId && keySet == null) //Couldn't find non-calendar key in the current set
                    {
                        keySet = 0;                                           //Add them in to the default key set
                    }
                    if (keySet.HasValue && keySet.Value != 0)
                    {
                        addkeyName += "-" + keySet.Value.ToString("D2");
                    }

                    try {
                        ups = ai.UserProperties;
                        ups.Add(addkeyName, keyType);
                    } catch (System.Exception ex) {
                        OGCSexception.Analyse(ex);
                        ups.Add(addkeyName, keyType, false);
                    } finally {
                        ups = (UserProperties)Calendar.ReleaseObject(ups);
                    }
                }
                else
                {
                    addkeyName = currentKeyName; //Might be suffixed with "-01"
                }
                ups = ai.UserProperties;
                ups[addkeyName].Value = keyValue;
                OutlookOgcs.Calendar.Instance.EphemeralProperties.Add(ai, new EphemeralProperty(EphemeralProperty.PropertyName.KeySet, keySet));
                OutlookOgcs.Calendar.Instance.EphemeralProperties.Add(ai, new EphemeralProperty(EphemeralProperty.PropertyName.MaxSet, keySet));
                log.Fine("Set userproperty " + addkeyName + "=" + keyValue.ToString());
            } finally {
                ups = (UserProperties)Calendar.ReleaseObject(ups);
            }
        }
        private void MapHeaders(CloudEvent cloudEvent)
        {
            var ignoreKeys = new List <string>(3)
            {
                CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion),
                CloudEventAttributes.IdAttributeName(cloudEvent.SpecVersion),
                CloudEventAttributes.DataContentTypeAttributeName(cloudEvent.SpecVersion),
            };

            foreach (var attribute in cloudEvent.GetAttributes())
            {
                if (!ignoreKeys.Contains(attribute.Key))
                {
                    var key = Constants.PropertyKeyPrefix + attribute.Key;
                    switch (attribute.Value)
                    {
                    case Uri uri:
                        UserProperties.Add(key, uri.ToString());
                        break;

                    default:
                        UserProperties.Add(key, attribute.Value);
                        break;
                    }
                }
            }
        }
예제 #4
0
        public static void AddUserProperty(MailItem mailitem, string ticketid)
        {
            UserProperties mailUserProperties = null;
            UserProperty   mailUserProperty   = null;

            try
            {
                mailUserProperties = mailitem.UserProperties;
                mailUserProperty   = mailUserProperties.Add("KayakoTicketId", OlUserPropertyType.olText, true, 1);
                // Where 1 is OlFormatText (introduced in Outlook 2007)
                mailUserProperty.Value = ticketid;
                mailitem.Save();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (mailUserProperty != null)
                {
                    Marshal.ReleaseComObject(mailUserProperty);
                }
                if (mailUserProperties != null)
                {
                    Marshal.ReleaseComObject(mailUserProperties);
                }
            }
        }
        private void addOutlookCustomProperty(ref AppointmentItem copiedAi, String addKeyName, OlUserPropertyType keyType, object keyValue)
        {
            UserProperties ups = null;

            try {
                ups = copiedAi.UserProperties;
                if (ups[addKeyName] == null)
                {
                    try {
                        ups.Add(addKeyName, keyType);
                    } catch (System.Exception ex) {
                        OGCSexception.Analyse(ex);
                        ups.Add(addKeyName, keyType, false);
                    }
                }
                ups[addKeyName].Value = keyValue;
            } catch (System.Exception) {
                log.Warn("Failed to add " + addKeyName);
                throw;
            } finally {
                ups = (UserProperties)Calendar.ReleaseObject(ups);
            }
        }
예제 #6
0
        private static UserProperties GetUserProperties(DirectoryEntry user)
        {
            var props = new UserProperties(propNamesDestination.Count, StringComparer.OrdinalIgnoreCase);

            foreach (var p in propNamesDestination)
            {
                var prop    = user.Properties[p];
                var strings = ConvertToStrings(prop);
                if (strings != null)
                {
                    props.Add(p, strings);
                }
            }
            return(props);
        }
예제 #7
0
        public int Add(PlotCollectionSet set, bool bUniqueOnly = false, bool bCopyUserProperties = true)
        {
            if (!bUniqueOnly)
            {
                if (set.m_rgSet.Count == 0)
                {
                    return(0);
                }

                m_rgSet.AddRange(set.m_rgSet);
                return(set.m_rgSet[0].Count);
            }

            int nCount = (m_rgSet.Count == 0) ? 0 : m_rgSet[0].Count;

            foreach (PlotCollection plots in set)
            {
                if (!m_rgSet.Contains(plots))
                {
                    m_rgSet.Add(plots);
                }
            }

            int nNewCount = m_rgSet[0].Count;

            if (bCopyUserProperties)
            {
                List <KeyValuePair <string, string> > rg = set.UserProperties.ToList();

                foreach (KeyValuePair <string, string> kv in rg)
                {
                    if (!UserProperties.ContainsKey(kv.Key))
                    {
                        UserProperties.Add(kv.Key, kv.Value);
                    }
                    else
                    {
                        UserProperties[kv.Key] = kv.Value;
                    }
                }
            }

            return(nNewCount - nCount);
        }
        /// <summary>
        /// Sets the user property value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="userProperties">The user properties collection to set user property for.</param>
        /// <param name="name">The name of the user property to set.</param>
        /// <param name="type">The type of the user property.</param>
        /// <param name="value">The value to set.</param>
        /// <param name="addToFolder">if set to <c>true</c> add to containing folder. Enables search/display column for user property.</param>
        public static void SetPropertyValue <T>(this UserProperties userProperties, string name, OlUserPropertyType type, T value, bool addToFolder)
        {
            using (var property = userProperties.Find(name, true).WithComCleanup())
            {
                var format = type == OlUserPropertyType.olInteger ? OlFormatNumber.olFormatNumberAllDigits : Type.Missing;

                if (property.Resource == null)
                {
                    using (var newProperty = userProperties.Add(name, type, addToFolder, format).WithComCleanup())
                    {
                        newProperty.Resource.Value = value;
                    }
                }
                else
                {
                    property.Resource.Value = value;
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Sets the property.
        /// </summary>
        /// <param name="properties">The properties.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns>True if Changed.</returns>
        public static bool SetProperty(this UserProperties properties, string key, string value)
        {
            var property = properties.Find(key, true);

            if (property == null)
            {
                properties.Add(key, OlUserPropertyType.olText, false, System.Type.Missing);
                properties.Find(key, true).Value = value;
                return(true);
            }

            if (property.Value != value)
            {
                property.Value = value;
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Gets the user property value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="userProperties">The user properties.</param>
        /// <param name="name">The name of the user property.</param>
        /// <param name="type">The type of the user property.</param>
        /// <param name="create">if set to <c>false</c> the property will not be created if it doesn't exist.</param>
        /// <param name="converter">The converter to use to convert the object to.</param>
        /// <param name="defaultValue">The default value to use if user property not found.</param>
        /// <returns>User property vlaue or default</returns>
        public static T GetPropertyValue <T>(this UserProperties userProperties, string name, OlUserPropertyType type, bool create, Func <object, T> converter, T defaultValue)
        {
            using (var property = userProperties.Find(name, true).WithComCleanup())
            {
                var format = type == OlUserPropertyType.olInteger ? OlFormatNumber.olFormatNumberAllDigits : Type.Missing;

                if (property.Resource == null && create)
                {
                    userProperties.Add(name, type, false, format).ReleaseComObject();
                }

                if (property.Resource == null)
                {
                    return(defaultValue);
                }

                var value = property.Resource.Value;
                return(converter(value));
            }
        }
        private void btnSelect_Click(object sender, EventArgs e)
        {
            string brName          = string.Empty;
            string partyId         = string.Empty;
            string contactPersonId = string.Empty;
            string contactName     = string.Empty;
            string contactPhone    = string.Empty;
            string contactEmail    = string.Empty;

            if (dataGridView1.SelectedRows.Count > 0)
            {
                DataGridViewRow row = (DataGridViewRow)dataGridView1.SelectedRows[0];
                brName  = Convert.ToString(row.Cells["NAME"].Value);
                partyId = Convert.ToString(row.Cells["PARTYID"].Value);
            }

            if (gridViewContacts.SelectedRows.Count > 0)
            {
                DataGridViewRow row = (DataGridViewRow)gridViewContacts.SelectedRows[0];
                contactPersonId = Convert.ToString(row.Cells[3].Value);
                contactName     = Convert.ToString(row.Cells[0].Value);
                contactPhone    = Convert.ToString(row.Cells[1].Value);
                contactEmail    = Convert.ToString(row.Cells[2].Value);
            }

            string sdValue = Convert.ToString(ddlSalesDistrict.SelectedValue);
            string sdText  = ddlSalesDistrict.Text;

            /*item.Body += System.Environment.NewLine;
            *  item.Body += String.Format("## WebCRM ==> ## ");
            *  item.Body += String.Format("Business Relation Name: {0}; ", brName);
            *  item.Body += String.Format("Identifier: {0}; ", partyId);
            *  item.Body += String.Format("Contact: {0}; ", contactPersonId);
            *  item.Body += String.Format("## <== WebCRM ##");
            *  item.Body += System.Environment.NewLine;*/

            UserProperties ups  = item.UserProperties;
            UserProperty   prop = ups.Add("PartyId", OlUserPropertyType.olText, false, null);

            prop.Value = partyId;
            prop       = ups.Add("ContactPersonId", OlUserPropertyType.olText, false, null);
            prop.Value = contactPersonId;

            //------------------------------------------------------
            string bodyText = item.Body;

            if (bodyText == null)
            {
                bodyText = String.Empty;
            }

            //String custDataBegin = "##<--Customer Data--##";
            String custDataBegin = "## CRM Data ==> ##";
            //String custDataEnd = "##--Customer Data-->##";
            String custDataEnd = "## <== CRM Data ##";
            int    cdStartPos  = bodyText.IndexOf(custDataBegin);
            int    cdEndPos    = bodyText.IndexOf(custDataEnd, cdStartPos == -1 ? 0 : cdStartPos);

            if (cdStartPos != -1 && cdEndPos != -1)
            {
                cdEndPos += custDataEnd.Length;
                bodyText  = bodyText.Remove(cdStartPos, cdEndPos - cdStartPos);
            }
            if (cdStartPos == -1)
            {
                cdStartPos = bodyText.Length;
            }
            String custDataTxt = String.Empty;

            String custDataInfo = String.Empty;

            custDataInfo += String.Format("Customer name: {0}", brName) + Environment.NewLine;
            custDataInfo += String.Format("Identifier: {0}", partyId) + Environment.NewLine;
            custDataInfo += String.Format("Customer ABC: {0}", "-") + Environment.NewLine;
            custDataInfo += String.Format("Sales Rep: {0}", String.Format("{0} ({1})", sdText, sdValue)) + Environment.NewLine;
            custDataInfo += String.Format("Mode of delivery: {0}", "-") + Environment.NewLine;
            custDataInfo += String.Format("Search name: {0}", "-") + Environment.NewLine;
            custDataInfo += String.Format("Contact ID: {0}", contactPersonId) + Environment.NewLine;
            custDataInfo += String.Format("Contact name: {0}", contactName) + Environment.NewLine;
            custDataInfo += String.Format("Contact phone : {0}", contactPhone) + Environment.NewLine;
            custDataInfo += String.Format("Contact email : {0}", contactEmail);

            custDataTxt  = Environment.NewLine;
            custDataTxt += custDataBegin + Environment.NewLine;
            custDataTxt += custDataInfo + Environment.NewLine;
            custDataTxt += custDataEnd;

            bodyText  = bodyText.Insert(cdStartPos, custDataTxt);
            item.Body = bodyText;
            //------------------------------------------------------

            this.Close();
        }
예제 #12
0
        /// <summary>
        /// Sets up properties by given XML file.
        /// </summary>
        /// <param name="fileName">Path to import profile XML</param>
        public static string InitializeImportProfile(string fileName)
        {
            // Reset error
            validationError = null;
            try
            {
                // Set profile path
                ImportProfileFilename = fileName;
                if (File.Exists(ImportProfileFilename))
                {
                    using (var schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                               GetManifestResourceName(typeof(ImportProfile), PROFILE_XSD)))
                    {
                        // Set profile path
                        ImportProfileFilename = fileName;

                        // Load XML with import profile
                        XmlDocument profile = new XmlDocument();

                        // Load XML schema
                        XmlSchema xmlSchema = XmlSchema.Read(schemaStream, xmlReaderSettings_ValidationEventHandler);

                        // Initialize reader settings
                        XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
                        xmlReaderSettings.ValidationType          = ValidationType.Schema;
                        xmlReaderSettings.ValidationEventHandler += xmlReaderSettings_ValidationEventHandler;
                        xmlReaderSettings.Schemas.Add(xmlSchema);

                        // Load and validate profile
                        using (XmlReader reader = XmlReader.Create(fileName, xmlReaderSettings))
                        {
                            profile.Load(reader);
                        }

                        if (String.IsNullOrEmpty(validationError))
                        {
                            // Get settings node
                            XmlNodeList settings = profile.GetElementsByTagName("setting");
                            foreach (XmlNode setting in settings)
                            {
                                if (setting.Attributes != null)
                                {
                                    object value = setting.Attributes["value"].Value;
                                    switch (setting.Attributes["key"].Value)
                                    {
                                    case "SQLServerAddress":
                                        SQLServerAddress = ValidationHelper.GetString(value.ToString(), string.Empty);
                                        break;

                                    case "SQLServerDatabase":
                                        SQLServerDatabase = ValidationHelper.GetString(value.ToString(), string.Empty);
                                        break;

                                    case "SQLServerUsername":
                                        SQLServerUsername = ValidationHelper.GetString(value.ToString(), string.Empty);
                                        break;

                                    case "SQLServerPassword":
                                        string sqlPassword = ValidationHelper.GetString(value.ToString(), string.Empty);
                                        try
                                        {
                                            // Try to decrypt password
                                            SQLServerPassword = DecryptPassword(sqlPassword);
                                        }
                                        catch
                                        {
                                            // Password is probably in plaintext form
                                            SQLServerPassword = sqlPassword;
                                        }

                                        break;

                                    case "SQLUseTrustedConnection":
                                        SQLUseTrustedConnection = ValidationHelper.GetBoolean(value.ToString(), true);
                                        break;

                                    case "ADControllerAddress":
                                        ADControllerAddress = ValidationHelper.GetString(value.ToString(), string.Empty);
                                        break;

                                    case "ADUseCurrentUserAccount":
                                        ADUseCurrentUserAccount = ValidationHelper.GetBoolean(value.ToString(), true);
                                        break;

                                    case "ADUsername":
                                        ADUsername = ValidationHelper.GetString(value.ToString(), string.Empty);
                                        break;

                                    case "ADPassword":
                                        string adPassword = ValidationHelper.GetString(value.ToString(), string.Empty);
                                        try
                                        {
                                            // Try to decrypt password
                                            ADPassword = DecryptPassword(adPassword);
                                        }
                                        catch
                                        {
                                            // Password is probably in plaintext form
                                            ADPassword = adPassword;
                                        }
                                        break;

                                    case "ImportUsersType":
                                        ImportUsersType = (ImportType)Enum.Parse(typeof(ImportType), value.ToString());

                                        break;

                                    case "ImportRolesType":
                                        ImportRolesType = (ImportType)Enum.Parse(typeof(ImportType), value.ToString());

                                        break;

                                    case "UpdateObjectData":
                                        UpdateObjectData = ValidationHelper.GetBoolean(value.ToString(), true);
                                        break;

                                    case "ImportOnlyUsersFromSelectedRoles":
                                        ImportNewUsersOnlyFromSelectedRoles = ValidationHelper.GetBoolean(value.ToString(), false);
                                        break;

                                    case "ImportAllUsersFromSelectedRolesAndIgnoreOthers":
                                        ImportUsersOnlyFromSelectedRoles = ValidationHelper.GetBoolean(value.ToString(), false);
                                        break;

                                    case "UpdateMemberships":
                                        UpdateMemberships = ValidationHelper.GetBoolean(value.ToString(), true);
                                        break;

                                    case "DeleteNotExistingObjects":
                                        DeleteNotExistingObjects = ValidationHelper.GetBoolean(value.ToString(), true);
                                        break;

                                    case "LogImportProcess":
                                        LogImportProcess = ValidationHelper.GetBoolean(value.ToString(), true);
                                        break;

                                    case "LogPath":
                                        LogPath = ValidationHelper.GetString(value.ToString(), string.Empty);
                                        break;

                                    case "UsernameFormat":
                                        UsernameFormat = (CodenameFormat)Enum.Parse(typeof(CodenameFormat), value.ToString());
                                        break;

                                    case "ConfigureAsCMSEditor":
                                        ConfigureAsCMSEditor = ValidationHelper.GetBoolean(value.ToString(), true);
                                        break;

                                    case "BindingEditorMode":
                                        BindingEditorMode = (BindingEditorMode)Enum.Parse(typeof(BindingEditorMode), value.ToString());
                                        break;

                                    case "RoleDisplayNameFormat":
                                        RoleDisplayNameFormat = (CodenameFormat)Enum.Parse(typeof(CodenameFormat), value.ToString());
                                        break;

                                    case "RoleCodeNameFormat":
                                        RoleCodeNameFormat = (CodenameFormat)Enum.Parse(typeof(CodenameFormat), value.ToString());
                                        break;

                                    case "ImportRoleDescription":
                                        ImportRoleDescription = ValidationHelper.GetBoolean(value.ToString(), true);
                                        break;

                                    case "ImportNow":
                                        ImportNow = ValidationHelper.GetBoolean(value.ToString(), true);
                                        break;
                                    }
                                }
                            }

                            // Get user properties bindings
                            XmlNodeList properties = profile.GetElementsByTagName("property");
                            UserProperties.Clear();
                            foreach (XmlNode property in properties)
                            {
                                if ((property.Attributes != null) && ((property.Attributes["cmsname"] != null) && (property.Attributes["adname"] != null)))
                                {
                                    string cmsPropertyName = property.Attributes["cmsname"].Value;
                                    string adPropertyName  = property.Attributes["adname"].Value;
                                    UserProperties.Add(cmsPropertyName, adPropertyName);
                                }
                            }

                            // Get users to import
                            XmlNodeList users = profile.GetElementsByTagName("user");
                            Users.Clear();
                            foreach (XmlNode user in users)
                            {
                                if ((user.Attributes) != null && (user.Attributes["guid"] != null))
                                {
                                    Guid userGuid = ValidationHelper.GetGuid(user.Attributes["guid"].Value, Guid.Empty);
                                    Users.Add(userGuid);
                                }
                            }

                            // Get groups to import
                            XmlNodeList groups = profile.GetElementsByTagName("group");
                            Groups.Clear();
                            foreach (XmlNode group in groups)
                            {
                                if ((group.Attributes) != null && (group.Attributes["guid"] != null))
                                {
                                    Guid groupGuid = ValidationHelper.GetGuid(group.Attributes["guid"].Value, Guid.Empty);
                                    Groups.Add(groupGuid);
                                }
                            }

                            // Get sites & roles
                            XmlNodeList sites = profile.GetElementsByTagName("site");
                            Sites.Clear();
                            foreach (XmlNode site in sites)
                            {
                                if ((site.Attributes != null) && (site.Attributes["codename"] != null))
                                {
                                    string      siteCodeName = site.Attributes["codename"].Value;
                                    List <Guid> roles        = new List <Guid>();
                                    foreach (XmlNode role in site.ChildNodes)
                                    {
                                        if (role.Attributes != null)
                                        {
                                            if (role.Attributes["guid"] != null)
                                            {
                                                XmlAttribute roleGuidAttr = role.Attributes["guid"];

                                                // Get guid of CMS role
                                                Guid roleGuid = Guid.Empty;
                                                if (roleGuidAttr != null)
                                                {
                                                    roleGuid = ValidationHelper.GetGuid(roleGuidAttr.Value, Guid.Empty);
                                                }
                                                roles.Add(roleGuid);
                                            }
                                        }
                                    }
                                    Sites.Add(siteCodeName.ToLowerCSafe(), roles);
                                }
                            }
                        }
                    }
                }
                else
                {
                    return(ResHelper.GetString("Error_ProfileDoesNotExist", ImportProfileFilename));
                }
            }
            catch (System.IO.IOException ex)
            {
                return(ex.Message);
            }
            catch (UnauthorizedAccessException ex)
            {
                return(ex.Message);
            }
            catch (Exception ex)
            {
                // Log detailed information when unexpected exception occurs
                return(LogHelper.GetExceptionLogMessage(ex));
            }

            return(validationError);
        }
예제 #13
0
        private void LoadUsersByFilter(ADServer server, DirectoryEntry rootDSE, string filter)
        {
            using (DirectorySearcher ds = new DirectorySearcher(rootDSE))
            {
                // if '>=' then we get last update twice
                // Note that the operators "<" and ">" are not supported. See "LDAP syntax filter clause"
                ds.Filter    = filter;
                ds.SizeLimit = 0; // unlimited
                ds.PageSize  = 1000;
                IList <string> propsToLoad = server.SourceDest.StartsWith("source", StringComparison.OrdinalIgnoreCase) ? propNamesSource : propNamesDestination;

                foreach (var p in propsToLoad)
                {
                    ds.PropertiesToLoad.Add(p);
                }

                using (SearchResultCollection results = ds.FindAll())
                {
                    var cnt = results.Count;
                    if (results != null && cnt > 0)
                    {
                        log.LogInfo("Reading " + cnt + " account(s) from " + server.ToString() + ". Current USN='" + CurrentHighUSN + "'. InvocationID='" + GetInvocationID + "'");
                        foreach (SearchResult user in results)
                        {
#if DEBUG
                            //foreach (var p in user.Properties)
                            //{
                            //    var prop = (ResultPropertyValueCollection)((System.Collections.DictionaryEntry)p).Value;
                            //    var propVal = (prop.Count > 0) ? Convert.ToString(prop[0]) : null;
                            //    Console.WriteLine(((System.Collections.DictionaryEntry)p).Key + "=" + propVal);
                            //}
#endif
                            //var user = r.GetDirectoryEntry();
                            var objectSID = user.Properties.Contains("objectSID") ? (new SecurityIdentifier(((byte[])user.Properties["objectSID"][0]), 0)).ToString() : string.Empty;
                            var dnProp    = user.Properties["distinguishedName"];
                            var dn        = (dnProp.Count > 0) ? Convert.ToString(dnProp[0]) : null;

                            // simbols '{}' are special for Format. So replace them in DN.
                            if (cnt <= 20)
                            {
                                log.LogInfo(" Read samAccountName='" + user.Properties["samAccountName"][0] + "', objectSID='" + objectSID + "', DN='" + dn.Replace('{', '(').Replace('}', ')') + "'");
                            }
                            UserProperties props = new UserProperties(propsToLoad.Count, StringComparer.OrdinalIgnoreCase);

                            //var groups = GetGroups(domainCtx, (string)user.Properties["samAccountName"][0]);

                            foreach (var p in propsToLoad)
                            {
                                var prop = user.Properties[p];
                                if ("objectSID".Equals(p, StringComparison.OrdinalIgnoreCase))
                                {
                                    props.Add(p, new string[] { objectSID });
                                }
                                else if (prop.Count > 0)// multi-value support  ("memberof".Equals(p, StringComparison.OrdinalIgnoreCase))
                                {
                                    var stringColl = ConvertToStrings(prop);
                                    props.Add(p, stringColl);
                                }
                                else
                                {
                                    props.Add(p, null); // property is set to null in AD
                                }
                            }

                            usersProperties.Add(props);
                        }
                    }
                }
            }
        }