@@ -55,14 +55,15 @@ public IList<Task<IObjectState>> SaveAllAsync(IList<IObjectState> states,
55
55
IList < IDictionary < string , IParseFieldOperation > > operationsList ,
56
56
string sessionToken ,
57
57
CancellationToken cancellationToken ) {
58
- var requests = states . Zip ( operationsList , ( item , ops ) => new Dictionary < string , object > {
59
- { "method" , ( item . ObjectId == null ? "POST" : "PUT" ) } ,
60
- { "path" , ( item . ObjectId == null ?
61
- string . Format ( "/1/classes/{0}" , Uri . EscapeDataString ( item . ClassName ) ) :
62
- string . Format ( "/1/classes/{0}/{1}" , Uri . EscapeDataString ( item . ClassName ) ,
63
- Uri . EscapeDataString ( item . ObjectId ) ) ) } ,
64
- { "body" , ParseObject . ToJSONObjectForSaving ( ops ) }
65
- } ) . Cast < object > ( ) . ToList ( ) ;
58
+
59
+ var requests = states
60
+ . Zip ( operationsList , ( item , ops ) => new ParseCommand (
61
+ item . ObjectId == null
62
+ ? string . Format ( "classes/{0}" , Uri . EscapeDataString ( item . ClassName ) )
63
+ : string . Format ( "classes/{0}/{1}" , Uri . EscapeDataString ( item . ClassName ) , Uri . EscapeDataString ( item . ObjectId ) ) ,
64
+ method : item . ObjectId == null ? "POST" : "PUT" ,
65
+ data : ParseObject . ToJSONObjectForSaving ( ops ) ) )
66
+ . ToList ( ) ;
66
67
67
68
var batchTasks = ExecuteBatchRequests ( requests , sessionToken , cancellationToken ) ;
68
69
var stateTasks = new List < Task < IObjectState > > ( ) ;
@@ -90,24 +91,25 @@ public Task DeleteAsync(IObjectState state,
90
91
public IList < Task > DeleteAllAsync ( IList < IObjectState > states ,
91
92
string sessionToken ,
92
93
CancellationToken cancellationToken ) {
93
- var requests = states . Where ( item => item . ObjectId != null ) . Select ( item => new Dictionary < string , object > {
94
- { "method" , "DELETE" } ,
95
- { "path" , string . Format ( "/1/classes/{0}/{1}" , Uri . EscapeDataString ( item . ClassName ) ,
96
- Uri . EscapeDataString ( item . ObjectId ) ) }
97
- } ) . Cast < object > ( ) . ToList ( ) ;
98
-
94
+ var requests = states
95
+ . Where ( item => item . ObjectId != null )
96
+ . Select ( item => new ParseCommand (
97
+ string . Format ( "classes/{0}/{1}" , Uri . EscapeDataString ( item . ClassName ) , Uri . EscapeDataString ( item . ObjectId ) ) ,
98
+ method : "DELETE" ,
99
+ data : null ) )
100
+ . ToList ( ) ;
99
101
return ExecuteBatchRequests ( requests , sessionToken , cancellationToken ) . Cast < Task > ( ) . ToList ( ) ;
100
102
}
101
103
102
104
// TODO (hallucinogen): move this out to a class to be used by Analytics
103
105
private const int MaximumBatchSize = 50 ;
104
- internal IList < Task < IDictionary < string , object > > > ExecuteBatchRequests ( IList < object > requests ,
106
+ internal IList < Task < IDictionary < string , object > > > ExecuteBatchRequests ( IList < ParseCommand > requests ,
105
107
string sessionToken ,
106
108
CancellationToken cancellationToken ) {
107
109
var tasks = new List < Task < IDictionary < string , object > > > ( ) ;
108
110
int batchSize = requests . Count ;
109
111
110
- IEnumerable < object > remaining = requests ;
112
+ IEnumerable < ParseCommand > remaining = requests ;
111
113
while ( batchSize > MaximumBatchSize ) {
112
114
var process = remaining . Take ( MaximumBatchSize ) . ToList ( ) ;
113
115
remaining = remaining . Skip ( MaximumBatchSize ) ;
@@ -121,7 +123,7 @@ internal IList<Task<IDictionary<string, object>>> ExecuteBatchRequests(IList<obj
121
123
return tasks ;
122
124
}
123
125
124
- private IList < Task < IDictionary < string , object > > > ExecuteBatchRequest ( IList < object > requests ,
126
+ private IList < Task < IDictionary < string , object > > > ExecuteBatchRequest ( IList < ParseCommand > requests ,
125
127
string sessionToken ,
126
128
CancellationToken cancellationToken ) {
127
129
var tasks = new List < Task < IDictionary < string , object > > > ( ) ;
@@ -133,10 +135,21 @@ private IList<Task<IDictionary<string, object>>> ExecuteBatchRequest(IList<objec
133
135
tasks . Add ( tcs . Task ) ;
134
136
}
135
137
136
- var command = new ParseCommand ( "/1/batch" ,
138
+ var encodedRequests = requests . Select ( r => {
139
+ var results = new Dictionary < string , object > {
140
+ { "method" , r . Method } ,
141
+ { "path" , r . Uri . AbsolutePath } ,
142
+ } ;
143
+
144
+ if ( r . DataObject != null ) {
145
+ results [ "body" ] = r . DataObject ;
146
+ }
147
+ return results ;
148
+ } ) . Cast < object > ( ) . ToList ( ) ;
149
+ var command = new ParseCommand ( "batch" ,
137
150
method : "POST" ,
138
151
sessionToken : sessionToken ,
139
- data : new Dictionary < string , object > { { "requests" , requests } } ) ;
152
+ data : new Dictionary < string , object > { { "requests" , encodedRequests } } ) ;
140
153
141
154
commandRunner . RunCommandAsync ( command , cancellationToken : cancellationToken ) . ContinueWith ( t => {
142
155
if ( t . IsFaulted || t . IsCanceled ) {
0 commit comments