Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                // Load configuration
                IConfiguration config = new ConfigurationBuilder()
                                        .AddJsonFile("appsettings.json", true, true)
                                        .Build();

                var sitemapBaseUrl      = config["sitemapBaseUrl"];
                var sitemapOutputPath   = config["sitemapOutputPath"];
                var renderUrl           = config["renderUrl"];
                var awsKey              = config["awsKey"];
                var awsSecret           = config["awsSecret"];
                var awsRegion           = config["awsRegion"];
                var uploadToAwsRaw      = config["uploadToAws"];
                var success             = bool.TryParse(uploadToAwsRaw, out var uploadToAws);
                var chromeExePath       = config["chromeExePath"];
                var localOutputPathHtml = $"{config["localHtmlOutputPath"]}{DateTime.Now.ToString("yyyyMMdd")}";
                var dynamoTableName     = config["dynamoTableName"];

                Utilities.Render.BaseUrl       = renderUrl;
                Utilities.Render.ChromeExePath = chromeExePath;
                Route.LocalPath = localOutputPathHtml;

                var dynamoManager = new DynamoManager(new AmazonDynamoDBClient(awsKey,
                                                                               awsSecret, RegionEndpoint.GetBySystemName(awsRegion)), dynamoTableName);
                var s3Client = new AmazonS3Client(awsKey, awsSecret, RegionEndpoint.GetBySystemName(awsRegion));

                // Get all site content from DynamoDB
                var siteContent = Task.Run(async() => await dynamoManager.GetContent()).Result;

                // Generate the site map
                var siteMapPath = MapSite(siteContent, sitemapOutputPath, sitemapBaseUrl);

                // Render the site
                var renderedContent = Task.Run(async() => await Utilities.Render.Execute(siteMapPath, true, success && uploadToAws, s3Client)).Result;

                if (!success || !uploadToAws)
                {
                    return;
                }

                // Upload the rendered content to S3
                foreach (var route in renderedContent)
                {
                    if (route.Uri != null && route.Query != "//" &&
                        !route.Query.Contains("sitemap") && !string.IsNullOrEmpty(route.Content))
                    {
                        Console.WriteLine($"Uploading page content: {route.Query}");
                        Task.Run(async() => await FileManager.Upload(route, sitemapBaseUrl, s3Client)).Wait();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error while rendering. {ex.Message} {ex.StackTrace}");
                throw;
            }
        }
        public async Task <ActionResult> Add(ContactModel model)
        {
            DynamoManager dm = new DynamoManager(_DynamoSettings, Amazon.RegionEndpoint.USEast2);

            if (model != null)
            {
                var result = await dm.PutContactModel(model);
            }

            return(View());
        }