本文整理汇总了C#中AtomicComposition.AddCompleteAction方法的典型用法代码示例。如果您正苦于以下问题:C# AtomicComposition.AddCompleteAction方法的具体用法?C# AtomicComposition.AddCompleteAction怎么用?C# AtomicComposition.AddCompleteAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AtomicComposition
的用法示例。
在下文中一共展示了AtomicComposition.AddCompleteAction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
}));
}
示例2: ChangeExports
private void ChangeExports(List<Export> newExports)
{
using (var atomicComposition = new AtomicComposition())
{
atomicComposition.AddCompleteAction(() => this._exports = newExports);
atomicComposition.SetValue(this, newExports);
var addedExports = newExports.Except(this._exports).Select(export => export.Definition);
var removedExports = this._exports.Except(newExports).Select(export => export.Definition);
this.OnExportsChanging(new ExportsChangeEventArgs(addedExports, removedExports, atomicComposition));
atomicComposition.AddCompleteAction(() => this.OnExportsChanged(
new ExportsChangeEventArgs(addedExports, removedExports, null)));
atomicComposition.Complete();
}
}
示例3: AfterComplete_AllMethodsShouldThrow
public void AfterComplete_AllMethodsShouldThrow()
{
var ct = new AtomicComposition();
ct.Complete();
ExceptionAssert.Throws<InvalidOperationException>(() => ct.AddCompleteAction(() => ct = null));
ExceptionAssert.Throws<InvalidOperationException>(() => ct.Complete());
ExceptionAssert.Throws<InvalidOperationException>(() => ct.SetValue(ct, 10));
object value;
ExceptionAssert.Throws<InvalidOperationException>(() => ct.TryGetValue(ct, out value));
}
示例4: Dispose_AllMethodsShouldThrow
public void Dispose_AllMethodsShouldThrow()
{
var ct = new AtomicComposition();
ct.Dispose();
ExceptionAssert.ThrowsDisposed(ct, () => ct.AddCompleteAction(() => ct = null));
ExceptionAssert.ThrowsDisposed(ct, () => ct.Complete());
ExceptionAssert.ThrowsDisposed(ct, () => ct.SetValue(ct, 10));
object value;
ExceptionAssert.ThrowsDisposed(ct, () => ct.TryGetValue(ct, out value));
}
示例5: AtomicComposition_CompleteActions
public void AtomicComposition_CompleteActions()
{
var setMe = false;
var setMeToo = false;
var dontSetMe = false;
using (var contextA = new AtomicComposition())
{
contextA.AddCompleteAction(() => setMe = true);
using (var contextB = new AtomicComposition(contextA))
{
contextB.AddCompleteAction(() => setMeToo = true);
contextB.Complete();
}
using (var contextC = new AtomicComposition(contextA))
{
contextC.AddCompleteAction(() => dontSetMe = true);
// Don't complete
}
Assert.IsFalse(setMe);
Assert.IsFalse(setMeToo);
Assert.IsFalse(dontSetMe);
contextA.Complete();
Assert.IsTrue(setMe);
Assert.IsTrue(setMeToo);
Assert.IsFalse(dontSetMe);
}
}
示例6: NoComplete_ShouldNotCopyActionsToInner
public void NoComplete_ShouldNotCopyActionsToInner()
{
bool executedAction = false;
var innerAtomicComposition = new AtomicComposition();
using (var ct = new AtomicComposition(innerAtomicComposition))
{
ct.AddCompleteAction(() => executedAction = true);
Assert.IsFalse(executedAction, "Action should not have been exectued yet");
// Do not complete
}
innerAtomicComposition.Complete();
Assert.IsFalse(executedAction);
}
示例7: Complete_ShouldExecuteActions
public void Complete_ShouldExecuteActions()
{
bool executedAction = false;
var ct = new AtomicComposition();
ct.AddCompleteAction(() => executedAction = true);
ct.Complete();
Assert.IsTrue(executedAction);
}
示例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: PreviewImports
/// <summary>
/// Previews all the required imports for the given <see cref="ComposablePart"/> to
/// ensure they can all be satisified. The preview does not actually set the imports
/// only ensures that they exist in the source provider. If the preview succeeds then
/// the <see cref="ImportEngine"/> also enforces that changes to exports in the source
/// provider will not break any of the required imports. If this enforcement needs to be
/// lifted for this part then <see cref="ReleaseImports"/> needs to be called for this
/// <see cref="ComposablePart"/>.
/// </summary>
/// <param name="part">
/// The <see cref="ComposablePart"/> to preview the required imports.
/// </param>
/// <param name="atomicComposition"></param>
/// <exception cref="CompositionException">
/// An error occurred during previewing and <paramref name="atomicComposition"/> is null.
/// <see cref="CompositionException.Errors"/> will contain a collection of errors that occurred.
/// The pre-existing composition is in an unknown state, depending on the errors that occured.
/// </exception>
/// <exception cref="ChangeRejectedException">
/// An error occurred during the previewing and <paramref name="atomicComposition"/> is not null.
/// <see cref="CompositionException.Errors"/> will contain a collection of errors that occurred.
/// The pre-existing composition remains in valid state.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The <see cref="ImportEngine"/> has been disposed of.
/// </exception>
public void PreviewImports(ComposablePart part, AtomicComposition atomicComposition)
{
this.ThrowIfDisposed();
Requires.NotNull(part, "part");
// NOTE : this is a very intricate area threading-wise, please use caution when changing, otherwise state corruption or deadlocks will ensue
// The gist of what we are doing is as follows:
// We need to lock the composition, as we will proceed modifying our internal state. The tricky part is when we release the lock
// Due to the fact that some actions will take place AFTER we leave this method, we need to KEEP THAT LOCK HELD until the transation is commiited or rolled back
// This is the reason we CAN'T use "using here.
// Instead, if the transaction is present we will queue up the release of the lock, otherwise we will release it when we exit this method
// We add the "release" lock to BOTH Commit and Revert queues, because they are mutually exclusive, and we need to release the lock regardless.
// This will take the lock, if necesary
IDisposable compositionLockHolder = this._lock.IsThreadSafe ? this._lock.LockComposition() : null;
bool compositionLockTaken = (compositionLockHolder != null);
try
{
// revert actions are processed in the reverse order, so we have to add the "release lock" action now
if (compositionLockTaken && (atomicComposition != null))
{
atomicComposition.AddRevertAction(() => compositionLockHolder.Dispose());
}
var partManager = GetPartManager(part, true);
var result = TryPreviewImportsStateMachine(partManager, part, atomicComposition);
result.ThrowOnErrors(atomicComposition);
StartSatisfyingImports(partManager, atomicComposition);
// Add the "release lock" to the commit actions
if (compositionLockTaken && (atomicComposition != null))
{
atomicComposition.AddCompleteAction(() => compositionLockHolder.Dispose());
}
}
finally
{
// We haven't updated the queues, so we can release the lock now
if (compositionLockTaken && (atomicComposition == null))
{
compositionLockHolder.Dispose();
}
}
}
示例10: GetEngineContext
private EngineContext GetEngineContext(AtomicComposition atomicComposition)
{
Assumes.NotNull(atomicComposition);
EngineContext engineContext;
if (!atomicComposition.TryGetValue(this, true, out engineContext))
{
EngineContext parentContext;
atomicComposition.TryGetValue(this, false, out parentContext);
engineContext = new EngineContext(this, parentContext);
atomicComposition.SetValue(this, engineContext);
atomicComposition.AddCompleteAction(engineContext.Complete);
}
return engineContext;
}
示例11: TryRecomposeImport
private CompositionResult TryRecomposeImport(PartManager partManager, bool partComposed,
ImportDefinition import, AtomicComposition atomicComposition)
{
if (partComposed && !import.IsRecomposable)
{
return new CompositionResult(ErrorBuilder.PreventedByExistingImport(partManager.Part, import));
}
// During recomposition you must always requery with the new atomicComposition you cannot use any
// cached value in the part manager
var exportsResult = TryGetExports(this._sourceProvider, partManager.Part, import, atomicComposition);
if (!exportsResult.Succeeded)
{
return exportsResult.ToResult();
}
var exports = exportsResult.Value.AsArray();
if (partComposed)
{
// Knowing that the part has already been composed before and that the only possible
// changes are to recomposable imports, we can safely go ahead and do this now or
// schedule it for later
if (atomicComposition == null)
{
return partManager.TrySetImport(import, exports);
}
else
{
atomicComposition.AddCompleteAction(() => partManager.TrySetImport(import, exports).ThrowOnErrors());
}
}
else
{
partManager.SetSavedImport(import, exports, atomicComposition);
}
return CompositionResult.SucceededResult;
}
示例12: TryRecomposeImports
private CompositionResult TryRecomposeImports(PartManager partManager,
IEnumerable<ExportDefinition> changedExports, AtomicComposition atomicComposition)
{
var result = CompositionResult.SucceededResult;
switch (partManager.State)
{
case ImportState.ImportsPreviewed:
case ImportState.Composed:
// Validate states to continue.
break;
default:
{
// All other states are invalid and for recomposition.
return new CompositionResult(ErrorBuilder.InvalidStateForRecompposition(partManager.Part));
}
}
var affectedImports = RecompositionManager.GetAffectedImports(partManager.Part, changedExports);
bool partComposed = (partManager.State == ImportState.Composed);
bool recomposedImport = false;
foreach (var import in affectedImports)
{
result = result.MergeResult(
TryRecomposeImport(partManager, partComposed, import, atomicComposition));
recomposedImport = true;
}
// Knowing that the part has already been composed before and that the only possible
// changes are to recomposable imports, we can safely go ahead and do this now or
// schedule it for later
if (result.Succeeded && recomposedImport && partComposed)
{
if (atomicComposition == null)
{
result = result.MergeResult(partManager.TryOnComposed());
}
else
{
atomicComposition.AddCompleteAction(() => partManager.TryOnComposed().ThrowOnErrors());
}
}
return result;
}