public async void UploadFileContainer()
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer("dev");

            autoFacContainer.Setup();
            var services = autoFacContainer.ContainerBuilder.Build();

            var azureBlobStorageAPI = services.Resolve <AzureBlobStorageAPI>();

            var testContainer3 = await azureBlobStorageAPI.GetOrCreateContainer("test-container3");

            var ssh = services.Resolve <SshOptions>();

            var json          = JsonConvert.SerializeObject(ssh);
            var baseDirectory = AppContext.BaseDirectory;

            Directory.GetCurrentDirectory();


            var filename = $"{baseDirectory}/ssh-options.json";

            File.WriteAllText(filename, json);

            using (var fileStream = File.OpenRead(filename))
            {
                await azureBlobStorageAPI.Upload("folder/ssh-options.json", fileStream, testContainer3.Name);
            }
        }
Exemplo n.º 2
0
        public void Test1()
        {
            CAbstract cAbstract = AutoFacContainer.Resolve <CAbstract>();
            string    d00       = cAbstract.Do();
            string    d01       = cAbstract.Rule.Validate();

            IAutoService autoService = AutoFacContainer.Resolve <IAutoService>();
            string       b00         = autoService.ShowAuto();

            ATest  atest = AutoFacContainer.Resolve <ATest>();
            string c00   = atest.title();

            var    service = AutoFacContainer.Resolve <IService>();
            string add     = service.Do();
            var    add01   = AutoFacContainer.ResolveNamed <IService>(typeof(FirstModel).Name);
            var    add02   = AutoFacContainer.ResolveNamed <IService>(typeof(FirstModel2).Name);


            ISecondService service2 = AutoFacContainer.Resolve <ISecondService>();
            string         add2     = service2.SecondDo();
            string         add22    = service2.Do();

            ThirdModel service3 = AutoFacContainer.Resolve <ThirdModel>();
            string     add3     = service3.Do();
        }
Exemplo n.º 3
0
        public void DownloadFile()
        {
            AutoFacContainer container = new AutoFacContainer();

            container.RegisterOptions <SshOptions>();
            container.ContainerBuilder.RegisterModule <SshModule>();
            var servicesContainer = container.ContainerBuilder.Build();

            using (var client = servicesContainer.Resolve <SftpClient>())
            {
                client.Connect();
                using (FileStream fs = new FileStream($"{AppContext.BaseDirectory}/downloaded.zip", FileMode.OpenOrCreate))
                {
                    client.DownloadFile("./4117.zip", fs);
                }

                using (MemoryStream ms = new MemoryStream())
                {
                    client.DownloadFile("./test2.txt", ms);
                    var text = Encoding.UTF8.GetString(ms.ToArray());
                    Debugger.Break();
                }
                client.Disconnect();
            }
        }
Exemplo n.º 4
0
        public void SetupAndInsertObject()
        {
            AutoFacContainer container = new AutoFacContainer();

            container.RegisterOptions <PostgreSQLEFOptions>();

            container.ContainerBuilder.Register(context =>
            {
                var options = context.Resolve <PostgreSQLEFOptions>();
                var builder = new DbContextOptionsBuilder <CodeFirstContext>();
                builder.UseNpgsql(options.ConnectionString);
                return(builder.Options);
            });

            container.ContainerBuilder.RegisterType <CodeFirstContext>();

            var serivcesContainer = container.ContainerBuilder.Build();

            using (CodeFirstContext context = serivcesContainer.Resolve <CodeFirstContext>())
            {
                context.Database.EnsureCreated();
                context.Users.Add(new User()
                {
                    Name      = "Tom",
                    YearBirth = 2001,
                    IsMale    = true
                });
                context.SaveChanges();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 生成文件名
        /// </summary>
        private void GenerateFileNameStragety_Test(T8FileEntity t8FileEntity)
        {
            AFileName service = AutoFacContainer.ResolveNamed <AFileName>(typeof(GeneralFileName).Name);
            GenerateFileNameStragety stragety = new GenerateFileNameStragety(service);

            Console.WriteLine($"AFileName一般文件名{stragety.FileName(t8FileEntity)},全路径:{stragety.FileFullName(t8FileEntity)}");
        }
Exemplo n.º 6
0
        public async void WriteCustomers()
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer("dev");

            autoFacContainer.Setup();
            var services = autoFacContainer.ContainerBuilder.Build();

            var azureTableStorageAPI = services.Resolve <AzureTableStorageAPI>();

            await azureTableStorageAPI.Put(new CustomerEntity()
            {
                CustomerType = "Student",
                CustomerName = "John Adams",
                Credit       = 200d,
                CustomerId   = 10082,
                DateOfBirth  = new DateTime(1995, 12, 25),
                PhoneNumber  = "0444333222"
            });

            await azureTableStorageAPI.Put(new CustomerEntity()
            {
                CustomerType = "Teacher",
                CustomerName = "John Smith",
                Credit       = 400d,
                CustomerId   = 10034,
                DateOfBirth  = new DateTime(1985, 12, 25),
                PhoneNumber  = "0444355222"
            });
        }
Exemplo n.º 7
0
        public async void ReplaceAndDeleteCustomers()
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer("dev");

            autoFacContainer.Setup();
            var services = autoFacContainer.ContainerBuilder.Build();

            var azureTableStorageAPI = services.Resolve <AzureTableStorageAPI>();

            await azureTableStorageAPI.Upsert <CustomerEntity>(new CustomerEntity()
            {
                CustomerType = "Student",
                CustomerName = "John Adams",
                Credit       = 600d,
                CustomerId   = 10044,
                DateOfBirth  = new DateTime(1995, 12, 25),
                PhoneNumber  = "0444666222"
            });

            var teacher = await azureTableStorageAPI.Delete <CustomerEntity>(new CustomerEntity()
            {
                CustomerType = "Teacher",
                CustomerName = "John Smith",
                ETag         = "*"
            });

            Debugger.Break();
        }
        public async void SendMessageToSQS()
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer("dev");

            autoFacContainer.RegisterOptions <AWSSQSOptions>();
            autoFacContainer.ContainerBuilder.RegisterModule <AWSSQSModule>();

            var services = autoFacContainer.ContainerBuilder.Build();

            var awsSQSAPI = services.Resolve <AWSSQSAPI>();

            JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings()
            {
                Converters = { new StringEnumConverter() }
            };


            for (int i = 0; i < 100; i++)
            {
                await awsSQSAPI.SendMessage(JsonConvert.SerializeObject(new CustomizedMessage()
                {
                    Type         = MessageTypeEnum.Promotional,
                    CustomerName = $"John Smith  #{i}",
                    Value        = "hello!"
                }, jsonSerializerSettings));
            }
        }
