示例#1
0
 private void AddResourceImpl(IEnumerable <IResource> formats, ICompositionService container)
 {
     foreach (var impl in formats)
     {
         try
         {
             var part = AttributedModelServices.CreatePart(impl);
             if (part.ImportDefinitions.Any())
             {
                 container.SatisfyImportsOnce(part);
             }
         }
         catch (Exception X)
         {
             System.Diagnostics.Trace.WriteLine(X.Message, impl.Tag);
         }
         foreach (var ext in impl.Extensions)
         {
             m_extension_map.Add(ext.ToUpperInvariant(), impl);
         }
         foreach (var signature in impl.Signatures)
         {
             m_signature_map.Add(signature, impl);
         }
     }
 }
示例#2
0
        public async Task <IDialController> TryCreateControllerAsync(IAsyncServiceProvider provider, CancellationToken cancellationToken)
        {
            var controller = await TryCreateControllerAsyncOverride(provider, cancellationToken);

            compositionService.SatisfyImportsOnce(controller);
            return(controller);
        }
示例#3
0
        public static TComponent Import(ICompositionService compositionService)
        {
            var importer = new SingleImporter();

            compositionService.SatisfyImportsOnce(importer);
            return(importer.Import);
        }
 public ViewViewModelFactory(
     IGitHubServiceProvider serviceProvider,
     ICompositionService cc)
 {
     this.serviceProvider = serviceProvider;
     cc.SatisfyImportsOnce(this);
 }
示例#5
0
        public static IEnumerable <Lazy <TComponent, TMetadata> > ImportMany(ICompositionService compositionService)
        {
            var importer = new ManyImporter();

            compositionService.SatisfyImportsOnce(importer);
            return(Orderer.Order(importer.Imports));
        }
示例#6
0
        public static IEnumerable <Lazy <TComponent> > ImportMany(ICompositionService compositionService)
        {
            ManyImporter importer = new ManyImporter();

            compositionService.SatisfyImportsOnce(importer);
            return(importer.Imports);
        }
示例#7
0
        public void SatisfyImports_AttributedAndBooleanOverride_NullAsCompositionService()
        {
            ICompositionService compositionService = null;

            Assert.Throws <ArgumentNullException>("compositionService", () =>
            {
                compositionService.SatisfyImportsOnce(new MockAttributedPart());
            });
        }
示例#8
0
        [MefFact(CompositionEngines.V1Compat, typeof(CompositionServiceImportingPart))] // intentionally leaves out ImportOnlyPart
        public void SatisfyImportsOnceWithUnknownImportOnlyPart(IContainer container)
        {
            var exportedPart = container.GetExportedValue <CompositionServiceImportingPart>();
            ICompositionService compositionService = exportedPart.CompositionService;

            var value = new ImportOnlyPart();

            compositionService.SatisfyImportsOnce(value);
            Assert.NotNull(value.SomePropertyThatImports);
        }
        /// <summary>
        ///     Satisfies the imports of the specified attributed object exactly once and they will not
        ///     ever be recomposed.
        /// </summary>
        /// <param name="part">
        ///     The attributed object to set the imports.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="attributedPart"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="CompositionException">
        ///     An error occurred during composition. <see cref="CompositionException.Errors"/> will
        ///     contain a collection of errors that occurred.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="ICompositionService"/> has been disposed of.
        /// </exception>
        public static ComposablePart SatisfyImportsOnce(this ICompositionService compositionService, object attributedPart)
        {
            Requires.NotNull(compositionService, "compositionService");
            Requires.NotNull(attributedPart, "attributedPart");

            ComposablePart part = AttributedModelServices.CreatePart(attributedPart);

            compositionService.SatisfyImportsOnce(part);

            return(part);
        }
示例#10
0
        /// <summary>
        ///     Satisfies the imports of the specified attributed object exactly once and they will not
        ///     ever be recomposed.
        /// </summary>
        /// <param name="part">
        ///     The attributed object to set the imports.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="compositionService"/> or <paramref name="attributedPart"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="CompositionException">
        ///     An error occurred during composition. <see cref="CompositionException.Errors"/> will
        ///     contain a collection of errors that occurred.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="ICompositionService"/> has been disposed of.
        /// </exception>
        public static ComposablePart SatisfyImportsOnce(this ICompositionService compositionService, object attributedPart)
        {
            Requires.NotNull(compositionService, nameof(compositionService));
            Requires.NotNull(attributedPart, nameof(attributedPart));
            Contract.Ensures(Contract.Result <ComposablePart>() != null);

            ComposablePart part = AttributedModelServices.CreatePart(attributedPart);

            compositionService.SatisfyImportsOnce(part);

            return(part);
        }
        /// <summary>
        ///     Satisfies the imports of the specified attributed object exactly once and they will not
        ///     ever be recomposed.
        /// </summary>
        /// <param name="compositionService">The composition service to use.</param>
        /// <param name="attributedPart">
        ///     The attributed object to set the imports.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="compositionService"/> or <paramref name="attributedPart"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="CompositionException">
        ///     An error occurred during composition. <see cref="CompositionException.Errors"/> will
        ///     contain a collection of errors that occurred.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="ICompositionService"/> has been disposed of.
        /// </exception>
        public static ComposablePart SatisfyImportsOnce(this ICompositionService compositionService, object attributedPart)
        {
            Requires.NotNull(compositionService, nameof(compositionService));
            Requires.NotNull(attributedPart, nameof(attributedPart));

            ComposablePart part = AttributedModelServices.CreatePart(attributedPart);

            compositionService.SatisfyImportsOnce(part);

            Debug.Assert(part != null);
            return(part);
        }
