예제 #1
0
            public void OnChanged(object sender, ComposablePartCatalogChangeEventArgs args)
            {
                Assert.IsTrue(this._expectedAdds != null || this._expectedRemoves != null);

                if (this._expectedAdds == null)
                {
                    EnumerableAssert.IsEmpty(args.AddedDefinitions);
                }
                else
                {
                    EnumerableAssert.AreSequenceEqual(this._expectedAdds, GetDisplayNames(args.AddedDefinitions));
                }

                if (this._expectedRemoves == null)
                {
                    EnumerableAssert.IsEmpty(args.RemovedDefinitions);
                }
                else
                {
                    EnumerableAssert.AreSequenceEqual(this._expectedRemoves, GetDisplayNames(args.RemovedDefinitions));
                }

                Assert.IsNull(args.AtomicComposition);
                Assert.IsTrue(ContainsChanges(), "The catalog should contain the changes");

                this._changedEventCount++;
            }
예제 #2
0
 /// <summary>
 /// Raises the <see cref="DeploymentCatalog.Changing"/> event.
 /// </summary>
 /// <param name="e">
 /// A <see cref="ComposablePartCatalogChangeEventArgs"/> object that contains the event data.
 /// </param>
 protected virtual void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
     if (this.Changing != null)
     {
         this.Changing(this, e);
     }
 }
예제 #3
0
            public void OnChanging(object sender, ComposablePartCatalogChangeEventArgs args)
            {
                Assert.True(this._expectedAdds != null || this._expectedRemoves != null);

                if (this._expectedAdds == null)
                {
                    Assert.Empty(args.AddedDefinitions);
                }
                else
                {
                    EqualityExtensions.CheckSequenceEquals(this._expectedAdds, GetDisplayNames(args.AddedDefinitions));
                }

                if (this._expectedRemoves == null)
                {
                    Assert.Empty(args.RemovedDefinitions);
                }
                else
                {
                    EqualityExtensions.CheckSequenceEquals(this._expectedRemoves, GetDisplayNames(args.RemovedDefinitions));
                }

                Assert.False(ContainsChanges(), "The catalog should NOT contain the changes yet");

                this._changingEventCount++;
            }
예제 #4
0
파일: Program.cs 프로젝트: Olezhka/Hipbot
        void directoryCatalog_Changing(object sender, ComposablePartCatalogChangeEventArgs e)
        {
            try
            {
                // Remove handlers
                foreach (var handler in Handlers)
                {
                    for (var i = handlerService.Handlers.Count - 1; i > 0; i--)
                    {
                        var h = handlerService.Handlers[i];

                        if (h.GetType() == handler.GetType())
                        {
                            handlerService.Handlers.RemoveAt(i);
                        }

                    }

                    Stencil.Instance.RemoveType(handler.GetType());
                }
            }
            catch (Exception ex)
            {              
                Out.WriteLine(ex.Message);
            }
        }
예제 #5
0
            public void OnChanged(object sender, ComposablePartCatalogChangeEventArgs args)
            {
                Assert.True(this._expectedAdds != null || this._expectedRemoves != null);

                if (this._expectedAdds == null)
                {
                    Assert.Empty(args.AddedDefinitions);
                }
                else
                {
                    EqualityExtensions.CheckSequenceEquals(this._expectedAdds, GetDisplayNames(args.AddedDefinitions));
                }

                if (this._expectedRemoves == null)
                {
                    Assert.Empty(args.RemovedDefinitions);
                }
                else
                {
                    EqualityExtensions.CheckSequenceEquals(this._expectedRemoves, GetDisplayNames(args.RemovedDefinitions));
                }

                Assert.Null(args.AtomicComposition);
                Assert.True(ContainsChanges());

                this._changedEventCount++;
            }
 public void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
     if (this.Changing != null)
     {
         this.Changing.Invoke(this, e);
     }
 }
예제 #7
0
 /// <summary>
 /// Raises the <see cref="Changed"/> event.
 /// </summary>
 /// <param name="e">The <see cref="System.ComponentModel.Composition.Hosting.ComposablePartCatalogChangeEventArgs"/> instance containing the event data.</param>
 protected virtual void OnChanged(ComposablePartCatalogChangeEventArgs e)
 {
     EventHandler<ComposablePartCatalogChangeEventArgs>? changedEvent = Changed;
     if (changedEvent != null)
     {
         changedEvent.Invoke(this, e);
     }
 }
예제 #8
0
 private void OnChanged(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     var changed = Changed;
     if (changed != null)
     {
         changed(this, e);
     }
 }
예제 #9
0
 /// <summary>
 ///     Raises the <see cref="INotifyComposablePartCatalogChanged.Changing"/> event.
 /// </summary>
 /// <param name="e">
 ///     An <see cref="ComposablePartCatalogChangeEventArgs"/> containing the data for the event.
 /// </param>
 protected virtual void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
     EventHandler<ComposablePartCatalogChangeEventArgs> changingEvent = this.Changing;
     if (changingEvent != null)
     {
         changingEvent(this, e);
     }
 }
예제 #10
0
 private void OnChangingInternal(object? sender, ComposablePartCatalogChangeEventArgs e)
 {
     var processedArgs = ProcessEventArgs(e);
     if (processedArgs != null)
     {
         OnChanging(ProcessEventArgs(processedArgs)!);
     }
 }
