Exemplo n.º 1
0
            public void OnReferenceDisposed()
            {
                string removeSopInstanceUid = null;

                lock (_syncLock)
                {
                    if (_referenceCount > 0)
                    {
                        --_referenceCount;
                    }

                    if (_referenceCount == 0)
                    {
                        _referenceCount = -1;
                        GC.SuppressFinalize(this);

                        removeSopInstanceUid = _realDataSource.SopInstanceUid;

                        try
                        {
                            _realDataSource.Dispose();
                        }
                        catch (Exception e)
                        {
                            Platform.Log(LogLevel.Debug, e);
                        }
                    }
                }

                if (removeSopInstanceUid != null)
                {
                    Remove(removeSopInstanceUid);
                }
            }
Exemplo n.º 2
0
 /// <summary>
 /// Disposes all resources being used by this <see cref="Sop"/>.
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing && _dataSource != null)
     {
         _dataSource.Dispose();
         _dataSource = null;
     }
 }
Exemplo n.º 3
0
 protected override void Dispose(bool disposing)
 {
     if (_sopDataSource != null)
     {
         _sopDataSource.Dispose();
         _sopDataSource = null;
     }
     base.Dispose(disposing);
 }
Exemplo n.º 4
0
        public static ISopDataCacheItemReference Add(ISopDataSource dataSource)
        {
            lock (_itemsLock)
            {
                CleanupDeadItems();

                WeakReference weakReference = null;
                Item          item          = null;

                if (_items.ContainsKey(dataSource.SopInstanceUid))
                {
                    weakReference = _items[dataSource.SopInstanceUid];
                    try
                    {
                        item = weakReference.Target as Item;
                    }
                    catch (InvalidOperationException)
                    {
                        weakReference = null;
                        item          = null;
                    }
                }

                if (weakReference == null)
                {
                    weakReference = new WeakReference(null);
                    _items[dataSource.SopInstanceUid] = weakReference;
                }


                if (item != null && weakReference.IsAlive)
                {
                    if (!ReferenceEquals(item.RealDataSource, dataSource))
                    {
                        dataSource.Dispose();                         //silently dispose the new one, we already have it.
                    }
                }
                else
                {
                    item = new Item(dataSource);
                    weakReference.Target = item;
                }

                return(new ItemReference(item));
            }
        }
Exemplo n.º 5
0
		public static ISopDataCacheItemReference Add(ISopDataSource dataSource)
		{
			lock(_itemsLock)
			{
				CleanupDeadItems();

				WeakReference weakReference = null;
				Item item = null;

				if (_items.ContainsKey(dataSource.SopInstanceUid))
				{
					weakReference = _items[dataSource.SopInstanceUid];
					try
					{
						item = weakReference.Target as Item;
					}
					catch (InvalidOperationException)
					{
						weakReference = null;
						item = null;
					}
				}

				if (weakReference == null)
				{
					weakReference = new WeakReference(null);
					_items[dataSource.SopInstanceUid] = weakReference;
				}


				if (item != null && weakReference.IsAlive)
				{
					if (!ReferenceEquals(item.RealDataSource, dataSource))
						dataSource.Dispose(); //silently dispose the new one, we already have it.
				}
				else
				{
					item = new Item(dataSource);
					weakReference.Target = item;
				}

				return new ItemReference(item);
			}
		}