System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run C# (CSharp) Method

Run() private method

private Run ( ) : void
return void
		internal void Run()
		{
			try
			{
				bool isLoop = true;
				ReadBegin();
				ReadSerializationHeaderRecord();
				while (isLoop)
				{
					SerTrace.Log( this, "Run loop ",((Enum)expectedType).ToString());
					BinaryHeaderEnum binaryHeaderEnum = BinaryHeaderEnum.Object;
					switch (expectedType)
					{
					case BinaryTypeEnum.ObjectUrt:
					case BinaryTypeEnum.ObjectUser:
					case BinaryTypeEnum.String:
					case BinaryTypeEnum.Object:
					case BinaryTypeEnum.ObjectArray:
					case BinaryTypeEnum.StringArray:
					case BinaryTypeEnum.PrimitiveArray:
						Byte inByte = dataReader.ReadByte();
						binaryHeaderEnum = (BinaryHeaderEnum)inByte;
						//Console.WriteLine("Beginning of loop "+((Enum)binaryHeaderEnum).ToString());
						switch (binaryHeaderEnum)
						{
						case BinaryHeaderEnum.Assembly:
						case BinaryHeaderEnum.CrossAppDomainAssembly:
							ReadAssembly(binaryHeaderEnum);
							break;
						case BinaryHeaderEnum.Object:
							ReadObject();
							break;
						case BinaryHeaderEnum.CrossAppDomainMap:
							ReadCrossAppDomainMap();
							break;
						case BinaryHeaderEnum.ObjectWithMap:
						case BinaryHeaderEnum.ObjectWithMapAssemId:
							ReadObjectWithMap(binaryHeaderEnum);
							break;
						case BinaryHeaderEnum.ObjectWithMapTyped:
						case BinaryHeaderEnum.ObjectWithMapTypedAssemId:
							ReadObjectWithMapTyped(binaryHeaderEnum);                                   
							break;
						case BinaryHeaderEnum.MethodCall:
						case BinaryHeaderEnum.MethodReturn:
							ReadMethodObject(binaryHeaderEnum);                                 
							break;
						case BinaryHeaderEnum.ObjectString:
						case BinaryHeaderEnum.CrossAppDomainString:
							ReadObjectString(binaryHeaderEnum);
							break;
						case BinaryHeaderEnum.Array:
						case BinaryHeaderEnum.ArraySinglePrimitive:
						case BinaryHeaderEnum.ArraySingleObject:
						case BinaryHeaderEnum.ArraySingleString:
							ReadArray(binaryHeaderEnum);
							break;
						case BinaryHeaderEnum.MemberPrimitiveTyped:
							ReadMemberPrimitiveTyped();
							break;                                                              
						case BinaryHeaderEnum.MemberReference:
							ReadMemberReference();
							break;
						case BinaryHeaderEnum.ObjectNull:
						case BinaryHeaderEnum.ObjectNullMultiple256:
						case BinaryHeaderEnum.ObjectNullMultiple:
							ReadObjectNull(binaryHeaderEnum);
							break;
						case BinaryHeaderEnum.MessageEnd:
							isLoop = false;
							ReadMessageEnd();
							ReadEnd();
							break;
						default:
							throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_BinaryHeader"),inByte));
						}
						break;
					case BinaryTypeEnum.Primitive:
						ReadMemberPrimitiveUnTyped();
						break;
					default:
						throw new SerializationException(Environment.GetResourceString("Serialization_TypeExpected"));

					}

					// If an assembly is encountered, don't advance
					// object Progress, 
					if (binaryHeaderEnum != BinaryHeaderEnum.Assembly)
					{
						// End of parse loop.
						bool isData = false;
						// Set up loop for next iteration.
						// If this is an object, and the end of object has been reached, then parse object end.
						while (!isData)
						{
							ObjectProgress op = (ObjectProgress)stack.Peek();
							if (op == null)
							{
								// No more object on stack, then the next record is a top level object
								SerTrace.Log( this, "Run loop op null, top level object");                      
								expectedType = BinaryTypeEnum.ObjectUrt;
								expectedTypeInformation = null;
								isData = true;
							}
							else
							{
								SerTrace.Log( this, "Run loop op not null, continue object");
								// Find out what record is expected next
								isData = op.GetNext(out op.expectedType, out op.expectedTypeInformation);
								expectedType = op.expectedType;
								expectedTypeInformation = op.expectedTypeInformation;
								SerTrace.Log( this, "Run loop opName ",op.name,", expectedType ",((Enum)expectedType).ToString()," expectedTypeInformation, ",expectedTypeInformation);

								SerTrace.Log( this, "Run ",isData);     
								if (!isData)
								{
									// No record is expected next, this is the end of an object or array
									SerTrace.Log( this, "Run End of Object ");
									stack.Dump();

									prs.Init();
									if (op.memberValueEnum == InternalMemberValueE.Nested)
									{
										// Nested object
										prs.PRparseTypeEnum = InternalParseTypeE.MemberEnd;
										prs.PRmemberTypeEnum = op.memberTypeEnum;
										prs.PRmemberValueEnum = op.memberValueEnum;
										objectReader.Parse(prs);
									}
									else
									{
										// Top level object
										prs.PRparseTypeEnum = InternalParseTypeE.ObjectEnd;
										prs.PRmemberTypeEnum = op.memberTypeEnum;
										prs.PRmemberValueEnum = op.memberValueEnum;                             
										objectReader.Parse(prs);
									}
									stack.Pop();
									PutOp(op);
								}
							}
						}
					}
				}
			}
			catch (EndOfStreamException)
			{

				// EOF should never be thrown since there is a MessageEnd record to stop parsing
				BCLDebug.Trace("BINARY", "\n*****EOF*************************\n");
				throw new SerializationException(Environment.GetResourceString("Serialization_StreamEnd"));             
			}
		}

