public async Task <IHttpActionResult> Post([FromBody] GraphQLQuery query) { if (WebServer.isBusy) { var result = new GraphQLExecutionResult(); result.errors.Add(new ExecutionError("Service is busy...")); return(Ok(result)); } else { WebServer.isBusy = true; ResolverEntry aEntry = new ResolverEntry(WebServer.Doc, WebServer.aRevitTask); GraphQLExecutionResult result = await aEntry.GetResultAsync(query); WebServer.isBusy = false; return(Ok(result)); } }
private async Task ProcessMessagesAsync(Message message, CancellationToken token) { // Process the message Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}"); if (message.Label == "Request") { // Complete the message so that it is not received again. // This can be done only if the queueClient is created in ReceiveMode.PeekLock mode (which is default). await queueClient.CompleteAsync(message.SystemProperties.LockToken); GraphQLExecutionResult result = null; if (_marconiIsBusy) { } else { _marconiIsBusy = true; try { var start = DateTime.UtcNow; string query = Encoding.UTF8.GetString(message.Body); ResolverEntry aEntry = new ResolverEntry(_doc, aRevitTask); result = await aEntry.GetResultAsync(JsonSerializer.Deserialize <GraphQLQuery>(query)); } catch (Exception e) { var m = e.Message; } _marconiIsBusy = false; } try { var responseMessage = new Message(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(result))) { ContentType = "application/json", Label = "Response", CorrelationId = message.MessageId, MessageId = Guid.NewGuid().ToString(), TimeToLive = TimeSpan.FromMinutes(5) }; // Send the message to the queue IQueueClient queueResponseClient = new QueueClient(ServiceBusConnectionStringBuilder); await queueClient.SendAsync(responseMessage); } catch (Exception e) { var m = e.Message; } } else { await queueClient.AbandonAsync(message.SystemProperties.LockToken); } // Note: Use the cancellationToken passed as necessary to determine if the queueClient has already been closed. // If queueClient has already been Closed, you may chose to not call CompleteAsync() or AbandonAsync() etc. calls // to avoid unnecessary exceptions. }