예제 #1
0
 public static KeysAndAttributesUnmarshaller GetInstance()
 {
     if (instance == null)
     {
         instance = new KeysAndAttributesUnmarshaller();
     }
     return(instance);
 }
예제 #2
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            BatchGetItemResponse response = new BatchGetItemResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Responses", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <String, List <Dictionary <string, AttributeValue> >, StringUnmarshaller, ListUnmarshaller <Dictionary <string, AttributeValue>, DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> > >(
                        StringUnmarshaller.GetInstance(), new ListUnmarshaller <Dictionary <string, AttributeValue>, DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> >(new DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller>(StringUnmarshaller.GetInstance(), AttributeValueUnmarshaller.GetInstance())));
                    response.Responses = unmarshaller.Unmarshall(context);

                    continue;
                }

                if (context.TestExpression("UnprocessedKeys", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <String, KeysAndAttributes, StringUnmarshaller, KeysAndAttributesUnmarshaller>(
                        StringUnmarshaller.GetInstance(), KeysAndAttributesUnmarshaller.GetInstance());
                    response.UnprocessedKeys = unmarshaller.Unmarshall(context);

                    continue;
                }

                if (context.TestExpression("ConsumedCapacity", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <ConsumedCapacity, ConsumedCapacityUnmarshaller>(
                        ConsumedCapacityUnmarshaller.GetInstance());
                    response.ConsumedCapacity = unmarshaller.Unmarshall(context);

                    continue;
                }
            }

            return(response);
        }
