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; } }
private static ADPropertyValueCollection ConvertLinkedGroupPolicyObjects(string rawGPLink) { ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection(); if (rawGPLink != null && rawGPLink.Length > 0) { string[] strArrays = rawGPLink.Split(GPLinkUtil.GpLinkSplitChars, StringSplitOptions.RemoveEmptyEntries); if (strArrays != null && (int)strArrays.Length > 0) { string[] strArrays1 = strArrays; for (int i = 0; i < (int)strArrays1.Length; i++) { string str = strArrays1[i]; Match match = GPLinkUtil.GpLinkRegEx.Match(str); if (match.Success) { aDPropertyValueCollection.Add(match.Groups[GPLinkUtil.GpLinkRegExDNGroup].Value); } } } } return aDPropertyValueCollection; }
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; } }
public override void SetPropertyValue(PSAdaptedProperty property, object valueObject) { Type realType; Type type; object obj = null; Exception exception = null; if (property != null) { ADEntity baseObject = property.BaseObject as ADEntity; if (baseObject != null) { PSObject pSObject = valueObject as PSObject; if (pSObject != null) { valueObject = pSObject.BaseObject; } PropertyInfo dotNetProperty = baseObject.GetDotNetProperty(property.Name); if (dotNetProperty == null) { if (this.IsSettable(property)) { if (valueObject != null) { realType = this.GetRealType(baseObject.GetPropertyType(property.Name)); type = this.GetRealType(valueObject.GetType()); if (realType == typeof(object) || realType == type) { baseObject[property.Name].Value = valueObject; return; } else { if (baseObject.PropertyIsSingleValue(property.Name) || valueObject as ICollection == null) { baseObject[property.Name].Value = this.ConvertValue(property, valueObject, realType, type); return; } else { if (!this.TryConvertValue(property, valueObject, realType, type, out obj, out exception)) { ICollection collections = valueObject as ICollection; ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection(); foreach (object obj1 in collections) { if (obj1 == null) { continue; } Type type1 = obj1.GetType(); if (type1 != realType) { aDPropertyValueCollection.Add(this.ConvertValue(property, obj1, realType, type1)); } else { aDPropertyValueCollection.Add(obj1); } } baseObject[property.Name].Value = aDPropertyValueCollection; return; } else { baseObject[property.Name].Value = obj; return; } } } } else { baseObject[property.Name].Value = null; return; } } else { object[] name = new object[1]; name[0] = property.Name; throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.PropertyIsReadonly, name)); } } else { if (dotNetProperty.CanWrite) { if (valueObject != null) { realType = this.GetRealType(dotNetProperty.PropertyType); type = this.GetRealType(valueObject.GetType()); if (realType == typeof(object) || realType == type) { dotNetProperty.SetValue(baseObject, valueObject, null); return; } else { dotNetProperty.SetValue(baseObject, this.ConvertValue(property, valueObject, realType, type), null); return; } } else { dotNetProperty.SetValue(baseObject, null, null); return; } } else { object[] objArray = new object[1]; objArray[0] = property.Name; throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.PropertyIsReadonly, objArray)); } } } else { object[] typeAdapterTypeName = new object[2]; typeAdapterTypeName[0] = ADEntityAdapter.TypeAdapterTypeName; typeAdapterTypeName[1] = ADEntityAdapter.ADEntityTypeName; throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.TypeAdapterForADEntityOnly, typeAdapterTypeName)); } } else { throw new ArgumentNullException("property"); } }
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); } }
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); } }