コード例 #1
0
        private async Task <byte[]> GetFileSensorValueBytesAsync(string product, string path)
        {
            var cts = new CancellationTokenSource();

            using var stream = new MemoryStream();
            GetFileSensorValueMessage request = new GetFileSensorValueMessage()
            {
                Path = path, Product = product
            };

            using (var streamingCall = _sensorsClient.GetFileSensorStream(request))
            {
                try
                {
                    await foreach (var val in streamingCall.ResponseStream.ReadAllAsync(cts.Token))
                    {
                        byte[] currentBytes = val.BytesData.ToByteArray();
                        stream.Write(currentBytes, 0, currentBytes.Length);
                    }
                }
                catch (Exception e)
                {
                    Logger.Error($"Error while loading file for {product}/{path}: {e}");
                }
            }

            return(stream.ToArray());
        }
コード例 #2
0
        public override async Task GetFileSensorStream(GetFileSensorValueMessage request, IServerStreamWriter <FileStreamMessage> responseStream,
                                                       ServerCallContext context)
        {
            var httpContext = context.GetHttpContext();

            var sensorValue = _monitoringCore.GetFileSensorValue(httpContext.User as User, request.Product, request.Path);

            byte[] bytes        = Encoding.UTF8.GetBytes(sensorValue);
            int    count        = 0;
            int    currentIndex = 0;
            int    bytesLeft    = bytes.Length;

            while (currentIndex < bytesLeft)
            {
                FileStreamMessage message = new FileStreamMessage();
                if (bytesLeft <= BLOCK_SIZE)
                {
                    message.BytesData  = ByteString.CopyFrom(bytes);
                    message.BlockSize  = bytesLeft;
                    message.BlockIndex = count;
                    currentIndex       = bytesLeft;
                }
                else
                {
                    message.BytesData  = ByteString.CopyFrom(bytes[currentIndex..(BLOCK_SIZE + currentIndex)]);
コード例 #3
0
        public override string GetFileSensorValueExtension(string product, string path)
        {
            GetFileSensorValueMessage request = new GetFileSensorValueMessage()
            {
                Path = path, Product = product
            };

            return(_sensorsClient.GetFileSensorExtension(request).Data);
        }