예제 #1
0
        /// <inheritdoc />
        protected override void RunRoutine()
        {
            try
            {
                Log(LogLevel.Debug, "Try to receive result from ObjectiveRoutine");
                // Receive object from inPipe
                InPipe.ReadInt();
                T t = InPipe.Read(Activator.CreateInstance <T>());
                Log(LogLevel.Debug, $"Received from ObjectiveRoutine: {t.ToString()}");

                // Map function
                List <Tuple <string, TV> > tuples = Map(t);
                Log(LogLevel.Debug, $"Mapping done, created {tuples.Count} tuples");

                // Tell Receiver the number of tuples
                Log(LogLevel.Debug, "Storing number of tuples");
                OutPipe.Store(tuples.Count);

                // Store tuples to outPipe
                int i = 1;
                foreach (Tuple <string, TV> tuple in tuples)
                {
                    // Write key
                    Log(LogLevel.Debug, $"Write key {i}: {tuple.Item1}");
                    OutPipe.Store(tuple.Item1);
                    // Write value (size & data)
                    Log(LogLevel.Debug, $"Write value {i}: {tuple.Item2.ToString()}");
                    byte[] data = ThriftSerializer.Serialize(tuple.Item2);
                    OutPipe.Store(data.Length); // size
                    OutPipe.Store(data);
                    i++;
                }
            }
            catch (Exception e)
            {
                Log(LogLevel.Error, $"Error while running map routine: {e.Message}");
                throw new RoutineException(e);
            }
        }
        /// <summary>
        /// Fetch an input parameter from the input pipe by its name. A command will be sent to the control pipe to
        /// feed the parameter to the input pipe, which will be read and mapped to the specific type T.
        /// </summary>
        /// <param name="name">The name of the input parameter to search for</param>
        /// <typeparam name="T">The type of the parameter to map to, which needs to be a Thrift generated type</typeparam>
        /// <returns>Returns an instance of type T created from the parameter</returns>
        /// <exception cref="AccessParameterException">If there is an error reading the parameter</exception>
        protected T GetParameter <T>(string name) where T : TBase
        {
            Log(LogLevel.Debug, $"Requesting Parameter {name}");

            Order getParam = new Order
            {
                Command = Command.GET_PARAMATER,
                Value   = name
            };

            try
            {
                CtrlPipe.Store(getParam);
                T param = InPipe.Read(Activator.CreateInstance <T>());
                Log(LogLevel.Debug, $"Received: {param}");
                return(param);
            }
            catch (Exception e)
            {
                throw new AccessParameterException(e);
            }
        }