Ejemplo n.º 1
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, CreateInvalidationResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Invalidation", targetDepth))
                    {
                        response.Invalidation = InvalidationUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }


            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent("Location"))
            {
                response.Location = responseData.GetHeaderValue("Location");
            }


            return;
        }
Ejemplo n.º 2
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateInvalidationResponse response = new CreateInvalidationResponse();

            UnmarshallResult(context, response);


            return(response);
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateInvalidationResponse response = new CreateInvalidationResponse();

            response.CreateInvalidationResult = CreateInvalidationResultUnmarshaller.GetInstance().Unmarshall(context);


            return(response);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateInvalidationResponse response = new CreateInvalidationResponse();

            UnmarshallResult(context, response);
            if (context.ResponseData.IsHeaderPresent("Location"))
            {
                response.Location = context.ResponseData.GetHeaderValue("Location");
            }

            return(response);
        }
Ejemplo n.º 6
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, CreateInvalidationResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Invalidation", targetDepth))
                    {
                        var unmarshaller = InvalidationUnmarshaller.Instance;
                        response.Invalidation = unmarshaller.Unmarshall(context);
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }

            return;
        }
        /// <summary>
        /// Invalidates objects from a CloudFront distribution.
        /// </summary>
        /// <param name="distributionId">The distribution to invalidate objects from.</param>
        /// <param name="items">The path of the objects to invalidate.</param>
        /// <param name="reference">A unique name that ensures the request can't be replayed.</param>
        /// <param name="settings">The <see cref="CloudFrontSettings"/> required to connect to Amazon CloudFront.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        public async Task <string> CreateInvalidation(string distributionId, IList <string> items, string reference, CloudFrontSettings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            //Get Reference
            if (String.IsNullOrEmpty(reference))
            {
                reference = DateTime.Now.Ticks.ToString();
            }



            //Correct Paths
            List <string> paths = new List <string>();

            foreach (string item in items)
            {
                if (!item.StartsWith("/"))
                {
                    paths.Add("/" + item);
                }
                else
                {
                    paths.Add(item);
                }
            }



            //Create Request
            InvalidationBatch batch = new InvalidationBatch()
            {
                Paths = new Paths()
                {
                    Items    = paths.ToList(),
                    Quantity = items.Count
                },

                CallerReference = reference
            };

            CreateInvalidationRequest request = new CreateInvalidationRequest()
            {
                DistributionId    = distributionId,
                InvalidationBatch = batch
            };



            //Send Request
            _Log.Verbose("Create Invalidation {0}", distributionId);

            AmazonCloudFrontClient client = this.GetClient(settings);

            CreateInvalidationResponse response = await client.CreateInvalidationAsync(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.Created)
            {
                return(response.Invalidation.Id);
            }
            else
            {
                _Log.Error("Error invalidating object {0}", distributionId);

                return("");
            }
        }