Exemplo n.º 9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // Add Autofac
            AutoFacContainer.Build <AutoFac.ManagementModule>(services);
            return(new AutofacServiceProvider(AutoFacContainer.container));
        }
Exemplo n.º 10
0
        private IContainer BuildContainer(string environment)
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer(environment);

            autoFacContainer.RegisterOptions <MongoOptions>();
            autoFacContainer.ContainerBuilder.RegisterModule <MongoModule>();
            return(autoFacContainer.ContainerBuilder.Build());
        }
Exemplo n.º 11
0
 protected void Application_Start()
 {
     AutoFacContainer.Register(new ContainerBuilder());
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
 }
Exemplo n.º 12
0
        public void CreateArangoCollection()
        {
            AutoFacContainer container = new AutoFacContainer();
            var serivcesContainer      = container.ContainerBuilder.Build();

            var conn   = serivcesContainer.Resolve <ArangoConnection>();
            var client = conn.CreateClient();

            client.CreateCollection(nameof(DemoEntity), type: CollectionType.Document);
        }
Exemplo n.º 13
0
        public async void DeleteAzureBlobStorageFile(string filename, string blobContainer)
        {
            AutoFacContainer container = new AutoFacContainer();

            container.RegisterOptions <AzureBlobStorageOptions>();
            container.ContainerBuilder.RegisterModule <AzureBlobStorageModule>();
            var servicesContainer = container.ContainerBuilder.Build();
            var api = servicesContainer.Resolve <AzureBlobStorageAPI>();
            await api.Delete(filename, blobContainer);
        }
        public PostgresSQLDataContext CreateDbContext(string[] args)
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer();

            autoFacContainer.RegisterOptions <PostgresSQLOptions>();
            autoFacContainer.ContainerBuilder.RegisterModule <PostgresSQLModule>();
            var services = autoFacContainer.ContainerBuilder.Build();

            return(services.Resolve <PostgresSQLDataContext>());
        }
Exemplo n.º 15
0
        public async void DeleteS3Bucket(string bucket)
        {
            AutoFacContainer container = new AutoFacContainer();

            container.RegisterOptions <AWSS3Options>();
            container.ContainerBuilder.RegisterModule <AWSS3Module>();
            var servicesContainer = container.ContainerBuilder.Build();
            var api = servicesContainer.Resolve <AWSS3API>();
            await api.DeleteBucket(bucket);
        }
Exemplo n.º 16
0
        public void CreateDatabase()
        {
            AutoFacContainer container = new AutoFacContainer();

            container.ContainerBuilder.RegisterModule <NpgSQLModule>();

            var serviceContainer = container.ContainerBuilder.Build();
            var bootstrap        = serviceContainer.Resolve <PostgreSQLBootstrap>();

            bootstrap.CreateDatabase();
        }
Exemplo n.º 17
0
        public void DeleteDatabase()
        {
            AutoFacContainer container = new AutoFacContainer();

            container.ContainerBuilder.RegisterModule <MongoModule>();
            var serivcesContainer = container.ContainerBuilder.Build();

            var mongoBootstrap = serivcesContainer.Resolve <MongoBootstrap>();

            mongoBootstrap.DeleteDatabase();
        }
