Skip to content

Commit

Permalink
Broadlinkデバイスの種別判定不具合を修正。
Browse files Browse the repository at this point in the history
  • Loading branch information
ume05rw committed Jan 22, 2019
1 parent 5d9b6eb commit 5ec6d9e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 97 deletions.
96 changes: 0 additions & 96 deletions BrWebHost/Models/Stores/BrDeviceStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,102 +19,6 @@ public class BrDeviceStore : IDisposable
private static List<SharpBroadlink.Devices.IDevice> SbDevices
= new List<SharpBroadlink.Devices.IDevice>();

//private static IServiceProvider Provider = null;
//private static ILogger Logger = null;
//private static Task LoopRunner = null;
//private static Job _loopRunnerJob = null;

//public static void SetLoopRunner(IServiceProvider provider)
//{
// BrDeviceStore.Provider = provider;
// BrDeviceStore.Logger = BrDeviceStore.Provider.GetService<ILogger<BrDeviceStore>>();

// using (var serviceScope = BrDeviceStore.Provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
// {
// // ジョブを取得する。
// using (var jobStore = serviceScope.ServiceProvider.GetService<JobStore>())
// {
// BrDeviceStore._loopRunnerJob = jobStore.CreateJob("Broadlink-Device LoopScanner")
// .ConfigureAwait(false)
// .GetAwaiter()
// .GetResult();
// }

// // 最初の一回目スキャンは同期的に行う。
// Xb.Util.Out("First Broadlink Device Scan");

// using (var store = serviceScope.ServiceProvider.GetService<BrDeviceStore>())
// store.Refresh();
// }

// // なんか違和感がある実装。
// // 代替案はあるか?
// BrDeviceStore.LoopRunner = Task.Run(async () =>
// {
// var status = new LoopJobStatus();

// // 5分に1回、LAN上のBroadlinkデバイスをスキャンする。
// while (true)
// {
// try
// {
// try
// {
// if (BrDeviceStore.Provider == null)
// break;
// }
// catch (Exception)
// {
// break;
// }

// using (var serviceScope = BrDeviceStore.Provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
// using (var store = serviceScope.ServiceProvider.GetService<BrDeviceStore>())
// {
// await Task.Delay(1000 * 60 * 5);

// Xb.Util.Out("Regularly Broadlink Device Scan");

// var devs = store.Refresh();

// status.Count++;
// status.StatusMessage = $"Cached Device Count: {devs.Count()}";
// var json = JsonConvert.SerializeObject(status);

// await BrDeviceStore._loopRunnerJob.SetProgress((decimal)0.5, json);
// }
// }
// catch (Exception ex)
// {
// BrDeviceStore.Logger.LogError(ex, "BrDeviceStore.LoopRunner Failure.");

// Xb.Util.Out(ex);
// Xb.Util.Out("FUUUUUUUUUUUUUUUUUUUUUUCK!!!");
// Xb.Util.Out("Regularly Scan FAIL!!!!!!!!!!!!");
// //throw;

// // 1秒待機。DBアクセスを連続させない。
// await Task.Delay(1000);

// status.Count++;
// status.ErrorCount++;
// status.LatestError = string.Join(" ", Xb.Util.GetErrorString(ex));
// var json = JsonConvert.SerializeObject(status);
// await BrDeviceStore._loopRunnerJob.SetProgress((decimal)0.5, json);
// }
// }

// BrDeviceStore.ReleaseServiceProvider();

// Xb.Util.Out("BrDeviceStore.LoopScan Closed");
// });
//}

//public static void ReleaseServiceProvider()
//{
// BrDeviceStore.Provider = null;
//}


private Dbc _dbc;
private ControlSetStore _controlSetStore;
Expand Down
6 changes: 5 additions & 1 deletion BrWebHost/Models/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,13 @@ private void InitTimerJobs()
{
using (var serviceScope = this._provider.GetRequiredService<IServiceScopeFactory>().CreateScope())
using (var store = serviceScope.ServiceProvider.GetService<ControlSetStore>())
using (var brStore = serviceScope.ServiceProvider.GetService<BrDeviceStore>())
using (var dbc = serviceScope.ServiceProvider.GetService<Dbc>())
{
var entities = dbc.BrDevices.ToList();
var entities = brStore.GetList()
.GetAwaiter()
.GetResult();

store.EnsureBrControlSets(entities)
.ConfigureAwait(false)
.GetAwaiter()
Expand Down

0 comments on commit 5ec6d9e

Please sign in to comment.