Ejemplo n.º 1
0
        public Type GetDotNetPropertyType(string propertyName)
        {
            this.Init();
            ADAttributeSyntax propertyType = this._adSchema.GetPropertyType(propertyName);

            return(this.GetDotNetPropertyTypeFromSyntax(propertyType));
        }
Ejemplo n.º 2
0
        private object[] FormatGuidValue(string propertyName, IList valueList)
        {
            object[]          byteArray;
            ADAttributeSyntax propertyType      = this.GetPropertyType(propertyName, ADAttributeSyntax.OctetString);
            ADAttributeSyntax aDAttributeSyntax = propertyType;

            if (aDAttributeSyntax == ADAttributeSyntax.OctetString || aDAttributeSyntax == ADAttributeSyntax.ReplicaLink)
            {
                byteArray = new byte[valueList.Count][];
                for (int i = 0; i < valueList.Count; i++)
                {
                    Guid item = (Guid)valueList[i];
                    byteArray[i] = item.ToByteArray();
                }
            }
            else
            {
                byteArray = new string[valueList.Count];
                for (int j = 0; j < valueList.Count; j++)
                {
                    byteArray[j] = valueList[j].ToString();
                }
            }
            return(byteArray);
        }
Ejemplo n.º 3
0
 internal static DateTime ParseDateTimeValue(string value, ADAttributeSyntax syntax)
 {
     if (syntax != ADAttributeSyntax.GeneralizedTime)
     {
         if (syntax != ADAttributeSyntax.UtcTime)
         {
             DebugLogger.LogWarning("ADTypeConverter", string.Concat("ParseDateTimeValue: Not supported syntax ", syntax.ToString()));
             throw new NotSupportedException();
         }
         else
         {
             int      num      = int.Parse(value.Substring(0, 2), NumberFormatInfo.InvariantInfo);
             int      num1     = int.Parse(value.Substring(2, 2), NumberFormatInfo.InvariantInfo);
             int      num2     = int.Parse(value.Substring(4, 2), NumberFormatInfo.InvariantInfo);
             int      num3     = int.Parse(value.Substring(6, 2), NumberFormatInfo.InvariantInfo);
             int      num4     = int.Parse(value.Substring(8, 2), NumberFormatInfo.InvariantInfo);
             int      num5     = int.Parse(value.Substring(10, 2), NumberFormatInfo.InvariantInfo);
             DateTime dateTime = new DateTime(num, num1, num2, num3, num4, num5, DateTimeKind.Utc);
             return(dateTime.ToLocalTime());
         }
     }
     else
     {
         int      num6      = int.Parse(value.Substring(0, 4), NumberFormatInfo.InvariantInfo);
         int      num7      = int.Parse(value.Substring(4, 2), NumberFormatInfo.InvariantInfo);
         int      num8      = int.Parse(value.Substring(6, 2), NumberFormatInfo.InvariantInfo);
         int      num9      = int.Parse(value.Substring(8, 2), NumberFormatInfo.InvariantInfo);
         int      num10     = int.Parse(value.Substring(10, 2), NumberFormatInfo.InvariantInfo);
         int      num11     = int.Parse(value.Substring(12, 2), NumberFormatInfo.InvariantInfo);
         DateTime dateTime1 = new DateTime(num6, num7, num8, num9, num10, num11, DateTimeKind.Utc);
         return(dateTime1.ToLocalTime());
     }
 }
Ejemplo n.º 4
0
 public ADSchemaAttribute(ADAttributeSyntax syntax, bool isSingleValued, bool isSystemOnly, int?linkID, bool isConstructed)
 {
     this._syntax         = syntax;
     this._isSingleValued = isSingleValued;
     this._isSystemOnly   = isSystemOnly;
     this._linkID         = linkID;
     this._isConstructed  = isConstructed;
 }
