Ejemplo n.º 1
0
        public async Task <List <T> > CustomSearch <T>(ILdapConnection conn, string filter, IEnumerable <int> employeeIds = null, string path = "")
        {
            return(await Task.Run(() =>
            {
                var searchPath = string.Empty;
                if (string.IsNullOrEmpty(path))
                {
                    searchPath = _config.Path;
                }
                else
                {
                    searchPath = path;
                }

                var attrs = LdapHelper.GetLdapAttributes <T>().ToArray();
                var search = conn.Search(searchPath, LdapConnection.ScopeSub, filter, attrs, false);

                return LdapHelper.ConvertLdapResult <T>(_logger, search, employeeIds, (propName, attr) =>
                {
                    if (propName == "Photo")
                    {
                        byte[] picData = (byte[])(Array)attr.ByteValue;
                        return Convert.ToBase64String(picData);
                    }
                    else
                    {
                        if (attr.StringValueArray.Length > 1)
                        {
                            return attr.StringValueArray.ToList();
                        }
                        else
                        {
                            return attr.StringValue;
                        }
                    }
                });
            }));
        }