Пример #1
0
 public static WriteRequestUnmarshaller GetInstance()
 {
     if (instance == null)
     {
         instance = new WriteRequestUnmarshaller();
     }
     return(instance);
 }
Пример #2
0
        public BatchWriteItemResult Unmarshall(JsonUnmarshallerContext context)
        {
            BatchWriteItemResult batchWriteItemResult = new BatchWriteItemResult();

            batchWriteItemResult.Responses        = null;
            batchWriteItemResult.UnprocessedItems = 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))
                    {
                        batchWriteItemResult.Responses = new Dictionary <String, BatchWriteResponse>();
                        KeyValueUnmarshaller <string, BatchWriteResponse, StringUnmarshaller, BatchWriteResponseUnmarshaller> unmarshaller = new KeyValueUnmarshaller <string, BatchWriteResponse, StringUnmarshaller, BatchWriteResponseUnmarshaller>(StringUnmarshaller.GetInstance(), BatchWriteResponseUnmarshaller.GetInstance());
                        while (context.Read())
                        {
                            if (((context.IsStartArray || context.IsStartElement || context.IsLeafValue) && (context.CurrentDepth == targetDepth)) ||
                                ((context.IsKey) && (context.CurrentDepth == targetDepth + 1)))
                            {
                                KeyValuePair <string, BatchWriteResponse> kvp = unmarshaller.Unmarshall(context);
                                batchWriteItemResult.Responses.Add(kvp.Key, kvp.Value);
                            }
                            else if (context.IsEndElement)
                            {
                                break;
                            }
                        }
                        continue;
                    }

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