예제 #11
0
        private void OnChangedInternal(object sender, ComposablePartCatalogChangeEventArgs e)
        {
            var processedArgs = ProcessEventArgs(e);

            if (processedArgs != null)
            {
                this.OnChanged(this.ProcessEventArgs(processedArgs));
            }
        }
        public void OnChanged(object sender, ComposablePartCatalogChangeEventArgs e)
        {
            var changedEvent = this.Changed;

            if (changedEvent != null)
            {
                changedEvent(sender, e);
            }
        }
        private void OnContainedCatalogChanged(object sender, ComposablePartCatalogChangeEventArgs e)
        {
            if (this._onChanged == null || this.Changed == null)
            {
                return;
            }

            this._onChanged.Invoke(e);
        }
예제 #14
0
        public void OnChanging(object sender, ComposablePartCatalogChangeEventArgs e)
        {
            var changingEvent = Changing;

            if (changingEvent != null)
            {
                changingEvent(sender, e);
            }
        }
예제 #15
0
        private void OnContainedCatalogChanging(object?sender, ComposablePartCatalogChangeEventArgs e)
        {
            if (_onChanging == null || Changing == null)
            {
                return;
            }

            _onChanging.Invoke(e);
        }
예제 #16
0
        private void OnCatalogChanging(object sender, ComposablePartCatalogChangeEventArgs e)
        {
            using (var atomicComposition = new AtomicComposition(e.AtomicComposition))
            {
                // Save the preview catalog to use in place of the original while handling
                // this event
                atomicComposition.SetValue(this._catalog,
                                           new CatalogChangeProxy(this._catalog, e.AddedDefinitions, e.RemovedDefinitions));

                IEnumerable <ExportDefinition> addedExports = e.AddedDefinitions
                                                              .SelectMany(part => part.ExportDefinitions)
                                                              .ToArray();
                IEnumerable <ExportDefinition> removedExports = e.RemovedDefinitions
                                                                .SelectMany(part => part.ExportDefinitions)
                                                                .ToArray();

                // Remove any parts based on eliminated definitions (in a atomicComposition-friendly
                // fashion)
                foreach (var definition in e.RemovedDefinitions)
                {
                    ComposablePart removedPart = null;
                    bool           removed     = false;

                    using (new ReadLock(_lock))
                    {
                        removed = this._activatedParts.TryGetValue(definition, out removedPart);
                    }
                    if (removed)
                    {
                        ReleasePart(null, removedPart, atomicComposition);
                        atomicComposition.AddCompleteActionAllowNull(() =>
                        {
                            using (new WriteLock(_lock))
                            {
                                this._activatedParts.Remove(definition);
                            }
                        });
                    }
                }

                UpdateRejections(addedExports.ConcatAllowingNull(removedExports), atomicComposition);

                this.OnExportsChanging(
                    new ExportsChangeEventArgs(addedExports, removedExports, atomicComposition));

                atomicComposition.AddCompleteAction(() => this.OnExportsChanged(
                                                        new ExportsChangeEventArgs(addedExports, removedExports, null)));

                atomicComposition.Complete();
            }
        }
        private void OnCatalogChanging(object sender, ComposablePartCatalogChangeEventArgs e)
        {
            using (var atomicComposition = new AtomicComposition(e.AtomicComposition))
            {
                // Save the preview catalog to use in place of the original while handling
                // this event
                atomicComposition.SetValue(_catalog,
                                           new CatalogChangeProxy(_catalog, e.AddedDefinitions, e.RemovedDefinitions));

                IEnumerable <ExportDefinition> addedExports   = GetExportsFromPartDefinitions(e.AddedDefinitions);
                IEnumerable <ExportDefinition> removedExports = GetExportsFromPartDefinitions(e.RemovedDefinitions);

                // Remove any parts based on eliminated definitions (in a atomicComposition-friendly
                // fashion)
                foreach (var definition in e.RemovedDefinitions)
                {
                    CatalogPart removedPart = null;
                    bool        removed     = false;

                    using (_lock.LockStateForRead())
                    {
                        removed = _activatedParts.TryGetValue(definition, out removedPart);
                    }

                    if (removed)
                    {
                        var capturedDefinition = definition;
                        DisposePart(null, removedPart, atomicComposition);
                        atomicComposition.AddCompleteActionAllowNull(() =>
                        {
                            using (_lock.LockStateForWrite())
                            {
                                _activatedParts.Remove(capturedDefinition);
                            }
                        });
                    }
                }

                UpdateRejections(addedExports.ConcatAllowingNull(removedExports), atomicComposition);

                OnExportsChanging(
                    new ExportsChangeEventArgs(addedExports, removedExports, atomicComposition));

                atomicComposition.AddCompleteAction(() => OnExportsChanged(
                                                        new ExportsChangeEventArgs(addedExports, removedExports, null)));

                atomicComposition.Complete();
            }
        }
