public static IEnumerable <Lazy <TComponent, TMetadata> > ImportMany(ICompositionService compositionService, IContentType contentType) { IEnumerable <Lazy <TComponent, TMetadata> > components = ComponentLocatorWithMetadata <TComponent, TMetadata> .ImportMany(compositionService); return(FilterByContentType(contentType, components)); }
void RunQueries(ICompositionService comp) { //var rq = comp.Get<IRepository<Model.DnsDomain, Model.Request>>().All.FirstOrDefault(); //if ( rq == null ) return; //Log.Info( "Precompiling: VirtualResponse - Get by ID" ); //comp.Get<IResponseService>().GetVirtualResponses( rq.Id, "1,2,3" ).FirstOrDefault(); //Log.Info( "Precompiling: VirtualResponse - Get by ID (done)" ); //var ctr = comp.Get<Controllers.RequestController>(); //var ctx = comp.Get<IRequestService>().GetRequestContext( rq.Id ); //var allSorts = from sk in Controllers.RequestController.ResponsesSort.AllKeys.StartWith( "" ) // let sd = Controllers.RequestController.ResponsesSort.GetSortDefinition( sk, null ) // from asc in new[] { sd.IsAscending, !sd.IsAscending } // from page in new[] { "0", "1" } // select new Models.RequestChildrenGetModel // { // Page = page, // Sort = sk, // SortDirection = asc ? "asc" : "desc" // }; //foreach ( var s in allSorts ) //{ // var msg = "Precompiling: VirtualResponse - order by " + (s.Sort.NullOrEmpty() ? "[default]" : s.Sort) + " " + s.SortDirection + ", page " + s.Page; // Log.Info( msg ); // ctr.ResponsesListModel( ctx, s ); // Log.Info( msg + " (done)" ); //} }
public async Task Initialize() { if (_initialized) { return; } var discovery = PartDiscovery.Combine(new AttributedPartDiscoveryV1(Resolver.DefaultInstance)); var catalog = ComposableCatalog.Create(Resolver.DefaultInstance) .AddParts(await discovery.CreatePartsAsync(Assembly.GetExecutingAssembly())) .AddParts(await discovery.CreatePartsAsync(Assembly.GetCallingAssembly())) .AddParts(await discovery.CreatePartsAsync(Assembly.GetEntryAssembly())) .AddParts(await discovery.CreatePartsAsync(_directoryCatalog.Assemblies)) .WithCompositionService(); // Makes an ICompositionService export available to MEF parts to import // Assemble the parts into a valid graph. var config = CompositionConfiguration.Create(catalog); // Prepare an ExportProvider factory based on this graph. Factory = config.CreateExportProviderFactory(); // Create an export provider, which represents a unique container of values. ExportProvider = Factory.CreateExportProvider(); CompositionService = ExportProvider.GetExportedValue <ICompositionService>(); _initialized = true; }
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 ConnectionWindow(ICompositionService compositionService) { InitializeComponent(); ViewModel = new ConnectionViewModel(compositionService); this.WhenActivated(d => { this.OneWayBind(ViewModel, viewModel => viewModel.Busy, view => view.bBusyIndicator.Visibility) .DisposeWith(d); this.OneWayBind(ViewModel, viewModel => viewModel.Interfaces, view => view.cbInterfaces.ItemsSource) .DisposeWith(d); this.Bind(ViewModel, viewModel => viewModel.Interface, view => view.cbInterfaces.SelectedItem) .DisposeWith(d); this.WhenAnyValue(v => v.upBitRate.Value) .Select(x => x.HasValue ? (int?)x.Value : null) .BindTo(this, v => v.ViewModel.BitRate) .DisposeWith(d); this.BindCommand(ViewModel, vm => vm.Connect, v => v.bOk, Observable.Return(this)) .DisposeWith(d); }); }
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel)).ConfigureAwait(true)); ICompositionService compositionService = componentModel.DefaultCompositionService; var debugFrameworksCmd = componentModel.DefaultExportProvider.GetExport <DebugFrameworksDynamicMenuCommand>(); var mcs = (await GetServiceAsync(typeof(IMenuCommandService)).ConfigureAwait(true)) as OleMenuCommandService; mcs.AddCommand(debugFrameworksCmd.Value); var debugFrameworksMenuTextUpdater = componentModel.DefaultExportProvider.GetExport <DebugFrameworkPropertyMenuTextUpdater>(); mcs.AddCommand(debugFrameworksMenuTextUpdater.Value); // Need to use the CPS export provider to get the dotnet compatibility detector Lazy <IProjectServiceAccessor> projectServiceAccessor = componentModel.DefaultExportProvider.GetExport <IProjectServiceAccessor>(); _dotNetCoreCompatibilityDetector = projectServiceAccessor.Value.GetProjectService().Services.ExportProvider.GetExport <IDotNetCoreProjectCompatibilityDetector>().Value; await _dotNetCoreCompatibilityDetector.InitializeAsync().ConfigureAwait(true); #if DEBUG DebuggerTraceListener.RegisterTraceListener(); #endif }
public static IEnumerable <Lazy <TComponent, TMetadata> > ImportMany(ICompositionService compositionService) { var importer = new ManyImporter(); compositionService.SatisfyImportsOnce(importer); return(Orderer.Order(importer.Imports)); }
public ViewViewModelFactory( IGitHubServiceProvider serviceProvider, ICompositionService cc) { this.serviceProvider = serviceProvider; cc.SatisfyImportsOnce(this); }
public static TComponent Import(ICompositionService compositionService) { var importer = new SingleImporter(); compositionService.SatisfyImportsOnce(importer); return(importer.Import); }
public static IEnumerable <Lazy <TComponent> > ImportMany(ICompositionService compositionService) { ManyImporter importer = new ManyImporter(); compositionService.SatisfyImportsOnce(importer); return(importer.Imports); }
public CremaAppHostViewModel(ICremaHost cremaHost, IAppConfiguration configs, ICompositionService compositionService) { this.cremaHost = cremaHost; this.cremaHost.Opened += CremaHost_Opened; this.configs = configs; this.compositionService = compositionService; this.theme = Themes.Keys.FirstOrDefault(); this.themeColor = FirstFloor.ModernUI.Presentation.AppearanceManager.Current.AccentColor; this.loginCommand = new DelegateCommand((p) => this.Login(), (p) => this.CanLogin); this.connectionItems = ConnectionItemCollection.Read(AppUtility.GetDocumentFilename("ConnectionList.xml")); this.compositionService.SatisfyImportsOnce(this.connectionItems); this.ConnectionItem = this.connectionItems.FirstOrDefault(item => item.IsDefault); this.authenticator = this.cremaHost.GetService(typeof(Authenticator)) as Authenticator; this.configs.Update(this); this.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(this.IsProgressing)) { this.Shell.IsProgressing = this.IsProgressing; } else if (e.PropertyName == nameof(this.ProgressMessage)) { this.Shell.ProgressMessage = this.ProgressMessage; } }; }
public CompositionViewModel(ICompositionService service) { //TODO I thought this was done in ShellViewModel. Investigate Provenance_X = Infrastructure.Constants.Palette.TruePaletteWidth; Provenance_Y = Infrastructure.Constants.Defaults.MeasureHeight; ProvenanceVisibility = Visibility.Collapsed; UploadDetailsVisibility = Visibility.Collapsed; //End TODO Hide(); MeasureManager.Initialize(); _service = service; if (_service.Composition == null || _service.Composition.Staffgroups.Count == 0) { service.CompositionLoadingComplete += CompositionLoadingComplete; service.CompositionLoadingError += CompositionLoadingError; service.GetCompositionAsync(); } else { LoadComposition(service.Composition); } SubscribeEvents(); DefineCommands(); ScaleX = 1; ScaleY = 1; ScrollWidth = EditorState.ViewportWidth - horizontalScrollOffset; ScrollHeight = EditorState.ViewportHeight - verticalScrollOffset; ScrollVisibility = ScrollBarVisibility.Auto; }
private byte[] GetFileSegment(ICompositionService scope, int fileId, int ofs, int size) { var buf = new byte[size]; using (var str = scope.Get <IFileSystemService <TestDomain> >().OpenFile(fileId)) { str.Position = Math.Max(0, ofs); var total = 0; while (total < size) { var read = str.Read(buf, total, size - total); if (read == 0) { break; } total += read; } if (total < size) { Array.Resize(ref buf, total); } return(buf); } }
public Factory([NotNull] IConfiguration configuration, [NotNull] ICompositionService compositionService, [NotNull] ITraceService trace, [NotNull] IConsoleService console, [NotNull] IFileSystem fileSystem) { Configuration = configuration; CompositionService = compositionService; Trace = trace; Console = console; FileSystem = fileSystem; }
public void SatisfyImports_AttributedAndBooleanOverride_NullAsCompositionService() { ICompositionService compositionService = null; Assert.Throws <ArgumentNullException>("compositionService", () => { compositionService.SatisfyImportsOnce(new MockAttributedPart()); }); }
public ModuleController(IModuleService moduleService, IServiceService serviceService, ITModuleService tmoduleService, IComposantService composantService, ICompositionService compositionService) { this._moduleService = moduleService; this._serviceService = serviceService; this._tmoduleService = tmoduleService; this._composantService = composantService; this._compositionService = compositionService; this._service = "Recherche & développement"; }
public static IEditorInstance CreateEditorInstance(ITextBuffer textBuffer, ICompositionService compositionService) { var importComposer = new ContentTypeImportComposer <IEditorFactory>(compositionService); var factory = importComposer.GetImport(textBuffer.ContentType.TypeName); var documentFactoryImportComposer = new ContentTypeImportComposer <IEditorDocumentFactory>(compositionService); var documentFactory = documentFactoryImportComposer.GetImport(textBuffer.ContentType.TypeName); return(factory?.CreateEditorInstance(textBuffer, documentFactory)); }
[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); }
public IPropertyFilter ParseComponent <TDomain>(ICompositionService comp, PropertyFilterFactory <TDomain> factory, IPropertyFilter sourceFilter, IAuditProperty p, PropertyValueComparison cmp, string value) { var res = from prop in Maybe.Value(p as IAuditProperty <TProp>) from selector in comp.Get <PropertyValueSelectorCache <TProp> >().GetSelector(prop) from parsed in Maybe.SafeValue(() => selector.ParsePostedValue(value)) select sourceFilter == null?factory.Create(prop, parsed, cmp) : sourceFilter.And(prop, parsed, cmp); return(res.ValueOrNull() ?? sourceFilter); }
/// <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> /// Reverses the order of imported items /// </summary> public static IEnumerable <Lazy <TComponent, TMetadata> > ReverseImportMany(ICompositionService compositionService) { List <Lazy <TComponent, TMetadata> > reversedList = new List <Lazy <TComponent, TMetadata> >(); foreach (Lazy <TComponent, TMetadata> item in ImportMany(compositionService)) { reversedList.Insert(0, item); } return(reversedList); }
/// <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 static IEditorInstance CreateEditorInstance(ITextBuffer textBuffer, ICompositionService cs) { var importComposer = new ContentTypeImportComposer<IEditorFactory>(cs); var factory = importComposer.GetImport(textBuffer.ContentType.TypeName); var documentFactoryImportComposer = new ContentTypeImportComposer<IEditorDocumentFactory>(EditorShell.Current.CompositionService); var documentFactory = documentFactoryImportComposer.GetImport(textBuffer.ContentType.TypeName); // Debug.Assert(factory != null, String.Format("No editor factory found for content type {0}", textBuffer.ContentType.TypeName)); if(factory != null) // may be null if file type only support colorization, like VBScript return factory.CreateEditorInstance(textBuffer, documentFactory); return null; }
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); }
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IComponentModel componentModel = (IComponentModel)GetService(typeof(SComponentModel)); ICompositionService compositionService = componentModel.DefaultCompositionService; var debugFrameworksCmd = componentModel.DefaultExportProvider.GetExport <DebugFrameworksDynamicMenuCommand>(); var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; mcs.AddCommand(debugFrameworksCmd.Value); var debugFrameworksMenuTextUpdater = componentModel.DefaultExportProvider.GetExport <DebugFrameworkPropertyMenuTextUpdater>(); mcs.AddCommand(debugFrameworksMenuTextUpdater.Value); }
public static IEditorInstance CreateEditorInstance(ITextBuffer textBuffer, ICompositionService cs) { var importComposer = new ContentTypeImportComposer <IEditorFactory>(cs); var factory = importComposer.GetImport(textBuffer.ContentType.TypeName); var documentFactoryImportComposer = new ContentTypeImportComposer <IEditorDocumentFactory>(EditorShell.Current.CompositionService); var documentFactory = documentFactoryImportComposer.GetImport(textBuffer.ContentType.TypeName); // Debug.Assert(factory != null, String.Format("No editor factory found for content type {0}", textBuffer.ContentType.TypeName)); if (factory != null) // may be null if file type only support colorization, like VBScript { return(factory.CreateEditorInstance(textBuffer, documentFactory)); } return(null); }
public static void MapAutomaticRoutes(this RouteCollection routes, ICompositionService comp) { //Contract.Requires( routes != null ); //Contract.Requires( comp != null ); foreach (var type in comp.GetMany <Lazy <IController, IComposableControllerMetadata> >() .Where(c => c.Metadata.AutoRoute) .Select(c => c.Value.GetType())) { routes.Add(new Route(AutoRouteFor(type), new RouteValueDictionary { { "controller", type.AssemblyQualifiedName } }, new MvcRouteHandler())); } }
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); }
private void Initialize() { MainThread = Thread.CurrentThread; MainThreadDispatcher = Dispatcher.FromThread(MainThread); var componentModel = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel)); _compositionService = componentModel.DefaultCompositionService; _exportProvider = componentModel.DefaultExportProvider; CheckVsStarted(); _settings = _exportProvider.GetExportedValue <IRSettings>(); _settings.LoadSettings(); ConfigureIdleSource(); ConfigureServices(); EditorShell.Current = this; }
public IEnumerable<ResourceDictionary> ImportAllResources(ICompositionService compositionService, bool merge) { var result = new List<ResourceDictionary>(); var cc = (compositionService as System.ComponentModel.Composition.Hosting.CompositionContainer); var providers_with_metadata = cc.GetExports<IXamlResourcesProvider, IXamlResourcesProviderMetadata>(); var ordered_providers = providers_with_metadata.OrderBy(x => x.Metadata.ImportOrder).ToList(); var providers_no_metadata = cc.GetExports<IXamlResourcesProvider>(); var all_providers = ordered_providers.Concat(providers_no_metadata).Distinct(); using (var enumerator = all_providers.GetEnumerator()) { while(enumerator.MoveNext()) { try { InternalTrace.Information($"Importing xaml resources from {enumerator.Current.Value.GetType().FullName}..."); var resources = enumerator.Current.Value.LoadResources().ToArray(); result.AddRange(resources); if(merge) foreach (var dict in resources) ResourcesManager.MergeResourceDictionary(dict); } catch(Exception ex) { InternalTrace.Error(ex.ToString()); } } } return result; }
public RootProcessor( [Import] ICompositionService composition, [Import] RnetBus bus, [Import] DriverManager driverManager, [Import] ProfileManager profileManager, [ImportMany] IEnumerable<Lazy<IRequestProcessor, RequestProcessorMetadata>> requestProcessors, [ImportMany] IEnumerable<Lazy<IResponseProcessor, ResponseProcessorMetadata>> responseProcessors) { Contract.Requires<ArgumentNullException>(composition != null); Contract.Requires<ArgumentNullException>(bus != null); Contract.Requires<ArgumentNullException>(requestProcessors != null); Contract.Requires<ArgumentNullException>(responseProcessors != null); Contract.Requires<ArgumentNullException>(driverManager != null); Contract.Requires<ArgumentNullException>(profileManager != null); this.composition = composition; this.bus = bus; this.driverManager = driverManager; this.profileManager = profileManager; this.requestProcessors = requestProcessors; this.responseProcessors = responseProcessors; }
public NoMangaController(ICompositionService compositionService) { this.compositionService = compositionService; }
public ProductService(ICompositionService compositionService, IProductRepository productRepository) { _compositionService = compositionService; _productRepository = productRepository; }
public ContentTypeLocator(ICompositionService cs) { cs.SatisfyImportsOnce(this); }
public ExportFactoryProvider(ICompositionService cc) { cc.SatisfyImportsOnce(this); }