Beispiel #1
0
        public void InserirNotaFiscal(NotaFiscal nf)
        {
            Type tipo = nf.GetType();

            PropertyInfo[] propriedades = tipo.GetProperties();

            ProcParam p = new ProcParam();

            p.paramsColection = new List <ProcAttr>();

            foreach (PropertyInfo prop in propriedades)
            {
                ProcAttr attr = new ProcAttr();
                if (prop.Name != "ItensDaNotaFiscal")
                {
                    attr.attrName = prop.Name;

                    recuperarSQLDBType(ref attr.attrType, prop.PropertyType.Name);

                    attr.attrValue = prop.GetValue(nf, null);
                    p.paramsColection.Add(attr);
                }
            }

            conexao.ExecutarProcedure("P_NOTA_FISCAL", p.paramsColection, out NfId);
        }
Beispiel #2
0
        public void InserirNotaFiscalItem(List <NotaFiscalItem> nfI)
        {
            foreach (NotaFiscalItem itemNF in nfI)
            {
                itemNF.IdNotaFiscal = NfId;

                Type           tipo         = itemNF.GetType();
                PropertyInfo[] propriedades = tipo.GetProperties();

                ProcParam p = new ProcParam();
                p.paramsColection = new List <ProcAttr>();

                foreach (PropertyInfo prop in propriedades)
                {
                    ProcAttr attr = new ProcAttr();

                    attr.attrName = prop.Name;

                    recuperarSQLDBType(ref attr.attrType, prop.PropertyType.Name);

                    attr.attrValue = prop.GetValue(itemNF, null);
                    p.paramsColection.Add(attr);
                }
                conexao.ExecutarProcedure("P_NOTA_FISCAL_ITEM", p.paramsColection, out NfItemId);
            }
        }
Beispiel #3
0
        public async Task Process_Start_CorrectlyRedirectsStdin()
        {
            //Given
            var script = @"
var readline = require('readline');

var rl = readline.createInterface({
  input: process.stdin,
  terminal: false
});

rl.on('line', function (line) {
  console.log(line);
  process.exit(0);
});
";
            var attr   = new ProcAttr
            {
                RedirectStdin  = true,
                RedirectStdout = true,
            };
            var process = Process.Start("node", new string[] { "-e", script }, attr);

            //When
            await process.Stdin.WriteLineAsync("hello node");

            await process.Stdin.FlushAsync();

            var result = await process.Stdout.ReadLineAsync();

            //Then
            process.Wait();
            Assert.Contains("hello node", result);
        }
Beispiel #4
0
        public Terminal StartNew(string command, IReadOnlyCollection <string> args)
        {
            var id = Guid.NewGuid();

            var attr = new ProcAttr
            {
                RedirectStdin  = true,
                RedirectStdout = true,
                RedirectStderr = true,

                Sys = new SysProcAttr
                {
                    UseTty = true,
                },
            };

            var proc     = Process.Start(command, args, attr);
            var terminal = new Terminal
            {
                Id      = id.ToString(),
                Command = command,
            };

            _terminals.TryAdd(terminal.Id, new TerminalProcess
            {
                Terminal = terminal,
                Process  = proc,
            });
            return(terminal);
        }
Beispiel #5
0
        public void Process_Start_ThrowsAnErrorArgsAreNull()
        {
            // Given
            var attr = new ProcAttr();

            // When, Then
            Assert.Throws <ArgumentNullException>(() =>
            {
                Process.Start("hello", null, attr);
            });
        }
Beispiel #6
0
        public void Process_Start_ThrowsAnErrorWhenCommandIsEmptyString()
        {
            // Given
            var attr = new ProcAttr();

            // When, Then
            Assert.Throws <ArgumentNullException>(() =>
            {
                Process.Start("", null, attr);
            });
        }
Beispiel #7
0
        public void Process_Start_CorrectlyReturnsExitCodeFromChild()
        {
            // Given
            var attr = new ProcAttr
            {
            };
            var process = Process.Start("node", new string[] { "-e", "process.exit(122)" }, attr);

            // When
            process.Wait();

            // Then
            Assert.Equal(122, process.ExitCode);
        }
Beispiel #8
0
        public async Task Process_Start_CorrectlyRedirectsStdErr()
        {
            // Given
            var attr = new ProcAttr
            {
                RedirectStderr = true,
            };
            var process = Process.Start("node", new string[] { "-e", "console.error('oh no')" }, attr);

            // When
            var result = await process.Stderr.ReadToEndAsync();

            // Then
            process.Wait();
            Assert.Contains("oh no", result);
        }
Beispiel #9
0
        public async Task Process_Start_CorrectlyRedirectsStdout()
        {
            // Given
            var attr = new ProcAttr
            {
                RedirectStdout = true,
            };
            var process = Process.Start("echo", new string[] { "hello" }, attr);

            // When
            var result = await process.Stdout.ReadToEndAsync();

            // Then
            process.Wait();
            Assert.Contains("hello", result);
            Assert.Equal(0, process.ExitCode);
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            var attr = new ProcAttr
            {
                RedirectStdout = true,
                Sys            = new SysProcAttr
                {
                    UseTty = true
                }
            };

            // This one works
            //var process = Process.Start("bash", new string[] { "-c", "ls --color=auto" }, attr);

            // This one doesn't work
            var process = Process.Start("pwsh", new string[] { "-command", "ls --color=auto" }, attr);

            var t = ReadStdOut(process, process.Stdout);

            process.Wait();
            Console.WriteLine($"Exited with {process.ExitCode}");
        }
Beispiel #11
0
        public async Task Process_Start_CorrectlyPassingGivenEnvVarsToSubProcess()
        {
            //Given
            var rand = Guid.NewGuid().ToString();
            var env  = new Dictionary <string, string>
            {
                { "RND_TEST_VAL", rand }
            };
            var attr = new ProcAttr
            {
                Env            = env,
                RedirectStdout = true,
            };

            //When
            var process = Process.Start("node", new string[] { "-e", "console.log(process.env)" }, attr);
            var result  = await process.Stdout.ReadToEndAsync();

            process.Wait();

            //Then
            Assert.Contains($"RND_TEST_VAL: '{rand}'", result);
        }