Beispiel #1
0
        public override string GetCns(int index)
        {
            Index = index;
            string conditionSeparator;

            switch (ConditionType)
            {
            case (ConditionType.And):
                conditionSeparator = "_a_";
                break;

            case (ConditionType.Or):
                conditionSeparator = "_o_";
                break;

            default:
                throw new Exception("ConditionType not supported");
            }

            if (index == 0)
            {
                return(Condition1.GetCns(index) + conditionSeparator + Condition2.GetCns(index + Condition1.GetCount()));
            }

            return("(" + Condition1.GetCns(index) + conditionSeparator + Condition2.GetCns(index + Condition1.GetCount()) + ")");
        }
        static void Main(string[] args)
        {
            Program p = new Program();

            List <int> lstInt = new List <int>();

            lstInt.Add(40);
            lstInt.Add(80);
            lstInt.Add(90);

            Predicate <int> pred = p.IsGreaterThan50;
            int             i    = lstInt.Find(pred);          // 找到匹配的第一个元素,此处为80

            Console.WriteLine("大于50的第一个元素为{0}", i);

            List <int> all = lstInt.FindAll(pred);

            for (int j = 0; j < all.Count(); j++)
            {
                Console.WriteLine("大于50的数组中元素为{0}", all[j]);  // 找出所有匹配条件的
            }

            List <Condition>          conditions = new List <Condition>();
            Condition0                c0         = new Condition0(p.testTrue);
            Condition1 <int>          c1         = new Condition1 <int>(p.IsGreaterThan50, 40);
            Condition1 <int>          c1a        = new Condition1 <int>(p.IsGreaterThan50, () => { return(60); });
            Condition2 <float, float> c2         = new Condition2 <float, float>(p.test2, () => { return(1); }, () => { return(2); });
            Condition2 <float, float> c2a        = new Condition2 <float, float>(p.test2, 0.1f, 0.01f);

            conditions.Add(c0);
            conditions.Add(c1);
            conditions.Add(c1a);
            conditions.Add(c2);
            conditions.Add(c2a);

            //failed
            //List<Operation<object>> list = new List<Operation<object>>();
            //list.Add(new Operation0<void>(()=>{}));

            Operation op1 = new Operation1 <uint>((uint id) => { Console.WriteLine("operation:" + id); }, Program.getId);

            op1.operate();
            op1.operate();
            op1.operate();
            op1.operate();

            //failed
            //object outObj = null;
            //Operation op2 = new Operation2<uint,out object>((uint id,out object obj) =>{ Console.WriteLine("operation:" + id); obj = id;}, Program.getId,out outObj);
            //op2.operate();

            foreach (Condition c in conditions)
            {
                Console.WriteLine(c.isTrue());
            }



            Console.ReadLine();
        }
Beispiel #3
0
        private void CreateUI()
        {
            Height = 84;
            Width  = 271;

            m_ll1.Text      = (Condition1 != null ? Condition1.GetText() : "Bedingung");
            m_ll1.Top       = 0;
            m_ll1.Left      = 0;
            m_ll1.Height    = Height;
            m_ll1.Width     = 90;
            m_ll1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            m_ll1.Click    += Ll1_Click;
            Controls.Add(m_ll1);

            Label pl = new Label();

            pl.Text      = "und";
            pl.Top       = 0;
            pl.Left      = 90;
            pl.Height    = Height;
            pl.Width     = 90;
            pl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            Controls.Add(pl);

            m_ll2.Text      = (Condition2 != null ? Condition1.GetText() : "Bedingung");
            m_ll2.Top       = 0;
            m_ll2.Left      = 180;
            m_ll2.Height    = Height;
            m_ll2.Width     = 90;
            m_ll2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            m_ll2.Click    += Ll2_Click;
            Controls.Add(m_ll2);
        }
Beispiel #4
0
        public override string GetText()
        {
            string con1 = (Condition1 != null ? Condition1.GetText() : "Bedingung");
            string con2 = (Condition2 != null ? Condition2.GetText() : "Bedingung");

            return("(" + con1 + " und " + con2 + ")");
        }
Beispiel #5
0
        public override bool GetResult()
        {
            bool result1 = (Condition1 != null ? Condition1.GetResult() : false);
            bool result2 = (Condition2 != null ? Condition2.GetResult() : false);

            Macros.AddLog("Play: Bedingung: Und: " + (result1 && result2));

            return(result1 && result2);
        }
 public override string ToSql()
 {
     if (LogicOp == LogicOpType.并且)
     {
         return("(" + Condition1.ToSql() + " AND " + Condition2.ToSql() + ")");
     }
     else
     {
         return("(" + Condition1.ToSql() + " OR " + Condition2.ToSql() + ")");
     }
 }
Beispiel #7
0
        public override string JSON()
        {
            string strReturn = "";

            strReturn += "{";
            strReturn += "\"type\": \"conditionAnd\",";
            strReturn += "\"condition1\": " + Condition1.JSON();
            strReturn += "\"condition2\": " + Condition2.JSON();
            strReturn += "}";
            return(strReturn);
        }
Beispiel #8
0
        private void Ll1_Click(object sender, EventArgs e)
        {
            FormCondition frm = new FormCondition(m_macro);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                Condition1 = frm.Condition;
                Condition1.OnConditionChanged += Condition1_OnConditionChanged;
                m_ll1.Text = (Condition1 != null ? Condition1.GetText() : "Bedingung");
                OnConditionChanged(this, new ConditionChangedArgs());
            }
        }
