/// <summary> /// Инициализация компонентов второго порядка. /// </summary> private static void InitialzieLoops() { // Создание цикла чтения ввода информации от пользователя. var readInputLoop = LoopFactory.Create <ReadInputLoop, string>(); // Получаем обработчик команд и подписываем его на ввод пользователя. var commandHandler = Toolbox.GetTool <CommandHandler>(); readInputLoop.Subscribe(commandHandler.Handle); // Создание цикла чтения информации с соединения. var readNetworkLoop = LoopFactory.Create <ReadNetworkLoop, string>(); // Получения буфера для хранения входящих сообщений. var messageBuffer = Toolbox.GetTool <MessageBuffer>(); readNetworkLoop.Subscribe((string str) => messageBuffer.Add(str)); }
public override Expression CreateExpression(VisualProgram context) { // If a start value is provided, set the target variable to that value. If not provided, do not var init = Start.HasValue ? Variable.ResolveRequiredSetterExpression(context, Start.ResolveRequiredExpression(context)) : Expression.Empty(); // Store some re-used expressions to prevent re-resolving them var variableExpr = Variable.ResolveRequiredGetterExpression(context); var changeExpr = Change.ResolveExpression(context) ?? Expression.Constant(1d, typeof(double)); var endExpr = End.ResolveRequiredExpression(context); var loop = LoopFactory.CreateLoop( // Loop body Expression.Block( // Run the given body Body.ResolveStatement(context), // Update the variable by 'Change' amount Variable.ResolveRequiredSetterExpression( context, Expression.Add(variableExpr, changeExpr) ) ), // Loop condition Expression.Condition( // If the 'Change' value is >= 0... Expression.GreaterThanOrEqual( changeExpr, Expression.Constant(0d, typeof(double)) ), // Then the condition is whether the variable is less than or equal to the end Expression.LessThanOrEqual(variableExpr, endExpr), // Otherwise (if 'Change' is < 0) the condition is whether variable is greater than or equal to the end Expression.GreaterThanOrEqual(variableExpr, endExpr) ) ); // Return a block that sets the initial value then executes the loop return(Expression.Block(init, loop)); }
public override Expression CreateExpression(VisualProgram context) => LoopFactory.CreateLoop( Body.ResolveStatement(context), Condition.ResolveRequiredExpression(context) );