本文整理汇总了C#中System.ComponentModel.Composition.Hosting.ExportProvider类的典型用法代码示例。如果您正苦于以下问题:C# ExportProvider类的具体用法?C# ExportProvider怎么用?C# ExportProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExportProvider类属于System.ComponentModel.Composition.Hosting命名空间,在下文中一共展示了ExportProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Document
/// <summary>
/// Initializes a new instance.
/// </summary>
/// <param name="xml"></param>
/// <param name="catalog"></param>
/// <param name="exports"></param>
Document(
Func<Document, XDocument> xml,
ComposablePartCatalog catalog,
ExportProvider exports)
{
Contract.Requires<ArgumentNullException>(xml != null);
// configure composition
this.configuration = GetConfiguration(catalog, exports);
this.container = new CompositionContainer(configuration.HostCatalog, true, new CompositionContainer(configuration.GlobalCatalog, true, configuration.Exports));
this.container.GetExportedValue<DocumentEnvironment>().SetHost(this);
// required services
this.invoker = container.GetExportedValue<IInvoker>();
this.trace = container.GetExportedValue<ITraceService>();
// initialize xml
this.xml = xml(this);
this.xml.AddAnnotation(this);
// parallel initialization of common interfaces
Parallel.ForEach(this.xml.DescendantNodesAndSelf(), i =>
{
Enumerable.Empty<object>()
.Concat(i.Interfaces<IOnInit>())
.Concat(i.Interfaces<IOnLoad>())
.ToLinkedList();
});
// initial invocation entry
this.invoker.Invoke(() => { });
}
示例2: Configurate
/// <summary>
/// Configurates the specified export provider.
/// </summary>
/// <param name="exportProvider">The export provider.</param>
/// <param name="loggerFactoryName">Name of the logger factory.</param>
/// <exception cref="System.ArgumentNullException">exportProvider</exception>
public static void Configurate(ExportProvider exportProvider, string loggerFactoryName = null)
{
if (exportProvider == null)
throw new ArgumentNullException("exportProvider");
var lazyLogFactory = exportProvider.GetExports<ILoggerFactory, ILoggerFactoryMetadata>()
.Where(f => string.IsNullOrEmpty(loggerFactoryName) || f.Metadata.Name.Equals(loggerFactoryName, StringComparison.OrdinalIgnoreCase))
.OrderBy(f => f.Metadata.Priority)
.FirstOrDefault();
if (lazyLogFactory == null)
return;
var metadata = lazyLogFactory.Metadata;
var configFiles = new List<string>();
if (!string.IsNullOrEmpty(metadata.ConfigFileName))
{
configFiles.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, metadata.ConfigFileName));
configFiles.Add(Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config"), metadata.ConfigFileName));
}
var facotry = lazyLogFactory.Value;
if (!facotry.Initialize(configFiles.ToArray()))
return;
m_Current = facotry;
}
示例3: ResolveAll
/// <summary>
/// Resolves an collection of objects wrapped inside <see cref="Lazy{T}"/>
/// from an <see cref="ExportProvider"/>.
/// </summary>
/// <param name="exportProvider">Export provider.</param>
/// <param name="type">Type to be resolved.</param>
/// <param name="name">Optional name.</param>
/// <returns>Resolved collection of lazy instances or null, if no instance has been found.</returns>
/// <remarks>
/// Does not resolve instances which are provided by means of
/// <see cref="FactoryExportProvider"/>.
/// </remarks>
public static IEnumerable<Lazy<object>> ResolveAll(ExportProvider exportProvider, Type type, string name)
{
if (exportProvider == null)
{
throw new ArgumentNullException("exportProvider");
}
if (type == null)
{
throw new ArgumentNullException("type");
}
var exports = exportProvider.GetExports(type, null, name);
if (exports.Count() == 0)
return Enumerable.Empty<Lazy<object>>();
var list = new List<Lazy<object>>();
foreach (var export in exports)
{
var lazyExportMetadata = export.Metadata as IDictionary<string, object>;
if (lazyExportMetadata != null &&
lazyExportMetadata.ContainsKey(FactoryExportDefinition.IsFactoryExportMetadataName) &&
true.Equals(lazyExportMetadata[FactoryExportDefinition.IsFactoryExportMetadataName]))
{
continue;
}
list.Add(export);
}
return list;
}
示例4: AggregateExportProvider
/// <summary>
/// Initializes a new instance of the <see cref="AggregateExportProvider"/> class.
/// </summary>
/// <param name="providers">The prioritized list of export providers.</param>
/// <exception cref="ArgumentException">
/// <paramref name="providers"/> contains an element that is <see langword="null"/>.
/// </exception>
/// <remarks>
/// <para>
/// The <see cref="AggregateExportProvider"/> will consult the providers in the order they have been specfied when
/// executing <see cref="ExportProvider.GetExports(ImportDefinition,AtomicComposition)"/>.
/// </para>
/// <para>
/// The <see cref="AggregateExportProvider"/> does not take ownership of the specified providers.
/// That is, it will not try to dispose of any of them when it gets disposed.
/// </para>
/// </remarks>
public AggregateExportProvider(params ExportProvider[] providers)
{
// NOTE : we optimize for the array case here, because the collection of providers is typically tiny
// Arrays are much more compact to store and much faster to create and enumerate
ExportProvider[] copiedProviders = null;
if (providers != null)
{
copiedProviders = new ExportProvider[providers.Length];
for (int i = 0; i < providers.Length; i++)
{
ExportProvider provider = providers[i];
if (provider == null)
{
throw ExceptionBuilder.CreateContainsNullElement("providers");
}
copiedProviders[i] = provider;
provider.ExportsChanged += this.OnExportChangedInternal;
provider.ExportsChanging += this.OnExportChangingInternal;
}
}
else
{
copiedProviders = new ExportProvider[] { };
}
this._providers = copiedProviders;
this._readOnlyProviders = new ReadOnlyCollection<ExportProvider>(this._providers);
}
示例5: Resolve
/// <summary>
/// Resolves an object wrapped inside <see cref="Lazy{T}"/> from an <see cref="ExportProvider"/>.
/// </summary>
/// <param name="exportProvider">Export provider.</param>
/// <param name="type">Type to be resolved.</param>
/// <param name="name">Optional name.</param>
/// <returns>Resolved instance or null, if no instance has been found.</returns>
/// <remarks>
/// Does not resolve instances which are provided by means of
/// <see cref="FactoryExportProvider"/>.
/// </remarks>
public static Lazy<object> Resolve(ExportProvider exportProvider, Type type, string name)
{
if (exportProvider == null)
{
throw new ArgumentNullException("exportProvider");
}
if (type == null)
{
throw new ArgumentNullException("type");
}
var exports = exportProvider.GetExports(type, null, name);
if (exports.Count() == 0)
return null;
if (exports.Count() > 1)
throw new ImportCardinalityMismatchException(Resources.TooManyInstances);
var lazyExport = exports.First();
var lazyExportMetadata = lazyExport.Metadata as IDictionary<string, object>;
if (lazyExportMetadata != null &&
lazyExportMetadata.ContainsKey(FactoryExportDefinition.IsFactoryExportMetadataName) &&
true.Equals(lazyExportMetadata[FactoryExportDefinition.IsFactoryExportMetadataName]))
{
return null;
}
return lazyExport;
}
示例6: GlimpseExportProvider
/// <summary>
/// Initialises a new instance of <see cref="GlimpseExportProvider"/>.
/// </summary>
/// <param name="provider">The inner export provider.</param>
internal GlimpseExportProvider(ExportProvider provider)
{
if (provider == null)
throw new ArgumentNullException("provider");
_provider = provider;
}
示例7: ImportEngine
public ImportEngine(ExportProvider sourceProvider, bool isThreadSafe)
{
Requires.NotNull(sourceProvider, "sourceProvider");
this._sourceProvider = sourceProvider;
this._sourceProvider.ExportsChanging += this.OnExportsChanging;
this._lock = new CompositionLock(isThreadSafe);
}
示例8: RazorVersionDetectorOverridingExportProvider
public RazorVersionDetectorOverridingExportProvider(ExportProvider exportProvider)
{
_inner = exportProvider;
_razorVersionDetectorExports = new[]
{
new Export(IRazorVersionDetectorName, DecorateRazorVersionDetector)
};
}
示例9: CreateIndexes
public static void CreateIndexes(ExportProvider catalogToGetnIndexingTasksFrom, IDocumentStore documentStore)
{
var tasks = catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>();
foreach (var task in tasks)
{
task.Execute(documentStore);
}
}
示例10: Initialize
protected override void Initialize()
{
base.Initialize();
_componentModel = (IComponentModel)GetService(typeof(SComponentModel));
_exportProvider = _componentModel.DefaultExportProvider;
_vim = _exportProvider.GetExportedValue<IVim>();
}
示例11: CreateIndexes
/// <summary>
/// Creates the indexes found in the specified catalog
/// </summary>
/// <param name="catalogToGetnIndexingTasksFrom">The catalog to get indexing tasks from.</param>
public static void CreateIndexes(ExportProvider catalogToGetnIndexingTasksFrom, IDatabaseCommands databaseCommands, DocumentConvention conventions)
{
var tasks = catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>();
foreach (var task in tasks)
{
task.Execute(databaseCommands, conventions);
}
}
示例12: RHistoryIntegrationTest
public RHistoryIntegrationTest(RComponentsMefCatalogFixture catalog) {
_exportProvider = catalog.CreateExportProvider();
_textBufferFactory = _exportProvider.GetExportedValue<ITextBufferFactoryService>();
_textEditorFactory = _exportProvider.GetExportedValue<ITextEditorFactoryService>();
_workflowProvider = _exportProvider.GetExportedValue<IRInteractiveWorkflowProvider>();
_contentTypeRegistryService = _exportProvider.GetExportedValue<IContentTypeRegistryService>();
_interactiveWindowComponentContainerFactory = _exportProvider.GetExportedValue<IInteractiveWindowComponentContainerFactory>();
_historyVisualComponentContainerFactory = _exportProvider.GetExportedValue<IRHistoryVisualComponentContainerFactory>();
}
示例13: ImportEngine
public ImportEngine(ExportProvider sourceProvider, CompositionOptions compositionOptions)
{
Requires.NotNull(sourceProvider, "sourceProvider");
this._compositionOptions = compositionOptions;
this._sourceProvider = sourceProvider;
this._sourceProvider.ExportsChanging += this.OnExportsChanging;
this._lock = new CompositionLock(compositionOptions.HasFlag(CompositionOptions.IsThreadSafe));
}
示例14: CreateIndexesAsync
/// <summary>
/// Creates the indexes found in the specified catalog
/// </summary>
/// <param name="catalogToGetnIndexingTasksFrom">The catalog to getn indexing tasks from.</param>
/// <param name="documentStore">The document store.</param>
public static Task CreateIndexesAsync(ExportProvider catalogToGetnIndexingTasksFrom, IDocumentStore documentStore)
{
var tasks = catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>();
Task[] array = tasks.Select(task => task.ExecuteAsync(documentStore)).ToArray();
var indexesAsync = new Task(() => Task.WaitAll(array));
indexesAsync.Start();
return indexesAsync;
}
示例15: Constructor3_ArrayAsProvidersArgument_ShouldNotAllowModificationAfterConstruction
public void Constructor3_ArrayAsProvidersArgument_ShouldNotAllowModificationAfterConstruction()
{
var providers = new ExportProvider[] { ExportProviderFactory.Create() };
var container = new CompositionContainer(CatalogFactory.Create(), providers);
providers[0] = null;
Assert.IsNotNull(container.Providers[0]);
}