Exemplo n.º 1
0
        private static ProcessReturn HandleUse(string[] args)
        {
            List <string> errors = new List <string>();

            if (ValidateArguments(args, 0))
            {
                _entity = null;
            }
            else if (!ValidateArguments(args, 1))
            {
                errors.Add("Argumentos invalidos para use de tabela");
            }
            else
            {
                if ((new string[] { "ingredient", "ingrediente", "recipe", "receita" }).Contains(args[0]))
                {
                    _entity = args[0];
                }
                else
                {
                    errors.Add("Tabela desconhecida");
                }
            }
            return(ProcessReturn.FromErrors(errors.ToArray()));
        }
Exemplo n.º 2
0
        public override JobCreateResult Create(PrinterInfo printerInfo)
        {
            var           warnings = new List <MessageType>();
            ProcessReturn result   = PrepareJobForPrinter(printerInfo, MyPrinterProfile, warnings);

            if (AutoStarting && warnings != null)
            {
                warnings.Clear();
            }

            return(new JobCreateResult(null, result, warnings));
        }
Exemplo n.º 3
0
        private static ProcessReturn HandleSelect(string[] args)
        {
            if (!Valid(args))
            {
                return(ProcessReturn.FromErrors(new string[] { "Faltando entidade para ser atualizada" }));
            }
            List <string> errors = new List <string>();

            switch (_entity ?? args[0])
            {
            case "ingrediente":
            case "ingredient":
                if (ValidateArguments(args, _entity != null ? 0 : 1))
                {
                    Ingredient.Select(out var _);
                }
                else if (ValidateArguments(args, _entity != null ? 1 : 2))
                {
                    Ingredient.Select(args[_entity != null ? 0 : 1], ref errors, out var _);
                }
                else if (ValidateArguments(args, _entity != null ? 2 : 3))
                {
                    Ingredient.Select(_entity != null ? args : args.Skip(1).ToArray(), ref errors, out var _);
                }
                else
                {
                    errors.Add($"Numero de argumentos invalido");
                }
                break;

            case "recipe":
            case "receita":
                if (ValidateArguments(args, _entity != null ? 0 : 1))
                {
                    Recipe.Select(out var _);
                }
                else if (ValidateArguments(args, _entity != null ? 1 : 2))
                {
                    Recipe.Select(args[_entity != null ? 0 : 1], ref errors, out var _);
                }
                else
                {
                    errors.Add($"Numero de argumentos invalido");
                }
                break;

            default:
                errors.Add($"Entidade desconhecida '{args[0]}'");
                break;
            }
            return(ProcessReturn.FromErrors(errors.ToArray()));
        }
Exemplo n.º 4
0
        private static ProcessReturn ProcessStatement(string[] statements)
        {
            List <string> errors = new List <string>();

            switch (statements[0])
            {
            case "novo":
            case "create":
                return(HandleCreate(statements.Skip(1).ToArray()));

            case "selecionar":
            case "select":
                return(HandleSelect(statements.Skip(1).ToArray()));

            case "atualizar":
            case "update":
                return(HandleUpdate(statements.Skip(1).ToArray()));

            case "deletar":
            case "delete":
                return(HandleDelete(statements.Skip(1).ToArray()));

            case "link":
            case "linkar":
                return(HandleLink(statements.Skip(1).ToArray()));

            case "unlink":
            case "deslinkar":
                return(HandleUnlink(statements.Skip(1).ToArray()));

            case "use":
                return(HandleUse(statements.Skip(1).ToArray()));

            default:
                errors.Add($"Token desconhecido '{statements[0]}'");
                break;
            }
            return(ProcessReturn.FromErrors(errors.ToArray()));
        }
Exemplo n.º 5
0
        private static ProcessReturn HandleUnlink(string[] args)
        {
            if (!Valid(args))
            {
                return(ProcessReturn.FromErrors(new string[] { "Faltanda entidade para ser deslinkada" }));
            }
            List <string> errors = new List <string>();

            switch (_entity ?? args[0])
            {
            case "recipe":
            case "receita":
                if (ValidateArguments(args, _entity != null ? 2 : 3))
                {
                    Recipe.Unlink(_entity != null ? args : args.Skip(1).ToArray(), ref errors);
                }
                else
                {
                    errors.Add("Numero de argumentos invalido");
                }
                break;
            }
            return(ProcessReturn.FromErrors(errors.ToArray()));
        }
