本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionContainer类的典型用法代码示例。如果您正苦于以下问题:C# CompositionContainer类的具体用法?C# CompositionContainer怎么用?C# CompositionContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompositionContainer类属于System.ComponentModel.Composition.Hosting命名空间,在下文中一共展示了CompositionContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtensionManager
/// <summary>
/// Default private constructor.
/// </summary>
private ExtensionManager()
{
if (!Config.DisableComposition)
{
// Let MEF scan for imports
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(Config.DisableCatalogSearch ? new DirectoryCatalog("Bin", "Piranha*.dll") : new DirectoryCatalog("Bin"));
#if !NET40
if (!System.Web.Compilation.BuildManager.IsPrecompiledApp)
{
#endif
try
{
// This feature only exists for Web Pages
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.Load("App_Code")));
}
catch { }
#if !NET40
}
#endif
Container = new CompositionContainer(catalog);
Container.ComposeParts(this);
}
}
示例2: AssembleComponents
/// <summary>
/// This method loads the plugins.
/// </summary>
private void AssembleComponents()
{
var catalog = new AggregateCatalog();
//Note: we load not only from the plugins folder, but from this assembly as well.
var executingAssemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
if (Directory.Exists(Environment.CurrentDirectory + "\\Plugins"))
{
catalog.Catalogs.Add(new DirectoryCatalog("Plugins"));
}
catalog.Catalogs.Add(executingAssemblyCatalog);
var container = new CompositionContainer(catalog);
try
{
container.ComposeParts(this);
}
catch (CompositionException compositionException)
{
_dialogService.ShowMessageAsync(_mainVm, "Error", string.Format("There was an error loading plugins: {0}", compositionException)).Forget();
}
}
示例3: LoadPlugins
public void LoadPlugins(IEnumerable<ComposablePartCatalog> catalogs = null)
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(GetType().Assembly));
if (catalogs != null)
{
foreach (var additionalCatalog in catalogs)
{
catalog.Catalogs.Add(additionalCatalog);
}
}
//Create the CompositionContainer with the parts in the catalog
Container = new CompositionContainer(catalog);
//Fill the imports of this object
try
{
Container.ComposeParts(this);
}
catch (CompositionException compositionException)
{
Console.WriteLine(compositionException.ToString());
}
}
示例4: FilterContext
public FilterContext(ObjectCache cache, CompositionContainer container, IAssetResolver assetResolver, FilterState state)
{
this.Container = container;
this.Cache = cache;
this.AssetResolver = assetResolver;
this.State = state;
}
示例5: Invoke
public override void Invoke(CompositionContainer container)
{
TemplateInfo templateInfo;
if (!this.TemplateResolver.TryResolve(this.Template, out templateInfo))
Console.WriteLine("Template not found: '{0}'.", this.Template);
do
{
foreach (string filename in templateInfo.GetFiles())
{
Console.WriteLine(filename);
string targetPath = System.IO.Path.Combine(this.Path, filename);
string targetDir = System.IO.Path.GetDirectoryName(targetPath);
Directory.CreateDirectory(targetDir);
using (var target = new FileStream(targetPath, FileMode.CreateNew, FileAccess.Write, FileShare.None))
using (var content = templateInfo.Source.OpenFile(filename, FileMode.Open))
{
content.CopyTo(target);
content.Close();
target.Close();
}
}
templateInfo = templateInfo.Inherits;
} while (this.IncludeInherited && templateInfo != null);
}
示例6: DualContainers
public void DualContainers()
{
var container1 = new CompositionContainer();
TypeDescriptorServices dat1 = new TypeDescriptorServices();
CompositionBatch batch = new CompositionBatch();
batch.AddPart(dat1);
container1.Compose(batch);
MetadataStore.AddAttribute(
typeof(DynamicMetadataTestClass),
( type, attributes) =>
Enumerable.Concat(
attributes,
new Attribute[] { new TypeConverterAttribute(typeof(DynamicMetadataTestClassConverter)) }
),
container1
);
var container2 = new CompositionContainer();
CompositionBatch batch2 = new CompositionBatch();
TypeDescriptorServices dat2 = new TypeDescriptorServices();
batch2.AddPart(dat2);
container2.Compose(batch2);
DynamicMetadataTestClass val = DynamicMetadataTestClass.Get("42");
var attached1 = dat1.GetConverter(val.GetType());
Assert.IsTrue(attached1.CanConvertFrom(typeof(string)), "The new type converter for DynamicMetadataTestClass should support round tripping");
var attached2 = dat2.GetConverter(val.GetType());
Assert.IsFalse(attached2.CanConvertFrom(typeof(string)), "The default type converter for DynamicMetadataTestClass shouldn't support round tripping");
}
示例7: AsyncMain
static async Task AsyncMain()
{
AggregateCatalog catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog("."));
CompositionContainer compositionContainer = new CompositionContainer(catalog);
Console.Title = "Samples.MefExtensionEndpoint";
LogManager.Use<DefaultFactory>().Level(LogLevel.Info);
EndpointConfiguration endpointConfiguration = new EndpointConfiguration("Samples.MefExtensionEndpoint");
endpointConfiguration.UsePersistence<InMemoryPersistence>();
endpointConfiguration.EnableInstallers();
await RunCustomizeConfiguration(compositionContainer, endpointConfiguration);
await RunBeforeEndpointStart(compositionContainer);
IEndpointInstance endpoint = await Endpoint.Start(endpointConfiguration);
await RunAfterEndpointStart(compositionContainer, endpoint);
try
{
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
finally
{
await RunBeforeEndpointStop(compositionContainer, endpoint);
await endpoint.Stop();
}
await RunAfterEndpointStop(compositionContainer);
}
示例8: TestMefStatusReportable
public void TestMefStatusReportable()
{
string dir = AssemblyDirectory;
//Lets get the nlog status reportable from MEF directory..
CompositionContainer _container;
//An aggregate catalog that combines multiple catalogs
var catalog = new AggregateCatalog();
//Adds all the parts found in the same assembly as the Program class
catalog.Catalogs.Add(new AssemblyCatalog(typeof(TestMEF).Assembly));
catalog.Catalogs.Add(new DirectoryCatalog(AssemblyDirectory));
//Create the CompositionContainer with the parts in the catalog
_container = new CompositionContainer(catalog);
//Fill the imports of this object
try
{
_container.ComposeParts(this);
}
catch (CompositionException compositionException)
{
Console.WriteLine(compositionException.ToString());
}
reporter.Report(2,1,"Test Report");
}
示例9: Initialize
public void Initialize()
{
var catalog = new AggregateCatalog();
//Adds the program's assembly
catalog.Catalogs.Add(new AssemblyCatalog(typeof(PluginInfrastructre).Assembly));
string programassembly = System.Reflection.Assembly.GetAssembly(typeof(PluginInfrastructre)).Location;
string programpath = Path.GetDirectoryName(programassembly);
//add the program's path
catalog.Catalogs.Add(new DirectoryCatalog(programpath));
_container = new CompositionContainer(catalog);
try
{
//Initialize types found and assign new instances to Plugins
Plugins = _container.GetExportedValues<IPlugin>();
}
catch (CompositionException compositionException)
{
throw;
}
}
示例10: Configure
/// <summary>
/// MEF Bootstrap (MEF comes from System.ComponentModel.Composition in the GAC).
/// <para>This will return a class containing all the application's aggregate roots.</para>
/// </summary>
public static ComposedDemoProgram Configure(params string[] pluginDirectories)
{
var catalogues =
pluginDirectories.Select<string, ComposablePartCatalog>(d=>new DirectoryCatalog(d)).
Concat(new []{new AssemblyCatalog(Assembly.GetExecutingAssembly())}).ToList();
var catalog = new AggregateCatalog(catalogues);
try
{
var container = new CompositionContainer(catalog);
var composedProgram = new ComposedDemoProgram();
container.SatisfyImportsOnce(composedProgram);
return composedProgram;
}
finally
{
catalog.Dispose();
foreach (var cat in catalogues)
{
cat.Dispose();
}
}
}
示例11: ProcessResultOperator
/// <summary>
/// Actually try and process this! The count consisits of a count integer and something to increment it
/// at its current spot.
/// </summary>
/// <param name="resultOperator"></param>
/// <param name="queryModel"></param>
/// <param name="codeEnv"></param>
/// <returns></returns>
public Expression ProcessResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, IGeneratedQueryCode gc, ICodeContext cc, CompositionContainer container)
{
if (gc == null)
throw new ArgumentNullException("CodeEnv must not be null!");
var c = resultOperator as CountResultOperator;
if (c == null)
throw new ArgumentNullException("resultOperator can only be a CountResultOperator and must not be null");
//
// The accumulator where we will store the result.
//
var accumulator = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
accumulator.SetInitialValue("0");
//
// Use the Aggregate infrasturcutre to do the adding. This
// has the advantage that it will correctly combine with
// similar statements during query optimization.
//
var add = Expression.Add(accumulator, Expression.Constant((int)1));
var addResolved = ExpressionToCPP.GetExpression(add, gc, cc, container);
gc.Add(new StatementAggregate(accumulator, addResolved));
return accumulator;
}
示例12: Initialize
public void Initialize()
{
container = new CompositionContainer(
new AggregateCatalog(
new AssemblyCatalog(
typeof (ITypedPool).Assembly
),
new TypeCatalog(typeof (Registrator)),
new TypeCatalog(typeof (ResourcePool)),
new TypeCatalog(typeof (NotifiedElementGetter)),
new TypeCatalog(typeof(NotifiedElementPoster)),
new TypeCatalog(typeof (UnnotifiedElementGetter)),
new TypeCatalog(typeof (UnnotifiedElementPoster))));
_uplink = _mockRepository.DynamicMock<AnnouncerUplink>();
_downlink = _mockRepository.DynamicMock<AnnouncerDownlink>();
_downlink.Expect(k => k.Subscribe(null))
.IgnoreArguments()
.Repeat.Once();
_downlink.Replay();
container.ComposeExportedValue(_uplink);
container.ComposeExportedValue(_downlink);
//_poster = _mockRepository.DynamicMock<NotifiedElementPoster>();
//_posterFactory = _mockRepository.DynamicMock<IPacketResourcePoster>();
// container.ComposeExportedValue<ResourcePoster>(_poster);
container.ComposeExportedValue(_posterFactory);
_pool = container.GetExportedValue<ITypedPool>();
_subscriptor = container.GetExportedValue<IAnnouncerSubscriptor>();
var service = container.GetExportedValue<ICacheServicing>();
service.Initialize(new Settings
{
}, container);
}
示例13: FileController
public FileController(CompositionContainer container, IMessageService messageService, IFileDialogService fileDialogService,
IShellService shellService, FileService fileService)
{
this.container = container;
this.messageService = messageService;
this.fileDialogService = fileDialogService;
this.shellService = shellService;
this.fileService = fileService;
this.documentTypes = new List<IDocumentType>();
this.newDocumentCommand = new DelegateCommand(NewDocumentCommand, CanNewDocumentCommand);
this.closeDocumentCommand = new DelegateCommand(CloseDocumentCommand, CanCloseDocumentCommand);
this.saveDocumentCommand = new DelegateCommand(SaveDocumentCommand, CanSaveDocumentCommand);
this.saveAllDocumentCommand = new DelegateCommand(SaveAllDocumentCommand, CanSaveAllDocumentCommand);
this.newSolutionCommand = new DelegateCommand(NewSolutionCommand);
this.openSolutionCommand = new DelegateCommand(OpenSolutionCommand);
this.closeSolutionCommand = new DelegateCommand(CloseSolutionCommand, CanCloseSolutionCommand);
this.showSolutionCommand = new DelegateCommand(ShowSolutionCommand, CanShowSolutionCommand);
this.fileService.NewDocumentCommand = this.newDocumentCommand;
this.fileService.CloseDocumentCommand = this.closeDocumentCommand;
this.fileService.SaveDocumentCommand = this.saveDocumentCommand;
this.fileService.SaveAllDocumentCommand = this.saveAllDocumentCommand;
this.fileService.NewSolutionCommand = this.newSolutionCommand;
this.fileService.OpenSolutionCommand = this.openSolutionCommand;
this.fileService.CloseSolutionCommand = this.closeSolutionCommand;
this.fileService.ShowSolutionCommand = this.showSolutionCommand;
this.recentSolutionList = Settings.Default.RecentSolutionList;
if (this.recentSolutionList == null) { this.recentSolutionList = new RecentFileList(); }
this.fileService.RecentSolutionList = recentSolutionList;
AddWeakEventListener(fileService, FileServicePropertyChanged);
}
示例14: CreateRun
private static IRun CreateRun()
{
ThreadPool.SetMinThreads(32, 32);
var args = ParseArguments();
var compositionContainer = new CompositionContainer(new AssemblyCatalog(typeof(Program).Assembly));
compositionContainer.ComposeExportedValue(new RunData
{
SampleRate = args.SampleRate,
Warmup = args.Warmup,
Duration = args.Duration,
Connections = args.Connections,
Payload = GetPayload(args.PayloadSize),
Senders = args.Senders,
Transport = args.Transport,
Host = args.Host,
Url = args.Url,
SendDelay = args.SendDelay,
// Scaleout
RedisServer = args.RedisServer,
RedisPort = args.RedisPort,
RedisPassword = args.RedisPassword,
ServiceBusConnectionString = args.ServiceBusConnectionString,
SqlConnectionString = args.SqlConnectionString,
SqlTableCount = args.SqlTableCount,
});
return compositionContainer.GetExportedValue<IRun>(args.RunName);
}
示例15: DoImport
public void DoImport()
{
//An aggregate catalog that combines multiple catalogs
var catalog = new AggregateCatalog();
directoryCatalog = new DirectoryCatalog(GetDirectory());
directoryCatalog.Changing += directoryCatalog_Changing;
directoryCatalog.Changed += directoryCatalog_Changed;
//Adds all the parts found in all assemblies in
//the same directory as the executing program
catalog.Catalogs.Add(directoryCatalog);
//Create the CompositionContainer with the parts in the catalog
var container = new CompositionContainer(catalog);
try
{
//Fill the imports of this object
container.ComposeParts(this);
}
catch (Exception ex)
{
Out.WriteLine("Unable to load plugins: {0}", ex.Message);
}
}