コード例 #1
0
ファイル: SampleData.cs プロジェクト: gerry123/g42
    public void Initialize(IServiceProvider serviceProvider)
    {
      _logger.LogInformation("add sensors start");
      _context = serviceProvider.GetService<Context>();
      /*
      // delete all existing data (cascading delete) should be easier, methode of context?
      foreach (var sen in _context.Sensors)
      {
        _context.Remove(sen);
      }
      _context.SaveChanges();
      _logger.LogInformation("all data removed");
      */
      // add sensors
      AddSensor("28.641EBC020000/temperature", "Speicher oben", 0, 1);
      AddSensor("28.2224BC020000/temperature", "Speicher unten", 0, 2);
      AddSensor("28.533BBC020000/temperature", "Kessel", 0, 3);
      AddSensor("28.18E4BB020000/temperature", "Au�en", 0, 4);
      AddSensor("28.DB1EBC020000/temperature", "Vorlauf", 0, 5);
      AddSensor("28.DB0DBC020000/temperature", "R�cklauf", 0, 6);
      AddSensor("28.76E3BB020000/temperature", "Wohnzimmer", -1.2, 7);
      AddSensor("28.9B05BC020000/temperature", "Wintergarten", 0, 8);
      AddSensor("28.9820BC020000/temperature", "Solar-Wasser", 0, 9);
      AddSensor("28.7FE0BB020000/temperature", "Solar-Luft", 0, 10);
      AddSensor("28.3A3128060000/temperature", "Puffer Vorlauf", 0, 11);
      AddSensor("28.231A26060000/temperature", "Puffer R�cklauf", 0, 12);
      AddSensor("28.E52E28060000/temperature", "Kessel Vorlauf", 0, 13);
      AddSensor("28.7C2426060000/temperature", "Kessel R�cklauf", 0, 14);
      AddSensor("28.986927060000/temperature", "Reserve", 0, 15);


      /* SQL
      select * from Sensor_Se as Se
        inner join Measurement_Me as Me on Me.IdSe = Se.Id

      delete from Measurement_Me  

      */

      /*

      if(serviceProvider.GetService<IRelationalDatabaseCreator>().Exists())
      {
          if (!context.Sensors.Any())
          {
              var s1 = context.Sensors.Add(new Sensor { Name = "Sensor1" }).Entity;
              context.SaveChanges();
          }
      }

      */
    }
コード例 #2
0
 public MeasurementsController(ILoggerFactory loggerFactory, IServiceProvider serviceProvider)
 {
   _logger = loggerFactory.CreateLogger("MeasurementsController");
   _context = serviceProvider.GetService<Context>();
 }