public object GetValue() { switch ((AdsType)adsvalue.dwType) { // Common for DNS and LDAP case AdsType.ADSTYPE_UTC_TIME: { SystemTime st = new SystemTime(); st.wYear = LowOfInt(adsvalue.generic.a); st.wMonth = HighOfInt(adsvalue.generic.a); st.wDayOfWeek = LowOfInt(adsvalue.generic.b); st.wDay = HighOfInt(adsvalue.generic.b); st.wHour = LowOfInt(adsvalue.generic.c); st.wMinute = HighOfInt(adsvalue.generic.c); st.wSecond = LowOfInt(adsvalue.generic.d); st.wMilliseconds = HighOfInt(adsvalue.generic.d); return new DateTime(st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); } case AdsType.ADSTYPE_DN_WITH_BINARY: { DnWithBinary dnb = new DnWithBinary(); Marshal.PtrToStructure(adsvalue.pointer.value, dnb); byte[] bytes = new byte[dnb.dwLength]; Marshal.Copy(dnb.lpBinaryValue, bytes, 0, dnb.dwLength); StringBuilder strb = new StringBuilder(); StringBuilder binaryPart = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { string s = bytes[i].ToString("X", CultureInfo.InvariantCulture); if (s.Length == 1) binaryPart.Append("0"); binaryPart.Append(s); } strb.Append("B:"); strb.Append(binaryPart.Length); strb.Append(":"); strb.Append(binaryPart.ToString()); strb.Append(":"); strb.Append(Marshal.PtrToStringUni(dnb.pszDNString)); return strb.ToString(); } case AdsType.ADSTYPE_DN_WITH_STRING: { DnWithString dns = new DnWithString(); Marshal.PtrToStructure(adsvalue.pointer.value, dns); string strValue = Marshal.PtrToStringUni(dns.pszStringValue); if (strValue == null) strValue = ""; StringBuilder strb = new StringBuilder(); strb.Append("S:"); strb.Append(strValue.Length); strb.Append(":"); strb.Append(strValue); strb.Append(":"); strb.Append(Marshal.PtrToStringUni(dns.pszDNString)); return strb.ToString(); } case AdsType.ADSTYPE_DN_STRING: case AdsType.ADSTYPE_CASE_EXACT_STRING: case AdsType.ADSTYPE_CASE_IGNORE_STRING: case AdsType.ADSTYPE_PRINTABLE_STRING: case AdsType.ADSTYPE_NUMERIC_STRING: case AdsType.ADSTYPE_OBJECT_CLASS: // string return Marshal.PtrToStringUni(adsvalue.pointer.value); case AdsType.ADSTYPE_BOOLEAN: // bool return adsvalue.generic.a != 0; case AdsType.ADSTYPE_INTEGER: // int return adsvalue.generic.a; case AdsType.ADSTYPE_NT_SECURITY_DESCRIPTOR: case AdsType.ADSTYPE_OCTET_STRING: case AdsType.ADSTYPE_PROV_SPECIFIC: // byte[] int len = adsvalue.octetString.length; byte[] value = new byte[len]; Marshal.Copy(adsvalue.octetString.value, value, 0, len); return value; case AdsType.ADSTYPE_INVALID: throw new InvalidOperationException(Res.GetString(Res.DSConvertTypeInvalid)); case AdsType.ADSTYPE_LARGE_INTEGER: return LowInt64; // not used in LDAP case AdsType.ADSTYPE_CASEIGNORE_LIST: case AdsType.ADSTYPE_OCTET_LIST: case AdsType.ADSTYPE_PATH: case AdsType.ADSTYPE_POSTALADDRESS: case AdsType.ADSTYPE_TIMESTAMP: case AdsType.ADSTYPE_NETADDRESS: case AdsType.ADSTYPE_FAXNUMBER: case AdsType.ADSTYPE_EMAIL: case AdsType.ADSTYPE_BACKLINK: case AdsType.ADSTYPE_HOLD: case AdsType.ADSTYPE_TYPEDNAME: case AdsType.ADSTYPE_REPLICAPOINTER: case AdsType.ADSTYPE_UNKNOWN: return new NotImplementedException(Res.GetString(Res.DSAdsvalueTypeNYI, "0x" + Convert.ToString(adsvalue.dwType, 16))); default: return new ArgumentException(Res.GetString(Res.DSConvertFailed, "0x" + Convert.ToString(LowInt64, 16), "0x" + Convert.ToString(adsvalue.dwType, 16))); } }
public object GetValue() { switch ((AdsType)adsvalue.dwType) { // Common for DNS and LDAP case AdsType.ADSTYPE_UTC_TIME: { SystemTime st = new SystemTime(); st.wYear = LowOfInt(adsvalue.a); st.wMonth = HighOfInt(adsvalue.a); st.wDayOfWeek = LowOfInt(adsvalue.b); st.wDay = HighOfInt(adsvalue.b); st.wHour = LowOfInt(adsvalue.c); st.wMinute = HighOfInt(adsvalue.c); st.wSecond = LowOfInt(adsvalue.d); st.wMilliseconds = HighOfInt(adsvalue.d); return(new DateTime(st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds)); } case AdsType.ADSTYPE_DN_WITH_BINARY: { DnWithBinary dnb = (DnWithBinary)Marshal.PtrToStructure((INTPTR_INTPTRCAST)adsvalue.a, typeof(DnWithBinary)); byte[] bytes = new byte[dnb.dwLength]; Marshal.Copy(dnb.lpBinaryValue, bytes, 0, dnb.dwLength); StringBuilder strb = new StringBuilder(); if (bytes.Length == 16) { strb.Append(new Guid(bytes).ToString()); } else { strb.Append(Convert.ToBase64String(bytes)); } strb.Append(":"); strb.Append(Marshal.PtrToStringUni(dnb.pszDNString)); return(strb.ToString()); } case AdsType.ADSTYPE_DN_WITH_STRING: { DnWithString dns = (DnWithString)Marshal.PtrToStructure((INTPTR_INTPTRCAST)adsvalue.a, typeof(DnWithString)); StringBuilder strb = new StringBuilder(Marshal.PtrToStringUni(dns.pszStringValue)); strb.Append(":"); strb.Append(Marshal.PtrToStringUni(dns.pszDNString)); return(strb.ToString()); } case AdsType.ADSTYPE_DN_STRING: case AdsType.ADSTYPE_CASE_EXACT_STRING: case AdsType.ADSTYPE_CASE_IGNORE_STRING: case AdsType.ADSTYPE_PRINTABLE_STRING: case AdsType.ADSTYPE_NUMERIC_STRING: case AdsType.ADSTYPE_OBJECT_CLASS: // string return(Marshal.PtrToStringUni((INTPTR_INTPTRCAST)adsvalue.a)); case AdsType.ADSTYPE_BOOLEAN: // bool return(adsvalue.a != 0); case AdsType.ADSTYPE_INTEGER: // int return(adsvalue.a); case AdsType.ADSTYPE_NT_SECURITY_DESCRIPTOR: case AdsType.ADSTYPE_OCTET_STRING: // byte[] int len = adsvalue.a; byte[] value = new byte[len]; Marshal.Copy((INTPTR_INTPTRCAST)adsvalue.b, value, 0, len); return(value); case AdsType.ADSTYPE_INVALID: throw new InvalidOperationException(Res.GetString(Res.DSConvertTypeInvalid)); case AdsType.ADSTYPE_LARGE_INTEGER: return(LowInt64); // not used in LDAP case AdsType.ADSTYPE_CASEIGNORE_LIST: case AdsType.ADSTYPE_OCTET_LIST: case AdsType.ADSTYPE_PATH: case AdsType.ADSTYPE_POSTALADDRESS: case AdsType.ADSTYPE_TIMESTAMP: case AdsType.ADSTYPE_NETADDRESS: case AdsType.ADSTYPE_FAXNUMBER: case AdsType.ADSTYPE_EMAIL: case AdsType.ADSTYPE_BACKLINK: case AdsType.ADSTYPE_HOLD: case AdsType.ADSTYPE_TYPEDNAME: case AdsType.ADSTYPE_REPLICAPOINTER: case AdsType.ADSTYPE_UNKNOWN: case AdsType.ADSTYPE_PROV_SPECIFIC: return(new NotImplementedException(Res.GetString(Res.DSAdsvalueTypeNYI, "0x" + Convert.ToString(adsvalue.dwType, 16)))); default: return(new ArgumentException(Res.GetString(Res.DSConvertFailed, "0x" + Convert.ToString(LowInt64, 16), "0x" + Convert.ToString(adsvalue.dwType, 16)))); } }
public object GetValue() { switch (this.adsvalue.dwType) { case 0: throw new InvalidOperationException(Res.GetString("DSConvertTypeInvalid")); case 1: case 2: case 3: case 4: case 5: case 12: return(Marshal.PtrToStringUni(this.adsvalue.pointer.value)); case 6: return(this.adsvalue.generic.a != 0); case 7: return(this.adsvalue.generic.a); case 8: case 11: case 0x19: { int length = this.adsvalue.octetString.length; byte[] destination = new byte[length]; Marshal.Copy(this.adsvalue.octetString.value, destination, 0, length); return(destination); } case 9: { SystemTime time = new SystemTime { wYear = LowOfInt(this.adsvalue.generic.a), wMonth = HighOfInt(this.adsvalue.generic.a), wDayOfWeek = LowOfInt(this.adsvalue.generic.b), wDay = HighOfInt(this.adsvalue.generic.b), wHour = LowOfInt(this.adsvalue.generic.c), wMinute = HighOfInt(this.adsvalue.generic.c), wSecond = LowOfInt(this.adsvalue.generic.d), wMilliseconds = HighOfInt(this.adsvalue.generic.d) }; return(new DateTime(time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds)); } case 10: return(this.LowInt64); case 13: case 14: case 15: case 0x10: case 0x11: case 0x12: case 0x13: case 20: case 0x15: case 0x16: case 0x17: case 0x18: case 0x1a: return(new NotImplementedException(Res.GetString("DSAdsvalueTypeNYI", new object[] { "0x" + Convert.ToString(this.adsvalue.dwType, 0x10) }))); case 0x1b: { DnWithBinary structure = new DnWithBinary(); Marshal.PtrToStructure(this.adsvalue.pointer.value, structure); byte[] buffer = new byte[structure.dwLength]; Marshal.Copy(structure.lpBinaryValue, buffer, 0, structure.dwLength); StringBuilder builder = new StringBuilder(); StringBuilder builder2 = new StringBuilder(); for (int i = 0; i < buffer.Length; i++) { string str = buffer[i].ToString("X", CultureInfo.InvariantCulture); if (str.Length == 1) { builder2.Append("0"); } builder2.Append(str); } builder.Append("B:"); builder.Append(builder2.Length); builder.Append(":"); builder.Append(builder2.ToString()); builder.Append(":"); builder.Append(Marshal.PtrToStringUni(structure.pszDNString)); return(builder.ToString()); } case 0x1c: { DnWithString str2 = new DnWithString(); Marshal.PtrToStructure(this.adsvalue.pointer.value, str2); string str3 = Marshal.PtrToStringUni(str2.pszStringValue); if (str3 == null) { str3 = ""; } StringBuilder builder3 = new StringBuilder(); builder3.Append("S:"); builder3.Append(str3.Length); builder3.Append(":"); builder3.Append(str3); builder3.Append(":"); builder3.Append(Marshal.PtrToStringUni(str2.pszDNString)); return(builder3.ToString()); } } return(new ArgumentException(Res.GetString("DSConvertFailed", new object[] { "0x" + Convert.ToString(this.LowInt64, 0x10), "0x" + Convert.ToString(this.adsvalue.dwType, 0x10) }))); }
public object GetValue() { switch (this.adsvalue.dwType) { case 0: throw new InvalidOperationException(Res.GetString("DSConvertTypeInvalid")); case 1: case 2: case 3: case 4: case 5: case 12: return Marshal.PtrToStringUni(this.adsvalue.pointer.value); case 6: return (this.adsvalue.generic.a != 0); case 7: return this.adsvalue.generic.a; case 8: case 11: case 0x19: { int length = this.adsvalue.octetString.length; byte[] destination = new byte[length]; Marshal.Copy(this.adsvalue.octetString.value, destination, 0, length); return destination; } case 9: { SystemTime time = new SystemTime { wYear = LowOfInt(this.adsvalue.generic.a), wMonth = HighOfInt(this.adsvalue.generic.a), wDayOfWeek = LowOfInt(this.adsvalue.generic.b), wDay = HighOfInt(this.adsvalue.generic.b), wHour = LowOfInt(this.adsvalue.generic.c), wMinute = HighOfInt(this.adsvalue.generic.c), wSecond = LowOfInt(this.adsvalue.generic.d), wMilliseconds = HighOfInt(this.adsvalue.generic.d) }; return new DateTime(time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds); } case 10: return this.LowInt64; case 13: case 14: case 15: case 0x10: case 0x11: case 0x12: case 0x13: case 20: case 0x15: case 0x16: case 0x17: case 0x18: case 0x1a: return new NotImplementedException(Res.GetString("DSAdsvalueTypeNYI", new object[] { "0x" + Convert.ToString(this.adsvalue.dwType, 0x10) })); case 0x1b: { DnWithBinary structure = new DnWithBinary(); Marshal.PtrToStructure(this.adsvalue.pointer.value, structure); byte[] buffer = new byte[structure.dwLength]; Marshal.Copy(structure.lpBinaryValue, buffer, 0, structure.dwLength); StringBuilder builder = new StringBuilder(); StringBuilder builder2 = new StringBuilder(); for (int i = 0; i < buffer.Length; i++) { string str = buffer[i].ToString("X", CultureInfo.InvariantCulture); if (str.Length == 1) { builder2.Append("0"); } builder2.Append(str); } builder.Append("B:"); builder.Append(builder2.Length); builder.Append(":"); builder.Append(builder2.ToString()); builder.Append(":"); builder.Append(Marshal.PtrToStringUni(structure.pszDNString)); return builder.ToString(); } case 0x1c: { DnWithString str2 = new DnWithString(); Marshal.PtrToStructure(this.adsvalue.pointer.value, str2); string str3 = Marshal.PtrToStringUni(str2.pszStringValue); if (str3 == null) { str3 = ""; } StringBuilder builder3 = new StringBuilder(); builder3.Append("S:"); builder3.Append(str3.Length); builder3.Append(":"); builder3.Append(str3); builder3.Append(":"); builder3.Append(Marshal.PtrToStringUni(str2.pszDNString)); return builder3.ToString(); } } return new ArgumentException(Res.GetString("DSConvertFailed", new object[] { "0x" + Convert.ToString(this.LowInt64, 0x10), "0x" + Convert.ToString(this.adsvalue.dwType, 0x10) })); }
public object GetValue() { switch ((AdsType)adsvalue.dwType) { // Common for DNS and LDAP case AdsType.ADSTYPE_UTC_TIME: { SystemTime st = new SystemTime(); st.wYear = LowOfInt(adsvalue.generic.a); st.wMonth = HighOfInt(adsvalue.generic.a); st.wDayOfWeek = LowOfInt(adsvalue.generic.b); st.wDay = HighOfInt(adsvalue.generic.b); st.wHour = LowOfInt(adsvalue.generic.c); st.wMinute = HighOfInt(adsvalue.generic.c); st.wSecond = LowOfInt(adsvalue.generic.d); st.wMilliseconds = HighOfInt(adsvalue.generic.d); return(new DateTime(st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds)); } case AdsType.ADSTYPE_DN_WITH_BINARY: { DnWithBinary dnb = new DnWithBinary(); Marshal.PtrToStructure(adsvalue.pointer.value, dnb); byte[] bytes = new byte[dnb.dwLength]; Marshal.Copy(dnb.lpBinaryValue, bytes, 0, dnb.dwLength); StringBuilder strb = new StringBuilder(); StringBuilder binaryPart = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { string s = bytes[i].ToString("X", CultureInfo.InvariantCulture); if (s.Length == 1) { binaryPart.Append("0"); } binaryPart.Append(s); } strb.Append("B:"); strb.Append(binaryPart.Length); strb.Append(":"); strb.Append(binaryPart.ToString()); strb.Append(":"); strb.Append(Marshal.PtrToStringUni(dnb.pszDNString)); return(strb.ToString()); } case AdsType.ADSTYPE_DN_WITH_STRING: { DnWithString dns = new DnWithString(); Marshal.PtrToStructure(adsvalue.pointer.value, dns); string strValue = Marshal.PtrToStringUni(dns.pszStringValue); if (strValue == null) { strValue = ""; } StringBuilder strb = new StringBuilder(); strb.Append("S:"); strb.Append(strValue.Length); strb.Append(":"); strb.Append(strValue); strb.Append(":"); strb.Append(Marshal.PtrToStringUni(dns.pszDNString)); return(strb.ToString()); } case AdsType.ADSTYPE_DN_STRING: case AdsType.ADSTYPE_CASE_EXACT_STRING: case AdsType.ADSTYPE_CASE_IGNORE_STRING: case AdsType.ADSTYPE_PRINTABLE_STRING: case AdsType.ADSTYPE_NUMERIC_STRING: case AdsType.ADSTYPE_OBJECT_CLASS: // string return(Marshal.PtrToStringUni(adsvalue.pointer.value)); case AdsType.ADSTYPE_BOOLEAN: // bool return(adsvalue.generic.a != 0); case AdsType.ADSTYPE_INTEGER: // int return(adsvalue.generic.a); case AdsType.ADSTYPE_NT_SECURITY_DESCRIPTOR: case AdsType.ADSTYPE_OCTET_STRING: case AdsType.ADSTYPE_PROV_SPECIFIC: // byte[] int len = adsvalue.octetString.length; byte[] value = new byte[len]; Marshal.Copy(adsvalue.octetString.value, value, 0, len); return(value); case AdsType.ADSTYPE_INVALID: throw new InvalidOperationException(SR.DSConvertTypeInvalid); case AdsType.ADSTYPE_LARGE_INTEGER: return(LowInt64); // not used in LDAP case AdsType.ADSTYPE_CASEIGNORE_LIST: case AdsType.ADSTYPE_OCTET_LIST: case AdsType.ADSTYPE_PATH: case AdsType.ADSTYPE_POSTALADDRESS: case AdsType.ADSTYPE_TIMESTAMP: case AdsType.ADSTYPE_NETADDRESS: case AdsType.ADSTYPE_FAXNUMBER: case AdsType.ADSTYPE_EMAIL: case AdsType.ADSTYPE_BACKLINK: case AdsType.ADSTYPE_HOLD: case AdsType.ADSTYPE_TYPEDNAME: case AdsType.ADSTYPE_REPLICAPOINTER: case AdsType.ADSTYPE_UNKNOWN: return(new NotImplementedException(String.Format(CultureInfo.CurrentCulture, SR.DSAdsvalueTypeNYI, "0x" + Convert.ToString(adsvalue.dwType, 16)))); default: return(new ArgumentException(String.Format(CultureInfo.CurrentCulture, SR.DSConvertFailed, "0x" + Convert.ToString(LowInt64, 16), "0x" + Convert.ToString(adsvalue.dwType, 16)))); } }