Ejemplo n.º 1
0
        /// <summary>
        /// Executes the provided command.
        /// </summary>
        /// <param name="command"> Command to be executed. </param>
        /// <returns> Delegates refering to the respective command, null when invalid. </returns>
        public string ExecuteCommand(Command command)
        {
            try
            {
                if (this.AppsHashed)
                {
                    switch (command.CommandString)
                    {
                    case "\n":
                        Console.Write("null");

                        return(null);

                        break;

                    case "exit":
                        this.Terminate();

                        break;

                    default:
                        try
                        {
                            aAppFunction appFunction = null;

                            if ((appFunction = this.GetAppFunction(command)) != null)
                            {
                                return(appFunction(new ApplicationArgument()));
                            }

                            throw new CommandNotFoundException(command);
                        }
                        catch (CommandNotFoundException e)
                        {
                            Console.WriteLine($"\nError: \"{command.CommandString}\" is not a valid command.");

                            return(null);
                        }

                        break;
                    }
                }
            }
            catch (UnhashedApplicationsException e)
            {
                e.Log();
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the sAppFunction delegate hashed to the provied command.
        /// </summary>
        /// <param name="command"> Command </param>
        /// <returns> Hashed sAppFunction delegate. </returns>
        public aAppFunction GetAppFunction(Command command)                     //	Returns the application function delegate
        {
            aAppFunction appFunction = null;

            try
            {
                if ((appFunction = this.GetHashedAppFuction(command.CommandString)) == null)
                {
                    throw new UnhashedApplicationsException();
                }

                Console.WriteLine($"Function Call {appFunction(new ApplicationArgument())}");

                return(appFunction);
            }
            catch (UnhashedApplicationsException e)
            {
                e.Log();
            }

            return(appFunction);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the app function hashed to the provided command.
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        private aAppFunction GetHashedAppFuction(string command)
        {
            aAppFunction appFunction = null;

            if (command == null)
            {
                return(new aAppFunction((ApplicationArgument argument) => null));
            }

            try
            {
                if (this.AppsHashed)
                {
                    try
                    {
                        appFunction = (aAppFunction)this.ApplicationHash[command];
                    }
                    catch (KeyNotFoundException e)
                    {
                        Error.Log(e);

                        return(appFunction);
                    }
                }
                else
                {
                    throw new UnhashedApplicationsException();
                }
            }
            catch (UnhashedApplicationsException e)
            {
                e.Log();
            }

            return(appFunction);
        }
Ejemplo n.º 4
0
 public Application(AppConfiguration configuration, aAppFunction appFunction)
 {
     this.Configuration       = configuration;
     this.ApplicationFunction = appFunction;
 }
Ejemplo n.º 5
0
 public Application()
 {
     this.Configuration       = new AppConfiguration();
     this.ApplicationFunction = new aAppFunction((ApplicationArgument x) => null);
 }