public async Task Put() { using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) { var input = await context.ReadForMemoryAsync(RequestBodyStream(), "Sorters"); if (input.TryGet("Sorters", out BlittableJsonReaderArray sorters) == false) { ThrowRequiredPropertyNameInRequest("Sorters"); } var command = new PutSortersCommand(Database.Name, GetRaftRequestIdFromQuery()); foreach (var sorterToAdd in sorters) { var sorterDefinition = JsonDeserializationServer.SorterDefinition((BlittableJsonReaderObject)sorterToAdd); sorterDefinition.Name = sorterDefinition.Name?.Trim(); if (LoggingSource.AuditLog.IsInfoEnabled) { var clientCert = GetCurrentCertificate(); var auditLog = LoggingSource.AuditLog.GetLogger(Database.Name, "Audit"); auditLog.Info($"Sorter {sorterDefinition.Name} PUT by {clientCert?.Subject} {clientCert?.Thumbprint} with definition: {sorterToAdd}"); } if (string.IsNullOrWhiteSpace(sorterDefinition.Name)) { throw new ArgumentException($"Sorter must have a '{nameof(SorterDefinition.Name)}' field"); } if (string.IsNullOrWhiteSpace(sorterDefinition.Code)) { throw new ArgumentException($"Sorter must have a '{nameof(SorterDefinition.Code)}' field"); } // check if sorter is compilable SorterCompilationCache.AddSorter(sorterDefinition, Database.Name); command.Sorters.Add(sorterDefinition); } var index = (await ServerStore.SendToLeaderAsync(command)).Index; await Database.RachisLogIndexNotifications.WaitForIndexNotification(index, ServerStore.Engine.OperationTimeout); NoContentStatus(); HttpContext.Response.StatusCode = (int)HttpStatusCode.Created; } }
public CustomComparatorSource(string sorterName, string databaseName, IndexQueryServerSide query) { _query = query; _activator = SorterCompilationCache.GetSorter(sorterName, databaseName); }