DoFixups() public method

public DoFixups ( bool asContainer, ObjectManager manager, bool strict ) : bool
asContainer bool
manager ObjectManager
strict bool
return bool
Esempio n. 1
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;
            }
        }
Esempio n. 2
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");
     }
 }
		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;
			}
		}
Esempio n. 4
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;
            }
        }
Esempio n. 5
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;
     }
 }
Esempio n. 6
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;
            }
        }