Example #1
0
        public void InsertFunctionsCommandInStaticStorage()
        {
            var commands = CommandsTypesClass.Select(cls => cls.GetMethods())
                           .Select(m => m.Where(m => m.Name.StartsWith(Utilities.Mode_4)).Select(m => (m.GetCustomAttribute(typeof(ClassCommandInfo)) as ClassCommandInfo).CommandName))
                           .Select(name => name.ToArray());

            ProgramStorageQueries.SetFunctionsCommand(commands);
        }
Example #2
0
 private void ExecuteApp(string className, string[] input)
 {
     try {
         var feature = ProgramStorageQueries.GetFeatureInfo(ClassesCommandFeaturesName.AppsList);
         (ProgramStorageQueries.GetInfoValue(feature, className) as CommandLineApplication).Execute(input);
     } catch (Exception e) {
         CMD.ShowApplicationMessageToUser($"message : {e.Message}\nroute : {this.ToString()}", showType: ShowType.DANGER);
     }
 }
Example #3
0
        /// <summary>
        /// return ienumerable of all class command and functions command in specific class
        /// </summary>
        /// <param name="className">name of class command</param>
        private static IEnumerable <string> AllCommandsByClassName(string className)
        {
            var commands = (ProgramStorageQueries.GetInfoValueOfClassCommand()).OfType <string>().ToList();

            if (className != "")
            {
                commands.AddRange(ProgramStorageQueries.GetFunctionsCommand(className));
            }
            return(commands);
        }
Example #4
0
        public void CallConventions()
        {
            var apps = ProgramStorageQueries.GetFeatureInfo(ClassesCommandFeaturesName.AppsList).Select(item => item.Item2);

            foreach (var app in apps)
            {
                (app as CommandLineApplication).HelpOption(inherited: true);
                (app as CommandLineApplication).Conventions
                .AddConvention(new MethodsAsSubcommandsConventions())
                .SetAppNameFromEntryAssembly();
            }
        }
Example #5
0
        /// <summary>
        /// read line from console
        /// </summary>
        /// <param name="className">name of class command</param>
        public static string[] ReadeUserCommandLineInput(string className = "")
        {
            var prefix = $"\n{className} > ";

            Console.Write(prefix);
            var commands = (ProgramStorageQueries.GetInfoValueOfClassCommand()).OfType <string>().ToList();
            var input    = ReadeKey(prefix.Length - 1, AllCommandsByClassName(className));

            Console.WriteLine();

            var array  = input.Split(' ');
            var length = array.Length;

            var args = new string[length];

            for (int i = 0; i < length; i++)
            {
                args[i] = array[i];
            }

            return(args);
        }
Example #6
0
        public void StartInteraction()
        {
            var route = string.Empty;
            var input = new string[] { };

            while (true)
            {
                try {
                    input = CMD.ReadeUserCommandLineInput(route).Where(s => !(String.IsNullOrEmpty(s)) || !(string.IsNullOrWhiteSpace(s))).ToArray();
                    if (ProgramStorageQueries.IsClassCommandExist(input[0]))
                    {
                        route = ProgramStorageQueries.GetClassName(input[0]);
                    }
                    if (ProgramStorageQueries.IsFunctionCommand(input[0]) || input[0].Contains("--help"))
                    {
                        ExecuteApp(route, input);
                    }
                    switch (Utilities.GetUtilitiesCommand(input[0]))
                    {
                    case "restart_route":
                        route = "";
                        break;

                    case "clear_console":
                        Console.Clear();
                        break;
                    }
                    if (!(ProgramStorageQueries.IsClassCommandExist(input[0]) || ProgramStorageQueries.IsFunctionCommand(input[0]) || input[0].Contains("--help") ||
                          Utilities.GetUtilitiesCommand(input[0]) != "not found"))
                    {
                        CMD.ShowApplicationMessageToUser("command not found .", showType: ShowType.ALERT);
                    }
                } catch (Exception e) {
                    CMD.ShowApplicationMessageToUser($"message : {e.Message}\nroute : {this.ToString()}", showType: ShowType.DANGER);
                }
            }
        }