Пример #1
0
 public ScriptRule(XElement Def)
 {
     Sensor           = Def.AttributeValue <string>("sensor").ToUpper();
     Timeout          = Def.AttributeValue <int>("timeout");
     TriggerOnTimeOut = Def.AttributeValue <bool>("trigger_on_timeout");
     foreach (var CmdDef in Def.Elements("command"))
     {
         ScriptDoorCommand Cmd = new ScriptDoorCommand(CmdDef);
         DoorCommands.Add(Cmd);
     }
 }
Пример #2
0
        public void Load(string Script)
        {
            Rules.Clear();
            List <string> Lines = Script.Split('\n').ToList();
            List <string> Parts = new List <string>();

            foreach (string Item in Lines)
            {
                string Line = Item.Trim();
                if (Line != "")
                {
                    Parts = Line.Split(',').ToList();
                    ScriptRule s = new ScriptRule();
                    s.Sensor = Parts[0];
                    for (int i = 1; i < Parts.Count; i++)
                    {
                        var CmdParts = Parts[i].Split(':');
                        var DoorCmd  = new ScriptDoorCommand();

                        DoorCmd.Door = CmdParts[0];
                        if (CmdParts[1].ToLower() == "o")
                        {
                            DoorCmd.Action = ScriptDoorCommand.DoorAction.Open;
                        }
                        else
                        {
                            DoorCmd.Action = ScriptDoorCommand.DoorAction.Close;
                        }
                        if (CmdParts.Length > 2)
                        {
                            int.TryParse(CmdParts[2], out DoorCmd.Delay);
                        }
                        s.DoorCommands.Add(DoorCmd);
                    }
                    Rules.Add(s);
                }
            }
        }
Пример #3
0
 public ScriptState(XElement Def)
 {
     Name = Def.AttributeValue <string>("name").ToLower();
     if (Def.AttributeValue <bool>("start"))
     {
         Type = StateType.Start;
     }
     else if (Def.AttributeValue <bool>("complete"))
     {
         Type = StateType.Complete;
     }
     foreach (var CmdDef in Def.Elements("command"))
     {
         ScriptDoorCommand Cmd = new ScriptDoorCommand(CmdDef);
         DoorCommands.Add(Cmd);
     }
     foreach (var CondDef in Def.Elements("when"))
     {
         ScriptCondition Cond = new ScriptCondition(CondDef);
         Cond.TimerExpired += Cond_TimerExpired;
         Conditions.Add(Cond);
     }
 }