Ejemplo n.º 1
0
 public override void InitializeTest()
 {
     m_innerScheduler  = CreateInnerScheduler();
     m_strandScheduler = new StrandSchedulerDecorator(m_innerScheduler);
     m_proxyScheduler  = new ProxyScheduler(m_strandScheduler);
     base.InitializeTest();
 }
 private StrandSchedulerDecorator getStrand(object invocationTarget)
 {
     return(m_strandActorDictionary.GetValue(invocationTarget, _ =>
     {
         var strandScheduler = new StrandSchedulerDecorator(m_primaryScheduler);
         var externalProxyScheduler = new ProxyScheduler(strandScheduler);
         return strandScheduler;
     }));
 }
        private void postTargetSub(StrandSchedulerDecorator strand, IInvocation invocation)
        {
            void postAction()
            {
                invocation.GetConcreteMethodInvocationTarget()
                .Invoke(invocation.InvocationTarget, invocation.Arguments);
                //Problems with Castle implementation (call from other thread does not work after upgrade to 4.3.1. version)
                //invocation.Proceed();
            }

            strand.Post((Action)postAction);
        }
        private void postTargetFunc(StrandSchedulerDecorator strand, IInvocation invocation)
        {
            var     methodInvocationTarget = invocation.MethodInvocationTarget;
            dynamic proxyTcs = null;

            proxyTcs = getProxyTcs(methodInvocationTarget);
            var isGenericReturnType = methodInvocationTarget.ReturnType.IsGenericType;

            invocation.ReturnValue = proxyTcs.Task;

            strand.Post(postFunc);

            Task postFunc()
            {
                Task resultTask   = null;
                var  hasException = false;

                try
                {
                    resultTask = invocation.GetConcreteMethodInvocationTarget()
                                 .Invoke(invocation.InvocationTarget, invocation.Arguments) as Task;
                    //Problems with Castle implementation (call from other thread does not work after upgrade to 4.3.1. version)
                    //invocation.Proceed();
                }
                catch (Exception e)
                {
                    hasException = true;
                    if (resultTask == null)
                    {
                        resultTask = TaskEx.TaskFromException(e);
                    }
                }
                finally
                {
                    if (!hasException && isGenericReturnType)
                    {
                        TaskEx.PrepareTcsTaskFromExistingTask((dynamic)resultTask, proxyTcs);
                    }
                    else
                    {
                        TaskEx.PrepareTcsTaskFromExistingTask(resultTask, proxyTcs);
                    }
                }

                return(resultTask);
            }
        }