Exemplo n.º 6
0
        private static void ChoiceRunTheProcess(string[] args)
        {
            if (!IsInstalled())
            {
                return;
            }
            if (_argCount > 2)
            {
                ManageErrors(WinService.ErrorCode.ERROR_InvalidArguments);
                return;
            }
            try
            {
                bool isShortcutExist = false;
                foreach (AllowedAppElement item in _section.AllowedApps)
                {
                    if (item.Shortcut == args[0])
                    {
                        isShortcutExist = true;
                    }
                }
                if (!isShortcutExist)
                {
                    ManageErrors(WinService.ErrorCode.ERROR_NotAllowed);
                    Trace.WriteLineIf(_traceSwitch.TraceVerbose, string.Format("[{0}]: ChoiceRunTheProcess Sorry you cannot run this application in admin mode !", DateTime.Now));
                    return;
                }
                else
                {
                    // _section.AllowedApps[args[0]].Path = app_path [-console]
                    // Add (DNP) with GUID (LESS_UAC_RUNNER-PIPE-DAT-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) if -console
                    string pipeName = "LESS_UAC_RUNNER-PIPE-DAT-" + Guid.NewGuid();

                    ControlData controlData = new ControlData();
                    controlData.FileName  = _section.AllowedApps[args[0]].Path;
                    controlData.Console   = _section.AllowedApps[args[0]].Console;
                    controlData.PipeName  = _section.AllowedApps[args[0]].Console ? pipeName : null;
                    controlData.Arguments = _section.AllowedApps[args[0]].Args;

                    // Hook stored arguments if dynamicArgument != string.Empty
                    // Inline arguments to console #1
                    string dynamicArgument = args.Length == 2 ? args[1] : string.Empty;
                    controlData.Arguments = dynamicArgument == "" ? _section.AllowedApps[args[0]].Args : dynamicArgument;

                    if (File.Exists(_section.AllowedApps[args[0]].Path))
                    {
                        //////// WRITE PROCESS NAME TO LAUNCHED IN CNP)
                        Trace.WriteLineIf(_traceSwitch.TraceVerbose, string.Format("[{0}]: ChoiceRunTheProcess calling WriteApplicationNameInPipe arg={1}", DateTime.Now, _section.AllowedApps[args[0]].Path));

                        var json = new JavaScriptSerializer().Serialize(controlData);
                        if (WriteApplicationNameInPipe(json))
                        {
                            ///////////////////////////////////////////////////////////////////////

                            //////// READ PROCESS RETURN FROM DNP)
                            // If -console we must connect to (DNP) / Read the content / Print the content to stdout / exit with PROCESS exitcode
                            _console = _section.AllowedApps[args[0]].Console;
                            if (_console)
                            {
                                Trace.WriteLineIf(_traceSwitch.TraceVerbose, string.Format("[{0}]: ChoiceRunTheProcess calling ReadReturnFromPipe arg={1}", DateTime.Now, pipeName));

                                _jsonReturnedData = ReadReturnFromPipe(pipeName);
                                if (_jsonReturnedData != string.Empty)
                                {
                                    // Extraction:
                                    _processReturnObject = new JavaScriptSerializer().Deserialize <ProcessReturn>(_jsonReturnedData);
                                    Trace.WriteLineIf(_traceSwitch.TraceVerbose, string.Format("[{0}]: ChoiceRunTheProcess read returnedData: {1}", DateTime.Now, _jsonReturnedData));
                                }
                                else
                                {
                                    Trace.WriteLineIf(_traceSwitch.TraceVerbose, string.Format("[{0}]: ChoiceRunTheProcess nothing returned or error", DateTime.Now));
                                    return;
                                }
                            }
                            ///////////////////////////////////////////////////////////////////////
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        ManageErrors(WinService.ErrorCode.ERROR_FileNotFound);
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                ManageErrors(e.Message);
                _commandExitCode = -1;
            }
            Trace.WriteLine(string.Format("{0}: >>>>> ChoiceRunTheProcess job ended successfully", DateTime.Now));
        }
Exemplo n.º 7
0
 public JobCreateResult(AbstractJob job, ProcessReturn result, List <MessageType> warnings)
 {
     Warnings = warnings;
     Result   = result;
     Job      = job;
 }
Exemplo n.º 8
0
        private static ProcessReturn ProcessMeta(string line)
        {
            var shouldClose = false;

            switch (line)
            {
            case "\\q":
                shouldClose = true;
                break;

            case "\\cls":
                Console.Clear();
                break;

            case "\\noData":
                showData = !showData;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"{(!showData ? "not " : "")}showing data");
                break;

            case "\\?":
            case "\\h":
            case "\\help":
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(Environment.NewLine + new string('-', Console.WindowWidth * 2));
                Console.Write(@"
Help Menu
To detailed help enter: \help <command>

select, selecionar:

    Selects the data of an object from a table.

create, novo:

    Crates a new data object in a table.

update, atualizar:

    Update the data of an object of a table.

delete, deletar:

    Delete an object of a table.

link, linkar:

    Links a object from a table to a object of another table.

unlink, deslinkar:

    Unlinks a object from a table to a object of another table.

use:

    Syntax sugar for table selection.

\q:

    Quits the application.

\cls:

    Clears the screen.

\noData:

    Omits the header of recipes selection.

");
                break;

            case "\\help select":
            case "\\help selecionar":
            case "\\h select":
            case "\\h selecionar":
            case "\\? select":
            case "\\? selecionar":
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(Environment.NewLine + new string('-', Console.WindowWidth * 2));
                Console.Write(@"
Help Menu

    Syntax:
        [select | selecionar] *table

            Selects all data of a table**.

        [select | selecionar] *table <id>

            Selects all data of a object in a table of matching id.

        [select | selecionar] *table <key> <value>

            Select all data of all matching object where the value of the key atribute is equals to the value parameter***.

    * Not necessary when using use syntax.

    ** Will not select array or linked object data.

    *** Currently does this syntax doesn't work with the recipes table.

");
                break;

            case "\\help create":
            case "\\help novo":
            case "\\h create":
            case "\\h novo":
            case "\\? create":
            case "\\? novo":
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(Environment.NewLine + new string('-', Console.WindowWidth * 2));
                Console.Write(@"
Help Menu

    Syntax:
        [create | novo] *table <values>

            Creates a new object in the table with the values.

    * Not necessary when using use syntax.

    Values order:

        ingredient: <nome: string> <rendimento: float> <preço: float>
        recipe: <nome: string> <rendimento: float>

");
                break;

            case "\\help update":
            case "\\help atualizar":
            case "\\h update":
            case "\\h atualizar":
            case "\\? update":
            case "\\? atualizar":
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(Environment.NewLine + new string('-', Console.WindowWidth * 2));
                Console.Write(@"
Help Menu

    Syntax:
        [update | atualizar] *table <id> <values>

            Updates the object of id data to the new values.

    * Not necessary when using use syntax.

    Values order:

        ingredient: <nome: string> <rendimento: float> <preço: float>
        recipe: <nome: string> <rendimento: float>

");
                break;

            case "\\help delete":
            case "\\help deletar":
            case "\\h delete":
            case "\\h deletar":
            case "\\? delete":
            case "\\? deletar":
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(Environment.NewLine + new string('-', Console.WindowWidth * 2));
                Console.Write(@"
Help Menu

    Syntax:
        [delete | deletar] *table <id>

            Deletes the object of id.

    * Not necessary when using use syntax.

");
                break;

            case "\\help link":
            case "\\help linkar":
            case "\\h link":
            case "\\h linkar":
            case "\\? link":
            case "\\? linkar":
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(Environment.NewLine + new string('-', Console.WindowWidth * 2));
                Console.Write(@"
Help Menu

    Syntax:
        [link | linkar] *recipe <id> <values>

            Makes a link of a ingredient with a recipe.

    * Not necessary when using use syntax.

    Values order:

        <id: int> <quantidade: float> <preço: float>

");
                break;

            case "\\help unlink":
            case "\\help deslinkar":
            case "\\h unlink":
            case "\\h deslinkar":
            case "\\? unlink":
            case "\\? deslinkar":
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(Environment.NewLine + new string('-', Console.WindowWidth * 2));
                Console.Write(@"
Help Menu

    Syntax:
        [unlink | deslinkar] *recipe <id1> <id2>

            Unlinks the ingredient of id2 from the recipe of id1.

    * Not necessary when using use syntax.

");
                break;

            case "\\help use":
            case "\\h use":
            case "\\? use":
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(Environment.NewLine + new string('-', Console.WindowWidth * 2));
                Console.Write(@"
Help Menu

    Syntax:
        use table

            Autofill the table option of all commands making then unnecessary, but with one table selected you can't use the command to read other.
            Enter '\use' to nullify the selection of table.

");
                break;
            }
            return(ProcessReturn.FromShouldClose(shouldClose));
        }