Ejemplo n.º 5
0
        private string FormatDateTimeValue(string propertyName, DateTime propertyValue)
        {
            object[]          objArray;
            ADAttributeSyntax propertyType      = this.GetPropertyType(propertyName, ADAttributeSyntax.GeneralizedTime);
            ADAttributeSyntax aDAttributeSyntax = propertyType;

            switch (aDAttributeSyntax)
            {
            case ADAttributeSyntax.Int64:
            {
                long fileTimeUtc = propertyValue.ToFileTimeUtc();
                return(fileTimeUtc.ToString());
            }

            case ADAttributeSyntax.Bool:
            case ADAttributeSyntax.Oid:
            {
                DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: DateTime value for ", propertyName, " of syntax ", propertyType.ToString()));
                objArray    = new object[1];
                objArray[0] = typeof(DateTime);
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
            }

            case ADAttributeSyntax.GeneralizedTime:
            {
                if (propertyValue.Year >= 0x3e8)
                {
                    propertyValue = propertyValue.ToUniversalTime();
                    return(propertyValue.ToString("yyyyMMddHHmmss.0Z"));
                }
                else
                {
                    int year = propertyValue.Year;
                    DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: Invalid year ", year.ToString(), " for ", propertyName));
                    throw new ArgumentOutOfRangeException(propertyName);
                }
            }

            case ADAttributeSyntax.UtcTime:
            {
                propertyValue = propertyValue.ToUniversalTime();
                return(propertyValue.ToString("yyMMddHHmmssZ"));
            }

            default:
            {
                DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: DateTime value for ", propertyName, " of syntax ", (object)propertyType.ToString()));
                objArray    = new object[1];
                objArray[0] = typeof(DateTime);
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
            }
            }
        }
Ejemplo n.º 6
0
        private object FormatCertificateValue(string propertyName, X509Certificate propertyValue)
        {
            ADAttributeSyntax propertyType      = this.GetPropertyType(propertyName, ADAttributeSyntax.OctetString);
            ADAttributeSyntax aDAttributeSyntax = propertyType;

            if (aDAttributeSyntax == ADAttributeSyntax.OctetString || aDAttributeSyntax == ADAttributeSyntax.ReplicaLink)
            {
                return(propertyValue.GetRawCertData());
            }
            else
            {
                return(propertyValue.ToString());
            }
        }
Ejemplo n.º 7
0
        private object FormatGuidValue(string propertyName, Guid propertyValue)
        {
            ADAttributeSyntax propertyType      = this.GetPropertyType(propertyName, ADAttributeSyntax.OctetString);
            ADAttributeSyntax aDAttributeSyntax = propertyType;

            if (aDAttributeSyntax == ADAttributeSyntax.OctetString || aDAttributeSyntax == ADAttributeSyntax.ReplicaLink)
            {
                return(propertyValue.ToByteArray());
            }
            else
            {
                return(propertyValue.ToString());
            }
        }
Ejemplo n.º 8
0
        public static ADAttributeSyntax OIDToSyntax(string OID)
        {
            ADAttributeSyntax aDAttributeSyntax = ADAttributeSyntax.CaseExactString;

            if (ADSyntax._syntaxMap.TryGetValue(OID, out aDAttributeSyntax))
            {
                return(aDAttributeSyntax);
            }
            else
            {
                DebugLogger.LogError("adschema", string.Format("OID {0} not found in mapping table", OID));
                return(ADAttributeSyntax.NotFound);
            }
        }
Ejemplo n.º 9
0
        public ADAttributeSyntax GetPropertyType(string propertyName, ADAttributeSyntax defaultSyntax)
        {
            ADSchemaAttribute aDSchemaAttribute = null;

            this._schemaProperties.TryGetValue(propertyName, out aDSchemaAttribute);
            if (aDSchemaAttribute == null)
            {
                return(defaultSyntax);
            }
            else
            {
                return(aDSchemaAttribute.Syntax);
            }
        }
Ejemplo n.º 10
0
        private object[] FormatCertificateValue(string propertyName, IList valueList)
        {
            object[]          rawCertData;
            ADAttributeSyntax propertyType      = this.GetPropertyType(propertyName, ADAttributeSyntax.OctetString);
            ADAttributeSyntax aDAttributeSyntax = propertyType;

            if (aDAttributeSyntax == ADAttributeSyntax.OctetString || aDAttributeSyntax == ADAttributeSyntax.ReplicaLink)
            {
                rawCertData = new byte[valueList.Count][];
                for (int i = 0; i < valueList.Count; i++)
                {
                    rawCertData[i] = ((X509Certificate)valueList[i]).GetRawCertData();
                }
            }
            else
            {
                rawCertData = new string[valueList.Count];
                for (int j = 0; j < valueList.Count; j++)
                {
                    rawCertData[j] = valueList[j].ToString();
                }
            }
            return(rawCertData);
        }
