Exemplo n.º 1
0
        /// <summary>
        /// Upsert (Insert or Update) multiple edges into the database using a TPL Dataflow block.
        /// This call uses the SQL API to upsert the edges as a document.
        /// </summary>
        /// <param name="edges">Edges to upsert</param>
        /// <param name="reportingCallback">[Optional] Method to be called based on the <paramref name="reportingInterval"/>. Generally used to provide a progress update to callers. Defaults to null./></param>
        /// <param name="reportingInterval">[Optional] interval in seconds to to call the reporting callback. Defaults to 10s</param>
        /// <param name="threads">[Optional] Number of threads to use for the paralel execution. Defaults to 4</param>
        /// <param name="cancellationToken">Cancellation token to cancel the operation</param>
        /// <exception cref="InvalidOperationException">Throws invalid operation exception if the GraphClient was initialized without a <see cref="CosmosClientSql"/>.</exception>
        /// <example>
        /// <![CDATA[
        /// await _client.UpsertVertex(elements, (partial) => { Console.WriteLine($"upserted {partial.Count()} vertices");
        /// ]]>
        /// </example>
        /// <returns><see cref="CosmosResponse"/> that tracks success status along with various performance parameters.</returns>
        public Task <IEnumerable <CosmosResponse> > UpsertEdges(IEnumerable <EdgeDefinition> edges, Action <IEnumerable <CosmosResponse> > reportingCallback = null, TimeSpan?reportingInterval = null, int threads = 4, CancellationToken cancellationToken = default(CancellationToken))
        {
            EnsureCosmosSqlClient();

            //Could've used InsertVertex instead of the lambda, but I don't want to the EnsureCosmosClient() for every call
            return(CosmosSqlClient.ProcessMultipleDocuments(edges, (EdgeDefinition edgeDef) => { return CosmosSqlClient.UpsertDocumentInternal(CosmosSerializer.ToGraphEdge(edgeDef.EdgeEntity, edgeDef.SourceVertex, edgeDef.TargetVertex, edgeDef.Single)); }, reportingCallback, reportingInterval, threads, cancellationToken));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Upsert (Insert or Update) multiple vertices into the database using a TPL Dataflow block.
 /// This call uses the SQL API to upsert the vertex]ices as a document.
 /// </summary>
 /// <param name="entities">Entites to upsert</param>
 /// <param name="reportingCallback">[Optional] Method to be called based on the <paramref name="reportingInterval"/>. Generally used to provide a progress update to callers. Defaults to null./></param>
 /// <param name="reportingInterval">[Optional] interval in seconds to to call the reporting callback. Defaults to 10s</param>
 /// <param name="threads">[Optional] Number of threads to use for the paralel execution. Defaults to 4</param>
 /// <param name="cancellationToken">Cancellation token to cancel the operation</param>
 /// <exception cref="InvalidOperationException">Throws invalid operation exception if the GraphClient was initialized without a <see cref="CosmosClientSql"/>.</exception>
 /// <example>
 /// <![CDATA[
 /// await _client.UpsertVertex(elements, (partial) => { Console.WriteLine($"upserted {partial.Count()} vertices");
 /// ]]>
 /// </example>
 /// <returns><see cref="CosmosResponse"/> that tracks success status along with various performance parameters.</returns>
 public Task <IEnumerable <CosmosResponse> > UpsertVertex <T>(IEnumerable <T> entities, Action <IEnumerable <CosmosResponse> > reportingCallback = null, TimeSpan?reportingInterval = null, int threads = 4, CancellationToken cancellationToken = default(CancellationToken))
 {
     EnsureCosmosSqlClient();
     //Could've used UpserVertex instead of the lambda, but I don't want to the EnsureCosmosClient() for every call
     return(CosmosSqlClient.ProcessMultipleDocuments(entities, (T entity) => { return CosmosSqlClient.UpsertDocumentInternal(CosmosSerializer.ToGraphVertex <T>(entity)); }, reportingCallback, reportingInterval, threads, cancellationToken));
 }