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); } } }
public async Task <IDialController> TryCreateControllerAsync(IAsyncServiceProvider provider, CancellationToken cancellationToken) { var controller = await TryCreateControllerAsyncOverride(provider, cancellationToken); compositionService.SatisfyImportsOnce(controller); return(controller); }
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); }
public static IEnumerable <Lazy <TComponent, TMetadata> > ImportMany(ICompositionService compositionService) { var importer = new ManyImporter(); compositionService.SatisfyImportsOnce(importer); return(Orderer.Order(importer.Imports)); }
public static IEnumerable <Lazy <TComponent> > ImportMany(ICompositionService compositionService) { ManyImporter importer = new ManyImporter(); compositionService.SatisfyImportsOnce(importer); return(importer.Imports); }
public void SatisfyImports_AttributedAndBooleanOverride_NullAsCompositionService() { ICompositionService compositionService = null; Assert.Throws <ArgumentNullException>("compositionService", () => { compositionService.SatisfyImportsOnce(new MockAttributedPart()); }); }
[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); }
/// <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); }
/// <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); }
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); }
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); }
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); }
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)); }
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); }
public NamedExportLocator(ICompositionService cs) { cs.SatisfyImportsOnce(this); }
public ExportFactoryProvider(ICompositionService cc) { cc.SatisfyImportsOnce(this); }
public static T Compose <T>(this ICompositionService compositionService, T obj) where T : class { compositionService.SatisfyImportsOnce(obj); return(obj); }
public ContentTypeLocator(ICompositionService cs) { cs.SatisfyImportsOnce(this); }
public ImportComposer(ICompositionService cs) { cs.SatisfyImportsOnce(this); }
public Holder(ICompositionService cc) { cc.SatisfyImportsOnce(this); }
public ContentTypeImportComposer(ICompositionService cs) : base(cs) { cs.SatisfyImportsOnce(this); }