예제 #18
0
        public void Notifications()
        {
            var         parts   = new TypeCatalog(typeof(FooImpl), typeof(FooImpl2), typeof(FooImpl2)).Parts;
            var         exports = parts.Select(p => Tuple.Create(p, p.ExportDefinitions.First()));
            TestCatalog catalog = new TestCatalog(
                () => parts,
                () => exports);

            CompositionScopeDefinition scope = new CompositionScopeDefinition(catalog, null);

            ComposablePartCatalogChangeEventArgs args = new ComposablePartCatalogChangeEventArgs(Enumerable.Empty <ComposablePartDefinition>(), Enumerable.Empty <ComposablePartDefinition>(), null);

            bool changedFired = false;

            scope.Changed += new EventHandler <ComposablePartCatalogChangeEventArgs>((o, e) =>
            {
                Assert.AreSame(args, e);
                Assert.AreSame(scope, o);
                changedFired = true;
            });

            bool changingFired = false;

            scope.Changing += new EventHandler <ComposablePartCatalogChangeEventArgs>((o, e) =>
            {
                Assert.AreSame(args, e);
                Assert.AreSame(scope, o);
                changingFired = true;
            });


            catalog.OnChanged(args);
            Assert.IsTrue(changedFired);

            catalog.OnChanging(args);
            Assert.IsTrue(changingFired);


            changedFired  = false;
            changingFired = false;

            scope.Dispose();

            catalog.OnChanged(args);
            catalog.OnChanging(args);

            Assert.IsFalse(changedFired);
            Assert.IsFalse(changingFired);
        }
예제 #19
0
        private ComposablePartCatalogChangeEventArgs ProcessEventArgs(ComposablePartCatalogChangeEventArgs e)
        {
            // the constructor for ComposablePartCatalogChangeEventArgs takes a snapshot of the arguments, so we don't have to
            var result = new ComposablePartCatalogChangeEventArgs(
                e.AddedDefinitions.Where(_filter),
                e.RemovedDefinitions.Where(_filter),
                e.AtomicComposition);

            // Only fire if we need to
            if (result.AddedDefinitions.FastAny() || result.RemovedDefinitions.FastAny())
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }
예제 #20
0
        /// <summary>
        /// </summary>
        /// <param name="assemblies">
        /// </param>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="DeploymentCatalog"/> has been disposed of.
        /// </exception>
        private void DiscoverParts(IEnumerable <Assembly> assemblies)
        {
            this.ThrowIfDisposed();

            var addedDefinitions = new List <ComposablePartDefinition>();
            var addedCatalogs    = new Dictionary <string, ComposablePartCatalog>();

            using (new ReadLock(this._lock))
            {
                foreach (var assembly in assemblies)
                {
                    if (addedCatalogs.ContainsKey(assembly.FullName))
                    {
                        // Nothing to do because the assembly has already been added.
                        continue;
                    }

                    var catalog = new AssemblyCatalog(assembly);
                    addedDefinitions.AddRange(catalog.Parts);
                    addedCatalogs.Add(assembly.FullName, catalog);
                }
            }

            // Generate notifications
            using (var atomicComposition = new AtomicComposition())
            {
                var changingArgs = new ComposablePartCatalogChangeEventArgs(addedDefinitions, Enumerable.Empty <ComposablePartDefinition>(), atomicComposition);
                this.OnChanging(changingArgs);

                using (new WriteLock(this._lock))
                {
                    foreach (var item in addedCatalogs)
                    {
                        this._catalogCollection.Catalogs.Add(item.Value);
                    }
                }
                atomicComposition.Complete();
            }

            var changedArgs = new ComposablePartCatalogChangeEventArgs(addedDefinitions, Enumerable.Empty <ComposablePartDefinition>(), null);

            this.OnChanged(changedArgs);
        }
예제 #21
0
        /// <summary>
        /// Handles the Changing event of the NotifyingCatalog control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.Composition.Hosting.ComposablePartCatalogChangeEventArgs"/> instance containing the event data.</param>
        private void NotifyingCatalog_Changing(object sender, ComposablePartCatalogChangeEventArgs e)
        {
            var removed = parts.Where(x => e.RemovedDefinitions.Contains(x.Key)).Select(x => x.Key).ToList();
            removed.Apply(x => parts.Remove(x));

            var added =
                e.AddedDefinitions.Select(
                    x => new KeyValuePair<ComposablePartDefinition, ComposablePartDefinition>(x, ConvertPart(x)));
            added.Apply(x => parts[x.Key] = x.Value);

            Changing(
                this,
                new ComposablePartCatalogChangeEventArgs(
                    added.Select(x => x.Value),
                    removed,
                    e.AtomicComposition
                    )
                );
        }
            private void OnDefinitionsChanged(ComposablePartDefinition definition, bool added)
            {
                ComposablePartDefinition[] addedDefinitions = added ? new ComposablePartDefinition[] { definition } : new ComposablePartDefinition[0];
                ComposablePartDefinition[] removeDefinitions = added ? new ComposablePartDefinition[0] : new ComposablePartDefinition[] { definition };

                var e = new ComposablePartCatalogChangeEventArgs(addedDefinitions, removeDefinitions, null);
                Changing(this, e);

                if (added)
                {
                    _definitions.Add(definition);
                }
                else
                {
                    _definitions.Remove(definition);
                }

                if (Changed != null)
                {
                    Changed(this, e);
                }
            }
 protected virtual new void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
   Contract.Requires(e != null);
 }
예제 #24
0
 private void OnChangingInternal(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     OnChanging(e);
 }
 /// <summary>
 ///     Raises the <see cref="INotifyComposablePartCatalogChanged.Changing"/> event.
 /// </summary>
 /// <param name="e">
 ///     An <see cref="ComposablePartCatalogChangeEventArgs"/> containing the data for the event.
 /// </param>
 protected virtual void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
     EventHandler<ComposablePartCatalogChangeEventArgs> changingEvent = this.Changing;
     if (changingEvent != null)
     {
         changingEvent(this, e);
     }
 }
예제 #26
0
 /// <summary>
 ///     Raises the <see cref="INotifyComposablePartCatalogChanged.Changing"/> event.
 /// </summary>
 /// <param name="e">
 ///     An <see cref="ComposablePartCatalogChangeEventArgs"/> containing the data for the event.
 /// </param>
 protected virtual void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
     _catalogs.OnChanging(this, e);
 }
