#@ template language="C#" inherits="BaseResponseUnmarshaller"#>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#
AddLicenseHeader();
AddCommonUsingStatements();
#>
namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
{
///
/// Response Unmarshaller for <#=this.UnmarshallerBaseName #> operation
///
public class <#=this.UnmarshallerBaseName #>ResponseUnmarshaller : EC2ResponseUnmarshaller
{
///
/// Unmarshaller the response from the service to the response class.
///
///
///
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
{
<#=this.UnmarshallerBaseName #>Response response = new <#=this.Operation.Name #>Response();
<# if (this.HasSuppressedResult)
{
#>
while (context.Read())
{
}
<#
}
else
{
#>
int originalDepth = context.CurrentDepth;
int targetDepth = originalDepth + 1;
if (context.IsStartOfDocument)
targetDepth = 2;
while (context.ReadAtDepth(originalDepth))
{
if (context.IsStartElement || context.IsAttribute)
{
<#
if(this.Structure != null)
{
if(this.IsWrapped)
{
#>
if ( context.TestExpression(".", targetDepth))
{
response.<#=MemberAccessorFor(this.Structure.Name)#> = <#=this.Structure.Name#>Unmarshaller.Instance.Unmarshall(context);
continue;
}
<#
}
else
{
foreach (var member in this.Structure.Members)
{
var testExpression = GeneratorHelpers.DetermineAWSQueryTestExpression(member);
#>
if (context.TestExpression("<#=testExpression#>", targetDepth))
{
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
<#
if (member.IsList)
{
#>
var item = unmarshaller.Unmarshall(context);
response.<#=MemberAccessorFor(member.PropertyName)#>.Add(item);
<#
}
else
{
#>
response.<#=MemberAccessorFor(member.PropertyName)#> = unmarshaller.Unmarshall(context);
<#
}
#>
continue;
}
<#
}
}
}
#>
}
}
<#
}
#>
return response;
}
///
/// Unmarshaller error response to exception.
///
///
///
///
///
public override AmazonServiceException UnmarshallException(XmlUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
{
ErrorResponse errorResponse = ErrorResponseUnmarshaller.GetInstance().Unmarshall(context);
<#
foreach (var exception in this.Operation.Exceptions)
{
#>
if (errorResponse.Code != null && errorResponse.Code.Equals("<#=exception.Code #>"))
{
return new <#=exception.Name #>(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
<#
}
#>
return new <#=this.BaseException#>(errorResponse.Message, innerException, errorResponse.Type, errorResponse.Code, errorResponse.RequestId, statusCode);
}
<#
this.AddResponseSingletonMethod();
#>
}
}
<#+
// if the result fields have been wrapped in a subordinate structure, wire the accessor
// to use it when addressing a member
string MemberAccessorFor(string memberName)
{
return string.IsNullOrEmpty(WrappedResultMember) ? memberName : WrappedResultMember;
}
#>