当前位置: 首页>>代码示例>>C#>>正文


C# AtomicComposition.Complete方法代码示例

本文整理汇总了C#中AtomicComposition.Complete方法的典型用法代码示例。如果您正苦于以下问题:C# AtomicComposition.Complete方法的具体用法?C# AtomicComposition.Complete怎么用?C# AtomicComposition.Complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AtomicComposition的用法示例。


在下文中一共展示了AtomicComposition.Complete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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));
        }
开发者ID:nlhepler,项目名称:mono,代码行数:12,代码来源:CompositionTransactionTests.cs

示例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));
                }
            }));
        }
开发者ID:Helen1987,项目名称:edu,代码行数:29,代码来源:NetworkAwareCatalog.cs

示例3: 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));
        }
开发者ID:nlhepler,项目名称:mono,代码行数:12,代码来源:CompositionTransactionTests.cs

示例4: DiscoverParts

        public static void DiscoverParts(AggregateCatalog catalog, IEnumerable<Assembly> assemblies)
        {
            using (var atomicComposition = new AtomicComposition())
            {
                foreach (var assembly in assemblies)
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("{0}", assembly.FullName));

                    catalog.Catalogs.Add(new AssemblyCatalog(assembly));
                }

                atomicComposition.Complete();
            }
        }
开发者ID:nblumhardt,项目名称:MefContrib-Tools,代码行数:14,代码来源:CatalogHelper.cs

示例5: 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();
                }
            }
开发者ID:JackFong,项目名称:FreeRadical,代码行数:18,代码来源:ExportProviderFactory.RecomposableExportProvider.cs