예제 #3
0
        public BatchGetItemResult Unmarshall(JsonUnmarshallerContext context)
        {
            BatchGetItemResult batchGetItemResult = new BatchGetItemResult();

            batchGetItemResult.Responses        = null;
            batchGetItemResult.UnprocessedKeys  = null;
            batchGetItemResult.ConsumedCapacity = null;

            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if ((context.IsKey) && (context.CurrentDepth == targetDepth))
                {
                    context.Read();
                    context.Read();

                    if (context.TestExpression("Responses", targetDepth))
                    {
                        batchGetItemResult.Responses = new Dictionary <String, List <Dictionary <string, AttributeValue> > >();
                        KeyValueUnmarshaller <string, List <Dictionary <string, AttributeValue> >, StringUnmarshaller, ListUnmarshaller <Dictionary <string, AttributeValue>, DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> > > unmarshaller = new KeyValueUnmarshaller <string, List <Dictionary <string, AttributeValue> >, StringUnmarshaller, ListUnmarshaller <Dictionary <string, AttributeValue>, DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> > >(StringUnmarshaller.GetInstance(), new ListUnmarshaller <Dictionary <string, AttributeValue>, DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> >(new DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller>(StringUnmarshaller.GetInstance(), AttributeValueUnmarshaller.GetInstance())));
                        while (context.Read())
                        {
                            if (((context.IsStartArray || context.IsStartElement || context.IsLeafValue) && (context.CurrentDepth == targetDepth)) ||
                                ((context.IsKey) && (context.CurrentDepth == targetDepth + 1)))
                            {
                                KeyValuePair <string, List <Dictionary <string, AttributeValue> > > kvp = unmarshaller.Unmarshall(context);
                                batchGetItemResult.Responses.Add(kvp.Key, kvp.Value);
                            }
                            else if (context.IsEndElement)
                            {
                                break;
                            }
                        }
                        continue;
                    }

                    if (context.TestExpression("UnprocessedKeys", targetDepth))
                    {
                        batchGetItemResult.UnprocessedKeys = new Dictionary <String, KeysAndAttributes>();
                        KeyValueUnmarshaller <string, KeysAndAttributes, StringUnmarshaller, KeysAndAttributesUnmarshaller> unmarshaller = new KeyValueUnmarshaller <string, KeysAndAttributes, StringUnmarshaller, KeysAndAttributesUnmarshaller>(StringUnmarshaller.GetInstance(), KeysAndAttributesUnmarshaller.GetInstance());
                        while (context.Read())
                        {
                            if (((context.IsStartArray || context.IsStartElement || context.IsLeafValue) && (context.CurrentDepth == targetDepth)) ||
                                ((context.IsKey) && (context.CurrentDepth == targetDepth + 1)))
                            {
                                KeyValuePair <string, KeysAndAttributes> kvp = unmarshaller.Unmarshall(context);
                                batchGetItemResult.UnprocessedKeys.Add(kvp.Key, kvp.Value);
                            }
                            else if (context.IsEndElement)
                            {
                                break;
                            }
                        }
                        continue;
                    }

                    if (context.TestExpression("ConsumedCapacity", targetDepth))
                    {
                        batchGetItemResult.ConsumedCapacity = new List <ConsumedCapacity>();
                        ConsumedCapacityUnmarshaller unmarshaller = ConsumedCapacityUnmarshaller.GetInstance();
                        while (context.Read())
                        {
                            if ((context.IsArrayElement) && (context.CurrentDepth == targetDepth))
                            {
                                batchGetItemResult.ConsumedCapacity.Add(unmarshaller.Unmarshall(context));
                            }
                            else if (context.IsEndArray)
                            {
                                break;
                            }
                        }
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth <= originalDepth)
                {
                    return(batchGetItemResult);
                }
            }


            return(batchGetItemResult);
        }
        private static void UnmarshallResult(JsonUnmarshallerContext context, BatchGetItemResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.TestExpression("Responses", targetDepth))
                {
                    context.Read();
                    response.Responses = new Dictionary <String, List <Dictionary <string, AttributeValue> > >();
                    if (context.CurrentTokenType == JsonToken.Null)
                    {
                        continue;
                    }
                    KeyValueUnmarshaller <string, List <Dictionary <string, AttributeValue> >, StringUnmarshaller, ListUnmarshaller <Dictionary <string, AttributeValue>, DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> > > unmarshaller = new KeyValueUnmarshaller <string, List <Dictionary <string, AttributeValue> >, StringUnmarshaller, ListUnmarshaller <Dictionary <string, AttributeValue>, DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> > >(StringUnmarshaller.GetInstance(), new ListUnmarshaller <Dictionary <string, AttributeValue>, DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> >(new DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller>(StringUnmarshaller.GetInstance(), AttributeValueUnmarshaller.GetInstance())));
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart || token == JsonToken.ObjectStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd || token == JsonToken.ObjectEnd)
                        {
                            break;
                        }
                        KeyValuePair <string, List <Dictionary <string, AttributeValue> > > kvp = unmarshaller.Unmarshall(context);
                        response.Responses.Add(kvp.Key, kvp.Value);
                    }
                    continue;
                }

                if (context.TestExpression("UnprocessedKeys", targetDepth))
                {
                    context.Read();
                    response.UnprocessedKeys = new Dictionary <String, KeysAndAttributes>();
                    if (context.CurrentTokenType == JsonToken.Null)
                    {
                        continue;
                    }
                    KeyValueUnmarshaller <string, KeysAndAttributes, StringUnmarshaller, KeysAndAttributesUnmarshaller> unmarshaller = new KeyValueUnmarshaller <string, KeysAndAttributes, StringUnmarshaller, KeysAndAttributesUnmarshaller>(StringUnmarshaller.GetInstance(), KeysAndAttributesUnmarshaller.GetInstance());
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart || token == JsonToken.ObjectStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd || token == JsonToken.ObjectEnd)
                        {
                            break;
                        }
                        KeyValuePair <string, KeysAndAttributes> kvp = unmarshaller.Unmarshall(context);
                        response.UnprocessedKeys.Add(kvp.Key, kvp.Value);
                    }
                    continue;
                }

                if (context.TestExpression("ConsumedCapacity", targetDepth))
                {
                    context.Read();
                    response.ConsumedCapacity = new List <ConsumedCapacity>();
                    if (context.CurrentTokenType == JsonToken.Null)
                    {
                        continue;
                    }
                    ConsumedCapacityUnmarshaller unmarshaller = ConsumedCapacityUnmarshaller.GetInstance();
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd)
                        {
                            break;
                        }
                        response.ConsumedCapacity.Add(unmarshaller.Unmarshall(context));
                    }
                    continue;
                }

                if (context.CurrentDepth <= originalDepth)
                {
                    return;
                }
            }

            return;
        }