Exemple #1
0
 public static KeysAndAttributesUnmarshaller GetInstance()
 {
     if (instance == null)
     {
         instance = new KeysAndAttributesUnmarshaller();
     }
     return(instance);
 }
        public BatchGetItemResult Unmarshall(JsonUnmarshallerContext context)
        {
            BatchGetItemResult batchGetItemResult = new BatchGetItemResult();

            batchGetItemResult.Responses       = null;
            batchGetItemResult.UnprocessedKeys = 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, BatchResponse>();
                        KeyValueUnmarshaller <string, BatchResponse, StringUnmarshaller, BatchResponseUnmarshaller> unmarshaller = new KeyValueUnmarshaller <string, BatchResponse, StringUnmarshaller, BatchResponseUnmarshaller>(StringUnmarshaller.GetInstance(), BatchResponseUnmarshaller.GetInstance());
                        while (context.Read())
                        {
                            if (((context.IsStartArray || context.IsStartElement || context.IsLeafValue) && (context.CurrentDepth == targetDepth)) ||
                                ((context.IsKey) && (context.CurrentDepth == targetDepth + 1)))
                            {
                                KeyValuePair <string, BatchResponse> 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;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth <= originalDepth)
                {
                    return(batchGetItemResult);
                }
            }
            return(batchGetItemResult);
        }