Exemplo n.º 1
0
            void DoBlock(string @operator, ConditionBlockAction action)
            {
                if (action == null)
                {
                    return;
                }
                Condition item = _root.Children.Find(p => p.Name == @operator);

                if (item == null)
                {
                    if (@operator == "$and" && _root.Children.Count == 0)
                    {
                        item = _root;
                    }
                    else
                    {
                        item = new Condition(@operator, ConditionTypes.Logical);
                    }
                }
                ConditionBlock block = new ConditionBlock(item);

                action(block);
                if (@operator == "$or" && item.Children.Count > 1)
                {
                    item.Children.IsArray = true;
                }
                if (item.Children.Count > 0 && item != _root)
                {
                    _root.Children.Add(item);
                }
            }
Exemplo n.º 2
0
        private ConditionBlock TranslateCondition(ICodeBlock parent, string condition, int startPos, out int endPos)
        {
            var result = new ConditionBlock(parent, Parser.ParseLine(condition), null);

            endPos = FindBlockEnd(startPos + 1);

            result.IfCode = Translate(result, startPos + 1, endPos);

            if (endPos >= Code.Count)
            {
                return(result);
            }

            var match = ElifBranch.Match(Code[endPos]);

            if (match.Success)
            {
                result.ElseCode = TranslateCondition(parent, match.Groups["condition"].ToString(),
                                                     endPos, out endPos);
            }
            else if (ElseBranch.IsMatch(Code[endPos]))
            {
                var endElse = FindBlockEnd(endPos + 1);
                result.ElseCode = Translate(result, endPos + 1, endElse);
                endPos          = endElse;
            }

            return(result);
        }
Exemplo n.º 3
0
        private void 다르다면FToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ConditionBlock block = new ConditionBlock(Board, Board);

            block.Control.Location = _lastRightClicked;
            AddBlock(block);
        }
Exemplo n.º 4
0
        private void TestConditionBlockBranch(string symbolName)
        {
            State state = _state.Value;

            if (!state.NestedFileStates.Any())
            {
                throw new Error("invalid condition block format for symbol: {0}", symbolName);
            }

            FileState currentFile = state.NestedFileStates.Peek();

            if (!currentFile.NestedConditionBlocks.Any())
            {
                throw new Error("invalid condition block format for symbol: {0}", symbolName);
            }

            ConditionBlock topBlock = currentFile.NestedConditionBlocks.Peek();

            topBlock.CurrentDefine = symbolName;
            topBlock.Defined       = false;

            // If one branch of the 'if' has been resolved, than don't evaluate other branches
            if (!topBlock.Resolved)
            {
                topBlock.Defined  = symbolName == null || _defines.Contains(symbolName);
                topBlock.Resolved = topBlock.Defined;
            }

            // The current line being parsed is defined if all nested 'if' blocks are defined.
            currentFile.IsCurrentCodeBlockDefined = currentFile.NestedConditionBlocks.All(d => d.Defined);
        }
Exemplo n.º 5
0
        public static ConditionalExpression CreateConditionalExpression(ConditionBlock conditionBlock, ConditionalExpression elseCondition, Token token)
        {
            ConditionalExpression result = CreateNode <ConditionalExpression>(token);

            result.SetIfBlock(conditionBlock);
            result.SetElseBlock(elseCondition);
            return(result);
        }
Exemplo n.º 6
0
        public void AddWhileBlock(byte id, string context, FuncCondition conditionFunction)
        {
            CheckId(id);

            var conditionBlock = new ConditionBlock(id, context, () => { return(conditionFunction.Invoke()); });

            mEnvironment.Add(id, new WhileBlock(id, null, conditionBlock));
        }
Exemplo n.º 7
0
 public IfThenBlock(
     string nm,
     Func <object, object> ifFxn,
     Func <object, object> actionFxn)
 {
     this.setName(nm);
     this.ifLogic = new ConditionBlock(this.Name + "-Condition", ifFxn);
     this.action  = new ActionBlock(this.Name + "-Action", actionFxn);
 }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="nm"></param>
 /// <param name="ifBlk"></param>
 /// <param name="actBlk"></param>
 public IfThenBlock(
     string nm,
     ConditionBlock ifBlk,
     ActionBlock actBlk)
 {
     this.setName(nm);
     this.ifLogic = ifBlk;
     this.action  = actBlk;
 }
Exemplo n.º 9
0
        private void 조건문CToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ConditionBlock block = new ConditionBlock(Board, Board);

            block.Location = _lastRightClicked;
            AddBlock(block);

            this.contextMenuStrip1.Close();
        }
