Ejemplo n.º 1
0
        public void SetMemberValue(ObjectManager manager, MemberInfo member, object value)
        {
            if (member is FieldInfo)
            {
                ((FieldInfo)member).SetValue(ObjectInstance, value);
            }
            else if (member is PropertyInfo)
            {
                ((PropertyInfo)member).SetValue(ObjectInstance, value, null);
            }
            else
            {
                throw new SerializationException("Cannot perform fixup");
            }

            if (Member != null)
            {
                ObjectRecord containerRecord = manager.GetObjectRecord(IdOfContainingObj);
                if (containerRecord.IsRegistered)
                {
                    containerRecord.SetMemberValue(manager, Member, ObjectInstance);
                }
            }
            else if (ArrayIndex != null)
            {
                ObjectRecord containerRecord = manager.GetObjectRecord(IdOfContainingObj);
                if (containerRecord.IsRegistered)
                {
                    containerRecord.SetArrayValue(manager, ObjectInstance, ArrayIndex);
                }
            }
        }
Ejemplo n.º 2
0
        private void RegisterObjectInternal(object obj, ObjectRecord record)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (record.IsRegistered)
            {
                if (record.OriginalObject != obj)
                {
                    throw new SerializationException("An object with Id " + record.ObjectID + " has already been registered");
                }
                else
                {
                    return;
                }
            }

            record.ObjectInstance = obj;
            record.OriginalObject = obj;

            if (obj is IObjectReference)
            {
                record.Status = ObjectRecordStatus.ReferenceUnsolved;
            }
            else
            {
                record.Status = ObjectRecordStatus.ReferenceSolved;
            }

            if (_selector != null)
            {
                record.Surrogate = _selector.GetSurrogate(
                    obj.GetType(), _context, out record.SurrogateSelector);
                if (record.Surrogate != null)
                {
                    record.Status = ObjectRecordStatus.ReferenceUnsolved;
                }
            }

            record.DoFixups(true, this, false);
            record.DoFixups(false, this, false);
            _registeredObjectsCount++;

            // Adds the object to the chain of registered objects. This chain
            // is needed to be able to to perform the final fixups in the right order

            if (_objectRecordChain == null)
            {
                _objectRecordChain = record;
                _lastObjectRecord  = record;
            }
            else
            {
                _lastObjectRecord.Next = record;
                _lastObjectRecord      = record;
            }
        }
Ejemplo n.º 3
0
        /// <summary>Returns the object with the specified object ID.</summary>
        /// <returns>The object with the specified object ID if it has been previously stored or null if no such object has been registered.</returns>
        /// <param name="objectID">The ID of the requested object. </param>
        /// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="objectID" /> parameter is less than or equal to zero. </exception>
        public virtual object GetObject(long objectID)
        {
            if (objectID <= 0L)
            {
                throw new ArgumentOutOfRangeException("objectID", "The objectID parameter is less than or equal to zero");
            }
            ObjectRecord objectRecord = (ObjectRecord)this._objectRecords[objectID];

            if (objectRecord == null || !objectRecord.IsRegistered)
            {
                return(null);
            }
            return(objectRecord.ObjectInstance);
        }
Ejemplo n.º 4
0
        /// <summary>Registers an object as it is deserialized, associating it with <paramref name="objectID" />, and recording the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> used with it.</summary>
        /// <param name="obj">The object to register. </param>
        /// <param name="objectID">The ID of the object to register. </param>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> used if <paramref name="obj" /> implements <see cref="T:System.Runtime.Serialization.ISerializable" /> or has a <see cref="T:System.Runtime.Serialization.ISerializationSurrogate" />. <paramref name="info" /> will be completed with any required fixup information and then passed to the required object when that object is completed. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="obj" /> parameter is null. </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="objectID" /> parameter is less than or equal to zero. </exception>
        /// <exception cref="T:System.Runtime.Serialization.SerializationException">The <paramref name="objectID" /> has already been registered for an object other than <paramref name="obj" />. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="MemberAccess" />
        /// </PermissionSet>
        public void RegisterObject(object obj, long objectID, SerializationInfo info)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj", "The obj parameter is null.");
            }
            if (objectID <= 0L)
            {
                throw new ArgumentOutOfRangeException("objectID", "The objectID parameter is less than or equal to zero");
            }
            ObjectRecord objectRecord = this.GetObjectRecord(objectID);

            objectRecord.Info = info;
            this.RegisterObjectInternal(obj, objectRecord);
        }
