Beispiel #1
0
 private static string FormatAttributeName(string prefix, string attribute)
 {
     return(XmlUtility.AddPrefix(prefix, attribute));
 }
Beispiel #2
0
        public static void Serialize(XmlDictionaryWriter writer, object value)
        {
            string str;

            byte[] numArray;
            object obj;
            bool   flag  = false;
            bool   flag1 = false;

            writer.LookupPrefix("http://www.w3.org/2001/XMLSchema");
            writer.WriteStartElement("value", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
            if (value.GetType() != typeof(byte[]))
            {
                TypeCode typeCode = Type.GetTypeCode(value.GetType());
                if (typeCode == TypeCode.Boolean)
                {
                    str  = "boolean";
                    flag = false;
                    if ((bool)value)
                    {
                        obj = "true";
                    }
                    else
                    {
                        obj = "false";
                    }
                    value = obj;
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                else if (typeCode == TypeCode.Char || typeCode == TypeCode.SByte || typeCode == TypeCode.Int16 || typeCode == TypeCode.UInt16 || typeCode == TypeCode.Int32 || typeCode == TypeCode.UInt32)
                {
                    str  = "int";
                    flag = false;
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                else if (typeCode == TypeCode.Byte)
                {
                    str   = "base64Binary";
                    flag  = true;
                    flag1 = false;
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                else if (typeCode == TypeCode.Int64 || typeCode == TypeCode.UInt64)
                {
                    str  = "long";
                    flag = false;
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                else if (typeCode == TypeCode.Single || typeCode == TypeCode.Double || typeCode == TypeCode.Decimal || typeCode == (TypeCode.Object | TypeCode.DateTime))
                {
                }
                else if (typeCode == TypeCode.DateTime)
                {
                    str   = "dateTime";
                    flag  = false;
                    value = XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.Utc);
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                else if (typeCode == TypeCode.String)
                {
                    str  = "string";
                    flag = false;
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                object[] objArray = new object[1];
                objArray[0] = value.GetType().ToString();
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ADWSXmlParserUnexpectedElement, objArray));
            }
            else
            {
                flag  = true;
                flag1 = true;
                str   = "base64Binary";
            }
            XmlUtility.WriteXsiTypeAttribute(writer, str);
            if (!flag)
            {
                writer.WriteString(value.ToString());
            }
            else
            {
                if (!flag1)
                {
                    numArray    = new byte[1];
                    numArray[0] = (byte)value;
                }
                else
                {
                    numArray = (byte[])value;
                }
                writer.WriteBase64(numArray, 0, (int)numArray.Length);
            }
            writer.WriteEndElement();
        }
Beispiel #3
0
        private static void DeserializeAttributeElement(XmlReader reader, ResultSerializer.ResultDialect dialect, ADWSResultEntry entry)
        {
            string str  = null;
            string str1 = null;
            string str2 = null;
            string str3 = null;
            bool   flag = false;

            if (string.IsNullOrEmpty(reader.Prefix))
            {
                if (!string.Equals(reader.NamespaceURI, "http://schemas.microsoft.com/2008/1/ActiveDirectory", StringComparison.Ordinal))
                {
                    flag = false;
                }
                else
                {
                    flag = true;
                }
            }
            else
            {
                string str4 = reader.LookupNamespace(reader.Prefix);
                if (!string.Equals(str4, "http://schemas.microsoft.com/2008/1/ActiveDirectory", StringComparison.Ordinal))
                {
                    flag = false;
                    //reader.Prefix;
                }
                else
                {
                    flag = true;
                    //reader.Prefix;
                }
            }
            if (!flag)
            {
                bool   flag1 = false;
                string str5  = string.Intern(reader.LocalName);
                if (str5.Equals("objectClass", StringComparison.OrdinalIgnoreCase))
                {
                    flag1 = true;
                }
                XmlUtility.DeserializeLdapAttributeOption(reader, ref str5);
                object obj = null;
                reader.Read();
                ADValueSerializer.Deserialize(reader, flag1, out obj);
                entry.DirObject.SetValue(str5, new ADPropertyValueCollection(obj));
                reader.ReadEndElement();
                return;
            }
            else
            {
                string localName = reader.LocalName;
                if (!string.Equals(localName, "container-hierarchy-parent", StringComparison.Ordinal))
                {
                    if (!string.Equals(localName, "distinguishedName", StringComparison.Ordinal))
                    {
                        if (!string.Equals(localName, "relativeDistinguishedName", StringComparison.Ordinal))
                        {
                            if (!string.Equals(localName, "objectReferenceProperty", StringComparison.Ordinal))
                            {
                                throw new ArgumentException(string.Format(StringResources.ADWSXmlParserInvalidAttribute, localName));
                            }
                            else
                            {
                                reader.ReadStartElement("objectReferenceProperty", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
                                ADValueSerializer.DeserializeSingleValue <string>(reader, out str3);
                                entry.ObjectReferenceProperty = str3;
                                reader.ReadEndElement();
                                return;
                            }
                        }
                        else
                        {
                            reader.ReadStartElement("relativeDistinguishedName", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
                            ADValueSerializer.DeserializeSingleValue <string>(reader, out str2);
                            entry.RelativeDistinguishedName = str2;
                            reader.ReadEndElement();
                            return;
                        }
                    }
                    else
                    {
                        reader.ReadStartElement("distinguishedName", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
                        ADValueSerializer.DeserializeSingleValue <string>(reader, out str1);
                        entry.DistinguishedName = str1;
                        reader.ReadEndElement();
                        return;
                    }
                }
                else
                {
                    reader.ReadStartElement("container-hierarchy-parent", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
                    ADValueSerializer.DeserializeSingleValue <string>(reader, out str);
                    entry.ParentContainer = str;
                    reader.ReadEndElement();
                    return;
                }
            }
        }