Пример #1
0
        public void TestMethod1()
        {
            ExpressionParser Parser = ExpressionParser.CreateParser();

            Parser.ParsingContext.Parameters.Add("x", Parameter.NewParameter(1));
            DummyAction dummy  = new DummyAction();
            WhileAction action = new WhileAction
            {
                Parser = Parser,
                ConditionExpression = "x < 5$",
                InnerAction         = new BlockAction
                {
                    ActionList = new List <IAction>
                    {
                        dummy,
                        new SetVariableAction
                        {
                            VariableName = "x",
                            Expression   = "x + 1$"
                        }
                    }
                }
            };

            action.ExecuteAction();
            Assert.AreEqual(4, dummy.Count);
        }
 public void Refresh(ActionHolder actionHolder, IAlgorithmContext algoContext)
 {
     ActionHolder     = actionHolder;
     AlgorithmContext = algoContext;
     _action          = (WhileAction)actionHolder.Action;
     actionView.Refresh(new ActionHolder(_action.Action), algoContext);
     checkerView.Refresh(new ActionHolder(_action.Checker), algoContext);
 }
Пример #3
0
        private void insert_Click(object sender, System.EventArgs e)
        {
            MacroAction a = null;

            try
            {
                if (varList.SelectedIndex == (int)WhileAction.WhileVarType.SysMessage)
                {
                    a = new WhileAction((WhileAction.WhileVarType)varList.SelectedIndex, txtAmount.Text);
                }
                else if (varList.SelectedIndex >= m_SkillStart)
                {
                    int skillId = -1;

                    foreach (Skill skill in World.Player.Skills)
                    {
                        if (Language.Skill2Str(skill.Index).Equals(varList.SelectedItem as string))
                        {
                            skillId = skill.Index;
                            break;
                        }
                    }

                    if (skillId != -1)
                    {
                        a = new WhileAction(WhileAction.WhileVarType.Skill, (sbyte)opList.SelectedIndex, Utility.ToDouble(txtAmount.Text, 0.0), skillId);
                    }
                }
                else if (varList.SelectedIndex >= (int)WhileAction.WhileVarType.BeginCountersMarker)
                {
                    a = new WhileAction(WhileAction.WhileVarType.Counter, (sbyte)opList.SelectedIndex,
                                        Utility.ToInt32(txtAmount.Text, 0), varList.SelectedItem as string);
                }
                else
                {
                    a = txtAmount.Text.Contains("{") // using an if variable
                        ? new WhileAction((WhileAction.WhileVarType)varList.SelectedIndex, (sbyte)opList.SelectedIndex,
                                          txtAmount.Text)
                        : new WhileAction((WhileAction.WhileVarType)varList.SelectedIndex, (sbyte)opList.SelectedIndex,
                                          Utility.ToInt32(txtAmount.Text, 0));
                }
            }
            catch
            {
                return;
            }

            if (m_Action == null)
            {
                m_Macro.Insert(m_Idx + 1, a);
            }
            else
            {
                m_Action.Parent.Convert(m_Action, a);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #4
0
 public void ProcessWhileAction()
 {
     if (_whileAction == null)
         _whileAction = new WhileAction();
     if (_whileAction.Action == null)
         _whileAction.Action = new ComplexAction();
     if (_whileAction.Checker == null)
         _whileAction.Checker = new ComplexChecker();
 }
Пример #5
0
 public WhileView(WhileAction whileAction)
 {
     if (whileAction == null)
         return;
     var context = new WhileViewContext(whileAction);
     this.DataContext = context;
     InitializeComponent();
     var ifControl = new ComplexActionView(context.Action) { RootControlsVisibility = Visibility.Collapsed };
     ifControl.Changed += (o, e) => RaiseChanged();
     this.gridIfHolder.Children.Add(ifControl);
     var checkerControl = new ComplexCheckerView(new OperatorCheckerPair() { Checker = context.Checker }) { RootControlsVisibility = Visibility.Collapsed };
     checkerControl.Changed += (o, e) => RaiseChanged();
     this.gridCheckerHolder.Children.Add(checkerControl);
     this.btRemove.Click += (o, e) =>
     {
         if (Utils.IsUserSureToDeleteCurrentOperator())
             if (Remove != null)
             {
                 Remove(this, new EventArgs());
                 RaiseChanged();
             }
     };
 }
Пример #6
0
 public WhileViewContext(WhileAction whileAction)
 {
     _whileAction = whileAction;
     ProcessWhileAction();
 }
Пример #7
0
 private void AddWhileControl(WhileAction action)
 {
     var view = new WhileView(action);
     view.Remove += (o, e) =>
     {
         ((ComplexActionViewContext)this.DataContext).RemoveAction(action);
         this.spActions.Children.Remove(view);
     };
     view.Changed += (o, e) => RaiseChanged();
     spActions.Children.Add(view);
     RaiseChanged();
 }