Ejemplo n.º 5
0
 private void RegisterObjectInternal(object obj, ObjectRecord record)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     if (!record.IsRegistered)
     {
         record.ObjectInstance = obj;
         record.OriginalObject = obj;
         if (obj is IObjectReference)
         {
             record.Status = ObjectRecordStatus.ReferenceUnsolved;
         }
         else
         {
             record.Status = ObjectRecordStatus.ReferenceSolved;
         }
         if (this._selector != null)
         {
             record.Surrogate = this._selector.GetSurrogate(obj.GetType(), this._context, out record.SurrogateSelector);
             if (record.Surrogate != null)
             {
                 record.Status = ObjectRecordStatus.ReferenceUnsolved;
             }
         }
         record.DoFixups(true, this, false);
         record.DoFixups(false, this, false);
         this._registeredObjectsCount++;
         if (this._objectRecordChain == null)
         {
             this._objectRecordChain = record;
             this._lastObjectRecord  = record;
         }
         else
         {
             this._lastObjectRecord.Next = record;
             this._lastObjectRecord      = record;
         }
         return;
     }
     if (record.OriginalObject != obj)
     {
         throw new SerializationException("An object with Id " + record.ObjectID + " has already been registered");
     }
 }
Ejemplo n.º 6
0
 /// <summary>Raises the deserialization event to any registered object that implements <see cref="T:System.Runtime.Serialization.IDeserializationCallback" />.</summary>
 public virtual void RaiseDeserializationEvent()
 {
     for (int i = this._onDeserializedCallbackRecords.Count - 1; i >= 0; i--)
     {
         ObjectRecord objectRecord = (ObjectRecord)this._onDeserializedCallbackRecords[i];
         this.RaiseOnDeserializedEvent(objectRecord.OriginalObject);
     }
     for (int j = this._deserializedRecords.Count - 1; j >= 0; j--)
     {
         ObjectRecord             objectRecord2           = (ObjectRecord)this._deserializedRecords[j];
         IDeserializationCallback deserializationCallback = objectRecord2.OriginalObject as IDeserializationCallback;
         if (deserializationCallback != null)
         {
             deserializationCallback.OnDeserialization(this);
         }
     }
 }
Ejemplo n.º 7
0
 public virtual void RaiseDeserializationEvent()
 {
     for (int i = _onDeserializedCallbackRecords.Count - 1; i >= 0; i--)
     {
         ObjectRecord record = (ObjectRecord)_onDeserializedCallbackRecords [i];
         RaiseOnDeserializedEvent(record.OriginalObject);
     }
     for (int i = _deserializedRecords.Count - 1; i >= 0; i--)
     {
         ObjectRecord             record = (ObjectRecord)_deserializedRecords [i];
         IDeserializationCallback obj    = record.OriginalObject as IDeserializationCallback;
         if (obj != null)
         {
             obj.OnDeserialization(this);
         }
     }
 }
Ejemplo n.º 8
0
        public virtual object GetObject(long objectID)
        {
            if (objectID <= 0)
            {
                throw new ArgumentOutOfRangeException("objectID", "The objectID parameter is less than or equal to zero");
            }
            ObjectRecord rec = (ObjectRecord)_objectRecords[objectID];

            if (rec == null || !rec.IsRegistered)
            {
                return(null);
            }
            else
            {
                return(rec.ObjectInstance);
            }
        }
