コード例 #1
0
 private void ItemCompleted(MediaItem nextItem)
 {
     Log.Logger.Debug($"Done item {nextItem.FilePath}");
     ItemCompletedEvent?.Invoke(this, new ItemMetaDataPopulatedEventArgs {
         MediaItem = nextItem
     });
 }
コード例 #2
0
        public void Handle(ItemCompletedEvent <LifetimeScope> applicationEvent)
        {
            var lifetimeScope = applicationEvent.Item;
            var messageEvent  = new MessageEvent(MessageRelevance.Information, "Lifetime scope disposed", lifetimeScope.Description);

            _applicationEventQueue.Enqueue(messageEvent);
        }
コード例 #3
0
        public void Handle(ItemCompletedEvent <InstanceLookup> applicationEvent)
        {
            if (applicationEvent.Item.SharedInstanceReused)
            {
                return;
            }

            var lifetime = applicationEvent.Item.ActivationScope;

            if (!lifetime.IsRootScope)
            {
                return;
            }

            var component = applicationEvent.Item.Component;

            if (component.IsTracked)
            {
                if (_warnedComponents.Contains(component))
                {
                    return;
                }

                var message      = string.Format("The disposable component {0} was activated in the root scope. This means the instance will be kept alive for the lifetime of the container.", component.Description);
                var messageEvent = new MessageEvent(MessageRelevance.Warning, "Tracked Component in Root Scope", message);
                _applicationEventQueue.Enqueue(messageEvent);
            }
        }
コード例 #4
0
        public void Handle(ItemCompletedEvent <LifetimeScope> applicationEvent)
        {
            if (applicationEvent.Item.IsRootScope)
            {
                return;
            }

            if (_activeScopes.ContainsKey(applicationEvent.Item))
            {
                _activeScopes.Remove(applicationEvent.Item);
            }
        }
コード例 #5
0
        public void Handle(ItemCompletedEvent <ResolveOperation> applicationEvent)
        {
            if (applicationEvent == null)
            {
                throw new ArgumentNullException("applicationEvent");
            }

            var instanceLookup = applicationEvent.Item.RootInstanceLookup;

            if (instanceLookup.SharedInstanceReused)
            {
                return;
            }

            var activationScope = instanceLookup.ActivationScope;

            if (!activationScope.IsRootScope)
            {
                return;
            }

            var component = instanceLookup.Component;

            if (component.LimitType.Identity.FullName == OwnedTypeFullName)
            {
                return;
            }

            LastNActivationsScopeTracker tracker;

            if (!_componentToScopeTrackers.TryGetValue(component.Id, out tracker))
            {
                tracker = new LastNActivationsScopeTracker(MaxActivationScopesToTrackPerComponent);
                _componentToScopeTrackers[component.Id] = tracker;
            }

            if (tracker.HasWarningBeenIssued)
            {
                return;
            }

            var resolveOperationsInThisScope = tracker.RecordActivation(activationScope.Id);

            if (resolveOperationsInThisScope == ResolveOperationsBeforeWarning)
            {
                var message = string.Format("The component {0} has been resolved twice directly from the container. This can indicate a potential memory leak.", component.Description);
                var warning = new MessageEvent(MessageRelevance.Warning, "Possible Memory Leak", message);
                _applicationEventQueue.Enqueue(warning);
                tracker.HasWarningBeenIssued = true;
            }
        }
コード例 #6
0
        public void Handle(ItemCompletedEvent <LifetimeScope> applicationEvent)
        {
            var lifetimeScope = applicationEvent.Item;

            if (lifetimeScope.ActiveChildren.Count != 0)
            {
                if (_descriptionsOfParentsWithWarningsIssued.Contains(lifetimeScope.Description))
                {
                    return;
                }

                _descriptionsOfParentsWithWarningsIssued.Add(lifetimeScope.Description);
                var children     = string.Join(", ", lifetimeScope.ActiveChildren.Select(ls => ls.Description));
                var message      = string.Format("A {0} lifetime scope was disposed before its active children (including {1}).", lifetimeScope.Description, children);
                var messageEvent = new MessageEvent(MessageRelevance.Error, "Out-of-Order Disposal", message);
                _applicationEventQueue.Enqueue(messageEvent);
            }
        }
コード例 #7
0
ファイル: MetaDataQueueConsumer.cs プロジェクト: fkdl/OnlyM
        private void RunConsumerTask()
        {
            try
            {
                while (!_cancellationToken.IsCancellationRequested)
                {
                    var nextItem = _collection.Take(_cancellationToken);

                    Log.Logger.Debug($"Consuming item {nextItem.FilePath}");

                    if (!IsPopulated(nextItem))
                    {
                        PopulateThumbnailAndMetaData(nextItem);

                        if (!IsPopulated(nextItem))
                        {
                            // put it back in the queue!
                            ReplaceInQueue(nextItem);
                        }
                        else
                        {
                            Log.Logger.Debug($"Done item {nextItem.FilePath}");
                            ItemCompletedEvent?.Invoke(this, new ItemMetaDataPopulatedEventArgs {
                                MediaItem = nextItem
                            });
                        }

                        Log.Logger.Verbose("Metadata queue size (consumer) = {QueueSize}", _collection.Count);

                        if (_collection.Count == 0)
                        {
                            AllItemsCompletedEvent?.Invoke(this, EventArgs.Empty);
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Log.Logger.Debug("Metadata consumer closed");
            }
        }
コード例 #8
0
        public void Handle(ItemCompletedEvent <ResolveOperation> applicationEvent)
        {
            var    resolveOperationId   = applicationEvent.Item.Id;
            var    componentDescription = applicationEvent.Item.RootInstanceLookup.Component.Description;
            string locationDescription  = null;

            if (applicationEvent.Item.CallingMethod != null)
            {
                locationDescription = applicationEvent.Item.CallingMethod.DisplayName;
            }

            _dispacher.Foreground(() =>
            {
                ResolveOperationEventViewModel resolveOperation;
                if (TryGetResolveOperationEvent(resolveOperationId, out resolveOperation))
                {
                    resolveOperation.ComponentDescription = componentDescription;
                    resolveOperation.LocationDescription  = locationDescription;
                }
            });
        }
コード例 #9
0
 public void Handle(ItemCompletedEvent <ResolveOperation> applicationEvent)
 {
     Enqueue(applicationEvent);
 }