本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionBatch类的典型用法代码示例。如果您正苦于以下问题:C# CompositionBatch类的具体用法?C# CompositionBatch怎么用?C# CompositionBatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompositionBatch类属于System.ComponentModel.Composition.Hosting命名空间,在下文中一共展示了CompositionBatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComposeWithTypesExportedFromPythonAndCSharp
public void ComposeWithTypesExportedFromPythonAndCSharp(
object compositionTarget,
string scriptsToImport,
params Type[] typesToImport)
{
ScriptSource script;
var engine = Python.CreateEngine();
using (var scriptStream = GetType().Assembly.
GetManifestResourceStream(GetType(), scriptsToImport))
using (var scriptText = new StreamReader(scriptStream))
{
script = engine.CreateScriptSourceFromString(scriptText.ReadToEnd());
}
var typeExtractor = new ExtractTypesFromScript(engine);
var exports = typeExtractor.GetPartsFromScript(script, typesToImport).ToList();
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog);
var batch = new CompositionBatch(exports, new ComposablePart[] { });
container.Compose(batch);
container.SatisfyImportsOnce(compositionTarget);
}
示例2: Compose
private bool Compose()
{
var catalog = new System.ComponentModel.Composition.Hosting.AggregateCatalog();
// var catalog = new AggregatingComposablePartCatalog();
catalog.Catalogs.Add(
new RubyCatalog(new RubyPartFile("calculator_ops.rb")));
catalog.Catalogs.Add(
new AssemblyCatalog(Assembly.GetExecutingAssembly()));
_container = new System.ComponentModel.Composition.Hosting.CompositionContainer(catalog);
//_container. AddPart(this);
var batch = new System.ComponentModel.Composition.Hosting.CompositionBatch();
batch.AddPart(this);
//_container.AddPart(this);
//_container.Compose(this);
try
{
_container.Compose(batch);
}
catch (CompositionException compositionException)
{
MessageBox.Show(compositionException.ToString());
return false;
}
return true;
}
示例3: OnComponentRegistrationOnActivated
private void OnComponentRegistrationOnActivated(object sender, ActivatedEventArgs<object> activation_event)
{
// compose by batch to allow for recomposition
var batch = new CompositionBatch();
batch.AddPart(activation_event.Instance);
_mefContainer.Compose(batch);
}
示例4: Configure
/// <summary>
/// By default, we are configured to use MEF
/// </summary>
protected override void Configure()
{
// Add all assemblies to AssemblySource (using a temporary DirectoryCatalog).
var directoryCatalog = new DirectoryCatalog(@"./");
AssemblySource.Instance.AddRange(
directoryCatalog.Parts
.Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly)
.Where(assembly => !AssemblySource.Instance.Contains(assembly)));
// Prioritise the executable assembly. This allows the client project to override exports, including IShell.
// The client project can override SelectAssemblies to choose which assemblies are prioritised.
var priorityAssemblies = SelectAssemblies().ToList();
var priorityCatalog = new AggregateCatalog(priorityAssemblies.Select(x => new AssemblyCatalog(x)));
var priorityProvider = new CatalogExportProvider(priorityCatalog);
// Now get all other assemblies (excluding the priority assemblies).
var mainCatalog = new AggregateCatalog(
AssemblySource.Instance
.Where(assembly => !priorityAssemblies.Contains(assembly))
.Select(x => new AssemblyCatalog(x)));
var mainProvider = new CatalogExportProvider(mainCatalog);
Container = new CompositionContainer(priorityProvider, mainProvider);
priorityProvider.SourceProvider = Container;
mainProvider.SourceProvider = Container;
var batch = new CompositionBatch();
BindServices(batch);
batch.AddExportedValue(mainCatalog);
Container.Compose(batch);
}
示例5: Init
public Runner Init(IFeedbackProvider feedbackProvider, string[] args)
{
var catalog = new AggregateCatalog(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
var currentDir = Environment.CurrentDirectory;
var assemblyDir = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath).Directory.FullName;
var paths = new string[]
{
assemblyDir,
Path.Combine(assemblyDir, "Tasks"),
currentDir,
Path.Combine(currentDir, "Tasks")
}.Unique();
var dirCatalogs = paths.Where(x => Directory.Exists(x))
.Select(x => new DirectoryCatalog(x, "*.Tasks.dll"));
dirCatalogs.Apply(x => catalog.Catalogs.Add(x));
var container = new CompositionContainer(catalog);
var parsed = new ArgumentParser().Parse(args);
var runner = new Runner(parsed.ActualArgs.ToArray());
var batch = new CompositionBatch();
batch.AddExportedValue<IFeedbackProvider>(feedbackProvider);
parsed.Options.Apply(x => batch.AddExportedValue<string>(x.Item1, x.Item2));
parsed.Switches.Apply(x => batch.AddExportedValue<bool>(x, true));
batch.AddPart(runner);
container.Compose(batch);
return runner;
}
示例6: SatisfyImportsOnce
public void SatisfyImportsOnce(ComposablePart part)
{
if (this.DoNothingOnSatisfyImportsOnce)
{
return;
}
CompositionBatch batch = new CompositionBatch();
// We only want to include the standard exports and parts to compose in the first composition
if (!this.alreadyComposed)
{
foreach (object instance in this.PartsToCompose)
{
batch.AddPart(instance);
}
foreach (Export export in this.ExportsToCompose)
{
batch.AddExport(export);
}
}
if (part != null)
{
batch.AddPart(part);
}
this.container.Compose(batch);
this.alreadyComposed = true;
}
开发者ID:SonarSource-VisualStudio,项目名称:sonarlint-visualstudio,代码行数:31,代码来源:ConfigurableCompositionService.cs
示例7: Compose
private void Compose()
{
var container = new CompositionContainer(directories);
var batch = new CompositionBatch();
batch.AddPart(this);
container.Compose(batch);
}
示例8: SatisfyImports
/// <summary>
/// Will satisfy the imports on a object instance based on a <see cref="CompositionContainer"/>
/// registered with the <see cref="CompositionHost"/>. By default if no <see cref="CompositionContainer"/>
/// is registered the first time this is called it will be initialized to a catalog
/// that contains all the assemblies loaded by the initial application XAP.
/// </summary>
/// <param name="instance">
/// Object instance that contains <see cref="ImportAttribute"/>s that need to be satisfied.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="instance"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="instance"/> contains <see cref="ExportAttribute"/>s applied on its type.
/// </exception>
/// <exception cref="ChangeRejectedException">
/// One or more of the imports on the object instance could not be satisfied.
/// </exception>
/// <exception cref="CompositionException">
/// One or more of the imports on the object instance caused an error while composing.
/// </exception>
public static void SatisfyImports(object instance)
{
if (instance == null)
{
throw new ArgumentNullException("instance");
}
var batch = new CompositionBatch();
var attributedPart = batch.AddPart(instance);
if (attributedPart.ExportDefinitions.Any())
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
"Cannot call SatisfyImports on a object of type '{0}' because it is marked with one or more ExportAttributes.",
instance.GetType().FullName), "instance");
}
CompositionContainer container = null;
// Ignoring return value because we don't need to know if we created it or not
CompositionHost.TryGetOrCreateContainer(_createContainer, out container);
container.Compose(batch);
}
示例9: OnStartup
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
#if (DEBUG != true)
// Don't handle the exceptions in Debug mode because otherwise the Debugger wouldn't
// jump into the code when an exception occurs.
DispatcherUnhandledException += AppDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
#endif
XmlConfigurator.Configure();
_log.Debug("OnStartup called");
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(Controller).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(IApplicationController).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ValidationModel).Assembly));
_container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
batch.AddExportedValue(_container);
_container.Compose(batch);
_controller = _container.GetExportedValue<IApplicationController>();
_controller.Initialize();
_controller.Run();
}
示例10: RestServer
public RestServer(ushort port)
: base(port)
{
this.HttpRequestReceived += new EventHandler<HttpServerEventArgs>(RestServer_RequestReceived);
batch = new CompositionBatch();
batch.AddPart(this);
}
示例11: MainForm
/// <summary>
/// Initialises a new instance of the <see cref="MainForm"/> class.
/// </summary>
public MainForm()
{
this.InitializeComponent();
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog("..\\..\\Crypto", "*.dll"));
var batch = new CompositionBatch();
batch.AddPart(this);
this.compositionContainer = new CompositionContainer(catalog);
////get all the exports and load them into the appropriate list tagged with the importmany
this.compositionContainer.Compose(batch);
this.CryptoAlgorithmComboBox.DataSource = (new List<CryptoAlgorithm> { CryptoAlgorithm.None }).Union(
this.CryptoProviders.Select(c => c.Metadata.Algorithm).Distinct()).ToList();
this.JoinedUsers = new BindingList<User>();
this.ConnectedUsersDataGridView.DataSource = this.JoinedUsers;
this.userProxy = new UserServiceClient(new InstanceContext(this));
this.userProxy.Open();
this.messagingProxy = new MessagingServiceClient(new InstanceContext(this));
this.messagingProxy.Open();
this.userProxy.Subscribe();
foreach (var u in this.userProxy.GetJoinedUsers())
{
this.AddUser(u);
}
this.uiSyncContext = SynchronizationContext.Current;
}
示例12: Configure
protected override void Configure()
{
_container = new CompositionContainer(new AggregateCatalog(AssemblySource
.Instance
.Select(x => new AssemblyCatalog(x))
.OfType<ComposablePartCatalog>()
)
);
var batch = new CompositionBatch();
_portName = SerialPort.GetPortNames()[0];
_ecr = new Dp25(_portName);
var messenger = new MessageAggregator();
messenger.GetStream<SelectedPortChangedEvent>()
.Subscribe(e => _ecr.ChangePort(e.PortName));
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IMessageAggregator>(messenger);
batch.AddExportedValue<Dp25>(_ecr);
batch.AddExportedValue(_container);
_container.Compose(batch);
}
示例13: Compose
private bool Compose()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
//catalog.Catalogs.Add(new AssemblyCatalog(typeof(IEmailService).Assembly));
_container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
batch.AddPart(this);
#if DEBUG
_container.Compose(batch);
#else
try
{
_container.Compose(batch);
}
catch (CompositionException compositionException)
{
MessageBox.Show(compositionException.ToString());
Shutdown(1);
return false;
}
#endif
return true;
}
示例14: GetMefContainer
public static CompositionContainer GetMefContainer(string binDirPath, CompositionBatch batch = null, RegistrationBuilder builder = null)
{
if (builder == null)
builder = new RegistrationBuilder();
builder.ForTypesDerivedFrom<Controller>()
.SetCreationPolicy(CreationPolicy.NonShared).Export();
builder.ForTypesDerivedFrom<ApiController>()
.SetCreationPolicy(CreationPolicy.NonShared).Export();
var catalogs = new DirectoryCatalog(binDirPath, builder);
var container = new CompositionContainer(catalogs, CompositionOptions.DisableSilentRejection |
CompositionOptions.IsThreadSafe);
if (batch == null)
batch = new CompositionBatch();
// make container availalbe for di
batch.AddExportedValue(container);
container.Compose(batch);
return container;
}
示例15: OnStartup
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
#if (DEBUG != true)
// Don't handle the exceptions in Debug mode because otherwise the Debugger wouldn't
// jump into the code when an exception occurs.
DispatcherUnhandledException += AppDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
#endif
catalog = new AggregateCatalog();
// Add the WpfApplicationFramework assembly to the catalog
catalog.Catalogs.Add(new AssemblyCatalog(typeof(Controller).Assembly));
// Add the Waf.BookLibrary.Library.Presentation assembly to the catalog
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
// Add the Waf.BookLibrary.Library.Applications assembly to the catalog
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly));
// Load module assemblies as well (e.g. Reporting extension). See App.config file.
foreach(string moduleAssembly in Settings.Default.ModuleAssemblies)
{
catalog.Catalogs.Add(new AssemblyCatalog(moduleAssembly));
}
container = new CompositionContainer(catalog);
CompositionBatch batch = new CompositionBatch();
batch.AddExportedValue(container);
container.Compose(batch);
moduleControllers = container.GetExportedValues<IModuleController>();
foreach (IModuleController moduleController in moduleControllers) { moduleController.Initialize(); }
foreach (IModuleController moduleController in moduleControllers) { moduleController.Run(); }
}