Exemplo n.º 10
0
        protected void AddFactorEdges(GraphWriter g, MethodInvoke mi)
        {
            var parameters = mi.method.GetParameters();

            for (int i = 0; i < mi.args.Count; i++)
            {
                var parameter = parameters[i];
                if (parameter.IsOut)
                {
                    AddEdge(g, mi, mi.args[i], parameter.Name);
                }
                else
                {
                    AddEdge(g, mi.args[i], mi, parameter.Name);
                }
            }
            if (mi.returnValue != null)
            {
                AddEdge(g, mi, mi.returnValue, "");
            }
            if (!UseContainers)
            {
                // add edges from condition variables to target (if there are no such edges already)
                IModelExpression      target   = (mi.returnValue != null) ? mi.returnValue : mi;
                Set <IStatementBlock> excluded = new Set <IStatementBlock>();
                if (target is Variable)
                {
                    // if target is in the ConditionBlock, then don't connect with the condition variable
                    Variable targetVar = (Variable)target;
                    excluded.AddRange(targetVar.Containers);
                }
                foreach (IStatementBlock block in mi.Containers)
                {
                    if (excluded.Contains(block))
                    {
                        continue;
                    }
                    if (block is ConditionBlock)
                    {
                        ConditionBlock  cb = (ConditionBlock)block;
                        Variable        c  = cb.ConditionVariableUntyped;
                        List <Variable> condVars;
                        if (!conditionVariables.TryGetValue(target, out condVars))
                        {
                            condVars = new List <Variable>();
                            conditionVariables[target] = condVars;
                        }
                        if (!condVars.Contains(c))
                        {
                            AddEdge(g, c, target, "condition");
                            condVars.Add(c);
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        public static ConditionBlock CreateConditionalBlock(int precedence, IExpression expression, BlockStatement blockStmt, Token token)
        {
            ConditionBlock result = CreateNode <ConditionBlock>(token);

            result.SetCondition(expression);
            result.SetBlockStatement(blockStmt);
            result.SetPrecedence(precedence);

            return(result);
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            Board board = new Board();

            EntryBlock           entry    = new EntryBlock(board);
            DeclareVariableBlock declare1 = new DeclareVariableBlock(board)
            {
                Variable = new Variable("a", 1)
            };
            DeclareVariableBlock declare2 = new DeclareVariableBlock(board)
            {
                Variable = new Variable("i", 1)
            };
            ConditionBlock small = new ConditionBlock(board, null, new ConditionBoolBlock(board, null)
            {
                Condition = new Condition()
                {
                    LType   = Condition.ValueType.Var,
                    L       = "i",
                    RType   = Condition.ValueType.Num,
                    R       = 10,
                    Compare = Condition.CompareType.Smaller
                }
            });
            ChangeVariableValueBlock change = new ChangeVariableValueBlock(board, null, "a", (a, i) => (dynamic)a * (dynamic)i)
            {
            };
            ChangeVariableValueBlock change2 = new ChangeVariableValueBlock(board, null, "i", (i, v) => (dynamic)i + (dynamic)v)
            {
            };

            Block.Connect(entry, declare1);
            Block.Connect(declare1, declare2);
            Block.Connect(declare2, small);
            Block.Connect(small, change);
            Block.Connect(change, change2);
            Block.Connect(change2, small);

            board.Entry = entry;
            board.Initialize();

            while (!board.Ended)
            {
                board.RunStep();
                board.PrintAllVariables();
            }

            Console.ReadLine();
        }
Exemplo n.º 13
0
        private MiraeBuildError BuildWhileBlock(WhileBlock environment, IBlock prev, byte conditionBlockId, out IBlock block)
        {
            ConditionBlock conditionBlock = environment.Condition;

            if (conditionBlock == null)
            {
                MiraeBuildError error = BuildConditionBlock(conditionBlockId, out conditionBlock);
                if (error > MiraeBuildError.Success)
                {
                    block = null;
                    return(error);
                }
            }

            block = new WhileBlock(environment.Id, prev, conditionBlock);
            return(MiraeBuildError.Success);
        }
        private void InitializeAvailableExpressions()
        {
            var availableElements = new Func <CompositeElement>[] {
                //()=> {
                //	var group = new CompositeElement { DisplayName = "Customer conditions" };
                //	group.AvailableChildrenGetters.AddRange(new Func<ExpressionElement>[] {
                //		()=> new ConditionCustomerStatus(this.ExpressionViewModel)
                //	});
                //	return group;
                //},

                () => {
                    var group = new CompositeElement {
                        DisplayName = "Case conditions".Localize()
                    };
                    group.AvailableChildrenGetters.AddRange(new Func <ExpressionElement>[] {
                        () => new ConditionCaseStatus(this.ExpressionViewModel)
                    });
                    return(group);
                }

                //()=> {
                //	var group = new CompositeElement { DisplayName = "Order conditions" };
                //	group.AvailableChildrenGetters.AddRange(new Func<ExpressionElement>[] {
                //		()=> new ConditionOrderStatus(this.ExpressionViewModel)
                //	});
                //	return group;
                //}
            };

            ConditionBlock.WithAvailabeChildren(availableElements);
            ConditionBlock.NewChildLabel = "+ add condition".Localize(null, LocalizationScope.DefaultCategory);

            availableElements = new Func <CompositeElement>[] {
                () => new ActionXslInlineAlert(this.ExpressionViewModel),
                () => new ActionHtmlInlineAlert(this.ExpressionViewModel),
                () => new ActionRedirectAlert(this.ExpressionViewModel)
            };

            ActionBlock.WithAvailabeChildren(availableElements);
            ActionBlock.NewChildLabel = "+ add effect".Localize(null, LocalizationScope.DefaultCategory);
        }
Exemplo n.º 15
0
        private MiraeBuildError BuildConditionBlock(byte id, out ConditionBlock block)
        {
            if (!mEnvironments.ContainsKey(id))
            {
                block = null;
                return(MiraeBuildError.UndefinedBlock);
            }

            var env = mEnvironments[id];

            if (env.BlockType != BlockType.Condition)
            {
                block = null;
                return(MiraeBuildError.WrongBlockType);
            }

            var conditionBlock = env as ConditionBlock;

            block = new ConditionBlock(conditionBlock.Id, conditionBlock.Context, conditionBlock.ConditionFunction);
            return(MiraeBuildError.Success);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="nm"></param>
        /// <param name="iFxns"></param>
        /// <param name="elseFxn"></param>
        public IfThenElseBlock(
            string nm,
            List <PairType <FxnBlock, FxnBlock> > iFxns,
            FxnBlock elseFxn)
        {
            if (string.IsNullOrEmpty(nm) ||
                CollectionUtilities.isEmpty(iFxns))
            {
                throw new ApplicationException("Cannot create IfThenElse block");
            }

            //Set the necessary fields
            this.ifMap = new Dictionary <string, bool>();
            this.setName(nm);
            this.ifElseBlockPairs = new List <PairType <ConditionBlock, ActionBlock> >();
            this.elseBlock        = new ActionBlock(nm + "-ElseAction", elseFxn);
            int cnt = 0;

            //Create the if blocks
            foreach (PairType <FxnBlock, FxnBlock> fxn in iFxns)
            {
                FxnBlock condFxn = fxn.Left;
                FxnBlock actFxn  = fxn.Right;

                //Create condition block
                ConditionBlock cndBlk = new ConditionBlock(nm + "-Condition-" + cnt, fxn.Left);
                //Create action block
                ActionBlock actBlk = new ActionBlock(nm + "-Action-" + cnt, fxn.Right);

                //Create bound pair of condition to action
                PairType <ConditionBlock, ActionBlock> ifElsBlk =
                    new PairType <ConditionBlock, ActionBlock>(cndBlk, actBlk);

                //Add this to the if else block pair list
                this.ifElseBlockPairs.Add(ifElsBlk);

                //Increase count
                cnt++;
            }
        }
        private void InitializeAvailableExpressions()
        {
            var availableElements = new Func <CompositeElement>[] {
                () => new ConditionCategoryIs(ExpressionViewModel),
                () => new ConditionEntryIs(ExpressionViewModel),
                () => new ConditionCurrencyIs(ExpressionViewModel)
            };

            ConditionBlock.WithAvailabeChildren(availableElements);
            ConditionBlock.NewChildLabel      = "+ add condition".Localize(null, LocalizationScope.DefaultCategory);
            ConditionBlock.IsChildrenRequired = true;
            ConditionBlock.ErrorMessage       = "Promotion requires at least one condition".Localize();

            availableElements = new Func <CompositeElement>[] {
                () => new ActionCatalogItemGetOfAbs(ExpressionViewModel),
                () => new ActionCatalogItemGetOfRel(ExpressionViewModel)
                , () => new ActionCatalogItemGiftNumItemOfSku(ExpressionViewModel)
            };
            ActionBlock.WithAvailabeChildren(availableElements);
            ActionBlock.NewChildLabel      = "+ add effect".Localize(null, LocalizationScope.DefaultCategory);
            ActionBlock.IsChildrenRequired = true;
            ActionBlock.ErrorMessage       = "Promotion requires at least one reward".Localize();
        }
        public System.Linq.Expressions.Expression <Func <IEvaluationContext, bool> > GetExpression()
        {
            var retVal = ConditionBlock.GetExpression();

            return(retVal);
        }
Exemplo n.º 19
0
 public ConditionBlockControl(ConditionBlock block)
 {
     InitializeComponent();
     _block = block;
 }