예제 #27
0
 private static void ThrowOnRecomposition(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     throw new ChangeRejectedException();
 }
 void catalog_Changed(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     _discoveredContracts = null;
 }
예제 #29
0
 private void OnInnerCatalogsChanged(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     this._isChanged = true;
     this.OnChanged(e);
 }
예제 #30
0
 private void OnChanged(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     this.OnChanged(e);
 }
 /// <summary>
 ///     Raises the <see cref="INotifyComposablePartCatalogChanged.Changing"/> event.
 /// </summary>
 /// <param name="e">
 ///     An <see cref="ComposablePartCatalogChangeEventArgs"/> containing the data for the event.
 /// </param>
 protected virtual void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
     this._catalogs.OnChanging(this, e);
 }
예제 #32
0
 /// <summary>
 /// Raises the <see cref="E:Changed"/> event.
 /// </summary>
 /// <param name="e">The <see cref="System.ComponentModel.Composition.Hosting.ComposablePartCatalogChangeEventArgs"/> instance containing the event data.</param>
 protected virtual void OnChanged(ComposablePartCatalogChangeEventArgs e)
 {
     EventHandler<ComposablePartCatalogChangeEventArgs> changedEvent = this.Changed;
     if (changedEvent != null)
     {
         changedEvent.Invoke(this, e);
     }
 }
예제 #33
0
 private void OnChangingInternal(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     this.OnChanging(e);
 }
예제 #34
0
        private void UpdateWebApiRegistry(ComposablePartCatalogChangeEventArgs eventArg)
        {
            using (TraceSources.AddInManager.TraceActivity("Updating WebApi routes."))
            {
                // TODO this could be cleaned up a bit

                foreach (var partDefinition in eventArg.RemovedDefinitions)
                {
                    IEnumerable<ExportDefinition> exports = partDefinition.ExportDefinitions;
                    var apiExport = exports.SingleOrDefault(export => StringComparer.Ordinal.Equals(export.ContractName, 
                                                                                                    Extensibility.ContractNames.ApiController));
                    if (apiExport == null)
                        continue;

                    IApiControllerMetadata controllerMetadata =
                        AttributedModelServices.GetMetadataView<IApiControllerMetadata>(apiExport.Metadata);

                    Type controllerType = AddInModelServices.GetPartType(partDefinition).Value;

                    string routeName = string.Format("{0}_{1}", 
                                                     controllerMetadata.PackageId, 
                                                     controllerType.FullName.Replace('.', '_'));

                    TraceSources.AddInManager.TraceInformation("Removing route: {0} (Source: {1}, Version: {2})", 
                                                               routeName, 
                                                               controllerMetadata.PackageId, 
                                                               controllerMetadata.PackageVersion);

                    RouteBase route = RouteTable.Routes[routeName];
                    using (RouteTable.Routes.GetWriteLock())
                    {
                        RouteTable.Routes.Remove(route);
                    }
                }

                foreach (var partDefinition in eventArg.AddedDefinitions)
                {
                    IEnumerable<ExportDefinition> exports = partDefinition.ExportDefinitions;
                    var apiExport = exports.SingleOrDefault(export => StringComparer.Ordinal.Equals(export.ContractName, 
                                                                                                    Extensibility.ContractNames.ApiController));
                    if (apiExport == null)
                        continue;

                    IApiControllerMetadata controllerMetadata =
                        AttributedModelServices.GetMetadataView<IApiControllerMetadata>(apiExport.Metadata);

                    Type controllerType = AddInModelServices.GetPartType(partDefinition).Value;

                    // Pacakge version explicitly ignored in order to remain backwards compatible
                    string urlTemplate = string.Format("api/{0}/{1}/", 
                                                       controllerMetadata.PackageId, 
                                                       controllerMetadata.UrlFragment.Trim('/'));

                    string routeName = string.Format("{0}_{1}", 
                                                     controllerMetadata.PackageId, 
                                                     controllerType.FullName.Replace('.', '_'));

                    string controllerName = controllerType.Name.Substring(0, controllerType.Name.Length - "Controller".Length);

                    TraceSources.AddInManager.TraceInformation(
                        "Adding route: {0} (Template: '{1}', Controller: {2}, Source: {3}, Version: {4})", 
                        routeName, 
                        urlTemplate, 
                        controllerName, 
                        controllerMetadata.PackageId, 
                        controllerMetadata.PackageVersion);

                    using (RouteTable.Routes.GetWriteLock())
                    {
                        RouteTable.Routes.MapHttpRoute(
                            routeName, 
                            urlTemplate, 
                            new
                                {
                                    Controller = controllerName, 
                                });
                    }
                }
            }
        }
예제 #35
0
 private void OnInnerCatalogsChanging(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     this.OnChanging(e);
 }
 /// <summary>
 /// Raises the <see cref="Changing"/> event.
 /// </summary>
 /// <param name="e">The <see cref="System.ComponentModel.Composition.Hosting.ComposablePartCatalogChangeEventArgs"/> instance containing the event data.</param>
 protected virtual void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
     Changing?.Invoke(this, e);
 }
예제 #37
0
 private void OnInnerCatalogsChanging(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     this.OnChanging(e);
 }