Ejemplo n.º 11
0
 private ADSyntax(ADAttributeSyntax attributeSyntax, string syntaxOID)
 {
     this._attributeSyntax = attributeSyntax;
     this._syntaxOid       = syntaxOID;
 }
Ejemplo n.º 12
0
        internal ADPropertyValueCollection ConvertFromRaw(string propertyName, ADPropertyValueCollection propertyValues)
        {
            string str = null;
            int    num = 0;
            ADPropertyValueCollection aDPropertyValueCollection;

            byte[] bytes;
            this.Init();
            if (propertyValues.Count != 0)
            {
                ADObjectSearcher.ContainsRangeRetrievalTag(propertyName, out str, out num);
                ADAttributeSyntax propertyType      = this._adSchema.GetPropertyType(str);
                ADAttributeSyntax aDAttributeSyntax = propertyType;
                switch (aDAttributeSyntax)
                {
                case ADAttributeSyntax.DirectoryString:
                case ADAttributeSyntax.DN:
                {
                    aDPropertyValueCollection = propertyValues;
                    break;
                }

                case ADAttributeSyntax.OctetString:
                {
                    aDPropertyValueCollection = propertyValues;
                    break;
                }

                case ADAttributeSyntax.SecurityDescriptor:
                {
                    aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
                    IEnumerator enumerator = propertyValues.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            byte[] current = (byte[])enumerator.Current;
                            ActiveDirectorySecurity activeDirectorySecurity = new ActiveDirectorySecurity();
                            activeDirectorySecurity.SetSecurityDescriptorBinaryForm(current);
                            aDPropertyValueCollection.Add(activeDirectorySecurity);
                        }
                        break;
                    }
                    finally
                    {
                        IDisposable disposable = enumerator as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }

                case ADAttributeSyntax.Int:
                case ADAttributeSyntax.Enumeration:
                {
                    aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
                    IEnumerator enumerator1 = propertyValues.GetEnumerator();
                    try
                    {
                        while (enumerator1.MoveNext())
                        {
                            string current1 = (string)enumerator1.Current;
                            aDPropertyValueCollection.Add(int.Parse(current1, NumberFormatInfo.InvariantInfo));
                        }
                        break;
                    }
                    finally
                    {
                        IDisposable disposable1 = enumerator1 as IDisposable;
                        if (disposable1 != null)
                        {
                            disposable1.Dispose();
                        }
                    }
                }

                case ADAttributeSyntax.Int64:
                {
                    aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
                    IEnumerator enumerator2 = propertyValues.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            string str1 = (string)enumerator2.Current;
                            aDPropertyValueCollection.Add(long.Parse(str1, NumberFormatInfo.InvariantInfo));
                        }
                        break;
                    }
                    finally
                    {
                        IDisposable disposable2 = enumerator2 as IDisposable;
                        if (disposable2 != null)
                        {
                            disposable2.Dispose();
                        }
                    }
                }

                case ADAttributeSyntax.Bool:
                {
                    aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
                    IEnumerator enumerator3 = propertyValues.GetEnumerator();
                    try
                    {
                        while (enumerator3.MoveNext())
                        {
                            string current2 = (string)enumerator3.Current;
                            if (string.Compare(current2, "TRUE", StringComparison.OrdinalIgnoreCase) != 0)
                            {
                                aDPropertyValueCollection.Add(false);
                            }
                            else
                            {
                                aDPropertyValueCollection.Add(true);
                            }
                        }
                        break;
                    }
                    finally
                    {
                        IDisposable disposable3 = enumerator3 as IDisposable;
                        if (disposable3 != null)
                        {
                            disposable3.Dispose();
                        }
                    }
                }

                case ADAttributeSyntax.Oid:
                case ADAttributeSyntax.DNWithBinary:
                case ADAttributeSyntax.DNWithString:
                case ADAttributeSyntax.IA5String:
                case ADAttributeSyntax.PrintableString:
                {
                    aDPropertyValueCollection = propertyValues;
                    break;
                }

                case ADAttributeSyntax.GeneralizedTime:
                case ADAttributeSyntax.UtcTime:
                {
                    aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
                    IEnumerator enumerator4 = propertyValues.GetEnumerator();
                    try
                    {
                        while (enumerator4.MoveNext())
                        {
                            string str2 = (string)enumerator4.Current;
                            aDPropertyValueCollection.Add(ADTypeConverter.ParseDateTimeValue(str2, propertyType));
                        }
                        break;
                    }
                    finally
                    {
                        IDisposable disposable4 = enumerator4 as IDisposable;
                        if (disposable4 != null)
                        {
                            disposable4.Dispose();
                        }
                    }
                }

                case ADAttributeSyntax.Sid:
                {
                    aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
                    IEnumerator enumerator5 = propertyValues.GetEnumerator();
                    try
                    {
                        while (enumerator5.MoveNext())
                        {
                            object obj = enumerator5.Current;
                            if (obj as string == null)
                            {
                                bytes = (byte[])obj;
                            }
                            else
                            {
                                bytes = ADTypeConverter._encoder.GetBytes((string)obj);
                            }
                            aDPropertyValueCollection.Add(new SecurityIdentifier(bytes, 0));
                        }
                        break;
                    }
                    finally
                    {
                        IDisposable disposable5 = enumerator5 as IDisposable;
                        if (disposable5 != null)
                        {
                            disposable5.Dispose();
                        }
                    }
                }

                default:
                {
                    aDPropertyValueCollection = propertyValues;
                    break;
                }
                }
                return(aDPropertyValueCollection);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 13
