Exemplo n.º 1
0
        public void Test1()
        {
            AutoFacContainer container = new AutoFacContainer();

            container.RegisterOptions <SshOptions>();
            container.ContainerBuilder.RegisterModule <SshModule>();
            var services   = container.ContainerBuilder.Build();
            var sftpClient = services.Resolve <SftpClient>();

            sftpClient.Connect();
            Random rnd = new Random((int)(DateTime.Now - new DateTime(2018, 1, 1)).TotalMilliseconds);

            TRandom random = new TRandom();

            for (int i = 51; i < 53; i++)
            {
                var sales = new List <SaleRecord>();
                for (int j = 0; j < 50000; j++)
                {
                    SaleRecord saleRecord = new SaleRecord()
                    {
                        StoreNo         = rnd.Next(99999).ToString().PadLeft(5, '0'),
                        HourOfDay       = rnd.Next(24),
                        MinuteOfHour    = rnd.Next(60),
                        NumberApple     = random.Poisson(12),
                        NumberOfBanana  = random.Poisson(5),
                        NumberOfBeer    = random.Poisson(4),
                        NumberOfChicken = random.Poisson(8),
                        TimeStamp       = DateTime.Now.AddSeconds(-rnd.Next(365 * 24 * 3600))
                    };

                    saleRecord.TotalValueEclGST =
                        saleRecord.NumberApple * 4 +
                        saleRecord.NumberOfBanana * 8 +
                        saleRecord.NumberOfBeer * 5 +
                        saleRecord.NumberOfChicken * 6;

                    sales.Add(saleRecord);
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    stream.WriteCsv(sales);
                    using (MemoryStream upload = new MemoryStream(stream.ToArray()))
                    {
                        sftpClient.UploadFile(upload, $"/root/{i.ToString().PadLeft(3,'0')}.csv");
                    }
                }
            }

            sftpClient.Disconnect();
            sftpClient.Dispose();
        }
Exemplo n.º 2
0
        public static void Main()
        {
            // 1) Use TRandom to generate a few random numbers - via IGenerator methods.
            Console.WriteLine("TRandom in action, used as an IGenerator");
            var trandom = new TRandom();

            Console.WriteLine(trandom.Next() - trandom.Next(5) + trandom.Next(3, 5));
            Console.WriteLine(trandom.NextDouble() * trandom.NextDouble(5.5) * trandom.NextDouble(10.1, 21.9));
            Console.WriteLine(trandom.NextBoolean());

            Console.WriteLine();

            // 2) Use TRandom to generate a few random numbers - via extension methods.
            Console.WriteLine("TRandom in action, used as an IGenerator augmented with extension methods");
            Console.WriteLine(string.Join(", ", trandom.Integers().Take(10)));
            Console.WriteLine(string.Join(", ", trandom.Doubles().Take(10)));
            Console.WriteLine(string.Join(", ", trandom.Booleans().Take(10)));

            Console.WriteLine();

            // 3) Use TRandom to generate a few distributed numbers.
            Console.WriteLine("TRandom in action, used as to get distributed numbers");
            Console.WriteLine(trandom.Normal(1.0, 0.1));
            Console.WriteLine(string.Join(", ", trandom.NormalSamples(1.0, 0.1).Take(20)));
            Console.WriteLine(trandom.Poisson(5));
            Console.WriteLine(string.Join(", ", trandom.PoissonSamples(5).Take(20)));

            Console.WriteLine();

            // 4) There are many generators available - XorShift128 is the default.
            var alf = new ALFGenerator(TMath.Seed());
            var nr3 = new NR3Generator();
            var std = new StandardGenerator(127);

            // 5) You can also use distribution directly, even with custom generators.
            Console.WriteLine("Showcase of some distributions");
            Console.WriteLine("Static sample for Normal: " + NormalDistribution.Sample(alf, 1.0, 0.1));
            Console.WriteLine("New instance for Normal: " + new NormalDistribution(1.0, 0.1).NextDouble());

            Console.WriteLine();
        }