예제 #38
0
            public void OnChanged(object sender, ComposablePartCatalogChangeEventArgs args)
            {
                Assert.IsTrue(this._expectedAdds != null || this._expectedRemoves != null);

                if (this._expectedAdds == null)
                {
                    EnumerableAssert.IsEmpty(args.AddedDefinitions);
                }
                else
                {
                    EnumerableAssert.AreSequenceEqual(this._expectedAdds, GetDisplayNames(args.AddedDefinitions));
                }

                if (this._expectedRemoves == null)
                {
                    EnumerableAssert.IsEmpty(args.RemovedDefinitions);
                }
                else
                {
                    EnumerableAssert.AreSequenceEqual(this._expectedRemoves, GetDisplayNames(args.RemovedDefinitions));
                }

                Assert.IsNull(args.AtomicComposition);
                Assert.IsTrue(ContainsChanges(), "The catalog should contain the changes");

                this._changedEventCount++;
            }
예제 #39
0
        /// <summary>
        /// </summary>
        /// <param name="assemblies">
        /// </param>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="XapCatalog"/> has been disposed of.
        /// </exception>
        private void DiscoverParts(IEnumerable<Assembly> assemblies)
        {
            ThrowIfDisposed();

            List<ComposablePartDefinition> addedDefinitions = new List<ComposablePartDefinition>();
            Dictionary<string, ComposablePartCatalog> addedCatalogs = new Dictionary<string, ComposablePartCatalog>();
            using (new ReadLock(_lock))
            {
                foreach (Assembly assembly in assemblies)
                {
                    if (addedCatalogs.ContainsKey(assembly.FullName))
                    {
                        // Nothing to do because the assembly has already been added.
                        continue;
                    }

                    AssemblyCatalog catalog = new AssemblyCatalog(assembly);
                    addedDefinitions.AddRange(catalog.Parts);
                    addedCatalogs.Add(assembly.FullName, catalog);
                }
            }

            // Generate notifications
            using (AtomicComposition atomicComposition = new AtomicComposition())
            {
                ComposablePartCatalogChangeEventArgs changingArgs = new ComposablePartCatalogChangeEventArgs(
                    addedDefinitions, Enumerable.Empty<ComposablePartDefinition>(), atomicComposition);
                OnChanging(changingArgs);

                using (new WriteLock(_lock))
                {
                    foreach (KeyValuePair<string, ComposablePartCatalog> item in addedCatalogs)
                    {
                        _catalogCollection.Catalogs.Add(item.Value);
                    }
                }
                atomicComposition.Complete();
            }

            ComposablePartCatalogChangeEventArgs changedArgs = new ComposablePartCatalogChangeEventArgs(
                addedDefinitions, Enumerable.Empty<ComposablePartDefinition>(), null);
            OnChanged(changedArgs);
        }
예제 #40
0
 private void OnChangingInternal(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     var processedArgs = ProcessEventArgs(e);
     if (processedArgs != null)
     {
         this.OnChanging(this.ProcessEventArgs(processedArgs));
     }
 }
예제 #41
0
파일: Editor.cs 프로젝트: akumetsuv/flood
 void catalog_Changed(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     Console.WriteLine(e);
 }
예제 #42
0
        private void OnChanging(ComposablePartCatalogChangeEventArgs e)
        {
            var handler = Changing;
            if (handler != null)
                handler(this, e);

            //changed is not used at all
        }
예제 #43
0
 public void OnChanging(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     Changing?.Invoke(sender, e);
 }
예제 #44
0
 protected virtual void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
     EventHandler<ComposablePartCatalogChangeEventArgs> handler = this.Changing;
     if (handler != null) handler(this, e);
 }
예제 #45
0
 private void OnCatalogChanging(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     throw new ChangeRejectedException(Strings.NotSupportedCatalogChanges);
 }
예제 #46
0
        /// <summary>
        ///     Adds a Package to the catalog. It will ensure that the same Package added more than
        ///     once will not cause duplication in the catalog. It will also ensure that the same
        ///     assembly appearing in multiple packages will not cause duplication in the catalog.
        /// </summary>
        /// <param name="package">
        ///     Package obtained by constructing a <see cref="Package" /> object or 
        ///     calling <see cref="Package.DownloadPackageAsync" />. 
        /// </param>
        public void AddPackage(Package package)
        {
            this.ThrowIfDisposed();

            Requires.NotNull(package, "package");

            List<AssemblyCatalog> addedCatalogs = new List<AssemblyCatalog>();
            ComposablePartDefinition[] addedDefinitions;

            using (new ReadLock(this._lock))
            {
                if (this._packages.ContainsKey(package.Uri))
                {
                    // Nothing to do because the package has already been added.
                    return;
                }

                foreach (Assembly assembly in package.Assemblies)
                {
                    if (!this._loadedAssemblies.Contains(assembly.FullName))
                    {
                        addedCatalogs.Add(new AssemblyCatalog(assembly));
                    }
                }
            }

            addedDefinitions = addedCatalogs.SelectMany(asmCat => asmCat.Parts).ToArray<ComposablePartDefinition>();

            if (addedDefinitions.Length == 0)
            {
                // If the package doesn't contain any added definitions then simply add it to the
                // list of known packages and then return
                using (new WriteLock(this._lock))
                {
                    if (!this._packages.ContainsKey(package.Uri))
                    {
                        this._packages.Add(package.Uri, package);
                    }
                }

                return;
            }

            // Need to raise the changing event inside an AtomicComposition to allow listeners
            // to contribute state change based on whether or not the changes to the catalog
            // are completed.
            using (var atomicComposition = new AtomicComposition())
            {
                var changingArgs = new ComposablePartCatalogChangeEventArgs(addedDefinitions, Enumerable.Empty<ComposablePartDefinition>(), atomicComposition);
                this.OnChanging(changingArgs); // throws ChangedRejectedException if these changes break the composition.

                using (new WriteLock(this._lock))
                {
                    if (this._packages.ContainsKey(package.Uri))
                    {
                        // Someone beat us to it so return and don't complete the AtomicComosition
                        return;
                    }

                    this._packages.Add(package.Uri, package);

                    foreach (var catalog in addedCatalogs)
                    {
                        if (!this._loadedAssemblies.Contains(catalog.Assembly.FullName))
                        {
                            this._loadedAssemblies.Add(catalog.Assembly.FullName);
                            this._parts.AddRange(catalog.Parts);
                        }
                    }
                }

                atomicComposition.Complete();
            }

            var changedArgs = new ComposablePartCatalogChangeEventArgs(addedDefinitions, Enumerable.Empty<ComposablePartDefinition>(), null);
            this.OnChanged(changedArgs);
        }
