Пример #1
0
        private void Slot(string caller, Guid?slotId, IDisposable disposable, string message)
        {
            IList <DisposableWeakReference> disposables;
            DisposableWeakReference         _disposable;

            if ((object)caller == null)
            {
                throw new ArgumentNullException(nameof(caller));
            }

            if ((object)slotId == null)
            {
                throw new ArgumentNullException(nameof(slotId));
            }

            if ((object)disposable == null)
            {
                throw new ArgumentNullException(nameof(disposable));
            }

            if ((object)message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            _disposable = new DisposableWeakReference(disposable);

            if (this.TrackedResources.TryGetValue(slotId, out disposables))
            {
                if (disposables.Contains(_disposable))
                {
                    throw new ResourceException(FormatOperation(this.ObjectIdGenerator, "error", slotId, disposable));
                }
            }
            else
            {
                disposables = new List <DisposableWeakReference>();

                if (!this.TrackedResources.TryAdd(slotId, disposables))
                {
                    throw new ResourceException(FormatOperation(this.ObjectIdGenerator, "error", slotId, disposable));
                }
            }

            disposables.Add(_disposable);

            this.Print(caller, message);
        }
Пример #2
0
        public void Dispose(Guid?slotId, IDisposable disposable, [CallerFilePath] string callerFilePath = null, [CallerLineNumber] int?callerLineNumber = null, [CallerMemberName] string callerMemberName = null)
        {
            IList <DisposableWeakReference> disposables;
            DisposableWeakReference         _disposable;

            if ((object)slotId == null)
            {
                throw new ArgumentNullException(nameof(slotId));
            }

            if ((object)disposable == null)
            {
                throw new ArgumentNullException(nameof(disposable));
            }

            if ((object)callerFilePath == null)
            {
                throw new ArgumentNullException(nameof(callerFilePath));
            }

            if ((object)callerLineNumber == null)
            {
                throw new ArgumentNullException(nameof(callerLineNumber));
            }

            if ((object)callerMemberName == null)
            {
                throw new ArgumentNullException(nameof(callerMemberName));
            }

            _disposable = new DisposableWeakReference(disposable);

            if (!this.TrackedResources.TryGetValue(slotId, out disposables) || !disposables.Contains(_disposable))
            {
                throw new ResourceException(FormatOperation(this.ObjectIdGenerator, "error", slotId, disposable));
            }

            disposables.Remove(_disposable);

            this.Print(FormatCallerInfo(callerFilePath, callerLineNumber, callerMemberName), FormatOperation(this.ObjectIdGenerator, "dispose", slotId, disposable));
        }