Exemplo n.º 1
0
        public override async Task <TabulateExecOutputReply> TabulateExecOutput(TabulateExecOutputRequest request, ServerCallContext context)
        {
            await _semaphoreSlim.WaitAsync();

            var reply = new TabulateExecOutputReply();

            try
            {
                using var memoryStream = new MemoryStream(request.SimConfig.Length);
                request.SimConfig.WriteTo(memoryStream);
                memoryStream.Position = 0;
                var simConfig = Serializer.Deserialize <SimConfig>(memoryStream);

                var numDataColumns = ROpsApi.TabulateExecOutput(simConfig.SimOutput);

                reply.Payload = new TabulateExecOutputPayload();

                foreach (var numDataColumn in numDataColumns)
                {
                    var doubleColumn = new DoubleColumn
                    {
                        Name = numDataColumn.Name
                    };
                    doubleColumn.Doubles.Add(numDataColumn.Data);
                    reply.Payload.DoubleColumns.Add(doubleColumn);
                }
            }
            catch (Exception ex)
            {
                reply.Error = PopulateError(ex);
                _logger.LogError(ex, nameof(TabulateExecOutput));
            }
            finally
            {
                _semaphoreSlim.Release();
            }

            return(await Task.FromResult(reply));
        }