Ejemplo n.º 9
0
        /// <summary>Registers a member of an array contained in an object while it is deserialized, associating it with <paramref name="objectID" />, and recording the <see cref="T:System.Runtime.Serialization.SerializationInfo" />.</summary>
        /// <param name="obj">The object to register. </param>
        /// <param name="objectID">The ID of the object to register. </param>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> used if <paramref name="obj" /> implements <see cref="T:System.Runtime.Serialization.ISerializable" /> or has a <see cref="T:System.Runtime.Serialization.ISerializationSurrogate" />. <paramref name="info" /> will be completed with any required fixup information and then passed to the required object when that object is completed. </param>
        /// <param name="idOfContainingObj">The ID of the object that contains <paramref name="obj" />. This parameter is required only if <paramref name="obj" /> is a value type. </param>
        /// <param name="member">The field in the containing object where <paramref name="obj" /> exists. This parameter has meaning only if <paramref name="obj" /> is a value type. </param>
        /// <param name="arrayIndex">If <paramref name="obj" /> is a <see cref="T:System.ValueType" /> and a member of an array, <paramref name="arrayIndex" /> contains the index within that array where <paramref name="obj" /> exists. <paramref name="arrayIndex" /> is ignored if <paramref name="obj" /> is not both a <see cref="T:System.ValueType" /> and a member of an array. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="obj" /> parameter is null. </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="objectID" /> parameter is less than or equal to zero. </exception>
        /// <exception cref="T:System.Runtime.Serialization.SerializationException">The <paramref name="objectID" /> has already been registered for an object other than <paramref name="obj" />, or <paramref name="member" /> is not a <see cref="T:System.Reflection.FieldInfo" /> and <paramref name="member" /> isn't null. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="MemberAccess" />
        /// </PermissionSet>
        public void RegisterObject(object obj, long objectID, SerializationInfo info, long idOfContainingObj, MemberInfo member, int[] arrayIndex)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj", "The obj parameter is null.");
            }
            if (objectID <= 0L)
            {
                throw new ArgumentOutOfRangeException("objectID", "The objectID parameter is less than or equal to zero");
            }
            ObjectRecord objectRecord = this.GetObjectRecord(objectID);

            objectRecord.Info = info;
            objectRecord.IdOfContainingObj = idOfContainingObj;
            objectRecord.Member            = member;
            objectRecord.ArrayIndex        = arrayIndex;
            this.RegisterObjectInternal(obj, objectRecord);
        }
Ejemplo n.º 10
0
        internal ObjectRecord GetObjectRecord(long objectID)
        {
            ObjectRecord objectRecord = (ObjectRecord)this._objectRecords[objectID];

            if (objectRecord == null)
            {
                if (this._finalFixup)
                {
                    throw new SerializationException("The object with Id " + objectID + " has not been registered");
                }
                objectRecord                  = new ObjectRecord();
                objectRecord.ObjectID         = objectID;
                this._objectRecords[objectID] = objectRecord;
            }
            if (!objectRecord.IsRegistered && this._finalFixup)
            {
                throw new SerializationException("The object with Id " + objectID + " has not been registered");
            }
            return(objectRecord);
        }
Ejemplo n.º 11
0
        internal ObjectRecord GetObjectRecord(long objectID)
        {
            ObjectRecord rec = (ObjectRecord)_objectRecords[objectID];

            if (rec == null)
            {
                if (_finalFixup)
                {
                    throw new SerializationException("The object with Id " + objectID + " has not been registered");
                }
                rec                      = new ObjectRecord();
                rec.ObjectID             = objectID;
                _objectRecords[objectID] = rec;
            }
            if (!rec.IsRegistered && _finalFixup)
            {
                throw new SerializationException("The object with Id " + objectID + " has not been registered");
            }
            return(rec);
        }
Ejemplo n.º 12
0
 public BaseFixupRecord(ObjectRecord objectToBeFixed, ObjectRecord objectRequired)
 {
     this.ObjectToBeFixed = objectToBeFixed;
     this.ObjectRequired  = objectRequired;
 }
