private void Handle_exception(Task task, Exception ex)
        {
            var exFlow = ex as FlowRuntimeException ?? new FlowRuntimeException(ex, task.Message);

            if (task.Message.Causalities.IsEmpty)
                UnhandledException(exFlow);
            else
                Catch_exception_with_causality(task, exFlow);
        }
 public void Process(Task task)
 {
     var ebcOp = task.Operation as EBCOperation;
     if (ebcOp != null)
     {
         var methodOp = ebcOp.Create_method_operation(task.Message);
         task = new Task(task.Message, methodOp);
     }
     Result(task);
 }
 public void Process(Task task)
 {
     try
     {
         task.Operation.Implementation(task.Message,
                                       output => Put_output_in_same_context_as_input(task, output),
                                       ex => Handle_exception(task, ex));
     }
     catch (Exception ex)
     {
         Handle_exception(task, ex);
     }
 }
        public void Output_is_in_same_context_as_input()
        {
            var sut = new Execute_task();

            var msg = new Message("a/b/x.in", "hello");
            var task = new Task(msg,
                                new Operation("x", (input, outputCont, _) => {
                                                                          		outputCont(new Message("x.out", input.Data.ToString() + "x"));
                                                                          }));
            var results = new List<IMessage>();
            sut.Result += _ => results.Add(_);

            sut.Process(task);
            Assert.AreEqual("hellox", results[0].Data.ToString());
            Assert.AreEqual("a/b/x.out", results[0].Port.Fullname);
        }
        private void Put_output_in_same_context_as_input(Task task, IMessage output)
        {
            if (!(task.Operation is IFlow) && task.Message.Port.Path != output.Port.Path)
                    output = new Message(Port.Build(task.Message.Port.Path, output.Port.OperationName, output.Port.InstanceNumber, output.Port.Name),
                                         output.Data,
                                         task.Message.CorrelationId);

            if (task.Message.Port.InstanceNumber != "" && output.Port.InstanceNumber == "")
                output = new Message(Port.Build(output.Port.Path, output.Port.OperationName, task.Message.Port.InstanceNumber, output.Port.Name),
                                     output.Data,
                                     task.Message.CorrelationId);

            if (!(task.Operation is IFlow)) output.FlowStack = task.Message.FlowStack;
            output.Causalities = task.Message.Causalities;

            Result(output);
        }
        public void Operation_with_single_output()
        {
            var sut = new Execute_task();

            var msg = new Message("x.in", "hello");
            var task = new Task(msg,
                                new Operation("x", (input, outputCont, _) => {
                                                                          		outputCont(input);
                                                                          }));

            IMessage result = null;
            sut.Result += _ => result = _;

            sut.Process(task);

            Assert.AreSame(msg, result);
        }
        public void Operation_with_multiple_outputs()
        {
            var sut = new Execute_task();

            var msg = new Message("x.in", "hello");
            var task = new Task(msg,
                                new Operation("x", (input, outputCont, _) => {
                                                                          		outputCont(new Message("1", input.Data.ToString() + "x"));
                                                                                outputCont(new Message("2", input.Data.ToString() + "y"));
                                                                          }));

            var results = new List<IMessage>();
            sut.Result += _ => results.Add(_);

            sut.Process(task);

            Assert.AreEqual("1", results[0].Port.Fullname);
            Assert.AreEqual("hellox", results[0].Data.ToString());
            Assert.AreEqual("2", results[1].Port.Fullname);
            Assert.AreEqual("helloy", results[1].Data.ToString());
        }
 public void Execute(Task task)
 {
     _execute(task);
 }
 private void Catch_exception_with_causality(Task task, FlowRuntimeException ex)
 {
     var c = task.Message.Causalities.Peek();
     var cMsg = new Message(c.Port, ex, task.Message.CorrelationId);
     HandledException(cMsg);
 }