0
 public ADSchemaAttribute(ADAttributeSyntax syntax, bool isSingleValued, bool isSystemOnly, int linkID) : this(syntax, isSingleValued, isSystemOnly, new int?(linkID), false)
 {
 }
Ejemplo n.º 14
0
 public ADSchemaAttribute(ADAttributeSyntax syntax, bool isSingleValued, bool isSystemOnly, bool isConstructed) : this(syntax, isSingleValued, isSystemOnly, null, isConstructed)
 {
 }
Ejemplo n.º 15
0
 public ADSchemaAttribute(ADAttributeSyntax syntax, bool isSingleValued, bool isSystemOnly) : this(syntax, isSingleValued, isSystemOnly, null, false)
 {
 }
Ejemplo n.º 16
0
		private ADSyntax(ADAttributeSyntax attributeSyntax, string syntaxOID)
		{
			this._attributeSyntax = attributeSyntax;
			this._syntaxOid = syntaxOID;
		}
Ejemplo n.º 17
0
		internal static DateTime ParseDateTimeValue(string value, ADAttributeSyntax syntax)
		{
			if (syntax != ADAttributeSyntax.GeneralizedTime)
			{
				if (syntax != ADAttributeSyntax.UtcTime)
				{
					DebugLogger.LogWarning("ADTypeConverter", string.Concat("ParseDateTimeValue: Not supported syntax ", syntax.ToString()));
					throw new NotSupportedException();
				}
				else
				{
					int num = int.Parse(value.Substring(0, 2), NumberFormatInfo.InvariantInfo);
					int num1 = int.Parse(value.Substring(2, 2), NumberFormatInfo.InvariantInfo);
					int num2 = int.Parse(value.Substring(4, 2), NumberFormatInfo.InvariantInfo);
					int num3 = int.Parse(value.Substring(6, 2), NumberFormatInfo.InvariantInfo);
					int num4 = int.Parse(value.Substring(8, 2), NumberFormatInfo.InvariantInfo);
					int num5 = int.Parse(value.Substring(10, 2), NumberFormatInfo.InvariantInfo);
					DateTime dateTime = new DateTime(num, num1, num2, num3, num4, num5, DateTimeKind.Utc);
					return dateTime.ToLocalTime();
				}
			}
			else
			{
				int num6 = int.Parse(value.Substring(0, 4), NumberFormatInfo.InvariantInfo);
				int num7 = int.Parse(value.Substring(4, 2), NumberFormatInfo.InvariantInfo);
				int num8 = int.Parse(value.Substring(6, 2), NumberFormatInfo.InvariantInfo);
				int num9 = int.Parse(value.Substring(8, 2), NumberFormatInfo.InvariantInfo);
				int num10 = int.Parse(value.Substring(10, 2), NumberFormatInfo.InvariantInfo);
				int num11 = int.Parse(value.Substring(12, 2), NumberFormatInfo.InvariantInfo);
				DateTime dateTime1 = new DateTime(num6, num7, num8, num9, num10, num11, DateTimeKind.Utc);
				return dateTime1.ToLocalTime();
			}
		}