예제 #47
0
        private ComposablePartCatalogChangeEventArgs ProcessEventArgs(ComposablePartCatalogChangeEventArgs e)
        {
            // the constructor for ComposablePartCatalogChangeEventArgs takes a snapshot of the arguments, so we don't have to
            var result = new ComposablePartCatalogChangeEventArgs(
                e.AddedDefinitions.Where(this._filter),
                e.RemovedDefinitions.Where(this._filter),
                e.AtomicComposition);

            // Only fire if we need to
            if (result.AddedDefinitions.FastAny() || result.RemovedDefinitions.FastAny())
            {
                return result;
            }
            else
            {
                return null;
            }
        }
예제 #48
0
 private void OnCatalogChanging(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     throw new ChangeRejectedException(SR.NotSupportedCatalogChanges);
 }
예제 #49
0
        public void FilteredNotifications()
        {
            var catalog1 = CreateSubCatalog1();
            var catalog2 = CreateSubCatalog2();
            var catalog  = new AggregateCatalog();

            var filter1 = catalog.Filter(p => p.Exports <IContract1>());
            var filter2 = catalog.Filter(p => p.Exports <IContract2>());

            bool filter1Ing = false;
            bool filter1Ed  = false;
            bool filter2Ing = false;
            bool filter2Ed  = false;

            ComposablePartCatalogChangeEventArgs edArgs  = null;
            ComposablePartCatalogChangeEventArgs ingArgs = null;

            filter1.Changing += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.Same(filter1, s);
                Assert.False(filter1Ing);
                Assert.False(filter1Ed);
                Assert.Null(ingArgs);
                Assert.Null(edArgs);

                filter1Ing = true;
                ingArgs    = a;
            };

            filter1.Changed += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.True(filter1Ing);
                Assert.False(filter1Ed);
                Assert.NotNull(ingArgs);
                Assert.Null(edArgs);

                filter1Ed = true;
                edArgs    = a;
                EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, edArgs.AddedDefinitions);
                EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, edArgs.RemovedDefinitions);
            };

            filter2.Changing += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.Same(filter2, s);
                Assert.False(filter2Ing);
                Assert.False(filter2Ed);
                Assert.Null(ingArgs);
                Assert.Null(edArgs);

                filter2Ing = true;
                ingArgs    = a;
            };

            filter2.Changed += (object s, ComposablePartCatalogChangeEventArgs a) =>
            {
                Assert.True(filter2Ing);
                Assert.False(filter2Ed);
                Assert.NotNull(ingArgs);
                Assert.Null(edArgs);

                filter2Ed = true;
                edArgs    = a;
                EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, edArgs.AddedDefinitions);
                EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, edArgs.RemovedDefinitions);
            };

            //at first everything is empty

            // add the first one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Add(catalog1);
            Assert.True(filter1Ing);
            Assert.True(filter1Ed);
            Assert.False(filter2Ing);
            Assert.False(filter2Ed);

            Assert.Equal(2, edArgs.AddedDefinitions.Count());
            Assert.Equal(0, edArgs.RemovedDefinitions.Count());
            Assert.Equal(0, filter2.Parts.Count());
            Assert.Equal(2, filter1.Parts.Count());

            EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, catalog1.Parts);
            EqualityExtensions.CheckEquals(edArgs.AddedDefinitions, catalog1.Parts);

            // add the second one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Add(catalog2);
            Assert.True(filter2Ing);
            Assert.True(filter2Ed);
            Assert.False(filter1Ing);
            Assert.False(filter1Ed);

            Assert.Equal(2, edArgs.AddedDefinitions.Count());
            Assert.Equal(0, edArgs.RemovedDefinitions.Count());
            Assert.Equal(2, filter2.Parts.Count());
            Assert.Equal(2, filter1.Parts.Count());

            EqualityExtensions.CheckEquals(ingArgs.AddedDefinitions, catalog2.Parts);
            EqualityExtensions.CheckEquals(edArgs.AddedDefinitions, catalog2.Parts);

            // remove the second one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Remove(catalog2);
            Assert.True(filter2Ing);
            Assert.True(filter2Ed);
            Assert.False(filter1Ing);
            Assert.False(filter1Ed);

            Assert.Equal(0, edArgs.AddedDefinitions.Count());
            Assert.Equal(2, edArgs.RemovedDefinitions.Count());
            Assert.Equal(0, filter2.Parts.Count());
            Assert.Equal(2, filter1.Parts.Count());

            EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, catalog2.Parts);
            EqualityExtensions.CheckEquals(edArgs.RemovedDefinitions, catalog2.Parts);

            // remove the first one
            filter1Ing = false;
            filter1Ed  = false;
            filter2Ing = false;
            filter2Ed  = false;
            ingArgs    = null;
            edArgs     = null;

            catalog.Catalogs.Remove(catalog1);
            Assert.True(filter1Ing);
            Assert.True(filter1Ed);
            Assert.False(filter2Ing);
            Assert.False(filter2Ed);

            Assert.Equal(0, edArgs.AddedDefinitions.Count());
            Assert.Equal(2, edArgs.RemovedDefinitions.Count());
            Assert.Equal(0, filter2.Parts.Count());
            Assert.Equal(0, filter1.Parts.Count());

            EqualityExtensions.CheckEquals(ingArgs.RemovedDefinitions, catalog1.Parts);
            EqualityExtensions.CheckEquals(edArgs.RemovedDefinitions, catalog1.Parts);
        }
