1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-29 09:10:09 +00:00
msfs-popout-panel-manager/WebServer/SimConnectService.cs

100 lines
2.7 KiB
C#
Raw Normal View History

2022-07-23 19:23:32 +00:00
using Microsoft.Extensions.Caching.Memory;
using MSFSPopoutPanelManager.SimConnectAgent.TouchPanel;
using System;
namespace MSFSPopoutPanelManager.WebServer
{
public class SimConnectService : ISimConnectService
{
private IMemoryCache _memCache;
private TouchPanelSimConnectProvider _simConnectorProvider;
public SimConnectService(IntPtr windowHandle)
{
_simConnectorProvider = new TouchPanelSimConnectProvider(windowHandle);
_simConnectorProvider.OnConnected += (source, e) =>
{
try { _memCache.Set("msfsStatus", true); } catch { }
};
_simConnectorProvider.OnDisconnected += (source, e) =>
{
try { _memCache.Set("msfsStatus", false); } catch { }
};
_simConnectorProvider.OnDataRefreshed += (source, e) =>
{
try { _memCache.Set("simdata", e); } catch { }
};
_simConnectorProvider.OnReceiveSystemEvent += (source, e) =>
{
try
{
var value = $"{e}-{DateTime.Now.Ticks}";
_memCache.Set("simSystemEvent", value.ToString());
}
catch { }
};
_simConnectorProvider.OnArduinoConnectionChanged += (source, e) =>
{
try { _memCache.Set("arduinoStatus", e); } catch { }
};
}
public TouchPanelConfigSetting TouchPanelConfigSetting { get; set; }
public void SetMemoryCache(IMemoryCache memCache)
{
_memCache = memCache;
}
public void Start()
{
_simConnectorProvider.Start(TouchPanelConfigSetting.IsUsedArduino);
}
public void Stop()
{
if (_simConnectorProvider != null)
{
_simConnectorProvider.Stop();
}
}
public void ExecAction(SimConnectActionData actionData)
{
_simConnectorProvider.ExecAction(actionData);
}
public void ResetSimConnectDataArea(string planeId)
{
_simConnectorProvider.ResetSimConnectDataArea(planeId);
}
2022-08-13 06:14:49 +00:00
public string GetFlightPlan()
{
return _simConnectorProvider.GetFlightPlan();
}
2022-07-23 19:23:32 +00:00
}
public interface ISimConnectService
{
public void SetMemoryCache(IMemoryCache memCache);
public void Start();
public void Stop();
public void ExecAction(SimConnectActionData data);
public void ResetSimConnectDataArea(string planeId);
2022-08-13 06:14:49 +00:00
public string GetFlightPlan();
2022-07-23 19:23:32 +00:00
public TouchPanelConfigSetting TouchPanelConfigSetting { get; set; }
}
}