示例#1
0
        private static bool TryGetAdsPathWithServer(string path, out AdsPath adsPath)
        {
            try
            {
                var uri = new Uri(path);

                var provider   = Enumeration.FromName <AdsProvider>(uri.Scheme.ToUpperInvariant());
                var server     = uri.Host;
                var objectName = DN.Parse(uri.LocalPath.Substring(1));
                adsPath = new AdsPath(provider, server, objectName);

                return(true);
            }
            catch (UriFormatException)
            {
                adsPath = null;
                return(false);
            }
        }
示例#2
0
        private static IAdsObjectName GetObjectNameFromString(string value)
        {
            if (DN.TryParse(value, out var dn))
            {
                return(dn);
            }

            if (GuidName.TryParse(value, out var guidName))
            {
                return(guidName);
            }

            if (SidName.TryParse(value, out var sidName))
            {
                return(sidName);
            }

            throw new ArgumentOutOfRangeException(nameof(value));
        }
示例#3
0
        public object ConvertFromDirectoryValue([CanBeNull] object value)
        {
            if (value == null)
            {
                return(null);
            }

            try
            {
                switch (value)
                {
                case byte[] ar when NotionalType == typeof(Guid):
                    return(new Guid(ar));

                case string s when NotionalType == typeof(DN):
                    return(DN.Parse(s));

                case int i when NotionalType == typeof(ADS_USER_FLAG):
                    return((ADS_USER_FLAG)i);

                case IADsLargeInteger i when typeof(DateTime?).IsAssignableFrom(NotionalType):
                    return(DateTimeFromLargeInteger(i));

                case IADsLargeInteger i when typeof(long?).IsAssignableFrom(NotionalType):
                    return(Int64FromLargeInteger(i));

                default:
                    return(value);
                }
            }
            catch (Exception e)
            {
                var message = string.Format(
                    ErrorMessages.DirectoryProperty_DirectoryServicesException_InappropriateDirectoryValue,
                    value,
                    value.GetType(),
                    Syntax,
                    Name);

                throw new DirectoryServicesException(message, e);
            }
        }