예제 #1
0
        /// <summary>
        /// Point of entry.
        /// </summary>
        /// <param name="args">Property.</param>
        public static void Main(string[] args)
        {
            if (args != null)
            {
                SetSettings(args);
            }

            Console.WriteLine($"File Cabinet Application, developed by {Program.DeveloperName}");
            Console.WriteLine(Program.HintMessage);
            Console.WriteLine();

            do
            {
                Console.Write("> ");
                var       inputs          = Console.ReadLine().Split(' ', 2);
                const int commandIndex    = 0;
                var       command         = inputs[commandIndex];
                const int parametersIndex = 1;
                var       parameters      = inputs.Length > 1 ? inputs[parametersIndex] : string.Empty;
                try
                {
                    ExcuteCommand(command, Commands)(parameters);
                }
                catch (ArgumentException)
                {
                    continue;
                }
            }while (isRunning);
        }
예제 #2
0
        /// <summary>
        /// Set settings.
        /// </summary>
        /// <param name="args">property of settings.</param>
        private static void SetSettings(string[] args)
        {
            for (int i = 0; i < args.Length; i++)
            {
                string command   = string.Empty;
                string parameter = string.Empty;
                if (args[i].StartsWith("--", StringComparison.InvariantCultureIgnoreCase))
                {
                    string[] split = args[i].Split('=', 2);
                    if (split.Length == 2)
                    {
                        command   = split[0];
                        parameter = split[1];
                    }
                }
                else if (args[i].StartsWith('-'))
                {
                    command = args[i];
                    if (i + 1 < args.Length)
                    {
                        i++;
                        parameter = args[i];
                    }
                }
                else
                {
                    continue;
                }

                try
                {
                    ExcuteCommand(command, ProgramSettings)(parameter);
                }
                catch (ArgumentException)
                {
                    continue;
                }
            }

            CreateFileCabinet();
            try
            {
                GenerateRecords(SettingsApp.RecordsAmount);
                Export(exportMethod);
            }
            catch (Exception ex) when(
                ex is ArgumentException || ex is NotSupportedException || ex is FileNotFoundException || ex is IOException ||
                ex is System.Security.SecurityException || ex is DirectoryNotFoundException || ex is UnauthorizedAccessException ||
                ex is PathTooLongException)
            {
                Console.WriteLine($"Export failed.");
            }
        }
예제 #3
0
 ///执行Binding的命令
 private void InvokeExcuteCommand()
 {
     if (ExcuteCommand != null)
     {
         ExcuteCommand.Execute(CommandParameter);
     }
 }
예제 #4
0
        private static void Import(string parameters)
        {
            string[]  inputs       = parameters.Split(' ', 2);
            const int commandIndex = 0;
            const int pathIndex    = 1;
            var       command      = inputs[commandIndex];
            var       path         = inputs[pathIndex];

            if (string.IsNullOrEmpty(command) || string.IsNullOrEmpty(path))
            {
                Console.WriteLine($"Error. Import [type import] [path]");
                return;
            }

            ExcuteCommand(command, Imports)(path);
        }
예제 #5
0
        /// <summary>
        /// Set settings.
        /// </summary>
        /// <param name="args">property of settings.</param>
        private static void SetSettings(string[] args)
        {
            for (int i = 0; i < args.Length; i++)
            {
                string command   = string.Empty;
                string parameter = string.Empty;
                if (args[i].StartsWith("--", StringComparison.InvariantCultureIgnoreCase))
                {
                    string[] split = args[i].Split('=', 2);
                    if (split.Length == 2)
                    {
                        command   = split[0];
                        parameter = split[1];
                    }
                }
                else if (args[i].StartsWith('-'))
                {
                    command = args[i];
                    if (i + 1 < args.Length && !command.Equals("-use-logger") && !command.Equals("-use-stopwatch"))
                    {
                        i++;
                        parameter = args[i];
                    }
                }
                else
                {
                    continue;
                }

                try
                {
                    ExcuteCommand(command, ProgramSetting)(parameter);
                }
                catch (ArgumentException)
                {
                    continue;
                }
            }

            CreateFileCabinetService();
        }