public void GetIntTypeWithNoGivenDefaultReturnTheDefault()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(default(int), parser.Get <int>("c")); // return the default value.
        }
        public void GetDoubleTypeWithNoGivenDefault()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(default(double), parser.Get <double>("c")); //  there is a value, so we will return the default.
        }
        public void GetIntTypeReturnTheDefault()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(12, parser.Get("c", 12)); // return the default value.
        }
        public void GetDoubleType()
        {
            // the arguments
            var args   = new[] { "--a", "12.34" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(12.34, parser.Get <double>("a", 0)); //  fake default
        }
        public void GetIntTypeThatIsNotAnInt()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(default(int), parser.Get("a", 12)); //  there is a value, so we will return the default.
        }
        public void GetIntType()
        {
            // the arguments
            var args   = new[] { "--a", "12" };
            var parser = new CommandlineParser(args);

            Assert.AreEqual(12, parser.Get("a", 0)); //  fake default
        }
Ejemplo n.º 7
0
        private static async Task Main(string[] args)
        {
            var arguments = new CommandlineParser(args, new CommandlineArgumentRules
            {
                new HelpCommandlineArgumentRule(new [] { "help", "h" }),
                new RequiredCommandlineArgumentRule("host"),
                new OptionalCommandlineArgumentRule("port", "443"),
                new OptionalCommandlineArgumentRule("scheme", "http")
            });

            var uriBuilder = new UriBuilder(arguments.Get <string>("scheme"),
                                            arguments.Get <string>("host"),
                                            arguments.Get <int>("port"));
            var uri     = uriBuilder.Uri;
            var sslTest = new SslTester(uriBuilder.Uri);

            Console.WriteLine($"Checking: {uri} (IP resolved as {await sslTest.GetIpAddressAsync().ConfigureAwait(false) ?? IPAddress.None})");

            // test the prefered/expected protocols
            await TestProtocols(
                sslTest,
                "Prefered:",
                new[] {
                SslProtocols.None,
                SslProtocols.Tls12,
                SslProtocols.Tls13
            }
                ).ConfigureAwait(false);

            // then test the obsolete protocols
            await TestProtocols(
                sslTest,
                "Obsolete:",
                new[] {
// we know it is obsolete, this is why we are testing for it
#pragma warning disable 618
                SslProtocols.Ssl2,
                SslProtocols.Ssl3,
#pragma warning restore 618
                SslProtocols.Tls,
                SslProtocols.Tls11
            }
                ).ConfigureAwait(false);
        }
        public void YouCannotGetWithANullKeyWithNonString()
        {
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);

            Assert.Throws <ArgumentNullException>(() =>
            {
                parser.Get(null, 12.34);
            });
        }
        public void TestFlagsWithValuesAndNoValuesNonDefaultLeadingPattern()
        {
            // the arguments
            var args   = new[] { "-a", "-b", "world" };
            var parser = new CommandlineParser(args, null, "-");

            Assert.IsTrue(parser.IsSet("a"));
            Assert.IsTrue(parser.IsSet("b"));
            Assert.AreEqual("world", parser.Get("b", "nope"));
        }
        public void TestFlagsWithNoValueAlone()
        {
            // the arguments
            var args   = new[] { "--a" };
            var parser = new CommandlineParser(args);

            // "a" exist
            Assert.IsTrue(parser.IsSet("a"));

            // not "b"
            Assert.IsFalse(parser.IsSet("b"));

            // but a and b are empty
            Assert.AreEqual(null, parser.Get("a"));
            Assert.AreEqual(null, parser.Get("b"));

            // even with a default
            Assert.AreEqual(null, parser.Get("a", "nope"));
            Assert.AreEqual("nope", parser.Get("b", "nope"));
        }
        public void TestFlagsWithNoValues()
        {
            // the arguments
            var args   = new[] { "--a", "--b", "--c", "hello" };
            var parser = new CommandlineParser(args);

            //  "c" has a value
            Assert.AreEqual("hello", parser.Get("c"));

            // the exist
            Assert.IsTrue(parser.IsSet("a"));
            Assert.IsTrue(parser.IsSet("b"));

            // but a and b are empty
            Assert.AreEqual(null, parser.Get("a"));
            Assert.AreEqual(null, parser.Get("b"));

            // even with a default
            Assert.AreEqual(null, parser.Get("a", "nope"));
            Assert.AreEqual(null, parser.Get("b", "nope"));
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            string argumentsHelp = Environment.NewLine +
                                   "EDR.Integrator Uso:" + Environment.NewLine + Environment.NewLine +
                                   "-help           Despliega esta pantalla de ayuda" + Environment.NewLine +
                                   "-site           Nombre del sitio EDR remoto a conectarse para extraer valores de las variables operativas" + Environment.NewLine +
                                   "-maxparallel    Máximo grado de paralelismo. Rango entre 1 y 20 (por defecto 10). Recomendado para este equipo: {0}" + Environment.NewLine +
                                   "-batchsize      Número de filas a procesar por lote (por defecto 2000)" + Environment.NewLine + Environment.NewLine +
                                   "Ejemplo EDR.Integrator.CommandLine -site srv_samaria3 [-maxparallel 12] [-batchsize 4000]";

            int    MAX_PARALLEL_DEGREE = 10;
            int    MAX_BATCH_SIZE      = 2000;
            string SITE_NAME           = string.Empty;

            string[] validArguments = { "site", "maxparalel", "batchsize", "help" };

            try
            {
                var arguments = new CommandlineParser(args, new CommandlineArgumentRules
                {
                    new HelpCommandlineArgumentRule(new [] { "help" }),
                    new OptionalCommandlineArgumentRule("batchsize", "2000"),
                    new OptionalCommandlineArgumentRule("maxparallel", "10"),
                    new OptionalCommandlineArgumentRule("site")
                }, "-"
                                                      );

                //cálculo del número óptimo de procesos en hilo con base a los CPU disponibles del equipo
                int maxCPU = Convert.ToInt32(Math.Ceiling((Environment.ProcessorCount * 0.75) * 2.0));
                //si el valor por defecto de 10 no es posible ejecutarlo en el equipo se establece con base a la capacidad
                if (MAX_PARALLEL_DEGREE > maxCPU)
                {
                    MAX_PARALLEL_DEGREE = maxCPU;
                }

                argumentsHelp = string.Format(argumentsHelp, maxCPU);

                if (arguments.IsHelp())
                {
                    Console.WriteLine(argumentsHelp);
                    return;
                }

                if (!arguments.IsSet("site"))
                {
                    Console.WriteLine(argumentsHelp);
                    return;
                }
                else
                {
                    string site = arguments.Get <string>("site");
                    if (string.IsNullOrEmpty(site))
                    {
                        Console.WriteLine(argumentsHelp);
                        Console.WriteLine("Valor de -site: " + site);
                        return;
                    }
                    else
                    {
                        SITE_NAME = site;
                    }
                }

                if (arguments.IsSet("maxparallel"))
                {
                    int maxparallel = arguments.Get <int>("maxparallel");
                    if (maxparallel > MAX_PARALLEL_DEGREE)
                    {
                        Console.WriteLine("El valor maxparallel es mayor al que el equipo puede ejecutar, se establece por defecto a " + MAX_PARALLEL_DEGREE.ToString());
                    }
                    if (maxparallel < 1 || maxparallel > 20)
                    {
                        Console.WriteLine("El valor maxparallel no está en el rango de 1 a 20 - Recomendado para este equipo: " + MAX_PARALLEL_DEGREE.ToString());
                        return;
                    }
                }

                if (arguments.IsSet("batchsize"))
                {
                    int maxBatchSize = arguments.Get <int>("batchsize");
                    if (maxBatchSize < 100 || maxBatchSize > 10000)
                    {
                        Console.WriteLine("El valor batchsize está fuera de una rango permitido ( >= 100 y <= 10,000)");
                        return;
                    }
                    else
                    {
                        MAX_BATCH_SIZE = maxBatchSize;
                    }
                }

                DateTime initTime   = DateTime.Now;
                DateTime finishTime = DateTime.Now;

                Console.WriteLine("*******ETL Site process INIT - " + SITE_NAME);

                ETLProcess.MaxBatchSize = MAX_BATCH_SIZE;
                ETLProcess.GetConfiguration(SITE_NAME);
                ETLProcess.GetVariablesOnSite();

                Parallel.ForEach(ETLProcess.serverOnSiteVariables,
                                 new ParallelOptions {
                    MaxDegreeOfParallelism = MAX_PARALLEL_DEGREE
                },
                                 v =>
                {
                    DateTime?dt = ETLProcess.GetLastSync(v);
                    if (dt != null)
                    {
                        v.LastSync = dt;
                    }
                    ETLProcess.ExtractAndLoad(v);
                });

                finishTime = DateTime.Now;
                long     elapsedTime = finishTime.Ticks - initTime.Ticks;
                TimeSpan elapsedSpan = new TimeSpan(elapsedTime);

                Console.WriteLine("*******ETL Site process FINISH: Start: " + initTime.ToString() + " | Finish:" + finishTime.ToString() + " | Elapsed time: " + elapsedSpan.TotalSeconds.ToString());
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            //1. Buscar la configuración de conexión del sitename y servername establecido en el parámetro
            //2. Leer las variables operativas activas
            //3. Leer la última sincronización (si no existe (NULL) es primera integración
            //4. Por cada variable operativa: Consultar los registros de la variable operativa
            //5. Integrar el dataset en la BD EDRDS guardando (de cada variable):
            //      - Número de registros obtenidos
            //      - TimeStamp del último registro leído en la tabla de control
            //      - Fecha de inicio y término del proceso
        }