Ejemplo n.º 18
0
		public ADAttributeSyntax GetPropertyType(string propertyName, ADAttributeSyntax defaultSyntax)
		{
			this.Init();
			return this._adSchema.GetPropertyType(propertyName, defaultSyntax);
		}
Ejemplo n.º 19
0
        internal ADPropertyValueCollection ConvertFromRaw(DirectoryAttribute property)
        {
            string str = null;
            int    num = 0;

            this.Init();
            if (property == null || property.Count == 0)
            {
                return(null);
            }
            else
            {
                ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection();
                ADObjectSearcher.ContainsRangeRetrievalTag(property.Name, out str, out num);
                ADAttributeSyntax propertyType      = this._adSchema.GetPropertyType(str);
                string[]          values            = null;
                byte[][]          numArray          = null;
                ADAttributeSyntax aDAttributeSyntax = propertyType;
                switch (aDAttributeSyntax)
                {
                case ADAttributeSyntax.DirectoryString:
                case ADAttributeSyntax.DN:
                {
                    aDPropertyValueCollection.AddRange(property.GetValues(typeof(string)));
                    break;
                }

                case ADAttributeSyntax.OctetString:
                {
                    aDPropertyValueCollection.AddRange(property.GetValues(typeof(byte[])));
                    break;
                }

                case ADAttributeSyntax.SecurityDescriptor:
                {
                    numArray = (byte[][])property.GetValues(typeof(byte[]));
                    byte[][] numArray1 = numArray;
                    for (int i = 0; i < (int)numArray1.Length; i++)
                    {
                        byte[] numArray2 = numArray1[i];
                        ActiveDirectorySecurity activeDirectorySecurity = new ActiveDirectorySecurity();
                        activeDirectorySecurity.SetSecurityDescriptorBinaryForm(numArray2);
                        aDPropertyValueCollection.Add(activeDirectorySecurity);
                    }
                    break;
                }

                case ADAttributeSyntax.Int:
                case ADAttributeSyntax.Enumeration:
                {
                    values = (string[])property.GetValues(typeof(string));
                    string[] strArrays = values;
                    for (int j = 0; j < (int)strArrays.Length; j++)
                    {
                        string str1 = strArrays[j];
                        aDPropertyValueCollection.Add(int.Parse(str1, NumberFormatInfo.InvariantInfo));
                    }
                    break;
                }

                case ADAttributeSyntax.Int64:
                {
                    values = (string[])property.GetValues(typeof(string));
                    string[] strArrays1 = values;
                    for (int k = 0; k < (int)strArrays1.Length; k++)
                    {
                        string str2 = strArrays1[k];
                        aDPropertyValueCollection.Add(long.Parse(str2, NumberFormatInfo.InvariantInfo));
                    }
                    break;
                }

                case ADAttributeSyntax.Bool:
                {
                    values = (string[])property.GetValues(typeof(string));
                    string[] strArrays2 = values;
                    for (int l = 0; l < (int)strArrays2.Length; l++)
                    {
                        string str3 = strArrays2[l];
                        if (string.Compare(str3, "TRUE", StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            aDPropertyValueCollection.Add(false);
                        }
                        else
                        {
                            aDPropertyValueCollection.Add(true);
                        }
                    }
                    break;
                }

                case ADAttributeSyntax.Oid:
                case ADAttributeSyntax.DNWithBinary:
                case ADAttributeSyntax.DNWithString:
                case ADAttributeSyntax.IA5String:
                case ADAttributeSyntax.PrintableString:
                {
                    aDPropertyValueCollection.AddRange(property.GetValues(typeof(string)));
                    break;
                }

                case ADAttributeSyntax.GeneralizedTime:
                case ADAttributeSyntax.UtcTime:
                {
                    values = (string[])property.GetValues(typeof(string));
                    string[] strArrays3 = values;
                    for (int m = 0; m < (int)strArrays3.Length; m++)
                    {
                        string str4 = strArrays3[m];
                        aDPropertyValueCollection.Add(ADTypeConverter.ParseDateTimeValue(str4, propertyType));
                    }
                    break;
                }

                case ADAttributeSyntax.Sid:
                {
                    numArray = (byte[][])property.GetValues(typeof(byte[]));
                    byte[][] numArray3 = numArray;
                    for (int n = 0; n < (int)numArray3.Length; n++)
                    {
                        byte[] numArray4 = numArray3[n];
                        aDPropertyValueCollection.Add(new SecurityIdentifier(numArray4, 0));
                    }
                    break;
                }

                default:
                {
                    if (aDAttributeSyntax == ADAttributeSyntax.ReplicaLink)
                    {
                        aDPropertyValueCollection.AddRange(property.GetValues(typeof(byte[])));
                        break;
                    }
                    aDPropertyValueCollection.AddRange(property.GetValues(typeof(string)));
                    break;
                }
                }
                return(aDPropertyValueCollection);
            }
        }
Ejemplo n.º 20
0
		public ADSchemaAttribute(ADAttributeSyntax syntax, bool isSingleValued, bool isSystemOnly, int linkID) : this(syntax, isSingleValued, isSystemOnly, new int?(linkID), false)
		{
		}
Ejemplo n.º 21
0
		public ADSchemaAttribute(ADAttributeSyntax syntax, bool isSingleValued, bool isSystemOnly) : this(syntax, isSingleValued, isSystemOnly, null, false)
		{
		}
Ejemplo n.º 22
0
 public ADAttributeSyntax GetPropertyType(string propertyName, ADAttributeSyntax defaultSyntax)
 {
     this.Init();
     return(this._adSchema.GetPropertyType(propertyName, defaultSyntax));
 }
Ejemplo n.º 23
0
        private Type GetDotNetPropertyTypeFromSyntax(ADAttributeSyntax syntax)
        {
            this.Init();
            ADAttributeSyntax aDAttributeSyntax = syntax;

            switch (aDAttributeSyntax)
            {
            case ADAttributeSyntax.DirectoryString:
            case ADAttributeSyntax.DN:
            {
                return(typeof(string));
            }

            case ADAttributeSyntax.OctetString:
            {
                return(typeof(byte[]));
            }

            case ADAttributeSyntax.SecurityDescriptor:
            {
                return(typeof(ActiveDirectorySecurity));
            }

            case ADAttributeSyntax.Int:
            case ADAttributeSyntax.Enumeration:
            {
                return(typeof(int));
            }

            case ADAttributeSyntax.Int64:
            {
                return(typeof(long));
            }

            case ADAttributeSyntax.Bool:
            {
                return(typeof(bool));
            }

            case ADAttributeSyntax.Oid:
            case ADAttributeSyntax.DNWithBinary:
            case ADAttributeSyntax.DNWithString:
            case ADAttributeSyntax.IA5String:
            case ADAttributeSyntax.PrintableString:
            {
                return(typeof(string));
            }

            case ADAttributeSyntax.GeneralizedTime:
            case ADAttributeSyntax.UtcTime:
            {
                return(typeof(DateTime));
            }

            case ADAttributeSyntax.Sid:
            {
                return(typeof(SecurityIdentifier));
            }

            default:
            {
                if (aDAttributeSyntax == ADAttributeSyntax.ReplicaLink)
                {
                    return(typeof(byte[]));
                }
                return(typeof(string));
            }
            }
        }
Ejemplo n.º 24
0
        private string[] FormatDateTimeValue(string propertyName, IList valueList)
        {
            DateTime item;

            object[]          objArray;
            string[]          str               = null;
            ADAttributeSyntax propertyType      = this.GetPropertyType(propertyName, ADAttributeSyntax.GeneralizedTime);
            ADAttributeSyntax aDAttributeSyntax = propertyType;

            if (aDAttributeSyntax == ADAttributeSyntax.Int64)
            {
                str = new string[valueList.Count];
                for (int i = 0; i < valueList.Count; i++)
                {
                    item = (DateTime)valueList[i];
                    long fileTimeUtc = item.ToFileTimeUtc();
                    str[i] = fileTimeUtc.ToString();
                }
            }
            else if (aDAttributeSyntax == ADAttributeSyntax.Bool || aDAttributeSyntax == ADAttributeSyntax.Oid)
            {
                DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: DateTime value for ", propertyName, " of syntax ", (object)propertyType.ToString()));
                objArray    = new object[1];
                objArray[0] = typeof(DateTime);
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
            }
            else if (aDAttributeSyntax == ADAttributeSyntax.GeneralizedTime)
            {
                str = new string[valueList.Count];
                int num = 0;
                while (num < valueList.Count)
                {
                    item = (DateTime)valueList[num];
                    if (item.Year >= 0x3e8)
                    {
                        item     = item.ToUniversalTime();
                        str[num] = item.ToString("yyyyMMddHHmmss.0Z");
                        num++;
                    }
                    else
                    {
                        int year = item.Year;
                        DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: Invalid year ", year.ToString(), " for ", propertyName));
                        throw new ArgumentOutOfRangeException(propertyName, (object)item, StringResources.InvalidYear);
                    }
                }
            }
            else if (aDAttributeSyntax == ADAttributeSyntax.UtcTime)
            {
                str = new string[valueList.Count];
                for (int j = 0; j < valueList.Count; j++)
                {
                    item   = (DateTime)valueList[j];
                    item   = item.ToUniversalTime();
                    str[j] = item.ToString("yyMMddHHmmssZ");
                }
            }
            else
            {
                DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: DateTime value for ", propertyName, " of syntax ", (object)propertyType.ToString()));
                objArray    = new object[1];
                objArray[0] = typeof(DateTime);
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
            }
            return(str);

            DebugLogger.LogWarning("ADTypeConverter", string.Concat("FormatDateTimeValue: DateTime value for ", propertyName, " of syntax ", propertyType.ToString()));
            objArray    = new object[1];
            objArray[0] = typeof(DateTime);
            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.InvalidType, objArray), propertyName);
        }