예제 #50
0
 protected virtual new void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
 }
예제 #51
0
파일: Program.cs 프로젝트: comsechq/autobot
        void directoryCatalog_Changed(object sender, ComposablePartCatalogChangeEventArgs e)
        {
            // Register handlers
            foreach (var handler in handlers)
            {
                Stencil.Instance.AddType(handler.GetType());

                var instance = Stencil.Instance.Resolve(handler.GetType()) as IHandler;

                handlerService.Handlers.Add(instance);
            }
        }
예제 #52
0
 protected virtual void OnChanged(ComposablePartCatalogChangeEventArgs e)
 {
     if (Changed != null)
         Changed(this, e);
 }
 protected virtual new void OnChanging(ComposablePartCatalogChangeEventArgs e)
 {
     Contract.Requires(e != null);
 }
예제 #54
0
        protected virtual void OnChanged(ComposablePartCatalogChangeEventArgs e)
        {
            var handler = this.Changed;

            if (handler != null)
            {
                handler(this, e);
            }
        }
예제 #55
0
        /// <summary>
        ///     Refreshes the <see cref="ComposablePartDefinition"/>s with the latest files in the directory that match
        ///     the searchPattern. If any files have been added they will be added to the catalog and if any files were
        ///     removed they will be removed from the catalog. For files that have been removed keep in mind that the
        ///     assembly cannot be unloaded from the process so <see cref="ComposablePartDefinition"/>s for those files
        ///     will simply be removed from the catalog.
        ///
        ///     Possible exceptions that can be thrown are any that <see cref="Directory.GetFiles(string, string)"/> or
        ///     <see cref="Assembly.Load(AssemblyName)"/> can throw.
        /// </summary>
        /// <exception cref="DirectoryNotFoundException">
        ///     The specified path has been removed since object construction.
        /// </exception>
        public void Refresh()
        {
            ThrowIfDisposed();
            if (_loadedFiles == null)
            {
                throw new Exception(SR.Diagnostic_InternalExceptionMessage);
            }

            List <Tuple <string, AssemblyCatalog> > catalogsToAdd;
            List <Tuple <string, AssemblyCatalog> > catalogsToRemove;

            ComposablePartDefinition[] addedDefinitions;
            ComposablePartDefinition[] removedDefinitions;
            object changeReferenceObject;

            string[] afterFiles;
            string[] beforeFiles;

            while (true)
            {
                afterFiles = GetFiles();

                using (new ReadLock(_thisLock))
                {
                    changeReferenceObject = _loadedFiles;
                    beforeFiles           = _loadedFiles.ToArray();
                }

                DiffChanges(beforeFiles, afterFiles, out catalogsToAdd, out catalogsToRemove);

                // Don't go any further if there's no work to do
                if (catalogsToAdd.Count == 0 && catalogsToRemove.Count == 0)
                {
                    return;
                }

                // Notify listeners to give them a preview before completeting the changes
                addedDefinitions = catalogsToAdd
                                   .SelectMany(cat => cat.Item2 as IEnumerable <ComposablePartDefinition>)
                                   .ToArray <ComposablePartDefinition>();

                removedDefinitions = catalogsToRemove
                                     .SelectMany(cat => cat.Item2 as IEnumerable <ComposablePartDefinition>)
                                     .ToArray <ComposablePartDefinition>();

                using (var atomicComposition = new AtomicComposition())
                {
                    var changingArgs = new ComposablePartCatalogChangeEventArgs(addedDefinitions, removedDefinitions, atomicComposition);
                    OnChanging(changingArgs);

                    // if the change went through then write the catalog changes
                    using (new WriteLock(_thisLock))
                    {
                        if (changeReferenceObject != _loadedFiles)
                        {
                            // Someone updated the list while we were diffing so we need to try the diff again
                            continue;
                        }

                        foreach (var catalogToAdd in catalogsToAdd)
                        {
                            _assemblyCatalogs.Add(catalogToAdd.Item1, catalogToAdd.Item2);
                            _catalogCollection.Add(catalogToAdd.Item2);
                        }

                        foreach (var catalogToRemove in catalogsToRemove)
                        {
                            _assemblyCatalogs.Remove(catalogToRemove.Item1);
                            _catalogCollection.Remove(catalogToRemove.Item2);
                        }

                        _loadedFiles = afterFiles.ToReadOnlyCollection();

                        // Lastly complete any changes added to the atomicComposition during the change event
                        atomicComposition.Complete();

                        // Break out of the while(true)
                        break;
                    } // WriteLock
                }     // AtomicComposition
            }   // while (true)

            var changedArgs = new ComposablePartCatalogChangeEventArgs(addedDefinitions, removedDefinitions, null);

            OnChanged(changedArgs);
        }