示例#12
0
        /// <summary>
        ///     Satisfies the imports of the specified attributed object exactly once and they will not
        ///     ever be recomposed.
        /// </summary>
        /// <param name="part">
        ///     The attributed object to set the imports.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="compositionService"/> or <paramref name="attributedPart"/>  or <paramref name="reflectionContext"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="CompositionException">
        ///     An error occurred during composition. <see cref="CompositionException.Errors"/> will
        ///     contain a collection of errors that occurred.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="ICompositionService"/> has been disposed of.
        /// </exception>
        public static ComposablePart SatisfyImportsOnce(this ICompositionService compositionService, object attributedPart, ReflectionContext reflectionContext)
        {
            Requires.NotNull(compositionService, "compositionService");
            Requires.NotNull(attributedPart, "attributedPart");
            Requires.NotNull(reflectionContext, "reflectionContext");
            Contract.Ensures(Contract.Result <ComposablePart>() != null);

            ComposablePart part = AttributedModelServices.CreatePart(attributedPart, reflectionContext);

            compositionService.SatisfyImportsOnce(part);

            return(part);
        }
示例#13
0
        public CoreEditor(string text, string filePath, string contentTypeName) {
            _compositionService = EditorShell.Current.CompositionService;
            _compositionService.SatisfyImportsOnce(this);
            _filePath = filePath;

            if (string.IsNullOrEmpty(_filePath) || Path.GetExtension(_filePath).Length == 0) {
                if (contentTypeName == null)
                    throw new ArgumentNullException(nameof(contentTypeName));

                _contentType = ContentTypeRegistryService.GetContentType(contentTypeName);
            }

            CreateTextViewHost(text, filePath);
        }
示例#14
0
        public CoreEditor(string text, string filePath, string contentTypeName)
        {
            _compositionService = EditorShell.Current.CompositionService;
            _compositionService.SatisfyImportsOnce(this);
            _filePath = filePath;

            if (string.IsNullOrEmpty(_filePath) || Path.GetExtension(_filePath).Length == 0)
            {
                if (contentTypeName == null)
                {
                    throw new ArgumentNullException(nameof(contentTypeName));
                }

                _contentType = ContentTypeRegistryService.GetContentType(contentTypeName);
            }

            CreateTextViewHost(text, filePath);
        }
示例#15
0
        private async Task <ExportProvider> Compose(object parentInstance)
        {
            ExportProvider exportProvider = null;
            PartDiscovery  discovery      = PartDiscovery.Combine(
                new AttributedPartDiscovery(Resolver.DefaultInstance),
                new AttributedPartDiscoveryV1(Resolver.DefaultInstance)); // ".NET MEF" attributes (System.ComponentModel.Composition)

            Assembly parentAssembly = parentInstance.GetType().Assembly;
            string   parentLocation = parentAssembly.Location;
            string   assemblyPath   = parentLocation;

            assemblyPath = assemblyPath.Substring(0, assemblyPath.LastIndexOf('\\'));

            Helpers       desktopBridgeHelper = new Helpers();
            List <string> assemblies          = new[] { parentLocation }
            .Concat(
                Directory.EnumerateFiles(assemblyPath, "*.dll", SearchOption.TopDirectoryOnly)
                .Where(_ => _.Contains("NUnit3GUI")))
            .ToList();

            DiscoveredParts discoveredParts = await discovery.CreatePartsAsync(assemblies);

            discoveredParts.ThrowOnErrors();

            ComposableCatalog catalog = ComposableCatalog.Create(Resolver.DefaultInstance)
                                        .AddParts(discoveredParts)
                                        .WithCompositionService();

            CompositionConfiguration config = CompositionConfiguration.Create(catalog);

            config.ThrowOnErrors();

            IExportProviderFactory epf = config.CreateExportProviderFactory();

            exportProvider = epf.CreateExportProvider();

            ICompositionService service = exportProvider.GetExportedValue <ICompositionService>();

            service.SatisfyImportsOnce(parentInstance);

            return(exportProvider);
        }