Ejemplo n.º 25
0
		public ADSchemaAttribute(ADAttributeSyntax syntax, bool isSingleValued, bool isSystemOnly, bool isConstructed) : this(syntax, isSingleValued, isSystemOnly, null, isConstructed)
		{
		}
Ejemplo n.º 26
0
		private Type GetDotNetPropertyTypeFromSyntax(ADAttributeSyntax syntax)
		{
			this.Init();
			ADAttributeSyntax aDAttributeSyntax = syntax;
			switch (aDAttributeSyntax)
			{
				case ADAttributeSyntax.DirectoryString:
				case ADAttributeSyntax.DN:
				{
					return typeof(string);
				}
				case ADAttributeSyntax.OctetString:
				{
					return typeof(byte[]);
				}
				case ADAttributeSyntax.SecurityDescriptor:
				{
					return typeof(ActiveDirectorySecurity);
				}
				case ADAttributeSyntax.Int:
				case ADAttributeSyntax.Enumeration:
				{
					return typeof(int);
				}
				case ADAttributeSyntax.Int64:
				{
					return typeof(long);
				}
				case ADAttributeSyntax.Bool:
				{
					return typeof(bool);
				}
				case ADAttributeSyntax.Oid:
				case ADAttributeSyntax.DNWithBinary:
				case ADAttributeSyntax.DNWithString:
				case ADAttributeSyntax.IA5String:
				case ADAttributeSyntax.PrintableString:
				{
					return typeof(string);
				}
				case ADAttributeSyntax.GeneralizedTime:
				case ADAttributeSyntax.UtcTime:
				{
					return typeof(DateTime);
				}
				case ADAttributeSyntax.Sid:
				{
					return typeof(SecurityIdentifier);
				}
				default:
				{
					if (aDAttributeSyntax == ADAttributeSyntax.ReplicaLink)
					{
						return typeof(byte[]);
					}
					return typeof(string);
				}
			}
		}
Ejemplo n.º 27
0
		public ADSchemaAttribute(ADAttributeSyntax syntax, bool isSingleValued, bool isSystemOnly, int? linkID, bool isConstructed)
		{
			this._syntax = syntax;
			this._isSingleValued = isSingleValued;
			this._isSystemOnly = isSystemOnly;
			this._linkID = linkID;
			this._isConstructed = isConstructed;
		}
Ejemplo n.º 28
0
		public ADAttributeSyntax GetPropertyType(string propertyName, ADAttributeSyntax defaultSyntax)
		{
			ADSchemaAttribute aDSchemaAttribute = null;
			this._schemaProperties.TryGetValue(propertyName, out aDSchemaAttribute);
			if (aDSchemaAttribute == null)
			{
				return defaultSyntax;
			}
			else
			{
				return aDSchemaAttribute.Syntax;
			}
		}