internal object ProcessBatchResponse(object result, IList<int> batchEtags)
{
if (result == null)
return null;
var list = new JsonArray();
var resultList = (IList<object>)result;
int i = 0;
foreach (var row in resultList)
{
if (row == null)
{
// row is null when omit_response_on_success = true
list.Add(null);
}
else
{
var batchResult = (IDictionary<string, object>)row;
var code = Convert.ToInt64(batchResult["code"], CultureInfo.InvariantCulture);
object bodyAsJsonObject = null;
try
{
if (batchEtags != null && batchEtags.Contains(i))
{
var jsonObject = new JsonObject();
var originalHeaders = (IList<object>)batchResult["headers"];
var headers = new JsonObject();
foreach (var originalHeader in originalHeaders)
{
var dict = (IDictionary<string, object>)originalHeader;
headers[(string)dict["name"]] = dict["value"];
}
jsonObject["headers"] = headers;
if (code != 304)
{
var body = (string)batchResult["body"];
jsonObject["body"] = bodyAsJsonObject = ProcessResponse(null, body, null, true, null);
}
bodyAsJsonObject = jsonObject;
}
else
{
var body = (string)batchResult["body"];
bodyAsJsonObject = ProcessResponse(null, body, null, false, null);
}
list.Add(bodyAsJsonObject);
}
catch (Exception ex)
{
list.Add(ex);
}
}
i++;
}
return list;
}
}