Exemplo n.º 18
0
        public async void TransferFile()
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer();

            autoFacContainer.RegisterOptions <AWSS3Options>();
            autoFacContainer.RegisterOptions <SshOptions>();
            autoFacContainer.ContainerBuilder.RegisterModule <DataTransferCoreModule>();
            var services     = autoFacContainer.ContainerBuilder.Build();
            var dataTransfer = services.Resolve <DataTransferCore>();
            var filename     = await dataTransfer.Transfer();
        }
Exemplo n.º 19
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AutoFacContainer.ConfigureContainer();
            var SeedStarterDataService = DependencyResolver.Current.GetService <ISeedStarterDataService>();

            SeedStarterDataService.SeedData();
        }
        public async void CreateContainer()
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer("dev");

            autoFacContainer.Setup();
            var services = autoFacContainer.ContainerBuilder.Build();

            var azureBlobStorageAPI = services.Resolve <AzureBlobStorageAPI>();

            var testContainer3 = await azureBlobStorageAPI.GetOrCreateContainer("test-container3");
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            Console.WriteLine("Execute AWS EC2 Job!");
            AutoFacContainer autoFacContainer = new AutoFacContainer();

            autoFacContainer.RegisterOptions <AWSEC2Options>();
            autoFacContainer.ContainerBuilder.RegisterModule <AWSEC2Module>();
            var services = autoFacContainer.ContainerBuilder.Build();
            var api      = services.Resolve <AWSEC2API>();

            api.ExecuteJob().Wait();
        }
Exemplo n.º 22
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.º 23
0
        public void DropTables()
        {
            AutoFacContainer container = new AutoFacContainer();

            container.ContainerBuilder.RegisterModule <NpgSQLModule>();
            container.ContainerBuilder.RegisterModule <NpgSQLDataModule>();

            var serviceContainer = container.ContainerBuilder.Build();
            var npgsqlData       = serviceContainer.Resolve <NpgSQLData>();

            npgsqlData.DropTable <DemoEntity>();
        }
Exemplo n.º 24
0
        public async void TransferDailySalesData()
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer("dev");

            autoFacContainer.Setup();
            var services = autoFacContainer.ContainerBuilder.Build();

            var sftpEtl = services.Resolve <SftpEtl>();

            await sftpEtl.TransferDailySalesData();

            Debugger.Break();
        }
Exemplo n.º 25
0
        public async void UploadDataToAzureBlobStorage()
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer("dev");

            autoFacContainer.Setup();
            var services = autoFacContainer.ContainerBuilder.Build();

            var dataGenerator = services.Resolve <DataGenerator>();

            await dataGenerator.WriteToBlobStorageContainer();

            Debugger.Break();
        }
Exemplo n.º 26
0
        protected override void OnStartup(StartupEventArgs e)
        {
            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            AutoFacContainer autoFacContainer = new AutoFacContainer(environment);

            autoFacContainer.RegisterOptions <AWSAthenaOptions>();
            autoFacContainer.RegisterOptions <AWSS3Options>();
            autoFacContainer.RegisterOptions <AthenaClientOptions>();
            autoFacContainer.ContainerBuilder.RegisterModule <AWSAthenaModule>();
            autoFacContainer.ContainerBuilder.RegisterModule <AWSS3Module>();
            Services = autoFacContainer.ContainerBuilder.Build();
            base.OnStartup(e);
        }
Exemplo n.º 27
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <string> FunctionHandler(string input, ILambdaContext context)
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer();

            autoFacContainer.RegisterOptions <AWSS3Options>();
            autoFacContainer.RegisterOptions <SshOptions>();
            autoFacContainer.ContainerBuilder.RegisterModule <DataTransferCoreModule>();
            var services     = autoFacContainer.ContainerBuilder.Build();
            var dataTransfer = services.Resolve <DataTransferCore>();
            var filename     = await dataTransfer.Transfer();

            return(filename == null ? "No File Transferred." : $"File {filename} Transferred.");
        }
Exemplo n.º 28
0
        public async void ReadDataFromDynamoDB()
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer("dev");

            autoFacContainer.Setup();
            var services = autoFacContainer.ContainerBuilder.Build();

            var awsDynamoAPI = services.Resolve <AWSDynamoAPI>();

            var customer = await awsDynamoAPI.ReadItem <Customer>("test02");

            Debugger.Break();
        }
        public async void SetupSalesTable()
        {
            AutoFacContainer autoFacContainer = new AutoFacContainer("dev");

            autoFacContainer.Setup();
            var services = autoFacContainer.ContainerBuilder.Build();

            var athenaTableSetup = services.Resolve <AthenaTableSetup>();

            await athenaTableSetup.CreateDailySalesTable();

            Debugger.Break();
        }
Exemplo n.º 30
0
        public async void CreateAzureBlobStorageFile(string filename, string blobContainer)
        {
            AutoFacContainer container = new AutoFacContainer();

            container.RegisterOptions <AzureBlobStorageOptions>();
            container.ContainerBuilder.RegisterModule <AzureBlobStorageModule>();
            var servicesContainer = container.ContainerBuilder.Build();
            var api = servicesContainer.Resolve <AzureBlobStorageAPI>();
            await api.UploadAsJson(filename, new
            {
                Name  = "Jack",
                Value = "Test"
            }, blobContainer);
        }