@@ -55,14 +55,15 @@ public IList<Task<IObjectState>> SaveAllAsync(IList<IObjectState> states,
5555 IList < IDictionary < string , IParseFieldOperation > > operationsList ,
5656 string sessionToken ,
5757 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 ( ) ;
6667
6768 var batchTasks = ExecuteBatchRequests ( requests , sessionToken , cancellationToken ) ;
6869 var stateTasks = new List < Task < IObjectState > > ( ) ;
@@ -90,24 +91,25 @@ public Task DeleteAsync(IObjectState state,
9091 public IList < Task > DeleteAllAsync ( IList < IObjectState > states ,
9192 string sessionToken ,
9293 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 ( ) ;
99101 return ExecuteBatchRequests ( requests , sessionToken , cancellationToken ) . Cast < Task > ( ) . ToList ( ) ;
100102 }
101103
102104 // TODO (hallucinogen): move this out to a class to be used by Analytics
103105 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 ,
105107 string sessionToken ,
106108 CancellationToken cancellationToken ) {
107109 var tasks = new List < Task < IDictionary < string , object > > > ( ) ;
108110 int batchSize = requests . Count ;
109111
110- IEnumerable < object > remaining = requests ;
112+ IEnumerable < ParseCommand > remaining = requests ;
111113 while ( batchSize > MaximumBatchSize ) {
112114 var process = remaining . Take ( MaximumBatchSize ) . ToList ( ) ;
113115 remaining = remaining . Skip ( MaximumBatchSize ) ;
@@ -121,7 +123,7 @@ internal IList<Task<IDictionary<string, object>>> ExecuteBatchRequests(IList<obj
121123 return tasks ;
122124 }
123125
124- private IList < Task < IDictionary < string , object > > > ExecuteBatchRequest ( IList < object > requests ,
126+ private IList < Task < IDictionary < string , object > > > ExecuteBatchRequest ( IList < ParseCommand > requests ,
125127 string sessionToken ,
126128 CancellationToken cancellationToken ) {
127129 var tasks = new List < Task < IDictionary < string , object > > > ( ) ;
@@ -133,10 +135,21 @@ private IList<Task<IDictionary<string, object>>> ExecuteBatchRequest(IList<objec
133135 tasks . Add ( tcs . Task ) ;
134136 }
135137
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" ,
137150 method : "POST" ,
138151 sessionToken : sessionToken ,
139- data : new Dictionary < string , object > { { "requests" , requests } } ) ;
152+ data : new Dictionary < string , object > { { "requests" , encodedRequests } } ) ;
140153
141154 commandRunner . RunCommandAsync ( command , cancellationToken : cancellationToken ) . ContinueWith ( t => {
142155 if ( t . IsFaulted || t . IsCanceled ) {
0 commit comments