示例#16
0
        public override void SelectObject(object obj)
        {
            if (this.descriptor != null)
            {
                if (this.descriptor is INotifyPropertyChanged)
                {
                    (this.descriptor as INotifyPropertyChanged).PropertyChanged -= Table_PropertyChanged;
                }
            }

            this.descriptor = obj as ITableDescriptor;

            if (this.descriptor != null)
            {
                if (this.descriptor is INotifyPropertyChanged)
                {
                    (this.descriptor as INotifyPropertyChanged).PropertyChanged += Table_PropertyChanged;
                }

                var browser = this.browser.Value;
                var types   = EnumerableUtility.Descendants <TreeViewItemViewModel, TypeTreeViewItemViewModel>(browser.Items, item => item.Items);
                var query   = from item in this.descriptor.TableInfo.Columns
                              join type in types on item.DataType equals(type.TypeInfo.CategoryPath + type.TypeInfo.Name)
                              select type;

                var typeItems = query.Distinct()
                                .Select(item => new TypeListBoxItemViewModel(item))
                                .ToArray();

                foreach (var item in typeItems)
                {
                    compositionService.SatisfyImportsOnce(item);
                }
                this.Types = typeItems;
            }

            this.NotifyOfPropertyChange(nameof(this.IsVisible));
            this.NotifyOfPropertyChange(nameof(this.SelectedObject));
        }
示例#17
0
        public ConnectionViewModel(ICompositionService compositionService)
        {
            compositionService.SatisfyImportsOnce(this);

            _changesetHelper = new ChangesetHelper <ICanPort>();

            var interfacesBindingDisposable = Observable.Timer(
                TimeSpan.Zero,
                TimeSpan.FromMilliseconds(500),
                RxApp.MainThreadScheduler)
                                              .Select(_ => _changesetHelper.ApplyChanges(GetPorts()))
                                              .Bind(out _interfaces)
                                              .Subscribe(changeSet =>
            {
                if (Interface != null && changeSet.Removes(Interface))
                {
                    Interface = null;
                }
                if (Interface == null && changeSet.Adds > 0)
                {
                    Interface = changeSet.GetFirstAddedItemOrDefault();
                }
            });

            var stateIsValid = this.WhenAnyValue(
                x => x.Interface,
                x => x.BitRate,
                (iface, bitRate) => iface != null && bitRate != null);

            Connect = ReactiveCommand.CreateFromTask <Window>(async window =>
            {
                Busy = true;

                try
                {
                    await Task.Run(async() =>
                    {
                        using (var cts = new CancellationTokenSource(Constants.InterfaceConnectionTimeoutMs))
                        {
                            Driver = await Interface.OpenAsync(BitRate.Value, cts.Token).ConfigureAwait(false);
                        }
                    });

                    window.DialogResult = true;
                    window.Close();
                }
                catch
                {
                    Busy = false;
                    throw;
                }
            },
                                                              canExecute: stateIsValid);

            var connectThrownExceptionsDisposable = Connect.ThrownExceptions
                                                    .Subscribe(ex =>
            {
                ErrorWindow.Show(
                    $"Cannot connect to {Interface.DisplayName} at bitrate {BitRate?.ToString() ?? "<Invalid>"}.",
                    ex.ToString());
            });

            _cleanUp = new CompositeDisposable(
                interfacesBindingDisposable,
                connectThrownExceptionsDisposable);
        }
示例#18
0
 public NamedExportLocator(ICompositionService cs)
 {
     cs.SatisfyImportsOnce(this);
 }
 public ExportFactoryProvider(ICompositionService cc)
 {
     cc.SatisfyImportsOnce(this);
 }
示例#20
0
 public static T Compose <T>(this ICompositionService compositionService, T obj) where T : class
 {
     compositionService.SatisfyImportsOnce(obj);
     return(obj);
 }
示例#21
0
 public ExportFactoryProvider(ICompositionService cc)
 {
     cc.SatisfyImportsOnce(this);
 }
 public ContentTypeLocator(ICompositionService cs)
 {
     cs.SatisfyImportsOnce(this);
 }
示例#23
0
 public ImportComposer(ICompositionService cs)
 {
     cs.SatisfyImportsOnce(this);
 }
示例#24
0
 public Holder(ICompositionService cc)
 {
     cc.SatisfyImportsOnce(this);
 }
 public ContentTypeImportComposer(ICompositionService cs)
     : base(cs)
 {
     cs.SatisfyImportsOnce(this);
 }
示例#26
0
 public ContentTypeLocator(ICompositionService cs)
 {
     cs.SatisfyImportsOnce(this);
 }