Beispiel #9
0
        public void Swap()
        {
            Format.MappingSettings rawSettings = (Condition1 != null) ? Condition1.RawSettings : (Condition2 != null) ? Condition2.RawSettings : null;
            if (rawSettings == null)
            {
                return;
            }

            ACondition swap = (Condition1 == null) ? null : Condition1.Copy(ConditionNumber.One);

            SetCondition(rawSettings, ConditionNumber.One, Condition2);
            SetCondition(rawSettings, ConditionNumber.Two, swap);
        }
Beispiel #10
0
 public void StartEvent()
 {
     if (Condition1.ConditionResult() && Condition2.ConditionResult())
     {
         Action3.Execute();
     }
     else if (Condition1.ConditionResult())
     {
         Action1.Execute();
     }
     else if (Condition2.ConditionResult())
     {
         Action2.Execute();
     }
 }
Beispiel #11
0
 public ViewModel()
 {
     this.Condition1 = new Condition(this.ToObservable(x => x.IsDoorClosed), () => this.IsDoorClosed)
     {
         Name = "Door open"
     };
     this.Condition2 = new Condition(this.ToObservable(x => x.IsMotorRunning), () => this.IsMotorRunning)
     {
         Name = "Motor running"
     };
     DependingCondition = new AndCondition(Condition1, Condition2)
     {
         Name = "Can start"
     };
     NegatedCondition1 = Condition1.Negate();
     _conditions       = new List <ICondition> {
         Condition1, Condition2, DependingCondition, NegatedCondition1
     };
     StartCommand = new ConditionRelayCommand(o => MessageBox.Show("Clicked " + o), DependingCondition);
     OtherCommand = new ConditionRelayCommand(o => MessageBox.Show("Clicked " + o), Condition1);
 }
Beispiel #12
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            ConditionTuple other = obj as ConditionTuple;

            if (other == null)
            {
                throw new ArgumentException("object must be a Tuple<ACondition, ACondition>");
            }

            // order doesn't matter

            var containsItem1 = false;

            if (Condition1 != null)
            {
                containsItem1 = Condition1.Equals(other.Condition1) || Condition1.Equals(other.Condition2);
            }
            else
            {
                containsItem1 = other.Condition1 == null || other.Condition2 == null;
            }

            var containsItem2 = false;

            if (Condition2 != null)
            {
                containsItem2 = Condition2.Equals(other.Condition2) || Condition2.Equals(other.Condition1);
            }
            else
            {
                containsItem2 = other.Condition2 == null || other.Condition1 == null;
            }

            return(containsItem1 && containsItem2);
        }
        private void chaxun_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;

            string url = RestUrl.indexdata;
            // Product p = new Product();
            indexinfo index = new indexinfo();
            string    indexcontxt;

            indexcontxt = IndexCon1.Text;
            switch (indexcontxt)
            {
            case "产品编码":
                index.num = 1;
                break;

            case "产品名称":
                index.num = 2;
                break;

            case "产品类别":
                index.num = 3;
                break;

            case "生产车间":
                index.num = 4;
                break;
            }
            index.conditon = Condition1.Text;

            Condition1.Clear();
            string jsonstring = string.Empty;

            jsonstring = fastJSON.JSON.Instance.ToJSON(index);
            HttpWebConnect helper = new HttpWebConnect();

            helper.RequestCompleted += new deleGetRequestObject(helper_RequestCompleted_getproducingProduct);
            helper.TryPostData(url, jsonstring);
        }
Beispiel #14
0
        /// This one is dumb and must not be called from other classes. RawMapping.Settings are ignored!
        private bool setCondition(ConditionNumber number, ACondition condition)
        {
            bool changed = false;

            if (number == ConditionNumber.One)
            {
                changed = (Condition1 != null && !Condition1.Equals(condition)) || (condition != null && !condition.Equals(Condition1));
                if (changed)
                {
                    Condition1 = condition;
                }
            }
            else
            {
                changed = (Condition2 != null && !Condition2.Equals(condition)) || (condition != null && !condition.Equals(Condition2));
                if (changed)
                {
                    Condition2 = condition;
                }
            }

            return(changed);
        }
Beispiel #15
0
        public string ToString2(string what = "both")
        {
            //what = "both";
            if (what == "one")
            {
                return(Condition1?.ToString() ?? "");
            }
            else if (what == "two")
            {
                return(Condition2?.ToString() ?? "");
            }
            else if (what == "both")
            {
                var conditions = new[] { Condition1, Condition2 }.Where(c => c != null);
                conditions.OrderBy(c => c.ToString());   // ???
                return(String.Join(" AND ", conditions.Select(c => c.ToString())));
            }
            else
            {
                throw new Exception("Invalid condition.toString()");
            }

            return("");
        }
 public override string ToString()
 {
     return("(" + Condition1.ToString() + ") AND (" + Condition2.ToString() + ")");
 }
Beispiel #17
0
 public override int GetCount()
 {
     return(Condition1.GetCount() + Condition2.GetCount());
 }
Beispiel #18
0
 public GuardConditionWaitset(Condition1 _enclosing, DDS.WaitSet waitset)
 {
     this._enclosing = _enclosing;
     this.waitset = waitset;
 }
 public bool IsTrue()
 {
     return(Condition1.IsTrue() && Condition2.IsTrue());
 }
 public ICondition Clone()
 {
     return(new AndCondition(Condition1.Clone(), Condition2.Clone()));
 }
Beispiel #21
0
 private void Condition1_OnConditionChanged(object sender, ConditionChangedArgs e)
 {
     m_ll1.Text = Condition1.GetText();
 }
Beispiel #22
0
 public override List <NameValuePair> GetVariables()
 {
     return(Condition1.GetVariables().Union(Condition2.GetVariables()).ToList());
 }
Beispiel #23
0
 public GuardConditionWaitset(Condition1 _enclosing, DDS.WaitSet waitset)
 {
     this._enclosing = _enclosing;
     this.waitset    = waitset;
 }