private void WriteXmlSchema(XmlWriter writer, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
 {
     IntPtr ptr;
     Bid.ScopeEnter(out ptr, "<ds.DataSet.WriteXmlSchema|INFO> %d#, schemaFormat=%d{ds.SchemaFormat}\n", this.ObjectID, (int) schemaFormat);
     try
     {
         if (writer != null)
         {
             XmlTreeGen gen = null;
             if (((schemaFormat == SchemaFormat.WebService) && (this.SchemaSerializationMode == System.Data.SchemaSerializationMode.ExcludeSchema)) && (writer.WriteState == WriteState.Element))
             {
                 gen = new XmlTreeGen(SchemaFormat.WebServiceSkipSchema);
             }
             else
             {
                 gen = new XmlTreeGen(schemaFormat);
             }
             gen.Save(this, null, writer, false, multipleTargetConverter);
         }
     }
     finally
     {
         Bid.ScopeLeave(ref ptr);
     }
 }
 private void WriteXmlSchema(TextWriter writer, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
 {
     if (writer != null)
     {
         XmlTextWriter writer2 = new XmlTextWriter(writer) {
             Formatting = Formatting.Indented
         };
         this.WriteXmlSchema(writer2, schemaFormat, multipleTargetConverter);
     }
 }
 private void WriteXmlSchema(string fileName, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
 {
     XmlTextWriter writer = new XmlTextWriter(fileName, null);
     try
     {
         writer.Formatting = Formatting.Indented;
         writer.WriteStartDocument(true);
         this.WriteXmlSchema(writer, schemaFormat, multipleTargetConverter);
         writer.WriteEndDocument();
     }
     finally
     {
         writer.Close();
     }
 }
        private void WriteXmlSchema(XmlWriter writer, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
        {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataSet.WriteXmlSchema|INFO> %d#, schemaFormat=%d{ds.SchemaFormat}\n", ObjectID, (int)schemaFormat);
            try {
                // Generate SchemaTree and write it out
                if (writer != null) {
                    XmlTreeGen treeGen = null;
                    if (schemaFormat == SchemaFormat.WebService &&
                        SchemaSerializationMode == SchemaSerializationMode.ExcludeSchema &&
                        writer.WriteState == WriteState.Element) {
                        treeGen = new XmlTreeGen(SchemaFormat.WebServiceSkipSchema);
                    }
                    else {
                        treeGen = new XmlTreeGen(schemaFormat);
                    }

                    treeGen.Save(this, (DataTable)null, writer, false, multipleTargetConverter);
                }
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
 public void WriteXmlSchema(XmlWriter writer, Converter<Type, string> multipleTargetConverter)
 {
     ADP.CheckArgumentNull(multipleTargetConverter, "multipleTargetConverter");
     this.WriteXmlSchema(writer, SchemaFormat.Public, multipleTargetConverter);
 }
示例#6
0
        // Object member encountered in stream
        private void ParseMember(ParseRecord pr)
        {
            ParseRecord objectPr = (ParseRecord)_stack.Peek();
            string      objName  = objectPr?._name;

            switch (pr._memberTypeEnum)
            {
            case InternalMemberTypeE.Item:
                ParseArrayMember(pr);
                return;

            case InternalMemberTypeE.Field:
                break;
            }

            //if ((pr.PRdtType == null) && !objectPr.PRobjectInfo.isSi)
            if (pr._dtType == null && objectPr._objectInfo._isTyped)
            {
                pr._dtType = objectPr._objectInfo.GetType(pr._name);

                if (pr._dtType != null)
                {
                    pr._dtTypeCode = Converter.ToCode(pr._dtType);
                }
            }

            if (pr._memberValueEnum == InternalMemberValueE.Null)
            {
                // Value is Null
                objectPr._objectInfo.AddValue(pr._name, null, ref objectPr._si, ref objectPr._memberData);
            }
            else if (pr._memberValueEnum == InternalMemberValueE.Nested)
            {
                ParseObject(pr);
                _stack.Push(pr);

                if ((pr._objectInfo != null) && pr._objectInfo._objectType != null && (pr._objectInfo._objectType.GetTypeInfo().IsValueType))
                {
                    pr._isValueTypeFixup = true;                                                            //Valuefixup
                    ValueFixupStack.Push(new ValueFixup(objectPr._newObj, pr._name, objectPr._objectInfo)); //valuefixup
                }
                else
                {
                    objectPr._objectInfo.AddValue(pr._name, pr._newObj, ref objectPr._si, ref objectPr._memberData);
                }
            }
            else if (pr._memberValueEnum == InternalMemberValueE.Reference)
            {
                // See if object has already been instantiated
                object refObj = _objectManager.GetObject(pr._idRef);
                if (refObj == null)
                {
                    objectPr._objectInfo.AddValue(pr._name, null, ref objectPr._si, ref objectPr._memberData);
                    objectPr._objectInfo.RecordFixup(objectPr._objectId, pr._name, pr._idRef); // Object not instantiated
                }
                else
                {
                    objectPr._objectInfo.AddValue(pr._name, refObj, ref objectPr._si, ref objectPr._memberData);
                }
            }

            else if (pr._memberValueEnum == InternalMemberValueE.InlineValue)
            {
                // Primitive type or String
                if (ReferenceEquals(pr._dtType, Converter.s_typeofString))
                {
                    ParseString(pr, objectPr);
                    objectPr._objectInfo.AddValue(pr._name, pr._value, ref objectPr._si, ref objectPr._memberData);
                }
                else if (pr._dtTypeCode == InternalPrimitiveTypeE.Invalid)
                {
                    // The member field was an object put the value is Inline either  bin.Base64 or invalid
                    if (pr._arrayTypeEnum == InternalArrayTypeE.Base64)
                    {
                        objectPr._objectInfo.AddValue(pr._name, Convert.FromBase64String(pr._value), ref objectPr._si, ref objectPr._memberData);
                    }
                    else if (ReferenceEquals(pr._dtType, Converter.s_typeofObject))
                    {
                        throw new SerializationException(SR.Format(SR.Serialization_TypeMissing, pr._name));
                    }
                    else
                    {
                        ParseString(pr, objectPr); // Register the object if it has an objectId
                        // Object Class with no memberInfo data
                        // only special case where AddValue is needed?
                        if (ReferenceEquals(pr._dtType, Converter.s_typeofSystemVoid))
                        {
                            objectPr._objectInfo.AddValue(pr._name, pr._dtType, ref objectPr._si, ref objectPr._memberData);
                        }
                        else if (objectPr._objectInfo._isSi)
                        {
                            // ISerializable are added as strings, the conversion to type is done by the
                            // ISerializable object
                            objectPr._objectInfo.AddValue(pr._name, pr._value, ref objectPr._si, ref objectPr._memberData);
                        }
                    }
                }
                else
                {
                    object var = pr._varValue != null ?
                                 pr._varValue :
                                 Converter.FromString(pr._value, pr._dtTypeCode);
                    objectPr._objectInfo.AddValue(pr._name, var, ref objectPr._si, ref objectPr._memberData);
                }
            }
            else
            {
                ParseError(pr, objectPr);
            }
        }
        private void WriteXmlSchema(TextWriter writer, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
        {
            if (writer == null)
                return;

            XmlTextWriter w = new XmlTextWriter(writer);
            w.Formatting = Formatting.Indented;

            this.WriteXmlSchema(w, schemaFormat, multipleTargetConverter);
        }
示例#8
0
        // Array object encountered in stream
        private void ParseArray(ParseRecord pr)
        {
            long genId = pr._objectId;

            if (pr._arrayTypeEnum == InternalArrayTypeE.Base64)
            {
                // ByteArray
                pr._newObj = pr._value.Length > 0 ?
                             Convert.FromBase64String(pr._value) :
                             Array.Empty <byte>();

                if (_stack.Peek() == pr)
                {
                    _stack.Pop();
                }
                if (pr._objectPositionEnum == InternalObjectPositionE.Top)
                {
                    TopObject = pr._newObj;
                }

                ParseRecord parentPr = (ParseRecord)_stack.Peek();

                // Base64 can be registered at this point because it is populated
                RegisterObject(pr._newObj, pr, parentPr);
            }
            else if ((pr._newObj != null) && Converter.IsWriteAsByteArray(pr._arrayElementTypeCode))
            {
                // Primtive typed Array has already been read
                if (pr._objectPositionEnum == InternalObjectPositionE.Top)
                {
                    TopObject = pr._newObj;
                }

                ParseRecord parentPr = (ParseRecord)_stack.Peek();

                // Primitive typed array can be registered at this point because it is populated
                RegisterObject(pr._newObj, pr, parentPr);
            }
            else if ((pr._arrayTypeEnum == InternalArrayTypeE.Jagged) || (pr._arrayTypeEnum == InternalArrayTypeE.Single))
            {
                // Multidimensional jagged array or single array
                bool couldBeValueType = true;
                if ((pr._lowerBoundA == null) || (pr._lowerBoundA[0] == 0))
                {
                    if (ReferenceEquals(pr._arrayElementType, Converter.s_typeofString))
                    {
                        pr._objectA      = new string[pr._lengthA[0]];
                        pr._newObj       = pr._objectA;
                        couldBeValueType = false;
                    }
                    else if (ReferenceEquals(pr._arrayElementType, Converter.s_typeofObject))
                    {
                        pr._objectA      = new object[pr._lengthA[0]];
                        pr._newObj       = pr._objectA;
                        couldBeValueType = false;
                    }
                    else if (pr._arrayElementType != null)
                    {
                        pr._newObj = Array.CreateInstance(pr._arrayElementType, pr._lengthA[0]);
                    }
                    pr._isLowerBound = false;
                }
                else
                {
                    if (pr._arrayElementType != null)
                    {
                        pr._newObj = Array.CreateInstance(pr._arrayElementType, pr._lengthA, pr._lowerBoundA);
                    }
                    pr._isLowerBound = true;
                }

                if (pr._arrayTypeEnum == InternalArrayTypeE.Single)
                {
                    if (!pr._isLowerBound && (Converter.IsWriteAsByteArray(pr._arrayElementTypeCode)))
                    {
                        pr._primitiveArray = new PrimitiveArray(pr._arrayElementTypeCode, (Array)pr._newObj);
                    }
                    else if (couldBeValueType && pr._arrayElementType != null)
                    {
                        if (!pr._arrayElementType.GetTypeInfo().IsValueType&& !pr._isLowerBound)
                        {
                            pr._objectA = (object[])pr._newObj;
                        }
                    }
                }

                // For binary, headers comes in as an array of header objects
                if (pr._objectPositionEnum == InternalObjectPositionE.Headers)
                {
                    _headers = (Header[])pr._newObj;
                }

                pr._indexMap = new int[1];
            }
            else if (pr._arrayTypeEnum == InternalArrayTypeE.Rectangular)
            {
                // Rectangle array

                pr._isLowerBound = false;
                if (pr._lowerBoundA != null)
                {
                    for (int i = 0; i < pr._rank; i++)
                    {
                        if (pr._lowerBoundA[i] != 0)
                        {
                            pr._isLowerBound = true;
                        }
                    }
                }

                if (pr._arrayElementType != null)
                {
                    pr._newObj = !pr._isLowerBound ?
                                 Array.CreateInstance(pr._arrayElementType, pr._lengthA) :
                                 Array.CreateInstance(pr._arrayElementType, pr._lengthA, pr._lowerBoundA);
                }

                // Calculate number of items
                int sum = 1;
                for (int i = 0; i < pr._rank; i++)
                {
                    sum = sum * pr._lengthA[i];
                }
                pr._indexMap       = new int[pr._rank];
                pr._rectangularMap = new int[pr._rank];
                pr._linearlength   = sum;
            }
            else
            {
                throw new SerializationException(SR.Format(SR.Serialization_ArrayType, pr._arrayTypeEnum));
            }
        }
示例#9
0
        // Array object item encountered in stream
        private void ParseArrayMember(ParseRecord pr)
        {
            ParseRecord objectPr = (ParseRecord)_stack.Peek();

            // Set up for inserting value into correct array position
            if (objectPr._arrayTypeEnum == InternalArrayTypeE.Rectangular)
            {
                if (objectPr._memberIndex > 0)
                {
                    NextRectangleMap(objectPr); // Rectangle array, calculate position in array
                }
                if (objectPr._isLowerBound)
                {
                    for (int i = 0; i < objectPr._rank; i++)
                    {
                        objectPr._indexMap[i] = objectPr._rectangularMap[i] + objectPr._lowerBoundA[i];
                    }
                }
            }
            else
            {
                objectPr._indexMap[0] = !objectPr._isLowerBound ?
                                        objectPr._memberIndex :                           // Zero based array
                                        objectPr._lowerBoundA[0] + objectPr._memberIndex; // Lower Bound based array
            }

            // Set Array element according to type of element

            if (pr._memberValueEnum == InternalMemberValueE.Reference)
            {
                // Object Reference

                // See if object has already been instantiated
                object refObj = _objectManager.GetObject(pr._idRef);
                if (refObj == null)
                {
                    // Object not instantiated
                    // Array fixup manager
                    int[] fixupIndex = new int[objectPr._rank];
                    Array.Copy(objectPr._indexMap, 0, fixupIndex, 0, objectPr._rank);

                    _objectManager.RecordArrayElementFixup(objectPr._objectId, fixupIndex, pr._idRef);
                }
                else
                {
                    if (objectPr._objectA != null)
                    {
                        objectPr._objectA[objectPr._indexMap[0]] = refObj;
                    }
                    else
                    {
                        ((Array)objectPr._newObj).SetValue(refObj, objectPr._indexMap); // Object has been instantiated
                    }
                }
            }
            else if (pr._memberValueEnum == InternalMemberValueE.Nested)
            {
                //Set up dtType for ParseObject
                if (pr._dtType == null)
                {
                    pr._dtType = objectPr._arrayElementType;
                }

                ParseObject(pr);
                _stack.Push(pr);

                if (objectPr._arrayElementType != null)
                {
                    if ((objectPr._arrayElementType.GetTypeInfo().IsValueType) && (pr._arrayElementTypeCode == InternalPrimitiveTypeE.Invalid))
                    {
                        pr._isValueTypeFixup = true;                                                       //Valuefixup
                        ValueFixupStack.Push(new ValueFixup((Array)objectPr._newObj, objectPr._indexMap)); //valuefixup
                    }
                    else
                    {
                        if (objectPr._objectA != null)
                        {
                            objectPr._objectA[objectPr._indexMap[0]] = pr._newObj;
                        }
                        else
                        {
                            ((Array)objectPr._newObj).SetValue(pr._newObj, objectPr._indexMap);
                        }
                    }
                }
            }
            else if (pr._memberValueEnum == InternalMemberValueE.InlineValue)
            {
                if ((ReferenceEquals(objectPr._arrayElementType, Converter.s_typeofString)) || (ReferenceEquals(pr._dtType, Converter.s_typeofString)))
                {
                    // String in either a string array, or a string element of an object array
                    ParseString(pr, objectPr);
                    if (objectPr._objectA != null)
                    {
                        objectPr._objectA[objectPr._indexMap[0]] = pr._value;
                    }
                    else
                    {
                        ((Array)objectPr._newObj).SetValue(pr._value, objectPr._indexMap);
                    }
                }
                else if (objectPr._isArrayVariant)
                {
                    // Array of type object
                    if (pr._keyDt == null)
                    {
                        throw new SerializationException(SR.Serialization_ArrayTypeObject);
                    }

                    object var = null;

                    if (ReferenceEquals(pr._dtType, Converter.s_typeofString))
                    {
                        ParseString(pr, objectPr);
                        var = pr._value;
                    }
                    else if (ReferenceEquals(pr._dtTypeCode, InternalPrimitiveTypeE.Invalid))
                    {
                        CheckSerializable(pr._dtType);
                        // Not nested and invalid, so it is an empty object
                        var = FormatterServices.GetUninitializedObject(pr._dtType);
                    }
                    else
                    {
                        var = pr._varValue != null ?
                              pr._varValue :
                              Converter.FromString(pr._value, pr._dtTypeCode);
                    }
                    if (objectPr._objectA != null)
                    {
                        objectPr._objectA[objectPr._indexMap[0]] = var;
                    }
                    else
                    {
                        ((Array)objectPr._newObj).SetValue(var, objectPr._indexMap); // Primitive type
                    }
                }
                else
                {
                    // Primitive type
                    if (objectPr._primitiveArray != null)
                    {
                        // Fast path for Soap primitive arrays. Binary was handled in the BinaryParser
                        objectPr._primitiveArray.SetValue(pr._value, objectPr._indexMap[0]);
                    }
                    else
                    {
                        object var = pr._varValue != null ?
                                     pr._varValue :
                                     Converter.FromString(pr._value, objectPr._arrayElementTypeCode);
                        if (objectPr._objectA != null)
                        {
                            objectPr._objectA[objectPr._indexMap[0]] = var;
                        }
                        else
                        {
                            ((Array)objectPr._newObj).SetValue(var, objectPr._indexMap); // Primitive type
                        }
                    }
                }
            }
            else if (pr._memberValueEnum == InternalMemberValueE.Null)
            {
                objectPr._memberIndex += pr._consecutiveNullArrayEntryCount - 1; //also incremented again below
            }
            else
            {
                ParseError(pr, objectPr);
            }

            objectPr._memberIndex++;
        }
示例#10
0
        // Given the wire type information, returns the actual type and additional information
        internal static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum,
                                          object typeInformation,
                                          ObjectReader objectReader,
                                          BinaryAssemblyInfo assemblyInfo,
                                          out InternalPrimitiveTypeE primitiveTypeEnum,
                                          out string typeString,
                                          out Type type,
                                          out bool isVariant)
        {
            isVariant         = false;
            primitiveTypeEnum = InternalPrimitiveTypeE.Invalid;
            typeString        = null;
            type = null;

            switch (binaryTypeEnum)
            {
            case BinaryTypeEnum.Primitive:
                primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation;
                typeString        = Converter.ToComType(primitiveTypeEnum);
                type = Converter.ToType(primitiveTypeEnum);
                break;

            case BinaryTypeEnum.String:
                type = Converter.s_typeofString;
                break;

            case BinaryTypeEnum.Object:
                type      = Converter.s_typeofObject;
                isVariant = true;
                break;

            case BinaryTypeEnum.ObjectArray:
                type = Converter.s_typeofObjectArray;
                break;

            case BinaryTypeEnum.StringArray:
                type = Converter.s_typeofStringArray;
                break;

            case BinaryTypeEnum.PrimitiveArray:
                primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation;
                type = Converter.ToArrayType(primitiveTypeEnum);
                break;

            case BinaryTypeEnum.ObjectUser:
            case BinaryTypeEnum.ObjectUrt:
                if (typeInformation != null)
                {
                    typeString = typeInformation.ToString();
                    type       = objectReader.GetType(assemblyInfo, typeString);
                    if (ReferenceEquals(type, Converter.s_typeofObject))
                    {
                        isVariant = true;
                    }
                }
                break;

            default:
                throw new SerializationException(SR.Format(SR.Serialization_TypeRead, binaryTypeEnum.ToString()));
            }
        }
示例#11
0
        // From the type create the BinaryTypeEnum and typeInformation which describes the type on the wire
        internal static BinaryTypeEnum GetBinaryTypeInfo(Type type, WriteObjectInfo objectInfo, string typeName, ObjectWriter objectWriter, out object typeInformation, out int assemId)
        {
            BinaryTypeEnum binaryTypeEnum;

            assemId         = 0;
            typeInformation = null;

            if (ReferenceEquals(type, Converter.s_typeofString))
            {
                binaryTypeEnum = BinaryTypeEnum.String;
            }
            else if (((objectInfo == null) || ((objectInfo != null) && !objectInfo._isSi)) && (ReferenceEquals(type, Converter.s_typeofObject)))
            {
                // If objectInfo.Si then can be a surrogate which will change the type
                binaryTypeEnum = BinaryTypeEnum.Object;
            }
            else if (ReferenceEquals(type, Converter.s_typeofStringArray))
            {
                binaryTypeEnum = BinaryTypeEnum.StringArray;
            }
            else if (ReferenceEquals(type, Converter.s_typeofObjectArray))
            {
                binaryTypeEnum = BinaryTypeEnum.ObjectArray;
            }
            else if (Converter.IsPrimitiveArray(type, out typeInformation))
            {
                binaryTypeEnum = BinaryTypeEnum.PrimitiveArray;
            }
            else
            {
                InternalPrimitiveTypeE primitiveTypeEnum = objectWriter.ToCode(type);
                switch (primitiveTypeEnum)
                {
                case InternalPrimitiveTypeE.Invalid:
                    string assembly = null;
                    if (objectInfo == null)
                    {
                        assembly        = type.Assembly.FullName;
                        typeInformation = type.FullName;
                    }
                    else
                    {
                        assembly        = objectInfo.GetAssemblyString();
                        typeInformation = objectInfo.GetTypeFullName();
                    }

                    if (assembly.Equals(Converter.s_urtAssemblyString) || assembly.Equals(Converter.s_urtAlternativeAssemblyString))
                    {
                        binaryTypeEnum = BinaryTypeEnum.ObjectUrt;
                        assemId        = 0;
                    }
                    else
                    {
                        binaryTypeEnum = BinaryTypeEnum.ObjectUser;
                        Debug.Assert(objectInfo != null, "[BinaryConverter.GetBinaryTypeInfo]objectInfo null for user object");
                        assemId = (int)objectInfo._assemId;
                        if (assemId == 0)
                        {
                            throw new SerializationException(SR.Format(SR.Serialization_AssemblyId, typeInformation));
                        }
                    }
                    break;

                default:
                    binaryTypeEnum  = BinaryTypeEnum.Primitive;
                    typeInformation = primitiveTypeEnum;
                    break;
                }
            }

            return(binaryTypeEnum);
        }
示例#12
0
文件: DataSet.cs 项目: dotnet/corefx
        private void WriteXmlSchema(XmlWriter writer, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataSet.WriteXmlSchema|INFO> {0}, schemaFormat={1}", ObjectID, schemaFormat);
            try
            {
                // Generate SchemaTree and write it out
                if (writer != null)
                {
                    XmlTreeGen treeGen = null;
                    if (schemaFormat == SchemaFormat.WebService &&
                        SchemaSerializationMode == SchemaSerializationMode.ExcludeSchema &&
                        writer.WriteState == WriteState.Element)
                    {
                        treeGen = new XmlTreeGen(SchemaFormat.WebServiceSkipSchema);
                    }
                    else
                    {
                        treeGen = new XmlTreeGen(schemaFormat);
                    }

                    treeGen.Save(this, null, writer, false, multipleTargetConverter);
                }
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }
示例#13
0
文件: DataSet.cs 项目: dotnet/corefx
        private void WriteXmlSchema(Stream stream, SchemaFormat schemaFormat, Converter<Type, string> multipleTargetConverter)
        {
            if (stream == null)
            {
                return;
            }

            XmlTextWriter w = new XmlTextWriter(stream, null);
            w.Formatting = Formatting.Indented;

            WriteXmlSchema(w, schemaFormat, multipleTargetConverter);
        }
示例#14
0
文件: DataSet.cs 项目: dotnet/corefx
 /// <summary>Writes the <see cref='DataSet'/> structure as an XML schema to a <see cref='TextWriter'/> object.</summary>
 /// <param name="writer">The <see cref='TextWriter'/> object with which to write.</param>
 /// <param name="multipleTargetConverter">A delegate used to convert <see cref='Type'/> into string.</param>
 public void WriteXmlSchema(TextWriter writer, Converter<Type, string> multipleTargetConverter)
 {
     ADP.CheckArgumentNull(multipleTargetConverter, nameof(multipleTargetConverter));
     WriteXmlSchema(writer, SchemaFormat.Public, multipleTargetConverter);
 }