Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client  = new Measure.MeasureClient(channel);

            using (var call = client.SendMeasure())
            {
                for (var i = 0; i < 5; i++)
                {
                    var measure = new MeasureRequest()
                    {
                        Name  = "Temp",
                        Value = Random.Next()
                    };
                    await call.RequestStream.WriteAsync(measure);

                    Console.WriteLine($"Measure send {measure.Value}");
                    await Task.Delay(2000);
                }

                await call.RequestStream.CompleteAsync();

                await call;
            }
        }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client  = new Measure.MeasureClient(channel);

            var authClient = new Auth.AuthClient(channel);
            var tokenReply = authClient.GetToken(new TokenRequest()
            {
                Name = "Coding4FunClient"
            });


            var headers = new Metadata();

            headers.Add("Authorization", $"Bearer {tokenReply.Token}");
            using (var call = client.SendMeasure(headers))
            {
                for (var i = 0; i < 5; i++)
                {
                    var measure = new MeasureRequest()
                    {
                        Name  = "Temp",
                        Value = Random.Next()
                    };
                    await call.RequestStream.WriteAsync(measure);

                    Console.WriteLine($"Measure send {measure.Value}");
                    await Task.Delay(2000);
                }

                await call.RequestStream.CompleteAsync();

                await call;
            }
        }
Ejemplo n.º 3
0
        public IEnumerable <Measure> GetMeasureList(MeasureRequest request = null)
        {
            request = request ?? new MeasureRequest();
            using (var dbContext = new ProjectDbContext())
            {
                IQueryable <Measure> Measure = dbContext.Measures;

                if (!string.IsNullOrEmpty(request.ProjectName))
                {
                    Measure = Measure.Where(u => u.ProjectName.Contains(request.ProjectName));
                }

                return(Measure.OrderByDescending(u => u.ID).ToPagedList(request.PageIndex, request.PageSize));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(MeasureRequest measuring)
        {
            return(await Task.Run(async() =>
            {
                var e = Convert.ToUInt64(measuring.EpochTime);
                var timestamp = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero)
                                .AddSeconds(e)
                                .DateTime;


                await _measureRepository.CreateAsync(new Measure
                {
                    Temperature = measuring.Temperature,
                    Timestamp = timestamp
                });


                return new OkObjectResult("Measure create OK");
            }));
        }
Ejemplo n.º 5
0
 public async Task <IActionResult> Create(
     [FromServices] IMeasureService measureService,
     [FromBody] MeasureRequest measuring) => await measureService.Create(measuring);
Ejemplo n.º 6
0
        public ActionResult Index(MeasureRequest request)
        {
            var result = this.ProjectService.GetMeasureList(request);

            return(View(result));
        }