Ejemplo n.º 13
0
        public bool LoadData(ObjectManager manager, ISurrogateSelector selector, StreamingContext context)
        {
            if (Info != null)
            {
                if (Surrogate != null)
                {
                    object new_obj = Surrogate.SetObjectData(ObjectInstance, Info, context, SurrogateSelector);
                    if (new_obj != null)
                    {
                        ObjectInstance = new_obj;
                    }
                    Status = ObjectRecordStatus.ReferenceSolved;
                }
                else if (ObjectInstance is ISerializable)
                {
                    object[]        pars = new object[] { Info, context };
                    ConstructorInfo con  = ObjectInstance.GetType().GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(SerializationInfo), typeof(StreamingContext) }, null);
                    if (con == null)
                    {
                        throw new SerializationException("The constructor to deserialize an object of type " + ObjectInstance.GetType().FullName + " was not found.");
                    }
                    con.Invoke(ObjectInstance, pars);
                }
                else
                {
                    throw new SerializationException("No surrogate selector was found for type " + ObjectInstance.GetType().FullName);
                }

                Info = null;
            }

            if (ObjectInstance is IObjectReference && Status != ObjectRecordStatus.ReferenceSolved)
            {
                try {
                    ObjectInstance = ((IObjectReference)ObjectInstance).GetRealObject(context);
                    int n = 100;
                    while (ObjectInstance is IObjectReference && n > 0)
                    {
                        object ob = ((IObjectReference)ObjectInstance).GetRealObject(context);
                        if (ob == ObjectInstance)
                        {
                            break;
                        }
                        ObjectInstance = ob;
                        n--;
                    }
                    if (n == 0)
                    {
                        throw new SerializationException("The implementation of the IObjectReference interface returns too many nested references to other objects that implement IObjectReference.");
                    }

                    Status = ObjectRecordStatus.ReferenceSolved;
                }
                catch (NullReferenceException) {
                    // Give a second chance
                    return(false);
                }
            }

            if (Member != null)
            {
                // If this object is a value object embedded in another object, the parent
                // object must be updated

                ObjectRecord containerRecord = manager.GetObjectRecord(IdOfContainingObj);
                containerRecord.SetMemberValue(manager, Member, ObjectInstance);
            }
            else if (ArrayIndex != null)
            {
                ObjectRecord containerRecord = manager.GetObjectRecord(IdOfContainingObj);
                containerRecord.SetArrayValue(manager, ObjectInstance, ArrayIndex);
            }

            return(true);
        }
Ejemplo n.º 14
0
        public virtual void DoFixups()
        {
            _finalFixup = true;

            try
            {
                if (_registeredObjectsCount < _objectRecords.Count)
                {
                    throw new SerializationException("There are some fixups that refer to objects that have not been registered");
                }


                ObjectRecord last       = _lastObjectRecord;
                bool         firstCicle = true;

                // Solve al pending fixups of all objects

                ObjectRecord record = _objectRecordChain;
                while (record != null)
                {
                    bool ready = !(record.IsUnsolvedObjectReference && firstCicle);
                    if (ready)
                    {
                        ready = record.DoFixups(true, this, true);
                    }
                    if (ready)
                    {
                        ready = record.LoadData(this, _selector, _context);
                    }

                    ObjectRecord next;

                    if (ready)
                    {
                        if (record.OriginalObject is IDeserializationCallback)
                        {
                            _deserializedRecords.Add(record);
                        }

                        SerializationCallbacks sc = SerializationCallbacks
                                                    .GetSerializationCallbacks(record.OriginalObject.GetType());
                        if (sc.HasDeserializedCallbacks)
                        {
                            _onDeserializedCallbackRecords.Add(record);
                        }
                        next = record.Next;
                    }
                    else
                    {
                        // There must be an unresolved IObjectReference instance.
                        // Chain the record at the end so it is solved later

                        if ((record.ObjectInstance is IObjectReference) && !firstCicle)
                        {
                            if (record.Status == ObjectRecordStatus.ReferenceSolvingDelayed)
                            {
                                throw new SerializationException("The object with ID " + record.ObjectID + " could not be resolved");
                            }
                            else
                            {
                                record.Status = ObjectRecordStatus.ReferenceSolvingDelayed;
                            }
                        }

                        if (record != _lastObjectRecord)
                        {
                            next                   = record.Next;
                            record.Next            = null;
                            _lastObjectRecord.Next = record;
                            _lastObjectRecord      = record;
                        }
                        else
                        {
                            next = record;
                        }
                    }

                    if (record == last)
                    {
                        firstCicle = false;
                    }
                    record = next;
                }
            }
            finally
            {
                _finalFixup = false;
            }
        }
