Example #1
0
        public void RemoveReference(object reference)
        {
            if (reference == null)
            {
                throw new ArgumentNullException(nameof(reference));
            }

            SyncSource syncObject = _referencePool.GetSyncObject(reference);

            if (syncObject == null)
            {
                throw new InvalidOperationException($"{nameof(reference)} is not tracked");
            }

            if (--syncObject.ReferenceCount <= 0)
            {
                bool isAlreadySynchronized = _addedSyncSourceObjects.Remove(syncObject) == false;
                if (isAlreadySynchronized)
                {
                    // Clients do not need to be notified of deleted objects
                    // that have not yet been synchronized.
                    _removedSyncSourceObjects.Add(syncObject);
                }
                // If reference is not tracked by targets remove immediately
                else
                {
                    RemoveSyncSourceObject(syncObject);
                }
            }
        }
Example #2
0
        public void AddReference(object reference)
        {
            if (reference == null)
            {
                throw new ArgumentNullException(nameof(reference));
            }

            if (_pendingForCreationReferenceCount.ContainsKey(reference))
            {
                _pendingForCreationReferenceCount[reference]++;
                return;
            }

            SyncSource syncSource = _referencePool.GetSyncObject(reference);

            if (syncSource == null)
            {
                ISyncSourceFactory sourceFactory = Settings.SyncSourceFactoryResolver
                                                   .FindMatchingSyncSourceFactory(reference);
                int referenceId = _referenceIdIncrementer++;

                _pendingForCreationReferenceCount[reference] = 1;
                syncSource =
                    sourceFactory.Create(this, referenceId, reference,
                                         _fieldDeserializerResolver);
                syncSource.ReferenceCount = _pendingForCreationReferenceCount[reference];
                _pendingForCreationReferenceCount.Remove(reference);

                _referencePool.AddSyncObject(referenceId, syncSource);
                _addedSyncSourceObjects.Add(syncSource);
            }
            else
            {
                _removedSyncSourceObjects.Remove(syncSource);
                syncSource.ReferenceCount++;
            }
        }
Example #3
0
 /// <summary>
 /// Removes the SyncSourceObject from referencePool.
 /// </summary>
 /// <param name="removedSyncSourceObject">The removed synchronize source object.</param>
 private void RemoveSyncSourceObject(SyncSource removedSyncSourceObject)
 {
     _referencePool.RemoveSyncObject(removedSyncSourceObject);
 }
Example #4
0
 public void MarkDirty(SyncSource syncSource)
 {
     _dirtySyncSourceObjects.Add(syncSource);
 }