Exemple #1
0
            public StringBuilder runCommand(BaconArgs Args, Environment Env)
            {
                Env.Debug.newScope("runCommand");
                StringBuilder response = new StringBuilder();

                if (Args.getArguments().Count > 0)
                {
                    string cmd = Args.getArguments()[0];
                    if (availableCommands.ContainsKey(cmd))
                    {
                        Args.getArguments().RemoveAt(0);
                        StringBuilder _tmp = new StringBuilder();
                        if (!availableCommands[cmd].exec(Args, Env, out _tmp))
                        {
                            response.AppendLine("an error occured during executing of '" + cmd + "'");
                        }
                        response.Append(_tmp.ToString());
                    }
                    else
                    {
                        Env.Debug.add("unknown command: " + cmd, BaconDebug.DEBUG);
                        response.AppendLine("unknown command: " + cmd);
                    }
                }
                else
                {
                    Env.Debug.add("no command given", BaconDebug.DEBUG);
                }

                Env.Debug.leaveScope();
                return(response);
            }
Exemple #2
0
 public BaconMessages(IMyTextPanel StorageDevice)
 {
     this.StorageDevice = StorageDevice;
     string[] data = (this.StorageDevice.GetPublicText() + this.StorageDevice.GetPrivateText()).Split(new Char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
     for (int i = 0; i < data.Length; i++)
     {
         BaconArgs R = BaconArgs.parse(data[0]);
         if ((R.getOption(Message.OPT_SENDER).Count > 0) && (R.getOption(Message.OPT_TIMECREATED).Count > 0) && (R.getOption(Message.OPT_TIMETOLIVE).Count > 0) && (R.getOption(Message.OPT_TYPE).Count > 0) && (R.getArguments().Count > 0))
         {
             int    TimeToLive  = 0;
             double TimeCreated = 0;
             string Content     = R.getArguments()[0];
             string Type        = R.getOption(Message.OPT_TYPE)[0];
             string Sender      = R.getOption(Message.OPT_SENDER)[0];
             if (int.TryParse(R.getOption(Message.OPT_TIMETOLIVE)[0], out TimeToLive) && double.TryParse(R.getOption(Message.OPT_TIMECREATED)[0], out TimeCreated))
             {
                 Message msg = new Message(Content, Sender, Type, TimeToLive, TimeCreated);
                 Add(msg);
             }
         }
     }
 }