Ejemplo n.º 15
0
 public DelayedFixupRecord(ObjectRecord objectToBeFixed, string memberName, ObjectRecord objectRequired) : base(objectToBeFixed, objectRequired)
 {
     _memberName = memberName;
 }
Ejemplo n.º 16
0
 public FixupRecord(ObjectRecord objectToBeFixed, MemberInfo member, ObjectRecord objectRequired) : base(objectToBeFixed, objectRequired)
 {
     _member = member;
 }
Ejemplo n.º 17
0
		public DelayedFixupRecord (ObjectRecord objectToBeFixed, string memberName, ObjectRecord objectRequired): base (objectToBeFixed, objectRequired) {
			_memberName = memberName;
		}
Ejemplo n.º 18
0
		public MultiArrayFixupRecord (ObjectRecord objectToBeFixed, int[] indices, ObjectRecord objectRequired): base (objectToBeFixed, objectRequired) {
			_indices = indices;
		}
Ejemplo n.º 19
0
		public BaseFixupRecord(ObjectRecord objectToBeFixed, ObjectRecord objectRequired)
		{
			ObjectToBeFixed = objectToBeFixed;
			ObjectRequired = objectRequired;
		}
Ejemplo n.º 20
0
		public virtual void DoFixups()
		{
			_finalFixup = true;

			try
			{
				if (_registeredObjectsCount < _objectRecords.Count)
					throw new SerializationException ("There are some fixups that refer to objects that have not been registered");


				ObjectRecord last = _lastObjectRecord;

				bool firstCycle = true;
				bool lastCycle = false;
				int unresolvedCount = 0; 		// Unresolved objects found in the current cycle
				int lastUnresolvedCount = 0;	// Unresolved objects before the current cycle

				// Solve al pending fixups of all objects

				ObjectRecord record = _objectRecordChain;
				while (record != null)
				{
					// We ignore object references in the first cycle
					bool ready = !(record.IsUnsolvedObjectReference && firstCycle);
					if (ready) ready = record.DoFixups (true, this, true);
					if (ready) ready = record.LoadData(this, _selector, _context);

					ObjectRecord next;

					if (ready)
					{
						if (record.OriginalObject is IDeserializationCallback)
							_deserializedRecords.Add (record);

						SerializationCallbacks sc = SerializationCallbacks
							.GetSerializationCallbacks (record.OriginalObject.GetType ());
						if (sc.HasDeserializedCallbacks)
							_onDeserializedCallbackRecords.Add (record);
						next = record.Next;
					}
					else
					{
						// There must be an unresolved IObjectReference instance.
						// Chain the record at the end so it is solved later

						if ((record.ObjectInstance is IObjectReference) && !firstCycle)
						{
							if (record.IsUnsolvedObjectReference && lastCycle)
								// No more chances to resolve
								throw new SerializationException ("The object with ID " + record.ObjectID + " could not be resolved");
							else {
								unresolvedCount++;
							}
						}

						if (record != _lastObjectRecord) {
							next = record.Next;
							record.Next = null;
							_lastObjectRecord.Next = record;
							_lastObjectRecord = record;
						}
						else
							next = record;
					}

					if (record == last) {
						last = _lastObjectRecord;
						if (firstCycle)
							firstCycle = false;
						else {
							if (lastUnresolvedCount == unresolvedCount)
								lastCycle = true;
						}
						lastUnresolvedCount = unresolvedCount;
						unresolvedCount = 0;
					}
					record = next;
				}
			}
			finally
			{
				_finalFixup = false;
			}
		}
