Example #1
0
        public static ShellApp BuildShellApp(Type type, PeerGroup grp)
        {
            ShellApp shellApp = System.Activator.CreateInstance(type, new object[] { }) as ShellApp;

            shellApp.Initialize(grp, Console.Out, Console.In);

            return(shellApp);
        }
Example #2
0
        public static ShellApp BuildShellApp(Type type, PeerGroup grp, TextWriter writer, TextReader reader)
        {
            ShellApp shellApp = System.Activator.CreateInstance(type, new object[] { }) as ShellApp;

            shellApp.Initialize(grp, writer, reader);

            return(shellApp);
        }
Example #3
0
        /// <summary>
        /// Interprets the command which is given by an input string
        /// </summary>
        /// <param name="input">Command as string</param>
        /// <returns></returns>
        public bool ProcessCommand(ref string input)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            bool     man      = false;

            input = input.Trim();

            if (input.Length < 3)
            {
                if (input.Length > 0)
                {
                    textWriter.WriteLine("command not found");
                }
                return(false);
            }

            if (input.Substring(0, 3).Equals("man"))
            {
                man = true;
                if (input.Length > 4)
                {
                    input = input.Substring(4, input.Length - 4);
                }
                else
                {
                    textWriter.WriteLine("For which command do you want help?");

                    // get all types of the current assembly
                    Type[] types = assembly.GetTypes();
                    for (int i = 0; i < types.Length; i++)
                    {
                        string cmd = types[i].ToString();

                        cmd = cmd.ToLower();

                        if (cmd.StartsWith("jxtanetshell"))
                        {
                            cmd = cmd.Remove(0, 13);

                            // don't print types, which don't implement a command
                            if ((cmd.Contains("+") != true) &&
                                (cmd.Contains("operation") != true) &&
                                (cmd.Contains("shellapp") != true) &&
                                (cmd.Contains("shell") != true))
                            {
                                textWriter.WriteLine("\t" + cmd);
                            }
                        }
                    }
                    return(false);
                }
            }

            char[]   sep     = { ' ' };
            string[] locargs = input.Split(sep);

            if ((locargs[0].Equals("exit") || locargs[0].Equals("quit")))
            {
                return(true);
            }

            Type type = assembly.GetType("JxtaNETShell." + locargs[0], false, true);

            if (type != null)
            {
                try
                {
                    ShellApp x = ShellAppFactory.BuildShellApp(type, netPeerGroup, textWriter, textReader);

                    if (man)
                    {
                        x.Help();
                    }
                    else
                    {
                        x.Run(locargs);
                    }
                }
                catch (Exception)
                {
                    textWriter.WriteLine("command not found");
                }
            }
            else
            {
                textWriter.WriteLine("command not found");
            }

            return(false);
        }