Esempio n. 1
0
        static void Main(string[] args)
        {
            // This application demostrate the basics of ConsoleAsync

            // Create forst console
            IConsole console = ConsoleAsync.CreateConsole("Console");

            // Add commands
            console.AddCommand("quit", (writer, strings) => ConsoleAsync.Quit());
            console.AddCommand("print", (writer, strings) => strings.ForEach(s => writer.Text(s).NewLine()));

            // Execute operation on console
            console.Execute(writer =>
            {
                writer.Info("ConsoleAsync").NewLine().NewLine();
                writer.Text(@"
Available commands:

quit   : close entirely the app
print  : print in console all the arguments
").NewLine();
            });

            // Wait commands from user
            ConsoleAsync.Run();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            LoginListener.instance.AddListener(delegate(GameProto.Login msg)
            {
                Console.WriteLine(String.Format("account = {0}", msg.Account));
                Console.WriteLine(String.Format("password = {0}", msg.Password));
            });

            LoginResListener.instance.AddListener(delegate(GameProto.LoginRes loginRes)
            {
                if (loginRes.IsMatch)
                {
                    Console.WriteLine("Login successfully.");
                }
                else
                {
                    Console.WriteLine("Login failed");
                }
            });

            Console.WriteLine("client is running...");
            ConsoleAsync console = new ConsoleAsync();

            while (!isShutdown)
            {
                string cmd = console.TryReadLine();
                if (cmd != null)
                {
                    ParseCommand(cmd);
                }

                NetManager.Update();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            LoginListener.instance.AddListener(delegate(Socket cfd, GameProto.Login login)
            {
                Console.WriteLine(String.Format("Check Account = {0}", login.Account));
                ServerNetManager.Send(cfd, (Int16)ProtocType.Login, login);
                ServerNetManager.Send(cfd, (Int16)ProtocType.LoginRes, new GameProto.LoginRes
                {
                    IsMatch = true,
                });
            });

            ServerNetManager.Bind("127.0.0.1", 8888);

            ConsoleAsync console = new ConsoleAsync();

            bool isShutdown = false;

            while (!isShutdown)
            {
                string cmd = console.TryReadLine();
                if (cmd != null)
                {
                    if (cmd == "exit")
                    {
                        isShutdown = true;
                    }
                }

                ServerNetManager.Update();
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // Create first console
            IConsole menuConsole = ConsoleAsync.CreateConsole(systemConsoleName);

            // Create a key filter for every key pressed in app
            menuConsole.AddKeyFilter((writer, info) =>
            {
                string ch = info.KeyChar.ToString(CultureInfo.InvariantCulture);

                // check if the cher is a valid commend, then refresh menu
                if (EvaluateCommand(writer, ch))
                {
                    WriteMenu(writer);
                }

                // return true only if char NOT in available chars
                // input row remains empty
                return(ConsoleAsync.AvailableInputChars.Contains(ch));
            });

            menuConsole.Execute(WriteMenu);

            ConsoleAsync.Run();
        }
Esempio n. 5
0
        static void CreateWorkerConsole(string name, TimeSpan interval, double margin)
        {
            // Create console
            IConsole console = ConsoleAsync.CreateConsole(name);

            // Create new instance of worker
            TestWorker worker = new TestWorker(interval, console.Name, margin);

            // Add worker to collection
            workers.Add(worker);

            // Add worker to newly created console
            IConsoleWorker workerInterface = console.AddWorker(worker);

            // Add command suspend
            console.AddCommand("suspend", (writer, list) =>
            {
                // Suspend worker and write a message
                workerInterface.Suspend();
                writer.Info("Worker suspended").NewLine();
            });

            // Add command resume
            console.AddCommand("resume", (writer, list) =>
            {
                // Resume worker and write a message
                workerInterface.Resume();
                writer.Info("Worker resumed").NewLine();
            });

            // Add command quit
            console.AddCommand("quit", (writer, list) => ConsoleAsync.Quit());
        }
Esempio n. 6
0
        static void CreateNewConsole()
        {
            // Create console name
            string name = string.Format("Console #{0:00}", consoleIndex + 1);

            // Create console
            IConsole console = ConsoleAsync.CreateConsole(name);

            // Add default command
            console.AddCommand("quit", (writer, strings) => ConsoleAsync.Quit());
            console.AddCommand("print", (writer, strings) => strings.ForEach(s => writer.Text(s).NewLine()));

            // Call execute to write a message
            console.Execute(writer =>
            {
                writer.Info(name).NewLine().NewLine();
                writer.Text(@"
Available commands:

quit   : close entirely the app
print  : print in console all the arguments
");
            });

            // Increment console count
            consoleIndex++;
        }
Esempio n. 7
0
        static void CreateControlConsole()
        {
            // Define an interval
            TimeSpan interval = TimeSpan.FromMilliseconds(500);

            // Create the console
            IConsole control = ConsoleAsync.CreateConsole("Control Console");

            // Add quit command
            control.AddCommand("quit", (writer, list) => ConsoleAsync.Quit());

            // Create worker from builtin type TimedWorker
            ConsoleWorker controlWorker = new TimedWorker(interval, (writer, span) =>
            {
                // Clear console and write title and info
                writer.Clear();
                writer.Info("CONTROL CONSOLE").NewLine();
                writer.Muted("Elapsed: {0}", span).NewLine().NewLine();

                // Cicle workers
                foreach (TestWorker worker in workers)
                {
                    // Calculate percentage of success over 60 characters
                    int success = (60 * worker.Successes + 1) / (worker.Successes + worker.Failures + 1);
                    int failure = 60 - success;

                    // Write worker name fitted on 16 char (to make bars aligned)
                    writer.Text(worker.Name.Fit(16));

                    // Write success bar
                    writer.Success("".Fit(success, '\u25A0'));

                    // Write error bar
                    writer.Error("".Fit(failure, '\u25A0'));

                    writer.NewLine();
                }

                // Write a message and commands help
                writer.NewLine().NewLine().NewLine().Info("Available commands").NewLine();
                writer.Text(@"
suspend     : suspend worker (not in control console)
resume      : resume worker (not in control console)
quit        : close application (in any console)
");
            });

            // Add worker to control console
            control.AddWorker(controlWorker);
        }
Esempio n. 8
0
        static bool EvaluateCommand(IConsoleWriter writer, string command)
        {
            int index;

            IConsole[] consoles = ConsoleAsync.EnumerateConsoles().ToArray();

            // Check if char is a number, else return false
            if (int.TryParse(command, out index) == false)
            {
                return(false);
            }

            if (index == 1)
            {
                // Add console maximum five
                if (consoles.Length == 6)
                {
                    writer.Error("Maximum console reached (for this app :)").NewLine();
                    return(false);
                }

                CreateNewConsole();
            }
            else if (index == 2)
            {
                // Destroy all console, except menu
                foreach (IConsole console in ConsoleAsync.EnumerateConsoles())
                {
                    if (console.Name != systemConsoleName)
                    {
                        ConsoleAsync.DestroyConsole(console.Name);
                    }
                }
                consoleIndex = 0;
            }
            else if (index == 3)
            {
                // Exit from app
                ConsoleAsync.Quit();
            }
            else
            {
                // Destroy console specified in menu item
                ConsoleAsync.DestroyConsole(consoles[index - 3].Name);
            }

            return(true);
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            // Initialize worker collection
            workers = new List <TestWorker>();

            // create control console
            CreateControlConsole();

            // Create variuos worker console
            CreateWorkerConsole("First Worker", TimeSpan.FromMilliseconds(550), .5);
            CreateWorkerConsole("Second Worker", TimeSpan.FromMilliseconds(800), .3);
            CreateWorkerConsole("Third Worker", TimeSpan.FromMilliseconds(1100), .7);

            // Wait for user input, the true parameter starts every worker in every console
            ConsoleAsync.Run(true);
        }
Esempio n. 10
0
        static void WriteMenu(IConsoleWriter writer)
        {
            // Clear console and write the static part of menu
            writer.Clear();
            writer.Info("Use number to select an option").NewLine().NewLine();
            writer.Text("01 - Create Console").NewLine();
            writer.Text("02 - Reset").NewLine();
            writer.Text("03 - Quit").NewLine();
            writer.NewLine();

            // Cicle through console and write a menu item for each
            int index = 4;

            foreach (IConsole console in ConsoleAsync.EnumerateConsoles())
            {
                if (console.Name != systemConsoleName)
                {
                    writer.Text("{0:00} - Delete console '{1}'", index++, console.Name).NewLine();
                }
            }

            writer.NewLine().NewLine();
        }
Esempio n. 11
0
 public void Show()
 {
     ConsoleAsync.ShowConsole(Name);
 }
Esempio n. 12
0
        static void Main(string[] args)
        {
            // Create console
            IConsole console = ConsoleAsync.CreateConsole("Folder Browser");

            // Add quit command to console
            ConsoleAsync.AddCommandToAllConsole("quit", (writer, strings) => ConsoleAsync.Quit());

            // Add help command to console
            console.AddCommand("help", (writer, strings) => writer.Text(@"
Switch to second console with TAB button
the available command are:

dir                          show content of a current directory
cd ..                        back to parent directory
cd <directory name>          enter in specified directory
md <directory name>          create a directory
rd <directory name>          delete a directory
").NewLine().NewLine());

            // Add cd commands to console
            console.AddCommand("cd", (writer, strings) =>
            {
                // check if there at least one parameter
                if (strings.Count > 0)
                {
                    ChangeFolder(writer, strings[0]);
                }
            });

            // Add cd.. commands to console
            console.AddCommand("cd..", (writer, strings) => ChangeFolder(writer, ".."));

            // Add cd commands to console
            console.AddCommand("dir", (writer, strings) => WriteFolder(writer));

            // Add md commands to console
            console.AddCommand("md", (writer, strings) =>
            {
                // check if there at least one parameter
                if (strings.Count < 1)
                {
                    // If not throw an exception
                    WriteError(writer, new ArgumentException("makedir require a parameter"));
                    return;
                }

                try
                {
                    // Try to create directory with passed parameter
                    Directory.CreateDirectory(Path.Combine(actualFolder, strings[0]));
                    writer.Info("Directory created").NewLine();
                }
                catch (Exception ex)
                {
                    // Write exception
                    WriteError(writer, ex);
                }
            });

            console.AddCommand("rd", (writer, strings) =>
            {
                // check if there at least one parameter
                if (strings.Count < 1)
                {
                    // If not throw an exception
                    WriteError(writer, new ArgumentException("removedir require a parameter"));
                    return;
                }

                try
                {
                    // Try to delete directory with passed parameter
                    Directory.Delete(Path.Combine(actualFolder, strings[0]));
                    writer.Info("Directory deleted").NewLine();
                }
                catch (Exception ex)
                {
                    // Write exception
                    WriteError(writer, ex);
                }
            });

            // Call an execute to write initial message to console
            console.Execute(writer =>
            {
                writer.Info("Folder Explorer sample").NewLine().NewLine();
                console.SendCommand("help");
            });

            // Wait for user commands
            ConsoleAsync.Run();
        }