Ejemplo n.º 21
0
		internal ObjectRecord GetObjectRecord (long objectID)
		{
			ObjectRecord rec = (ObjectRecord)_objectRecords[objectID];
			if (rec == null)
			{
				if (_finalFixup) throw new SerializationException ("The object with Id " + objectID + " has not been registered");
				rec = new ObjectRecord();
				rec.ObjectID = objectID;
				_objectRecords[objectID] = rec;
			}
			if (!rec.IsRegistered && _finalFixup) throw new SerializationException ("The object with Id " + objectID + " has not been registered");
			return rec;
		}
Ejemplo n.º 22
0
 public bool LoadData(ObjectManager manager, ISurrogateSelector selector, StreamingContext context)
 {
     if (this.Info != null)
     {
         if (this.Surrogate != null)
         {
             object obj = this.Surrogate.SetObjectData(this.ObjectInstance, this.Info, context, this.SurrogateSelector);
             if (obj != null)
             {
                 this.ObjectInstance = obj;
             }
             this.Status = ObjectRecordStatus.ReferenceSolved;
         }
         else
         {
             if (!(this.ObjectInstance is ISerializable))
             {
                 throw new SerializationException("No surrogate selector was found for type " + this.ObjectInstance.GetType().FullName);
             }
             object[] parameters = new object[]
             {
                 this.Info,
                 context
             };
             ConstructorInfo constructor = this.ObjectInstance.GetType().GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[]
             {
                 typeof(SerializationInfo),
                 typeof(StreamingContext)
             }, null);
             if (constructor == null)
             {
                 throw new SerializationException("The constructor to deserialize an object of type " + this.ObjectInstance.GetType().FullName + " was not found.");
             }
             constructor.Invoke(this.ObjectInstance, parameters);
         }
         this.Info = null;
     }
     if (this.ObjectInstance is IObjectReference && this.Status != ObjectRecordStatus.ReferenceSolved)
     {
         try
         {
             this.ObjectInstance = ((IObjectReference)this.ObjectInstance).GetRealObject(context);
             int num = 100;
             while (this.ObjectInstance is IObjectReference && num > 0)
             {
                 object realObject = ((IObjectReference)this.ObjectInstance).GetRealObject(context);
                 if (realObject == this.ObjectInstance)
                 {
                     break;
                 }
                 this.ObjectInstance = realObject;
                 num--;
             }
             if (num == 0)
             {
                 throw new SerializationException("The implementation of the IObjectReference interface returns too many nested references to other objects that implement IObjectReference.");
             }
             this.Status = ObjectRecordStatus.ReferenceSolved;
         }
         catch (NullReferenceException)
         {
             return(false);
         }
     }
     if (this.Member != null)
     {
         ObjectRecord objectRecord = manager.GetObjectRecord(this.IdOfContainingObj);
         objectRecord.SetMemberValue(manager, this.Member, this.ObjectInstance);
     }
     else if (this.ArrayIndex != null)
     {
         ObjectRecord objectRecord2 = manager.GetObjectRecord(this.IdOfContainingObj);
         objectRecord2.SetArrayValue(manager, this.ObjectInstance, this.ArrayIndex);
     }
     return(true);
 }
Ejemplo n.º 23
0
		private void RegisterObjectInternal (object obj, ObjectRecord record)
		{
			if (obj == null) throw new ArgumentNullException("obj");

			if (record.IsRegistered)
			{
				if (record.OriginalObject != obj) throw new SerializationException ("An object with Id " + record.ObjectID + " has already been registered");
				else return;
			}

			record.ObjectInstance = obj;
			record.OriginalObject = obj;

			if (obj is IObjectReference) record.Status = ObjectRecordStatus.ReferenceUnsolved;
			else record.Status = ObjectRecordStatus.ReferenceSolved;

			if (_selector != null) {
				record.Surrogate = _selector.GetSurrogate (
					obj.GetType(), _context, out record.SurrogateSelector);
				if (record.Surrogate != null)
					record.Status = ObjectRecordStatus.ReferenceUnsolved;
			}

			record.DoFixups (true, this, false);
			record.DoFixups (false, this, false);
			_registeredObjectsCount++;

			// Adds the object to the chain of registered objects. This chain
			// is needed to be able to to perform the final fixups in the right order

			if (_objectRecordChain == null)
			{
				_objectRecordChain = record;
				_lastObjectRecord = record;
			}
			else 
			{
				_lastObjectRecord.Next = record;
				_lastObjectRecord = record;
			}
		}
