Exemplo n.º 1
0
        public void InvalidateCloudFrontDistribution(string distId, List <string> invalidPaths)
        {
            Log.Debug("Invalidating paths", invalidPaths);
            var invReq = new CreateInvalidationRequest
            {
                DistributionId    = distId,
                InvalidationBatch = new InvalidationBatch
                {
                    Paths = new Paths
                    {
                        Quantity = invalidPaths.Count,
                        Items    = invalidPaths
                    },
                    CallerReference = DateTime.Now.Ticks.ToString()
                }
            };

            var resp = _cfclient.CreateInvalidation(invReq);

            if (resp.HttpStatusCode == HttpStatusCode.Created)
            {
                Log.Info(string.Format("Created invalidation for Cloudfront Distribution {0}", distId));
            }
            else
            {
                Log.Error(string.Format("Got unexpected result creating invalidation for Cloudfront Distribution {0}: {1}", distId, resp.HttpStatusCode));
            }
        }
Exemplo n.º 2
0
        private static void UploadWeb()
        {
            var path = "../../../Web/";

            try
            {
                var m = Directory.GetFiles(path);
                Console.WriteLine("Starting Web Upload");
                TransferUtility directoryTransferUtility = new TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.USWest2), new TransferUtilityConfig()
                {
                    ConcurrentServiceRequests = 50,
                });
                var transferUtilityUploadDirectoryRequest = new TransferUtilityUploadDirectoryRequest()
                {
                    Directory               = path,
                    BucketName              = "socialwargames.com",
                    SearchPattern           = "*.*",
                    SearchOption            = SearchOption.AllDirectories,
                    UploadFilesConcurrently = true,
                    CannedACL               = S3CannedACL.PublicRead
                };
                transferUtilityUploadDirectoryRequest.UploadDirectoryProgressEvent += (sender, e) =>
                {
                    Console.WriteLine("Files Uploaded: " + e.NumberOfFilesUploaded);
                };



                directoryTransferUtility.UploadDirectory(transferUtilityUploadDirectoryRequest);
                Console.WriteLine("Starting Invalidate");


                AmazonCloudFrontClient    oClient  = new AmazonCloudFrontClient(Amazon.RegionEndpoint.USWest2);
                CreateInvalidationRequest oRequest = new CreateInvalidationRequest();
                oRequest.DistributionId    = "E34LW6CB5ZCWQU";
                oRequest.InvalidationBatch = new InvalidationBatch
                {
                    CallerReference = DateTime.Now.Ticks.ToString(),
                    Paths           = new Paths()
                    {
                        Items = new List <string>()
                        {
                            "/*"
                        }, Quantity = 1
                    }
                };

                CreateInvalidationResponse oResponse = oClient.CreateInvalidation(oRequest);
                oClient.Dispose();
                Console.WriteLine("Done Web Upload");
            }

            catch (AmazonS3Exception e)
            {
                Console.WriteLine(e.Message, e.InnerException);
            }
        }