WriteEnd() private method

private WriteEnd ( ) : void
return void
Beispiel #1
0
        // Commences the process of serializing the entire graph.
        // initialize the graph walker.
        internal void Serialize(Object graph, Header[] inHeaders, SoapWriter serWriter)
        {
            InternalST.Soap( this, "Serialize Entry 2 ",graph,((headers == null)?" no headers ": "headers"));

            serializationPermission.Demand();

            if (graph == null)
                throw new ArgumentNullException("graph",SoapUtil.GetResourceString("ArgumentNull_Graph"));

            if (serWriter == null)
                throw new ArgumentNullException("serWriter",String.Format(SoapUtil.GetResourceString("ArgumentNull_WithParamName"), "serWriter"));

            serObjectInfoInit = new SerObjectInfoInit();        
            this.serWriter = serWriter;
            this.headers = inHeaders;

            if (graph is IMethodMessage)
            {
                bRemoting = true;
                MethodBase methodBase = ((IMethodMessage)graph).MethodBase;
                if (methodBase != null)
                    serWriter.WriteXsdVersion(ProcessTypeAttributes(methodBase.ReflectedType));
                else
                    serWriter.WriteXsdVersion(XsdVersion.V2001);
            }
            else
                serWriter.WriteXsdVersion(XsdVersion.V2001);

            m_idGenerator = new ObjectIDGenerator();
            m_objectQueue = new Queue();

            if (graph is ISoapMessage)
            {
                // Fake method call is to be written
                bRemoting = true;
                ISoapMessage ismc = (ISoapMessage)graph;
                graph = new InternalSoapMessage(ismc.MethodName, ismc.XmlNameSpace, ismc.ParamNames, ismc.ParamValues, ismc.ParamTypes);
                headers = ismc.Headers;
            }


            InternalST.Soap( this, "Serialize New SerializedTypeTable");
            m_serializedTypeTable = new Hashtable();

            serWriter.WriteBegin();

            long headerId = 0;
            Object obj;
            long objectId;
            bool isNew;

            topId = m_idGenerator.GetId(graph, out isNew);

            if (headers != null)
                headerId = m_idGenerator.GetId(headers, out isNew);
            else
                headerId = -1;

            WriteSerializedStreamHeader(topId, headerId);

            InternalST.Soap( this, "Serialize Schedule 0");

            // Write out SerializedStream header
            if (!((headers == null) || (headers.Length == 0)))
            {
                ProcessHeaders(headerId);
            }

            m_objectQueue.Enqueue(graph);

            while ((obj = GetNext(out objectId))!=null)
            {
                InternalST.Soap( this, "Serialize GetNext ",obj);
                WriteObjectInfo objectInfo = null;

                // GetNext will return either an object or a WriteObjectInfo. 
                // A WriteObjectInfo is returned if this object was member of another object
                if (obj is WriteObjectInfo)
                {
                    InternalST.Soap( this, "Serialize GetNext recognizes WriteObjectInfo");
                    objectInfo = (WriteObjectInfo)obj;
                }
                else
                {
                    objectInfo = WriteObjectInfo.Serialize(obj, m_surrogates, m_context, serObjectInfoInit, m_formatterConverter, null);
                    objectInfo.assemId = GetAssemblyId(objectInfo);
                }

                objectInfo.objectId = objectId;
                NameInfo typeNameInfo = TypeToNameInfo(objectInfo);
                typeNameInfo.NIisTopLevelObject = true;
                if (bRemoting && obj  == graph)
                    typeNameInfo.NIisRemoteRecord = true;
                Write(objectInfo, typeNameInfo, typeNameInfo);
                PutNameInfo(typeNameInfo);
                objectInfo.ObjectEnd();
            }

            serWriter.WriteSerializationHeaderEnd();
            serWriter.WriteEnd();

            m_idGenerator = new ObjectIDGenerator();
            InternalST.Soap( this, "*************Serialize New SerializedTypeTable 2");
            m_serializedTypeTable = new System.Collections.Hashtable();

            InternalST.Soap( this, "Serialize Exit ");
        }
 internal void Serialize(object graph, Header[] inHeaders, SoapWriter serWriter)
 {
     object obj2;
     long num2;
     bool flag;
     serializationPermission.Demand();
     if (graph == null)
     {
         throw new ArgumentNullException("graph", SoapUtil.GetResourceString("ArgumentNull_Graph"));
     }
     if (serWriter == null)
     {
         throw new ArgumentNullException("serWriter", string.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("ArgumentNull_WithParamName"), new object[] { "serWriter" }));
     }
     this.serObjectInfoInit = new SerObjectInfoInit();
     this.serWriter = serWriter;
     this.headers = inHeaders;
     if (graph is IMethodMessage)
     {
         this.bRemoting = true;
         MethodBase methodBase = ((IMethodMessage) graph).MethodBase;
         if (methodBase != null)
         {
             serWriter.WriteXsdVersion(this.ProcessTypeAttributes(methodBase.ReflectedType));
         }
         else
         {
             serWriter.WriteXsdVersion(XsdVersion.V2001);
         }
     }
     else
     {
         serWriter.WriteXsdVersion(XsdVersion.V2001);
     }
     this.m_idGenerator = new ObjectIDGenerator();
     this.m_objectQueue = new Queue();
     if (graph is ISoapMessage)
     {
         this.bRemoting = true;
         ISoapMessage message = (ISoapMessage) graph;
         graph = new InternalSoapMessage(message.MethodName, message.XmlNameSpace, message.ParamNames, message.ParamValues, message.ParamTypes);
         this.headers = message.Headers;
     }
     this.m_serializedTypeTable = new Hashtable();
     serWriter.WriteBegin();
     long headerId = 0L;
     this.topId = this.m_idGenerator.GetId(graph, out flag);
     if (this.headers != null)
     {
         headerId = this.m_idGenerator.GetId(this.headers, out flag);
     }
     else
     {
         headerId = -1L;
     }
     this.WriteSerializedStreamHeader(this.topId, headerId);
     if ((this.headers != null) && (this.headers.Length != 0))
     {
         this.ProcessHeaders(headerId);
     }
     this.m_objectQueue.Enqueue(graph);
     while ((obj2 = this.GetNext(out num2)) != null)
     {
         WriteObjectInfo objectInfo = null;
         if (obj2 is WriteObjectInfo)
         {
             objectInfo = (WriteObjectInfo) obj2;
         }
         else
         {
             objectInfo = WriteObjectInfo.Serialize(obj2, this.m_surrogates, this.m_context, this.serObjectInfoInit, this.m_formatterConverter, null, this);
             objectInfo.assemId = this.GetAssemblyId(objectInfo);
         }
         objectInfo.objectId = num2;
         NameInfo memberNameInfo = this.TypeToNameInfo(objectInfo);
         memberNameInfo.NIisTopLevelObject = true;
         if (this.bRemoting && (obj2 == graph))
         {
             memberNameInfo.NIisRemoteRecord = true;
         }
         this.Write(objectInfo, memberNameInfo, memberNameInfo);
         this.PutNameInfo(memberNameInfo);
         objectInfo.ObjectEnd();
     }
     serWriter.WriteSerializationHeaderEnd();
     serWriter.WriteEnd();
     this.m_idGenerator = new ObjectIDGenerator();
     this.m_serializedTypeTable = new Hashtable();
     this.m_objectManager.RaiseOnSerializedEvent();
 }