Ejemplo n.º 24
0
 /// <summary>Performs all the recorded fixups.</summary>
 /// <exception cref="T:System.Runtime.Serialization.SerializationException">A fixup was not successfully completed. </exception>
 public virtual void DoFixups()
 {
     this._finalFixup = true;
     try
     {
         if (this._registeredObjectsCount < this._objectRecords.Count)
         {
             throw new SerializationException("There are some fixups that refer to objects that have not been registered");
         }
         ObjectRecord lastObjectRecord = this._lastObjectRecord;
         bool         flag             = true;
         ObjectRecord objectRecord2;
         for (ObjectRecord objectRecord = this._objectRecordChain; objectRecord != null; objectRecord = objectRecord2)
         {
             bool flag2 = !objectRecord.IsUnsolvedObjectReference || !flag;
             if (flag2)
             {
                 flag2 = objectRecord.DoFixups(true, this, true);
             }
             if (flag2)
             {
                 flag2 = objectRecord.LoadData(this, this._selector, this._context);
             }
             if (flag2)
             {
                 if (objectRecord.OriginalObject is IDeserializationCallback)
                 {
                     this._deserializedRecords.Add(objectRecord);
                 }
                 SerializationCallbacks serializationCallbacks = SerializationCallbacks.GetSerializationCallbacks(objectRecord.OriginalObject.GetType());
                 if (serializationCallbacks.HasDeserializedCallbacks)
                 {
                     this._onDeserializedCallbackRecords.Add(objectRecord);
                 }
                 objectRecord2 = objectRecord.Next;
             }
             else
             {
                 if (objectRecord.ObjectInstance is IObjectReference && !flag)
                 {
                     if (objectRecord.Status == ObjectRecordStatus.ReferenceSolvingDelayed)
                     {
                         throw new SerializationException("The object with ID " + objectRecord.ObjectID + " could not be resolved");
                     }
                     objectRecord.Status = ObjectRecordStatus.ReferenceSolvingDelayed;
                 }
                 if (objectRecord != this._lastObjectRecord)
                 {
                     objectRecord2               = objectRecord.Next;
                     objectRecord.Next           = null;
                     this._lastObjectRecord.Next = objectRecord;
                     this._lastObjectRecord      = objectRecord;
                 }
                 else
                 {
                     objectRecord2 = objectRecord;
                 }
             }
             if (objectRecord == lastObjectRecord)
             {
                 flag = false;
             }
         }
     }
     finally
     {
         this._finalFixup = false;
     }
 }
Ejemplo n.º 25
0
		public ArrayFixupRecord (ObjectRecord objectToBeFixed, int index, ObjectRecord objectRequired): base (objectToBeFixed, objectRequired) {
			_index = index;
		}
Ejemplo n.º 26
0
 public ArrayFixupRecord(ObjectRecord objectToBeFixed, int index, ObjectRecord objectRequired) : base(objectToBeFixed, objectRequired)
 {
     _index = index;
 }
Ejemplo n.º 27
0
		public FixupRecord (ObjectRecord objectToBeFixed, MemberInfo member, ObjectRecord objectRequired): base (objectToBeFixed, objectRequired) {
			_member = member;
		}
Ejemplo n.º 28
0
 public MultiArrayFixupRecord(ObjectRecord objectToBeFixed, int[] indices, ObjectRecord objectRequired) : base(objectToBeFixed, objectRequired)
 {
     _indices = indices;
 }
