/// <summary> /// This method first adds and then checks the configuration for a /// static website in an Amazon S3 bucket. /// </summary> /// <param name="client">The Amazon S3 client used to add and then check the /// website configuration.</param> /// <param name="bucketName">The name of the bucket that will serve as /// a static website.</param> /// <param name="indexDocumentSuffix">The index document suffix for the /// website.</param> /// <param name="errorDocument">The name of the error document for the /// static website.</param> public static async Task AddWebsiteConfigurationAsync( IAmazonS3 client, string bucketName, string indexDocumentSuffix, string errorDocument) { try { // Put the website configuration. PutBucketWebsiteRequest putRequest = new PutBucketWebsiteRequest() { BucketName = bucketName, WebsiteConfiguration = new WebsiteConfiguration() { IndexDocumentSuffix = indexDocumentSuffix, ErrorDocument = errorDocument, }, }; PutBucketWebsiteResponse response = await client.PutBucketWebsiteAsync(putRequest); // Get the website configuration. GetBucketWebsiteRequest getRequest = new GetBucketWebsiteRequest() { BucketName = bucketName, }; GetBucketWebsiteResponse getResponse = await client.GetBucketWebsiteAsync(getRequest); Console.WriteLine($"Index document: {getResponse.WebsiteConfiguration.IndexDocumentSuffix}"); Console.WriteLine($"Error document: {getResponse.WebsiteConfiguration.ErrorDocument}"); } catch (AmazonS3Exception ex) { Console.WriteLine($"Error encountered on server. Message:'{ex.Message}' when writing an object."); } }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { GetBucketWebsiteResponse getBucketWebsiteResponse = new GetBucketWebsiteResponse(); while (context.Read()) { if (context.get_IsStartElement()) { UnmarshallResult(context, getBucketWebsiteResponse); } } return(getBucketWebsiteResponse); }
private static void UnmarshallResult(XmlUnmarshallerContext context, GetBucketWebsiteResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } response.WebsiteConfiguration = new WebsiteConfiguration(); while (context.Read()) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("RedirectAllRequestsTo", targetDepth)) { response.WebsiteConfiguration.RedirectAllRequestsTo = RoutingRuleRedirectUnmarshaller.Instance.Unmarshall(context); continue; } if (context.TestExpression("IndexDocument/Suffix", targetDepth)) { response.WebsiteConfiguration.IndexDocumentSuffix = StringUnmarshaller.Instance.Unmarshall(context); continue; } if (context.TestExpression("ErrorDocument/Key", targetDepth)) { response.WebsiteConfiguration.ErrorDocument = StringUnmarshaller.Instance.Unmarshall(context); continue; } if (context.TestExpression("RoutingRule", targetDepth + 1)) { response.WebsiteConfiguration.RoutingRules.Add(RoutingRuleUnmarshaller.Instance.Unmarshall(context)); continue; } } else if (context.IsEndElement && context.CurrentDepth < originalDepth) { return; } } return; }
public async Task <GenericResponse> AddWebsiteConfigurationAsync(string bucketName, string indexDocumentSuffix, string errorDocument) { var result = new GenericResponse(); try { // 1. Put the website configuration. PutBucketWebsiteRequest putRequest = new PutBucketWebsiteRequest() { BucketName = bucketName, WebsiteConfiguration = new WebsiteConfiguration() { IndexDocumentSuffix = indexDocumentSuffix, ErrorDocument = errorDocument } }; PutBucketWebsiteResponse response = await _client.PutBucketWebsiteAsync(putRequest); // 2. Get the website configuration. GetBucketWebsiteRequest getRequest = new GetBucketWebsiteRequest() { BucketName = bucketName }; GetBucketWebsiteResponse getResponse = await _client.GetBucketWebsiteAsync(getRequest); Console.WriteLine("Index document: {0}", getResponse.WebsiteConfiguration.IndexDocumentSuffix); Console.WriteLine("Error document: {0}", getResponse.WebsiteConfiguration.ErrorDocument); result.Text = "SUCCESS"; result.Value = bucketName; result.Status = "OK"; } catch (AmazonS3Exception e) { result.Text = e.Message; result.Value = e.StackTrace; result.Status = "ERROR"; } catch (Exception e) { result.Text = e.Message; result.Value = e.StackTrace; result.Status = "ERROR"; } return(result); }
private static void GetBucketWebsite() { try { GetBucketWebsiteRequest request = new GetBucketWebsiteRequest() { BucketName = bucketName }; GetBucketWebsiteResponse response = client.GetBucketWebsite(request); Console.WriteLine("GetBucketWebsite response: {0}", response.StatusCode); Console.WriteLine("GetBucketWebsite website configuration error document: {0}", response.Configuration.ErrorDocument); Console.WriteLine("GetBucketWebsite website configuration index document: {0}", response.Configuration.ErrorDocument); } catch (ObsException ex) { Console.WriteLine("Exception errorcode: {0}, when get bucket website.", ex.ErrorCode); Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage); } }
static async Task AddWebsiteConfigurationAsync(string bucketName, string indexDocumentSuffix, string errorDocument) { try { // 1. Put the website configuration. PutBucketWebsiteRequest putRequest = new PutBucketWebsiteRequest() { BucketName = bucketName, WebsiteConfiguration = new WebsiteConfiguration() { IndexDocumentSuffix = indexDocumentSuffix, ErrorDocument = errorDocument } }; PutBucketWebsiteResponse response = await client.PutBucketWebsiteAsync(putRequest); // 2. Get the website configuration. GetBucketWebsiteRequest getRequest = new GetBucketWebsiteRequest() { BucketName = bucketName }; GetBucketWebsiteResponse getResponse = await client.GetBucketWebsiteAsync(getRequest); Console.WriteLine("Index document: {0}", getResponse.WebsiteConfiguration.IndexDocumentSuffix); Console.WriteLine("Error document: {0}", getResponse.WebsiteConfiguration.ErrorDocument); } catch (AmazonS3Exception e) { Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message); } catch (Exception e) { Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message); } }
private static void UnmarshallResult(XmlUnmarshallerContext context, GetBucketWebsiteResponse response) { int currentDepth = context.get_CurrentDepth(); int num = currentDepth + 1; if (context.get_IsStartOfDocument()) { num += 2; } response.WebsiteConfiguration = new WebsiteConfiguration(); while (context.Read()) { if (context.get_IsStartElement() || context.get_IsAttribute()) { if (context.TestExpression("RedirectAllRequestsTo", num)) { response.WebsiteConfiguration.RedirectAllRequestsTo = RoutingRuleRedirectUnmarshaller.Instance.Unmarshall(context); } else if (context.TestExpression("IndexDocument/Suffix", num)) { response.WebsiteConfiguration.IndexDocumentSuffix = StringUnmarshaller.get_Instance().Unmarshall(context); } else if (context.TestExpression("ErrorDocument/Key", num)) { response.WebsiteConfiguration.ErrorDocument = StringUnmarshaller.get_Instance().Unmarshall(context); } else if (context.TestExpression("RoutingRule", num + 1)) { response.WebsiteConfiguration.RoutingRules.Add(RoutingRuleUnmarshaller.Instance.Unmarshall(context)); } } else if (context.get_IsEndElement() && context.get_CurrentDepth() < currentDepth) { break; } } }
private async Task <GetBucketWebsiteResponse> getBucketWebsite(AmazonS3Client client, GetBucketWebsiteRequest request) { GetBucketWebsiteResponse response = await client.GetBucketWebsiteAsync(request); return(response); }