コード例 #1
0
        private void DoWork(object state)
        {
            Console.WriteLine("Timed Background Service is working.");
            Console.WriteLine("Estoy corriendo cada 5 secs");
            using (var scope = _scopeFactory.CreateScope())
            {
                IRipeningServices   ripeningServices   = scope.ServiceProvider.GetRequiredService <IRipeningServices>();
                IExperimentServices experimentServices = scope.ServiceProvider.GetRequiredService <IExperimentServices>();

                Ripening   ripening   = ripeningServices.GetCurrentRipening().Result;
                Experiment experiment = experimentServices.GetCurrentExperiment().Result;

                string message = "";

                if (ripening != null)
                {
                    DateTime ripeDay = DateTime.Now.AddDays(ripening.Cheese.DaysToRipe);
                    if (ripeDay < DateTime.Now)
                    {
                        message += "¡Tu maduracion esta lista!";
                    }
                }

                if (experiment != null && experiment.EstimatedEndTime < DateTime.Now)
                {
                    message += "¡Tu experimento esta listo!";
                }

                if (!string.IsNullOrEmpty(message))
                {
                    string token = TokenRepository.GetInstance().FirebaseToken;
                    _messaging.SendNotification(token, "Maduracion Terminada", message);
                }
            }
        }
コード例 #2
0
ファイル: RipeningServices.cs プロジェクト: Aguvar/cheeseIT
        public void ValidateMeasure(Measurement measure)
        {
            Cheese currentCheese = GetCurrentRipening().Result.Cheese;

            string message = "";

            if (Math.Abs(measure.Humidity - currentCheese.IdealHumidity) > currentCheese.HumidityThreshold)
            {
                message += $"Se ha registrado una humedad {(measure.Humidity - currentCheese.IdealHumidity) - currentCheese.HumidityThreshold}% por fuera del rango establecido en la maduracion actual. \n";
            }

            if (Math.Abs(measure.Temperature - currentCheese.IdealTemperature) > currentCheese.TemperatureThreshold)
            {
                message += $"Se ha registrado una temperatura {(measure.Temperature - currentCheese.IdealTemperature) - currentCheese.TemperatureThreshold}°C por fuera del rango establecido en la maduracion actual. \n";
            }

            if (!string.IsNullOrEmpty(message))
            {
                string token = TokenRepository.GetInstance().FirebaseToken;

                _messaging.SendNotification(token, "Alerta de Medicion", message);
            }
        }