static async Task HandleChangesAsync(IReadOnlyCollection <object> changes, CancellationToken cancellationToken) { MongoSink.BlobUploader blobUploader = new MongoSink.BlobUploader( blobConnectionString, blobContainer); MongoSink.MongoSink mongoSink = new MongoSink.MongoSink(destConnectionString, destDBName, destContainerName, insertRetries, blobConnectionString, blobContainer, isUpsert); SourceTransformation sourceTransformation = null; if (!string.IsNullOrEmpty(sourceKeyTransformationString)) { try { sourceTransformation = JsonConvert.DeserializeObject <SourceTransformation> (sourceKeyTransformationString); } catch (Exception exp) { Console.WriteLine(exp.Message); } } Transformation transformation = new Transformation(transformationType, sourceKeys, destinationKey, delimiter, sourceTransformation, swapKeyValues); Console.WriteLine("Received data from the source:" + changes.Count.ToString()); foreach (object item in changes) { try { //Console.WriteLine(item.ToString()); JObject objects = JObject.Parse(item.ToString()); objects.Remove("_lsn"); objects.Remove("_metadata"); objects.Remove("_id"); string json = objects.ToString(); MongoDB.Bson.BsonDocument bdoc = CosmosDbSchemaDecoder.GetBsonDocument(json, false); if (transformationType != "NONE") { transformation.Execute(bdoc); } await mongoSink.InsertAsync(bdoc, source.Token); } catch (Exception exp) { blobUploader.Upload(item.ToString()); } } }
private void uploadFailedDocumentsToBlob(string failedData) { try { BlobUploader blobUploader = new BlobUploader(this.BlobConnectionString, this.BlobContainerName); blobUploader.Upload(failedData); } catch (Exception exp) { Console.WriteLine(exp.Message); throw; } }
public BlobToCosmos(string blobConnection, string blobContainer, string mongoConnection, string mongoDatabase, string mongoCollection ) { this.BlobConnectionString = blobConnection; this.MongoConnectionString = mongoConnection; this.BlobContainer = blobContainer; this.MongoDatabase = mongoDatabase; this.MongoCollection = mongoCollection; this.BlobUploader = new BlobUploader(BlobConnectionString, BlobContainer); }