示例6: PreviewImports_Successful_AtomicComposition_Completeted_ShouldBlockChanges

        public void PreviewImports_Successful_AtomicComposition_Completeted_ShouldBlockChanges()
        {
            var exportProvider = ExportProviderFactory.CreateRecomposable();
            var engine = new ImportEngine(exportProvider);

            var import = ImportDefinitionFactory.Create("Value");
            var importer = PartFactory.CreateImporter(import);

            exportProvider.AddExport("Value", 21);

            using (var atomicComposition = new AtomicComposition())
            {
                engine.PreviewImports(importer, atomicComposition);
                atomicComposition.Complete();
            }

            ExceptionAssert.Throws<ChangeRejectedException>(() =>
                exportProvider.AddExport("Value", 22));

            ExceptionAssert.Throws<ChangeRejectedException>(() =>
                exportProvider.RemoveExport("Value"));

            GC.KeepAlive(importer);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:24,代码来源:ImportEngineTests.cs

示例7: AddRevertAction_ShouldBeCopiedWhenCompleteed

        public void AddRevertAction_ShouldBeCopiedWhenCompleteed()
        {
            Stack<int> stack = new Stack<int>();
            stack.Push(1);
            stack.Push(2);
            stack.Push(11);
            stack.Push(12);
            stack.Push(3);

            using (var ct = new AtomicComposition())
            {
                ct.AddRevertAction(() => Assert.AreEqual(1, stack.Pop()));
                ct.AddRevertAction(() => Assert.AreEqual(2, stack.Pop()));

                using (var ct2 = new AtomicComposition(ct))
                {
                    ct2.AddRevertAction(() => Assert.AreEqual(11, stack.Pop()));
                    ct2.AddRevertAction(() => Assert.AreEqual(12, stack.Pop()));

                    // completeting should move those revert actions to ct
                    ct2.Complete();

                    Assert.AreEqual(5, stack.Count);
                }

                ct.AddRevertAction(() => Assert.AreEqual(3, stack.Pop()));

                // Do not complete let ct dispose and revert
            }

            Assert.IsTrue(stack.Count == 0);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:32,代码来源:CompositionTransactionTests.cs

示例8: AddRevertAction_ShouldNotExecuteWhenCompleteted

        public void AddRevertAction_ShouldNotExecuteWhenCompleteted()
        {
            var ct = new AtomicComposition();
            bool executed = false;

            ct.AddRevertAction(() => executed = true);

            ct.Complete();

            Assert.IsFalse(executed);

            ct.Dispose();

            Assert.IsFalse(executed);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:15,代码来源:CompositionTransactionTests.cs

示例9: AtomicComposition_NestedQueries

        public void AtomicComposition_NestedQueries()
        {
            // This is a rather convoluted test that exercises the way AtomicComposition used to work to
            // ensure consistency of the newer design
            var key = new Object();

            using (var contextA = new AtomicComposition())
            {
                SetQuery(contextA, key, (int parameter, Func<int, bool> parentQuery) =>
                {
                    if (parameter == 22)
                        return true;
                    if (parentQuery != null)
                        return parentQuery(parameter);
                    return false;
                });
                TestQuery(contextA, key, 22, true);

                using (var contextB = new AtomicComposition(contextA))
                {
                    TestQuery(contextB, key, 22, true);
                    SetQuery(contextB, key, (int parameter, Func<int, bool> parentQuery) =>
                    {
                        if (parentQuery != null)
                            return !parentQuery(parameter);
                        Assert.Fail(); // Should never have no parent
                        return false;
                    });
                    TestQuery(contextB, key, 21, true);
                    TestQuery(contextB, key, 22, false);

                    using (var contextC = new AtomicComposition(contextB))
                    {
                        SetQuery(contextC, key, (int parameter, Func<int, bool> parentQuery) =>
                        {
                            if (parameter == 23)
                                return true;
                            if (parentQuery != null)
                                return !parentQuery(parameter);
                            Assert.Fail(); // Should never have no parent
                            return false;
                        });
                        TestQuery(contextC, key, 21, false);
                        TestQuery(contextC, key, 22, true);
                        TestQuery(contextC, key, 23, true);
                        contextC.Complete();
                    }

                    using (var contextD = new AtomicComposition(contextB))
                    {
                        SetQuery(contextD, key, (int parameter, Func<int, bool> parentQuery) =>
                        {
                            if (parentQuery != null)
                                return parentQuery(parameter + 1);
                            Assert.Fail(); // Should never have no parent
                            return false;
                        });
                        TestQuery(contextD, key, 21, true);
                        TestQuery(contextD, key, 22, true);
                        TestQuery(contextD, key, 23, false);
                        // No complete
                    }

                    contextB.Complete();
                }
                TestQuery(contextA, key, 21, false);
                TestQuery(contextA, key, 22, true);
                TestQuery(contextA, key, 23, true);
                contextA.Complete();
            }
        }
开发者ID:nlhepler,项目名称:mono,代码行数:71,代码来源:CompositionTransactionTests.cs

示例10: AtomicComposition_CompleteValues

        public void AtomicComposition_CompleteValues()
        {
            object key1 = new Object();
            object key2 = new Object();

            using (var contextA = new AtomicComposition())
            {
                TestNoValue(contextA, key1);
                TestNoValue(contextA, key2);
                contextA.SetValue(key1, "Hello");
                TestValue(contextA, key1, "Hello");
                TestNoValue(contextA, key2);

                // Try overwriting
                using (var contextB = new AtomicComposition(contextA))
                {
                    TestValue(contextB, key1, "Hello");
                    TestNoValue(contextB, key2);
                    contextB.SetValue(key1, "Greetings");
                    TestValue(contextB, key1, "Greetings");
                    TestNoValue(contextB, key2);

                    contextB.Complete();
                }
                TestValue(contextA, key1, "Greetings");
                TestNoValue(contextA, key2);

                // Try overwrite with revert
                using (var contextC = new AtomicComposition(contextA))
                {
                    TestValue(contextC, key1, "Greetings");
                    TestNoValue(contextC, key2);
                    contextC.SetValue(key1, "Goodbye");
                    contextC.SetValue(key2, "Goodbye, Again");
                    TestValue(contextC, key1, "Goodbye");
                    TestValue(contextC, key2, "Goodbye, Again");

                    // Don't complete
                }
                TestValue(contextA, key1, "Greetings");
                TestNoValue(contextA, key2);

                contextA.Complete();
            }
        }
开发者ID:nlhepler,项目名称:mono,代码行数:45,代码来源:CompositionTransactionTests.cs

示例11: 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);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:18,代码来源:CompositionTransactionTests.cs

示例12: Complete_ShouldCopyValuesToInner

        public void Complete_ShouldCopyValuesToInner()
        {
            var innerAtomicComposition = new AtomicComposition();

            object value;
            using (var ct = new AtomicComposition(innerAtomicComposition))
            {
                ct.SetValue(this, 21);

                Assert.IsFalse(innerAtomicComposition.TryGetValue(this, out value));

                ct.Complete();

                Assert.IsTrue(innerAtomicComposition.TryGetValue(this, out value));
                Assert.AreEqual(21, value);
            }

            // reverify after dispose
            Assert.IsTrue(innerAtomicComposition.TryGetValue(this, out value));
            Assert.AreEqual(21, value);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:21,代码来源:CompositionTransactionTests.cs

示例13: Complete_ShouldExecuteActions

        public void Complete_ShouldExecuteActions()
        {
            bool executedAction = false;

            var ct = new AtomicComposition();

            ct.AddCompleteAction(() => executedAction = true);

            ct.Complete();

            Assert.IsTrue(executedAction);
        }
开发者ID:nlhepler,项目名称:mono,代码行数:12,代码来源:CompositionTransactionTests.cs

示例14: 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();
            }
        }
开发者ID:doublekill,项目名称:MefContrib,代码行数:35,代码来源:InterceptingCatalog.cs

示例15: DiscoverParts

        /// <summary>
        /// </summary>
        /// <param name="assemblies">
        /// </param>
        /// <exception cref="ObjectDisposedException">
        ///     The <see cref="XapCatalog"/> has been disposed of.
        /// </exception>
        private void DiscoverParts(IEnumerable<Assembly> assemblies)
        {
            ThrowIfDisposed();

            List<ComposablePartDefinition> addedDefinitions = new List<ComposablePartDefinition>();
            Dictionary<string, ComposablePartCatalog> addedCatalogs = new Dictionary<string, ComposablePartCatalog>();
            using (new ReadLock(_lock))
            {
                foreach (Assembly assembly in assemblies)
                {
                    if (addedCatalogs.ContainsKey(assembly.FullName))
                    {
                        // Nothing to do because the assembly has already been added.
                        continue;
                    }

                    AssemblyCatalog catalog = new AssemblyCatalog(assembly);
                    addedDefinitions.AddRange(catalog.Parts);
                    addedCatalogs.Add(assembly.FullName, catalog);
                }
            }

            // Generate notifications
            using (AtomicComposition atomicComposition = new AtomicComposition())
            {
                ComposablePartCatalogChangeEventArgs changingArgs = new ComposablePartCatalogChangeEventArgs(
                    addedDefinitions, Enumerable.Empty<ComposablePartDefinition>(), atomicComposition);
                OnChanging(changingArgs);

                using (new WriteLock(_lock))
                {
                    foreach (KeyValuePair<string, ComposablePartCatalog> item in addedCatalogs)
                    {
                        _catalogCollection.Catalogs.Add(item.Value);
                    }
                }
                atomicComposition.Complete();
            }

            ComposablePartCatalogChangeEventArgs changedArgs = new ComposablePartCatalogChangeEventArgs(
                addedDefinitions, Enumerable.Empty<ComposablePartDefinition>(), null);
            OnChanged(changedArgs);
        }
开发者ID:rafaelorion,项目名称:MigSharp,代码行数:50,代码来源:XapCatalog.cs


注:本文中的AtomicComposition.Complete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。