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 <AddAddPacketsPartsResult> AddIfNotExistsPacketsPartsAsync(AgentIdentifierData agentId, IList <AddPacketPartRequest> requests, CancellationToken cancellationToken = default(CancellationToken)) { var leaseResult = await this.dbClusterService.RenewLeaseAsync(cancellationToken); var store = this.GetPacketsStoreRoundRobin(leaseResult.ReservedList); return(await store.AddIfNotExistsPacketsPartsAsync(agentId, requests, cancellationToken)); }
public AgentDynamicConfiguration GetConfigurationData(AgentIdentifierData idData) { var cnf = this.config; return(new AgentDynamicConfiguration { Token = cnf.GetHashCode().ToString(), StreamFactory = () => new MemoryStream(Encoding.UTF8.GetBytes(cnf)), }); }
private AddPacketPartRequest CreateAddPacketRequest(AgentIdentifierData agentIdentifierData, PacketFormDataItem item, byte[] bytes) { return(new AddPacketPartRequest { PacketId = item.PacketId, ProviderKey = item.ProviderKey, StartPosition = item.StartPosition, EndPosition = item.EndPosition, IsFinal = item.IsFinal, Bytes = bytes, }); }
public async Task <AddAddPacketsPartsResult> AddIfNotExistsPacketsPartsAsync(AgentIdentifierData agentId, IList <AddPacketPartRequest> requests, CancellationToken cancellationToken = default(CancellationToken)) { if (requests == null) { throw new ArgumentException("requests"); } if (!requests.Any()) { return(AddAddPacketsPartsResult.EmptyResult()); } if (!this.initialized) { await this.InitAsync(cancellationToken); } // IsOrdered = false, неупорядоченные операции - при выполнении отдельных операций они выполняются не упорядочено и они не останавливают исполнение остальных операций try { await this.chunks.InsertManyAsync(requests.Select(this.Get), new InsertManyOptions() { IsOrdered = false }); return(AddAddPacketsPartsResult.CreateResult(this.storageToken, requests.Select(request => AddAddPacketPartResult.SuccessResult(request)))); } catch (MongoBulkWriteOperationException ex) { // Instrumentation ??? var results = new List <AddAddPacketPartResult>(); for (int i = 0; i < requests.Count; i++) { var request = requests[i]; var rqNonDupKeyErrors = ex.WriteErrors.Where(x => x.Index == i && x.Category != ServerErrorCategory.DuplicateKey); results.Add(rqNonDupKeyErrors.Any() ? AddAddPacketPartResult.FailResult(request) : AddAddPacketPartResult.SuccessResult(request)); } return(AddAddPacketsPartsResult.CreateResult(this.storageToken, results)); } }