Esempio n. 1
0
        static string Execute(ConsoleCommand command)
        {
            var entries = new List <LogItem>();

            Console.Clear();

            //iterates over every other argument in the ConsoleCommand
            //it it matches run the associated command via switch
            for (int i = 0; i < command.Arguments.Count; i += 2)
            {
                var cmd = command.Arguments[i];
                switch (cmd)
                {
                case "-file":
                    entries = ParseFile(command.Arguments[i + 1]);
                    break;

                case "-sort":
                    entries = SortLogs(entries, command.Arguments[i + 1]);
                    break;

                case "-search":
                    entries = SearchLogs(entries, command.Arguments[i + 1]);
                    break;
                }
            }
            //builds a string in a nicely formated way to be displayed to the user
            var sb = new StringBuilder();

            foreach (var log in entries)
            {
                var logProps = log.GetType().GetProperties();
                foreach (var item in logProps)
                {
                    var name  = item.Name;
                    var value = item.GetValue(log).ToString();
                    sb.AppendFormat("{0}: {1}", name, value);
                    sb.AppendLine();
                }
                sb.Append("\n==============END OF RESULT==============\n\n");
            }
            return(sb.ToString());
        }
Esempio n. 2
0
        static void Run()
        {
            while (true)
            {
                var consoleInput = ReadFromConsole();
                if (string.IsNullOrWhiteSpace(consoleInput))
                {
                    continue;
                }
                try {
                    var cmd = new ConsoleCommand(consoleInput);

                    string result = Execute(cmd);
                    WriteToConsole(result);
                }
                catch (Exception ex) {
                    WriteToConsole(ex.Message);
                }
            }
        }
Esempio n. 3
0
        static string Execute(ConsoleCommand command)
        {
            var entries = new List<LogItem>();
            Console.Clear();

            //iterates over every other argument in the ConsoleCommand
            //it it matches run the associated command via switch
            for (int i = 0; i < command.Arguments.Count; i += 2) {
                var cmd = command.Arguments[i];
                switch (cmd) {
                    case "-file":
                        entries = ParseFile(command.Arguments[i + 1]);
                        break;

                    case "-sort":
                        entries = SortLogs(entries, command.Arguments[i + 1]);
                        break;

                    case "-search":
                        entries = SearchLogs(entries, command.Arguments[i + 1]);
                        break;
                }
            }
            //builds a string in a nicely formated way to be displayed to the user
            var sb = new StringBuilder();
            foreach (var log in entries) {
                var logProps = log.GetType().GetProperties();
                foreach (var item in logProps) {
                    var name = item.Name;
                    var value = item.GetValue(log).ToString();
                    sb.AppendFormat("{0}: {1}", name, value);
                    sb.AppendLine();
                }
                sb.Append("\n==============END OF RESULT==============\n\n");
            }
            return sb.ToString();
        }
Esempio n. 4
0
        static void Run()
        {
            while (true) {
                var consoleInput = ReadFromConsole();
                if (string.IsNullOrWhiteSpace(consoleInput)) {
                    continue;
                }
                try {
                    var cmd = new ConsoleCommand(consoleInput);

                    string result = Execute(cmd);
                    WriteToConsole(result);
                }
                catch (Exception ex) {
                    WriteToConsole(ex.Message);
                }
            }
        }