Usage Example

コード例 #1
0
 internal object Deserialize(HeaderHandler handler, __BinaryParser serParser, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage)
 {
     if (serParser == null)
     {
         throw new ArgumentNullException("serParser", Environment.GetResourceString("ArgumentNull_WithParamName", (object)serParser));
     }
     this.bFullDeserialization = false;
     this.TopObject            = (object)null;
     this.topId             = 0L;
     this.bMethodCall       = false;
     this.bMethodReturn     = false;
     this.bIsCrossAppDomain = isCrossAppDomain;
     this.bSimpleAssembly   = this.formatterEnums.FEassemblyFormat == FormatterAssemblyStyle.Simple;
     if (fCheck)
     {
         CodeAccessPermission.Demand(PermissionType.SecuritySerialization);
     }
     this.handler = handler;
     serParser.Run();
     if (this.bFullDeserialization)
     {
         this.m_objectManager.DoFixups();
     }
     if (!this.bMethodCall && !this.bMethodReturn)
     {
         if (this.TopObject == null)
         {
             throw new SerializationException(Environment.GetResourceString("Serialization_TopObject"));
         }
         if (this.HasSurrogate(this.TopObject.GetType()) && this.topId != 0L)
         {
             this.TopObject = this.m_objectManager.GetObject(this.topId);
         }
         if (this.TopObject is IObjectReference)
         {
             this.TopObject = ((IObjectReference)this.TopObject).GetRealObject(this.m_context);
         }
     }
     if (this.bFullDeserialization)
     {
         this.m_objectManager.RaiseDeserializationEvent();
     }
     if (handler != null)
     {
         this.handlerObject = handler(this.headers);
     }
     if (this.bMethodCall)
     {
         this.TopObject = (object)this.binaryMethodCall.ReadArray(this.TopObject as object[], this.handlerObject);
     }
     else if (this.bMethodReturn)
     {
         this.TopObject = (object)this.binaryMethodReturn.ReadArray(this.TopObject as object[], methodCallMessage, this.handlerObject);
     }
     return(this.TopObject);
 }
All Usage Examples Of System.Runtime.Serialization.Formatters.Binary.__BinaryParser::Run