예제 #56
0
        /// <summary>
        /// Fires the <see cref="Changed"/> event.
        /// </summary>
        /// <param name="addedDefinitions">The collection of added <see cref="ComposablePartDefinition"/> instances.</param>
        /// <param name="removedDefinitions">The collection of removed <see cref="ComposablePartDefinition"/> instances.</param>
        /// <param name="composition"><see cref="AtomicComposition"/> instance.</param>
        protected virtual void OnChanged(IEnumerable<ComposablePartDefinition> addedDefinitions, IEnumerable<ComposablePartDefinition> removedDefinitions, AtomicComposition composition)
        {
            if (Changed != null)
            {
                if (addedDefinitions == null) addedDefinitions = Enumerable.Empty<ComposablePartDefinition>();
                if (removedDefinitions == null) removedDefinitions = Enumerable.Empty<ComposablePartDefinition>();

                var args = new ComposablePartCatalogChangeEventArgs(
                    addedDefinitions, removedDefinitions, composition);

                Changed(this, args);
            }
        }
        /// <summary>
        ///     Refreshes the <see cref="ComposablePartDefinition"/>s with the latest files in the directory that match
        ///     the searchPattern. If any files have been added they will be added to the catalog and if any files were
        ///     removed they will be removed from the catalog. For files that have been removed keep in mind that the 
        ///     assembly cannot be unloaded from the process so <see cref="ComposablePartDefinition"/>s for those files
        ///     will simply be removed from the catalog.
        /// 
        ///     Possible exceptions that can be thrown are any that <see cref="Directory.GetFiles(string, string)"/> or 
        ///     <see cref="Assembly.Load(AssemblyName)"/> can throw.
        /// </summary>
        /// <exception cref="DirectoryNotFoundException">
        ///     The specified <paramref name="path"/> has been removed since object construction.
        /// </exception>
        public void Refresh()
        {
            this.ThrowIfDisposed();
            Assumes.NotNull(this._loadedFiles);

            List<Tuple<string, AssemblyCatalog>> catalogsToAdd;
            List<Tuple<string, AssemblyCatalog>> catalogsToRemove;
            ComposablePartDefinition[] addedDefinitions;
            ComposablePartDefinition[] removedDefinitions;
            object changeReferenceObject;
            string[] afterFiles;
            string[] beforeFiles;

            while (true)
            {
                afterFiles = this.GetFiles();

                using (new ReadLock(this._thisLock))
                {
                    changeReferenceObject = this._loadedFiles;
                    beforeFiles = this._loadedFiles.ToArray();
                }

                this.DiffChanges(beforeFiles, afterFiles, out catalogsToAdd, out catalogsToRemove);

                // Don't go any further if there's no work to do
                if (catalogsToAdd.Count == 0 && catalogsToRemove.Count == 0)
                {
                    return;
                }

                // Notify listeners to give them a preview before completeting the changes
                addedDefinitions = catalogsToAdd
                    .SelectMany(cat => cat.Item2.Parts)
                    .ToArray<ComposablePartDefinition>();

                removedDefinitions = catalogsToRemove
                    .SelectMany(cat => cat.Item2.Parts)
                    .ToArray<ComposablePartDefinition>();

                using (var atomicComposition = new AtomicComposition())
                {
                    var changingArgs = new ComposablePartCatalogChangeEventArgs(addedDefinitions, removedDefinitions, atomicComposition);
                    this.OnChanging(changingArgs);
       
                    // if the change went through then write the catalog changes
                    using (new WriteLock(this._thisLock))
                    {
                        if (changeReferenceObject != this._loadedFiles)
                        {
                            // Someone updated the list while we were diffing so we need to try the diff again
                            continue;
                        }

                        foreach (var catalogToAdd in catalogsToAdd)
                        {
                            this._assemblyCatalogs.Add(catalogToAdd.Item1, catalogToAdd.Item2);
                            this._catalogCollection.Add(catalogToAdd.Item2);
                        }

                        foreach (var catalogToRemove in catalogsToRemove)
                        {
                            this._assemblyCatalogs.Remove(catalogToRemove.Item1);
                            this._catalogCollection.Remove(catalogToRemove.Item2);
                        }

                        this._partsQuery = this._catalogCollection.AsQueryable().SelectMany(catalog => catalog.Parts);
                        this._loadedFiles = afterFiles.ToReadOnlyCollection();

                        // Lastly complete any changes added to the atomicComposition during the change event
                        atomicComposition.Complete();

                        // Break out of the while(true)
                        break;
                    } // WriteLock
                } // AtomicComposition
            }   // while (true)

            var changedArgs = new ComposablePartCatalogChangeEventArgs(addedDefinitions, removedDefinitions, null);
            this.OnChanged(changedArgs);
        }
예제 #58
0
 private void HandleInterceptedCatalogChanging(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     Recompose(e.AddedDefinitions, e.RemovedDefinitions, e.AtomicComposition);
 }
예제 #59
0
 static void _catalog_Changed(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     _catalog.Refresh();
 }
예제 #60
0
 private void OnInnerCatalogsChanged(object sender, ComposablePartCatalogChangeEventArgs e)
 {
     this._isChanged = true;
     this.OnChanged(e);
 }