private void ShowHelp(TcpAppInputCommand sender)
        {
            string        aliasName = sender.Command.Parameter("Alias").Value;
            List <string> lines     = null;

            if (aliasName == "-")
            {
                //Print Help Screen - Write to sender.OutputMessage
                lines = new List <string>
                {
                    "TCP Aplication Server Version " + Version.ToString(),
                    " ",
                    "==== USAGE ====",
                    "  SEND: <Command> [Param0] ... [ParamN]",
                    "  RECV: <Command> <Status> [Return Message]",
                    " ",
                    " Notes:",
                    "  <> = Required parameters",
                    "  [] = Optional parameters",
                    " ",
                };

                lines.AddRange(TcpAppCommon.PrintCommandHelpContents(Commands));
                sender.OutputMessage = string.Join("\r\n", lines.ToArray());
                sender.Status        = TcpAppCommandStatus.OK;
            }
            else
            {
                //Get Help Content for selected object.
                ITcpAppServerPlugin plugin = Plugins.FirstOrDefault(x => string.Compare(x.Alias, sender.Command.Parameter("Alias").Value, true) == 0);
                if (plugin == null)
                {
                    sender.Status        = TcpAppCommandStatus.ERR;
                    sender.OutputMessage = "Object [" + aliasName + "] not exist!";
                }
                else
                {
                    plugin.ShowHelp(sender);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Print help screen for selected plugin components.
 /// </summary>
 /// <param name="sender"></param>
 public void ShowHelp(TcpAppInputCommand sender)
 {
     sender.OutputMessage = string.Join("\r\n", TcpAppCommon.PrintCommandHelpContents(Commands));
     sender.Status        = TcpAppCommandStatus.OK;
 }
コード例 #3
0
        private void ShowHelp(TcpAppInputCommand sender)
        {
            string        aliasName = sender.Command.Parameter("Plugin").Value;
            List <string> lines     = null;

            if (aliasName == "-")
            {
                lines = new List <string>
                {
                    "[ TCP Aplication Server V" + Version.ToString() + " ]",
                    " ",
                    "==== USAGE ====",
                    "  Execute Tcp App Server Command:",
                    "  SEND: <Command> [Param0] ... [ParamN]",
                    "  RECV: <Status> [Return Message]",
                    " ",
                    "  Execute plugin Command:",
                    "  SEND: <Alias> <Command> [Param0] ... [ParamN]",
                    "  RECV: <Status> [Return Message]",
                    " ",
                    "  Notes:",
                    "   Command are not case sensitive.",
                    "   <> = Required parameters",
                    "   [] = Optional parameters",
                    " ",
                };

                //Insert Application Header if defined.
                string header = OnShowHelpGetApplicationHeader();
                if (!string.IsNullOrEmpty(header))
                {
                    lines.Insert(0, header);
                }

                lines.AddRange(TcpAppCommon.PrintCommandHelpContents(Commands));

                //Print registered plugins
                if (PluginTypes.Count > 0)
                {
                    lines.Add("[ PLUGINS ]");
                    lines.AddRange(PluginTypes.Select(x => string.Format(" {0, -20}  {1}", x.Name, x.Description)).ToArray());
                    lines.Add(" ");
                }

                if (_Plugins.Count > 0)
                {
                    lines.Add("[ OBJECTS ]");
                    lines.AddRange(_Plugins.Select(x => string.Format(" {0, -20}  {1}", x.Alias, "(" + PluginTypes.FirstOrDefault(n => n.Type == x.GetType())?.Name + ")")).ToArray());
                }

                sender.OutputMessage = string.Join(TcpAppCommon.NewLine, lines.ToArray());
                sender.Status        = TcpAppCommandStatus.OK;
            }
            else
            {
                //Get Help Content for selected object.
                string pluginName              = sender.Command.Parameter("Plugin").Value;
                ITcpAppServerPlugin    plugin  = null;
                TcpAppServerPluginType ptrType = PluginTypes.FirstOrDefault(x => x.Name.Equals(pluginName, StringComparison.InvariantCultureIgnoreCase));
                if (ptrType != null)
                {
                    //Get help by type
                    Type pluginType = ptrType.Type;
                    plugin = _Plugins.FirstOrDefault(x => x.GetType() == pluginType);
                    if (plugin != null)
                    {
                        //Show Help using existing object
                        plugin.ShowHelp(sender);
                        return;
                    }

                    //Create instance and show help, dispose after use
                    plugin = Activator.CreateInstance(pluginType) as ITcpAppServerPlugin;
                    plugin.ShowHelp(sender);
                    plugin.DisposeRequest();
                    plugin = null;
                    return;
                }
                else
                {
                    //Get help by alias name
                    plugin = _Plugins.FirstOrDefault(x => string.Compare(x.Alias, pluginName, true) == 0);
                    if (plugin != null)
                    {
                        plugin.ShowHelp(sender);
                        return;
                    }
                }
                sender.Status        = TcpAppCommandStatus.ERR;
                sender.OutputMessage = "Object [" + aliasName + "] not exist!";
            }
        }