@@ -162,7 +162,7 @@ private static Task<ItemResult> AddItemAsync(Container container, ExpandoObject
162
162
return t . Result ;
163
163
}
164
164
165
- return new ItemResult ( null , HttpStatusCode . InternalServerError ) ;
165
+ return new ItemResult ( null , mode , HttpStatusCode . InternalServerError ) ;
166
166
} , cancellationToken ) ;
167
167
return task ;
168
168
}
@@ -190,14 +190,24 @@ private static async Task<ItemResult> PopulateItem(Container container, ExpandoO
190
190
var upsertResponse = await container . UpsertItemAsync ( item , cancellationToken : cancellationToken ) ;
191
191
statusCode = upsertResponse . StatusCode ;
192
192
break ;
193
+ case DataWriteMode . DeleteStream :
194
+ ArgumentNullException . ThrowIfNull ( partitionKeyPath , nameof ( partitionKeyPath ) ) ;
195
+ var deleteMessage = await container . DeleteItemStreamAsync ( itemId , new PartitionKey ( GetPropertyValue ( item , partitionKeyPath . TrimStart ( '/' ) ) ) , cancellationToken : cancellationToken ) ;
196
+ statusCode = deleteMessage . StatusCode ;
197
+ break ;
198
+ case DataWriteMode . Delete :
199
+ ArgumentNullException . ThrowIfNull ( partitionKeyPath , nameof ( partitionKeyPath ) ) ;
200
+ var deleteResponse = await container . DeleteItemAsync < ExpandoObject > ( itemId , new PartitionKey ( GetPropertyValue ( item , partitionKeyPath . TrimStart ( '/' ) ) ) , cancellationToken : cancellationToken ) ;
201
+ statusCode = deleteResponse . StatusCode ;
202
+ break ;
193
203
}
194
204
195
205
if ( statusCode == null )
196
206
{
197
207
throw new ArgumentOutOfRangeException ( nameof ( mode ) , $ "Invalid data write mode specified: { mode } ") ;
198
208
}
199
209
200
- return new ItemResult ( itemId , statusCode . Value ) ;
210
+ return new ItemResult ( itemId , mode , statusCode . Value ) ;
201
211
}
202
212
203
213
private static MemoryStream CreateItemStream ( ExpandoObject item )
@@ -216,9 +226,10 @@ public IEnumerable<IDataExtensionSettings> GetSettings()
216
226
yield return new CosmosSinkSettings ( ) ;
217
227
}
218
228
219
- public record ItemResult ( string ? Id , HttpStatusCode StatusCode )
229
+ public record ItemResult ( string ? Id , DataWriteMode DataWriteMode , HttpStatusCode StatusCode )
220
230
{
221
- public bool IsSuccess => StatusCode is HttpStatusCode . OK or HttpStatusCode . Created ;
231
+ public bool IsSuccess => StatusCode is HttpStatusCode . OK or HttpStatusCode . Created ||
232
+ ( StatusCode is HttpStatusCode . NoContent or HttpStatusCode . NotFound && DataWriteMode is DataWriteMode . Delete or DataWriteMode . DeleteStream ) ;
222
233
public int ItemCount => IsSuccess ? 1 : 0 ;
223
234
}
224
235
}
0 commit comments