예제 #1
0
파일: Blocks.cs 프로젝트: cbries/ecos
        /// <returns>the added event instance, null on any error</returns>
        public Event AddPlusEvent(EventType type, S88Feedback feedback, int delayMs = 0)
        {
            if (feedback == null)
            {
                return(null);
            }
            var item = PlusEvents.GetBy(feedback.Name);

            if (item != null)
            {
                return(null);
            }
            var ev = new Event(Ctx)
            {
                Type     = type,
                Feedback = feedback,
                DelayMs  = delayMs
            };

            PlusEvents.Add(ev);
            return(ev);
        }
예제 #2
0
파일: Blocks.cs 프로젝트: cbries/ecos
        public JObject GetJson()
        {
            var o = new JObject
            {
                ["name"]        = Name,
                ["description"] = Description
            };

            if (WaitMode != null)
            {
                o["waitMode"] = WaitMode.GetJson();
            }
            else
            {
                o["waitMode"] = null;
            }

            if (Exclude != null)
            {
                var ar = new JArray();
                for (int i = 0; i < Exclude.Count; ++i)
                {
                    var exItem = Exclude[i];
                    ar.Add(exItem.GetJson());
                }

                o["exclude"] = ar;
            }
            else
            {
                o["exclude"] = null;
            }

            if (Occupation != null)
            {
                o["occupation"] = Occupation.GetJson();
            }
            else
            {
                o["occupation"] = null;
            }

            o["commuting"] = Commuting;

            var plusNames = new JArray();

            foreach (var blk in _sidePlus)
            {
                if (blk == null)
                {
                    continue;
                }
                if (!blk.IsValid())
                {
                    continue;
                }
                plusNames.Add(blk.Name);
            }
            o["sidePlus"] = plusNames;

            var minusNames = new JArray();

            foreach (var blk in _sideMinus)
            {
                if (blk == null)
                {
                    continue;
                }
                if (!blk.IsValid())
                {
                    continue;
                }
                minusNames.Add(blk.Name);
            }
            o["sideMinus"] = minusNames;

            o["plusEvents"]  = PlusEvents.ToJson();
            o["minusEvents"] = MinusEvents.ToJson();

            return(o);
        }