private static void UnmarshallResult(XmlUnmarshallerContext context, GetBucketPolicyResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 1; } while (context.Read()) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("Policy", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Policy = unmarshaller.Unmarshall(context); continue; } } else if (context.IsEndElement && context.CurrentDepth < originalDepth) { return; } } return; }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { GetBucketPolicyResponse getBucketPolicyResponse = new GetBucketPolicyResponse(); UnmarshallResult(context, getBucketPolicyResponse); return(getBucketPolicyResponse); }
void GetBucketPolicyWebResponse(object sender, ResponseEventArgs args) { AmazonS3Exception result = args.Response as AmazonS3Exception; S3Common.client.OnS3Response -= GetBucketPolicyWebResponse; if (null != result) { S3ErrorResponse(result); return; } GetBucketPolicyResponse policyResponse = args.Response as GetBucketPolicyResponse; if (null != policyResponse) { if (!string.IsNullOrEmpty(policyResponse.AmazonId2) && (!string.IsNullOrEmpty(policyResponse.RequestId))) { this.Dispatcher.BeginInvoke(() => { GetBucketResult = policyResponse.Policy; }); } } else { this.Dispatcher.BeginInvoke(() => { GetBucketResult = string.Format(CultureInfo.InvariantCulture, "Error Processing GetPolicy Request"); }); } }
private static void UnmarshallResult(XmlUnmarshallerContext context, GetBucketPolicyResponse response) { using (StreamReader streamReader = new StreamReader(context.get_Stream())) { response.Policy = streamReader.ReadToEnd(); if (response.Policy.StartsWith("<?xml", StringComparison.OrdinalIgnoreCase)) { response.Policy = null; } } }
static void GetBucketPolicy() { try { GetBucketPolicyRequest request = new GetBucketPolicyRequest() { BucketName = bucketName, }; GetBucketPolicyResponse response = client.GetBucketPolicy(request); Console.WriteLine("Get bucket policy response: {0}", response.StatusCode); Console.WriteLine("Bucket policy: {0}", response.Policy); } catch (ObsException ex) { Console.WriteLine("Exception errorcode: {0}, when set bucket policy.", ex.ErrorCode); Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage); } }