Exemple #1
0
        public void Execute(ProcessContext context)
        {
            TInput input = default(TInput);

            if ((typeof(TInput).IsPrimitive) || (typeof(TInput).Equals(typeof(String))))
            {
                if (context.Inputs[0] != null)
                {
                    input = (TInput)context.Inputs[0];
                }
            }
            else if (typeof(TInput).Name.StartsWith("Tuple"))
            {
                object[] args = new object[typeof(TInput).GetGenericArguments().Count()];
                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = context.Inputs[i];
                }
                input = (TInput)Activator.CreateInstance(typeof(TInput), args);
            }

            try
            {
                TOutput output = _process(input);

                if ((typeof(TOutput).IsPrimitive) || (typeof(TOutput).Equals(typeof(String))))
                {
                    context.Outputs[0] = output;
                }
                else if (typeof(TOutput).Name.StartsWith("Tuple"))
                {
                    for (int i = 0; i < typeof(TOutput).GetGenericArguments().Count(); i++)
                    {
                        PropertyInfo p = typeof(TOutput).GetProperty(string.Format("Item{0}", i));
                        context.Outputs[i] = p.GetValue(input);
                    }
                }
            }
            catch (Exception exc)
            {
                int i = 0;
            }
        }
Exemple #2
0
 private ProcessContext GetProcessContext(IModule module, Func <IModule, ProcessContext> fnProcessContentForModule)
 {
     object[] inputs  = new object[module.NumInputs];
     object[] outputs = new object[module.NumOutputs];
     for (int i = 0; i < module.NumInputs; i++)
     {
         DirectedEdge <IModule> edge = _edges.Where(e => e.Subsequent.Equals(module) && e.SubsequentInputPortNumber == i).FirstOrDefault();
         bool isInputConnected       = edge != null;
         if (isInputConnected)
         {
             IModule        antecedent        = edge.Antecedent;
             ProcessContext antecedentContext = fnProcessContentForModule(antecedent);
             inputs[i] = antecedentContext.Outputs[edge.AntecedentOutputPortNumber];
         }
     }
     return(new ProcessContext()
     {
         Inputs = inputs, Outputs = outputs
     });
 }