예제 #1
0
        /// <summary>
        ///     Tracks the <see cref="target" /> for synchronization
        /// </summary>
        /// <param name="referencehe reference.</param>
        /// <remarks>The <see cref="target">reference's</see> synchronize-able child references are also tracked recursively</remarks>
        /// <exception cref="ArgumentNullException">reference</exception>
        public void Synchronize(object reference)
        {
            if (reference == null)
            {
                throw new ArgumentNullException(nameof(reference));
            }

            SourceSynchronizer sourceSynchronizer = _referencePool.GetSyncSource(reference);

            if (sourceSynchronizer == null)
            {
                if (_pendingForSynchronization.Contains(reference))
                {
                    return;
                }

                Type referenceType = reference.GetType();
                if (referenceType.HasElementType)
                {
                    _typeEncoder.RegisterType(referenceType.GetElementType());
                }
                _typeEncoder.RegisterType(referenceType);

                ISynchronizer sourceFactory = Settings.Synchronizers.FindSynchronizerByType(referenceType);
                var           referenceId   = _referenceIdIncrementer++;
                _pendingForSynchronization.Add(reference);
                sourceSynchronizer = sourceFactory.Synchronize(this, referenceId, reference);
                _pendingForSynchronization.Remove(reference);
                _referencePool.AddSyncSource(sourceSynchronizer);
                _pendingTrackedSyncSourceObjects.Add(sourceSynchronizer);
            }
        }
예제 #2
0
 /// <summary>
 ///     Registers the <see cref="syncSource" /> for removal.
 ///     the <see cref="syncSource" /> can be revived by calling <see cref="Synchronize" />
 ///     on the object that the <see cref="syncSource" /> references.
 /// </summary>
 /// <param name="synchronizerSourcenchronize reference.</param>
 /// <exception cref="ArgumentNullException">sourceSynchronizer</exception>
 internal void RegisterSyncSourceToBeUntracked(SourceSynchronizer sourceSynchronizer)
 {
     lock (_pendingUntrackedSyncSourceObjects)
     {
         if (sourceSynchronizer == null)
         {
             throw new ArgumentNullException(nameof(sourceSynchronizer));
         }
         _pendingUntrackedSyncSourceObjects.Add(sourceSynchronizer);
     }
 }
예제 #3
0
 /// <summary>
 ///     Indicates that the <see cref="syncSource" /> has changes and should be serialized on next
 ///     <see cref="WriteChanges" />.
 /// </summary>
 /// <param name="synchronizerSourcenchronize reference.</param>
 public void MarkDirty(SourceSynchronizer sourceSynchronizer)
 {
     _dirtySyncSourceObjects.Add(sourceSynchronizer);
 }
예제 #4
0
 /// <summary>Removes the reference.</summary>
 /// <param name="reference">The reference.</param>
 /// <returns>The referenceId of the reference that got removed. 0 if no reference was removed</returns>
 public void RemoveSyncSource(SourceSynchronizer sourceSynchronizer)
 {
     _syncObjects.Remove(sourceSynchronizer);
 }
예제 #5
0
 public void AddSyncSource(SourceSynchronizer sourceSynchronizerObject)
 {
     _syncObjects.Add(sourceSynchronizerObject.Reference, sourceSynchronizerObject);
 }