Ejemplo n.º 29
0
		public virtual void DoFixups()
		{
			_finalFixup = true;

			try
			{
				if (_registeredObjectsCount < _objectRecords.Count)
					throw new SerializationException ("There are some fixups that refer to objects that have not been registered");


				ObjectRecord last = _lastObjectRecord;
				bool firstCicle = true;

				// Solve al pending fixups of all objects

				ObjectRecord record = _objectRecordChain;
				while (record != null)
				{
					bool ready = !(record.IsUnsolvedObjectReference && firstCicle);
					if (ready) ready = record.DoFixups (true, this, true);
					if (ready) ready = record.LoadData(this, _selector, _context);

					ObjectRecord next;

					if (ready)
					{
						if (record.OriginalObject is IDeserializationCallback)
							_deserializedRecords.Add (record);

						SerializationCallbacks sc = SerializationCallbacks
							.GetSerializationCallbacks (record.OriginalObject.GetType ());
						if (sc.HasDeserializedCallbacks)
							_onDeserializedCallbackRecords.Add (record);
						next = record.Next;
					}
					else
					{
						// There must be an unresolved IObjectReference instance.
						// Chain the record at the end so it is solved later

						if ((record.ObjectInstance is IObjectReference) && !firstCicle)
						{
							if (record.Status == ObjectRecordStatus.ReferenceSolvingDelayed)
								throw new SerializationException ("The object with ID " + record.ObjectID + " could not be resolved");
							else
								record.Status = ObjectRecordStatus.ReferenceSolvingDelayed;
						}

						if (record != _lastObjectRecord) {
							next = record.Next;
							record.Next = null;
							_lastObjectRecord.Next = record;
							_lastObjectRecord = record;
						}
						else
							next = record;
					}

					if (record == last) firstCicle = false;
					record = next;
				}
			}
			finally
			{
				_finalFixup = false;
			}
		}
Ejemplo n.º 30
0
        public virtual void DoFixups()
        {
            _finalFixup = true;

            try
            {
                if (_registeredObjectsCount < _objectRecords.Count)
                {
                    throw new SerializationException("There are some fixups that refer to objects that have not been registered");
                }


                ObjectRecord last = _lastObjectRecord;

                bool firstCycle          = true;
                bool lastCycle           = false;
                int  unresolvedCount     = 0;                   // Unresolved objects found in the current cycle
                int  lastUnresolvedCount = 0;                   // Unresolved objects before the current cycle

                // Solve al pending fixups of all objects

                ObjectRecord record = _objectRecordChain;
                while (record != null)
                {
                    // We ignore object references in the first cycle
                    bool ready = !(record.IsUnsolvedObjectReference && firstCycle);
                    if (ready)
                    {
                        ready = record.DoFixups(true, this, true);
                    }
                    if (ready)
                    {
                        ready = record.LoadData(this, _selector, _context);
                    }

                    ObjectRecord next;

                    if (ready)
                    {
                        if (record.OriginalObject is IDeserializationCallback)
                        {
                            _deserializedRecords.Add(record);
                        }

                        SerializationCallbacks sc = SerializationCallbacks
                                                    .GetSerializationCallbacks(record.OriginalObject.GetType());
                        if (sc.HasDeserializedCallbacks)
                        {
                            _onDeserializedCallbackRecords.Add(record);
                        }
                        next = record.Next;
                    }
                    else
                    {
                        // There must be an unresolved IObjectReference instance.
                        // Chain the record at the end so it is solved later

                        if ((record.ObjectInstance is IObjectReference) && !firstCycle)
                        {
                            if (record.IsUnsolvedObjectReference && lastCycle)
                            {
                                // No more chances to resolve
                                throw new SerializationException("The object with ID " + record.ObjectID + " could not be resolved");
                            }
                            else
                            {
                                unresolvedCount++;
                            }
                        }

                        if (record != _lastObjectRecord)
                        {
                            next                   = record.Next;
                            record.Next            = null;
                            _lastObjectRecord.Next = record;
                            _lastObjectRecord      = record;
                        }
                        else
                        {
                            next = record;
                        }
                    }

                    if (record == last)
                    {
                        last = _lastObjectRecord;
                        if (firstCycle)
                        {
                            firstCycle = false;
                        }
                        else
                        {
                            if (lastUnresolvedCount == unresolvedCount)
                            {
                                lastCycle = true;
                            }
                        }
                        lastUnresolvedCount = unresolvedCount;
                        unresolvedCount     = 0;
                    }
                    record = next;
                }
            }
            finally
            {
                _finalFixup = false;
            }
        }