Esempio n. 1
0
        public static void Parse(string[] strArgs, params ICommandArg[] expected)
        {
            Dictionary <string, ICommandArg> args = new Dictionary <string, ICommandArg>();

            foreach (ICommandArg e in expected)
            {
                args.Add(e.Name, e);
            }

            for (int i = 0; i < strArgs.Length; i++)
            {
                if (args.ContainsKey(strArgs[i]))
                {
                    ICommandArg arg = args[strArgs[i]];
                    arg.Found = true;
                    arg.ParseValue((arg.NeedValue) ? strArgs[++i] : "");
                }
            }

            foreach (ICommandArg arg in expected)
            {
                if (arg.Required && !arg.Found)
                {
                    throw new InvalidDataException(string.Format("Usage:{0}", GenerateHelp(expected)));
                }
            }
        }
Esempio n. 2
0
 private void OnReceiveCommandHandler(IConnector connector, ICommandArg arg)
 {
     try
     {
         if (connector != null) { _commands.Execute(connector, arg); }
     }
     catch (Exception ex) { NetLogger.Log(ex, LogType.Exception); }
 }
Esempio n. 3
0
 public void AppendArgsTo(TCommand command, string[] charArgs)
 {
     for (int i = 0; i < _commandArgs.Length; i++)
     {
         ICommandArg <TCommand> arg = _commandArgs[i];
         arg.GetCommandArg(command,
                           enabled: charArgs.Any(c => arg.TryEnable(c)));
     }
 }
Esempio n. 4
0
 private void AddCommandToSendClients(ICommandArg comarg)
 {
     lock (_astSync)
     {
         if (_argsSendToAllClients != null)
         {
             _argsSendToAllClients.Add(comarg);
         }
     }
 }
Esempio n. 5
0
        public static string GenerateHelp(ICommandArg arg)
        {
            StringBuilder help = new StringBuilder(arg.Name);
            if (arg.NeedValue)
                help.Append(" x");

            if (!arg.Required)
            {
                help.Insert(0, "[");
                help.Append("]");
            }
            return help.ToString();
        }
Esempio n. 6
0
        public static string GenerateHelp(ICommandArg arg)
        {
            StringBuilder help = new StringBuilder(arg.Name);

            if (arg.NeedValue)
            {
                help.Append(" x");
            }

            if (!arg.Required)
            {
                help.Insert(0, "[");
                help.Append("]");
            }
            return(help.ToString());
        }
Esempio n. 7
0
        private void SendDrawObject(DrawObject drObj)
        {
            if (drObj == null || drObj.Picture == null)
            {
                return;
            }

            long        picBoxID = drObj.Picture.UniqueID; //canvas
            ICommandArg arg      = null;

            if (drObj is BrushLineObject)
            {
                BrushLineObject line = drObj as BrushLineObject;
                arg = new ArgBrushObject(_netClient.ClientID, picBoxID, line);
            }
            else if (drObj is LineObject)
            {
                LineObject line = drObj as LineObject;
                arg = new ArgLineObject(_netClient.ClientID, picBoxID, line);
            }
            else if (drObj is RectObject)
            {
                RectObject rect = drObj as RectObject;
                arg = new ArgRectObject(_netClient.ClientID, picBoxID, rect);
            }
            else if (drObj is EllipseObject)
            {
                EllipseObject ellipse = drObj as EllipseObject;
                arg = new ArgEllipseObject(_netClient.ClientID, picBoxID, ellipse);
            }
            else if (drObj is MoveObject)
            {
                MoveObject move = drObj as MoveObject;
                arg = new ArgMoveObject(_netClient.ClientID, picBoxID, move);
            }
            else if (drObj is SelectorObject)
            {
                SelectorObject selector = drObj as SelectorObject;
                arg = new ArgSelectorCopyObject(_netClient.ClientID, picBoxID, selector);
            }

            if (arg != null && _netClient.Connector != null)
            {
                _netClient.Connector.SendCommand(arg);
            }
        }
Esempio n. 8
0
 public static void Execute(IList <string> args)
 {
     if (args.Count > 0)
     {
         string      command = args[0];
         ICommandArg cmd     = commandArgs.FirstOrDefault(o => o.Command.ToLower() == command);
         if (cmd != null)
         {
             args.RemoveAt(0); //remove command itself
             cmd.Execute(args);
         }
     }
     else
     {
         App.Window.ShowApp();
     }
 }
Esempio n. 9
0
 public static void Execute(IList <string> args)
 {
     // todo restart command line args?
     if (args.Count > 0 && args[0] != SingleInstance <App> .Restart)
     {
         string      command = args[0];
         ICommandArg cmd     = commandArgs.FirstOrDefault(o => o.Command.ToLower() == command);
         if (cmd != null)
         {
             args.RemoveAt(0); //remove command itself
             cmd.Execute(args);
         }
     }
     else
     {
         App.API.ShowApp();
     }
 }