コード例 #1
0
        public void DisposesDisposableAndKeepsPermanentTokens()
        {
            var localMap = new ActionPipeMap()
                           .StartsAt <DummyDisposableAction1>()
                           .Then <DummyDisposableAction2>();

            var newToken        = new ActionToken();
            var disposableType1 = new DummyDisposableType1();
            var disposableType2 = new DummyDisposableType2();

            newToken.Set(disposableType1, ItemLifespan.Permanent);
            newToken.Set(disposableType2, ItemLifespan.SingleRun);
            newToken.Set(new DummyType(), ItemLifespan.Permanent);
            newToken.Set(new DummyType2(), ItemLifespan.SingleRun);

            var pipe = new ActionPipe(localMap, newToken, new TransientDependencyResolver());

            using (var dispatcher = new ActionDispatcher(ResourcePlan.Empty, 2, TaskCreationOptions.None, pipe))
            {
                dispatcher.AsyncExecute().Wait();
            }

            Assert.IsFalse(newToken.Contains <IDisposable>());
            Assert.IsTrue(newToken.Contains <DummyDisposableType1>());
            Assert.IsFalse(newToken.Contains <DummyDisposableType2>());
            Assert.IsFalse(disposableType1.DisposeCalled);
            Assert.IsTrue(disposableType2.DisposeCalled);
            Assert.IsTrue(newToken.Contains <DummyType>());
            Assert.IsFalse(newToken.Contains <DummyType2>());
        }
コード例 #2
0
        void ExecuteAction(IResourceManager resourceManager, IAction action)
        {
            var inType = action.InputType;

            object GetValue(Type type) =>
            type == typeof(NullObject) ? NullObject.Value : ActionToken.Get(type);

            object GetMultiple(Type[] types)
            {
                var values = types.Select(GetValue).ToArray();

                return(Activator.CreateInstance(inType, values));
            }

            var inValue = inType.FullName.StartsWith("System.ValueTuple")
                ? GetMultiple(inType.GenericTypeArguments)
                : GetValue(inType);
            var outValue = action.ExecuteUntyped(resourceManager, inValue);

            if (!(outValue is NullObject))
            {
                ActionToken.Set(outValue, action.OutputType, ItemLifespan.SingleRun);
            }
        }