Пример #1
0
        public GxSimpleCollection <string> GetAttribute(string name, string context, GXProperties atts)
        {
            if (_entry != null)
            {
                _entry.Close();
                _entry = null;
            }
            string context1;

            if (context.Trim().Length == 0)
            {
                context1 = "";
            }
            else
            {
                context1 = "/" + context;
            }
            AuthenticationTypes at = getAuthentication();

            _entry = new DirectoryEntry("LDAP://" + getPath() + context1, _user, _password, at);
            string filter = "";

            if (atts.Count == 0)
            {
                filter = "(" + name + "=*)";
            }
            else
            {
                for (int i = 0; i < atts.Count; i++)
                {
                    filter += "(" + atts.GetKey(i).Trim() + "=" + atts[i].Trim() + ")";
                }
                if (atts.Count > 1)
                {
                    filter = "(&" + filter + ")";
                }
            }
            DirectorySearcher           ds = new DirectorySearcher(_entry, filter, new string[] { name });
            GxSimpleCollection <string> sc = new GxSimpleCollection <string>();

            try
            {
                foreach (System.DirectoryServices.SearchResult result in ds.FindAll())
                {
                    PropertyValueCollection values = (PropertyValueCollection)(result.GetDirectoryEntry().Properties[name]);
                    StringBuilder           sb     = new StringBuilder();
                    for (int i = 0; i < values.Count; i++)
                    {
                        sb.Append(values[i].ToString() + " ");
                    }
                    sc.Add(sb.ToString());
                }
            }
            catch (Exception ex)
            {
                GXLogging.Error(log, "GetAttribute Method Error.", ex);
            }
            return(sc);
        }
Пример #2
0
        public Message GetBaseMessage(MessagePropertyFilter mpf)
        {
            int           i  = 0;
            StringBuilder sb = new StringBuilder();

            if (properties.Count > 0)
            {
                bool hasUserProps = false;
                sb.Append("[GxPtys:]");
                for (i = 0; i < properties.Count; i++)
                {
                    if (!canAddMSMQPropertiesToGet(mpf, properties.GetKey(i), properties.Get(properties.GetKey(i))))
                    {
                        sb.Append(properties.GetKey(i) + "=" + properties.Get(properties.GetKey(i)) + ";");
                        hasUserProps = true;
                    }
                }
                if (hasUserProps)
                {
                    message.Body = Text + sb.ToString();
                }
            }
            return(message);
        }
Пример #3
0
        public GxSimpleCollection <string> GetAttribute(string name, string context, GXProperties atts)
        {
            string filter = "";

            if (atts.Count == 0)
            {
                filter = "(" + name + "=*)";
            }
            else
            {
                for (int i = 0; i < atts.Count; i++)
                {
                    filter += "(" + atts.GetKey(i).Trim() + "=" + atts[i].Trim() + ")";
                }
                if (atts.Count > 1)
                {
                    filter = "(&" + filter + ")";
                }
            }
            GxSimpleCollection <string> sc = new GxSimpleCollection <string>();

            try
            {
#if NETCORE
                if (!GXUtil.IsWindowsPlatform)
                {
                    NovellConnect();

                    string             searchBase   = context;
                    int                searchScope  = LdapConnection.ScopeSub;
                    string             searchFilter = filter;
                    ILdapSearchResults lsc          = _conn.Search(searchBase, searchScope, searchFilter, new string[] { name }, false);

                    while (lsc.HasMore())
                    {
                        LdapEntry nextEntry = null;
                        try
                        {
                            nextEntry = lsc.Next();
                        }
                        catch (LdapException)
                        {
                            continue;
                        }
                        LdapAttributeSet attributeSet = nextEntry.GetAttributeSet();
                        IEnumerator      ienum        = attributeSet.GetEnumerator();
                        StringBuilder    sb           = new StringBuilder();
                        while (ienum.MoveNext())
                        {
                            LdapAttribute attribute    = (LdapAttribute)ienum.Current;
                            string        attributeVal = attribute.StringValue;
                            sb.Append(attributeVal + " ");
                        }
                        sc.Add(sb.ToString() + " ");
                    }
                }
                else
#endif
                {
                    if (_entry != null)
                    {
                        _entry.Close();
                        _entry = null;
                    }
                    string context1;
                    if (context.Trim().Length == 0)
                    {
                        context1 = "";
                    }
                    else
                    {
                        context1 = "/" + context;
                    }
                    AuthenticationTypes at = getAuthentication();
                    _entry = new DirectoryEntry("LDAP://" + getPath() + context1, _user, _password, at);
                    DirectorySearcher ds = new DirectorySearcher(_entry, filter, new string[] { name });
                    foreach (SearchResult result in ds.FindAll())
                    {
                        PropertyValueCollection values = (PropertyValueCollection)(result.GetDirectoryEntry().Properties[name]);
                        StringBuilder           sb     = new StringBuilder();
                        for (int i = 0; i < values.Count; i++)
                        {
                            sb.Append(values[i].ToString() + " ");
                        }
                        sc.Add(sb.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                GXLogging.Error(log, "GetAttribute Method Error.", ex);
            }
            return(sc);
        }