private PacketPart Get(AddPacketPartRequest request) { return(new PacketPart { ProviderKey = request.ProviderKey, PacketId = request.PacketId, IsFinal = request.IsFinal, StartPosition = request.StartPosition, EndPosition = request.EndPosition, Bytes = request.Bytes, FinalPartTransferTime = request.IsFinal ? (DateTime?)DateTime.UtcNow : null, }); }
public async Task <AddAddPacketPartResult> AddIfNotExistsPacketPartAsync(AgentIdentifierData agentId, AddPacketPartRequest request, CancellationToken cancellationToken = default(CancellationToken)) { if (request == null) { throw new ArgumentException("request"); } if (!this.initialized) { await this.InitAsync(cancellationToken); } try { await this.UpdateLeaseIfNeeded(); await this.chunks.InsertOneAsync(this.Get(request)); return(AddAddPacketPartResult.SuccessResult(request)); } catch (MongoWriteException ex) { // Instrumentation ??? var nonDupKeyExceptions = ex.WriteError.Category != ServerErrorCategory.DuplicateKey; if (nonDupKeyExceptions) { return(AddAddPacketPartResult.FailResult(request)); } return(AddAddPacketPartResult.SuccessResult(request)); } }
public async Task <AddAddPacketPartResult> AddIfNotExistsPacketPartAsync(AgentIdentifierData agentId, AddPacketPartRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var leaseResult = await this.dbClusterService.RenewLeaseAsync(cancellationToken); var store = this.GetPacketsStoreRoundRobin(leaseResult.ReservedList); return(await store.AddIfNotExistsPacketPartAsync(agentId, request, cancellationToken)); }