コード例 #1
0
ファイル: City.cs プロジェクト: Eugene-El/MyCity
 void StartRain()
 {
     if (WeatherNow != Weather.Rainy)
     {
         WeatherNow = Weather.Rainy;
         Log("Weather now: Rainy", ConsoleColor.DarkCyan);
         RainEvent?.Invoke();
     }
 }
コード例 #2
0
ファイル: Prompt.cs プロジェクト: silverweed/colony
        private void cheatSpawnEvent(string[] tokens)
        {
            if (tokens.Length < 2)
            {
                TextController.Instance.Add("Available events: bear, skunk, attack, rain, toxic");
                return;
            }

            float timeout = -1;

            if (tokens.Length > 2)
            {
                try {
                    timeout = float.Parse(tokens[2]);
                } catch {}
            }

            Event evt = null;

            switch (tokens[1].ToLower())
            {
            case "bear":
                evt = new BearEvent();
                break;

            case "skunk":
                evt = new SkunkEvent();
                break;

            case "attack":
                evt = new AttackEvent();
                break;

            case "rain":
                evt = new RainEvent();
                break;

            case "toxic":
            case "toxicpollen":
                evt = new ToxicPollenEvent();
                break;

            default:
                return;
            }

            if (timeout >= 0)
            {
                evt.Timeout = timeout;
            }

            EventManager.Instance.LaunchEvent(evt);
        }
コード例 #3
0
 public void Insert(RainEvent rainEvent)
 {
     try{
         if (rainEvent.Id == 0)
         {
             _rainEventRepository.Insert(rainEvent);
         }
         else
         {
             _rainEventRepository.Update(rainEvent);
         }
     } catch (Exception ex) {
         throw new Exception(ex.Message);
     }
 }
コード例 #4
0
        // POST api/sensors
        public string Post([FromBody] SensorDataModel sensorDataModel)
        {
            try {
                var unitService               = new UnitService();
                var soilReadingService        = new SoilReadingService();
                var temperatureReadingService = new TemperatureReadingService();
                var rainEventService          = new RainEventService();
                var cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
                var now     = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, cstZone);

                var unitId = unitService.ValidateProductKey(sensorDataModel.ProductKey);
                if (unitId == -1)
                {
                    return("Invalid product key.");
                }
                var unitSettings = unitService.GetUnitById(unitId).Settings;
                var rainFlag     = (unitSettings != null && unitSettings.RainLimit < sensorDataModel.Rain);
                //if (unitSettings != null && unitSettings.RainLimit < sensorDataModel.Rain) {
                var rainEvent = new RainEvent {
                    DateTime   = now,
                    UnitId     = unitId,
                    RainAmount = sensorDataModel.Rain
                };
                rainEventService.Insert(rainEvent);

                //rainFlag = true;
                //}
                var soilLimitsDict = sensorDataModel.SoilReadings.ToDictionary(x => (int.Parse(x.SensorNumber) - 1), x => (unitSettings != null && x.SoilMoisture > unitSettings.SoilMoistureLimit));
                var tempFlag       = unitSettings != null && unitSettings.StopOnFreeze && sensorDataModel.Temperature < 34.0;
                var commandDict    = unitService.GetValveCommands(unitId, soilLimitsDict, tempFlag, rainFlag);

                soilReadingService.Insert(sensorDataModel.SoilReadings, unitId);
                var tempReading = new TemperatureReading {
                    UnitId      = unitId,
                    DateTime    = now,
                    Temperature = sensorDataModel.Temperature
                };
                temperatureReadingService.Insert(tempReading);

                var serializer = new JavaScriptSerializer();
                var jsonString = serializer.Serialize(commandDict);
                return(jsonString);
            } catch (Exception ex) {
                return(ex.Message);
            }
        }