本文整理汇总了C#中AtomicComposition类的典型用法代码示例。如果您正苦于以下问题:C# AtomicComposition类的具体用法?C# AtomicComposition怎么用?C# AtomicComposition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AtomicComposition类属于命名空间,在下文中一共展示了AtomicComposition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExportsCore
/// <summary>
/// Gets the available set of exports for the given import definition.
/// </summary>
/// <param name="definition">The defintion of the import.</param>
/// <param name="atomicComposition">The atomic composition of the import.</param>
/// <returns>The available set of exports for the given import definition.</returns>
protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
{
Throw.IfArgumentNull(definition, "definition");
if (SourceProvider == null)
Throw.InvalidOperation(
string.Format(
CultureInfo.CurrentUICulture,
Resources.Exceptions.PropertyCannotBeNull,
"Sourceprovider"));
var contractDefinition = definition as ContractBasedImportDefinition;
if (contractDefinition == null
|| !contractDefinition.RequiredTypeIdentity.StartsWith(PartFactoryContractPrefix))
return EmptyExports;
var info = _definitionCache.Fetch(contractDefinition, () => new PartFactoryImport(contractDefinition));
var exports = SourceProvider.GetExports(info.ImportDefinition, atomicComposition);
var result = exports
.Select(e => info.CreateMatchingExport(e.Definition, SourceProvider))
.ToArray();
foreach (var export in exports.OfType<IDisposable>())
export.Dispose();
return result;
}
示例2: NetworkAvailabilityChanged
private void NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
// We invoke on the dispatcher because we are needing to recompose UI.
// If we don't do this, an exception will be thrown as the composition isn't
// guaranteed to happen on the necesary UI thread.
Dispatcher.CurrentDispatcher.Invoke(new Action(() =>
{
var oldStatus = _networkStatus;
var newStatus = (e.IsAvailable) ? "Online" : "Offline";
var added = MatchingParts(newStatus);
var removed = NonMatchingParts(newStatus);
using (var atomic = new AtomicComposition())
{
atomic.AddCompleteAction(() => _networkStatus = newStatus);
if (Changing != null)
{
Changing(this, new ComposablePartCatalogChangeEventArgs(added, removed, atomic));
}
atomic.Complete();
}
if (Changed != null)
{
Changed(this, new ComposablePartCatalogChangeEventArgs(added, removed, null));
}
}));
}
示例3: GetExportsCore
protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
{
if (definition.Cardinality != ImportCardinality.ExactlyOne)
{
return Enumerable.Empty<Export>();
}
ExportSource exportSource;
if (_exactlyOneExports.TryGetValue(definition.ContractName, out exportSource))
{
AddMemberType(exportSource, definition);
return new[] { exportSource.Export };
}
string typeName = ImportDefinitionConstraintAnalyser.GetRequiredTypeIdentity(definition.Constraint);
Type type = GetType(typeName);
if (!CanHandleType(type))
{
return Enumerable.Empty<Export>();
}
exportSource = new ExportSource(definition.ContractName, definition.Metadata);
exportSource.AddType(type);
AddMemberType(exportSource, definition);
_exactlyOneExports[definition.ContractName] = exportSource;
return new[] { exportSource.Export };
}
示例4: GetExportsCore
protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
{
if (definition == null) throw new ArgumentNullException("definition");
if (SourceProvider == null) throw new InvalidOperationException("SourceProvider must be set.");
var cbid = definition as ContractBasedImportDefinition;
if (cbid == null || !cbid.RequiredTypeIdentity.StartsWith(PartCreatorContractPrefix))
return EmptyExports;
var importInfo = _importDefinitionCache.GetOrCreate(
cbid,
() => new ExportFactoryImport(cbid));
var sourceExports = SourceProvider
.GetExports(importInfo.ProductImport, atomicComposition);
var result = sourceExports
.Select(e => importInfo.CreateMatchingExport(e.Definition, SourceProvider))
.ToArray();
foreach (var e in sourceExports.OfType<IDisposable>())
e.Dispose();
return result;
}
示例5: GetExportsCore
protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
{
var serviceTypeName = definition.ContractName;
if (serviceTypeName.IndexOf('.') == -1 ||
serviceTypeName.StartsWith("System.") ||
serviceTypeName.StartsWith("Clide."))
return Enumerable.Empty<Export>();
return serviceExports.GetOrAdd (serviceTypeName, contractName => {
var serviceType = typeMap.GetOrAdd(contractName, typeName => MapType(typeName));
if (serviceType == null)
return Enumerable.Empty<Export>();
// NOTE: if we can retrieve a valid instance of the service at least once, we
// assume we'll be able to retrieve it later on. Note also that we don't return
// the single retrieved instance from the export, but rather provide a function
// that does the GetService call every time, since we're caching the export but
// we don't know if the service can be safely cached.
var service = services.GetService(serviceType);
if (service == null)
return Enumerable.Empty<Export>();
return new Export[] { new Export(serviceTypeName, () => services.GetService(serviceType)) };
});
}
示例6: GetExportsCore
protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
{
List<Export> exports = new List<Export>();
ImportDefinition queryImport = TranslateImport(definition);
if (queryImport == null)
{
return exports;
}
// go through the catalogs and see if there's anything there of interest
foreach (CompositionScopeDefinition childCatalog in this._scopeDefinition.Children)
{
foreach (var partDefinitionAndExportDefinition in childCatalog.GetExportsFromPublicSurface(queryImport))
{
using (var container = this.CreateChildContainer(childCatalog))
{
// We create a nested AtomicComposition() because the container will be Disposed and
// the RevertActions need to operate before we Dispose the child container
using (var ac = new AtomicComposition(atomicComposition))
{
var childCatalogExportProvider = container.CatalogExportProvider;
if (!childCatalogExportProvider.DetermineRejection(partDefinitionAndExportDefinition.Item1, ac))
{
exports.Add(this.CreateScopeExport(childCatalog, partDefinitionAndExportDefinition.Item1, partDefinitionAndExportDefinition.Item2));
}
}
}
}
}
return exports;
}
示例7: GetExportsCore
protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
{
var contractName = definition.ContractName;
if (contractName != SettingsConstants.SettingsContract)
yield break;
if (definition.Cardinality == ImportCardinality.ZeroOrMore)
yield break;
// TODO can't figure out how to get data injected into the Metadata collection
//string settingsKey = definition.Metadata[SettingsConstants.SettingsMetadataKey] as string;
LazyMemberInfo lazyMember = ReflectionModelServices.GetImportingMember(definition);
MemberInfo member = lazyMember.GetAccessors().First();
MethodInfo getterOrSetter = (MethodInfo)member;
// HACK this is pretty evil
PropertyInfo propInfo = getterOrSetter.DeclaringType.GetProperty(getterOrSetter.Name.Substring(4));
ImportSettingAttribute settingsAttr = propInfo.GetCustomAttribute<ImportSettingAttribute>();
if (settingsAttr == null)
yield break;
object value;
if (!this._settingsProvider.TryGetValue(settingsAttr.SettingsKey, out value))
yield break;
yield return new Export(SettingsConstants.SettingsContract, () => value);
}
示例8: Recompose
private void Recompose(IEnumerable<ComposablePartDefinition> added, IEnumerable<ComposablePartDefinition> removed, AtomicComposition outerComposition)
{
EnsurePartsInitialized();
var addedInnerPartDefinitions = added.Select(GetPart);
var removedInnerPartDefinitions = removed.Select(def => innerParts[def]);
using (var composition = new AtomicComposition(outerComposition))
{
var addedDefinitions = addedInnerPartDefinitions.Select(p => p.Definition).ToList();
var removedDefinitions = removedInnerPartDefinitions.Select(p => p.Definition).ToList();
composition.AddCompleteAction(() => OnChanged(
addedDefinitions,
removedDefinitions,
null));
OnChanging(
addedDefinitions,
removedDefinitions,
composition);
foreach (var innerPart in addedInnerPartDefinitions)
{
innerParts.Add(innerPart.Original, innerPart);
}
foreach (var removedDefinition in removedInnerPartDefinitions)
{
innerParts.Remove(removedDefinition.Original);
}
composition.Complete();
}
}
示例9: GetExportsCore
protected override System.Collections.Generic.IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
{
var type = Type.GetType(definition.ContractName);
Export e;
var exports = base.GetExportsCore(definition, atomicComposition);
return exports;
}
示例10: GetExportsCore
protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
{
if (definition.ContractName == _textUndoHistoryRegistryContractName ||
definition.ContractName == _basicUndoHistoryRegistryContractName)
{
yield return _export;
}
}
示例11: Constructor2
public void Constructor2()
{
// Null should be allowed
var ct = new AtomicComposition(null);
// Another AtomicComposition should be allowed
var ct2 = new AtomicComposition(ct);
}
示例12: GetExportsCore
protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
{
if (definition.ContractName.Equals(typeof(ILogger).FullName))
{
yield return new Export(definition.ContractName, () => new Logger() { Header = "Factory - " });
}
}
示例13: Constructor2_MultipleTimes
public void Constructor2_MultipleTimes()
{
var outer = new AtomicComposition();
var ct1 = new AtomicComposition(outer);
ExceptionAssert.Throws<InvalidOperationException>(() => new AtomicComposition(outer));
}
示例14: TryGetExports
/// <summary>
/// Invokes TryGetExports, returning the output as a collection.
/// </summary>
/// <param name="provider"></param>
/// <param name="definition"></param>
/// <param name="atomicComposition"></param>
/// <returns></returns>
public static IEnumerable<Export> TryGetExports(this ExportProvider provider, ImportDefinition definition, AtomicComposition atomicComposition)
{
Contract.Requires<ArgumentNullException>(provider != null);
Contract.Requires<ArgumentNullException>(definition != null);
IEnumerable<Export> exports;
provider.TryGetExports(definition, atomicComposition, out exports);
return exports;
}
示例15: GetExportsCore
protected override IEnumerable<Export> GetExportsCore(
ImportDefinition definition,
AtomicComposition atomicComposition
) {
return from kv in _exports
where definition.IsConstraintSatisfiedBy(kv.Key)
select kv.Value;
}