我正在创建一个可移植的 MockGeoLocationWatcher,人们可以用它代替 IMvxGeoLocationWatcher 的具体实现,直到拥有一个实际的设备。这应该有助于开发和测试需要地理位置的应用程序。
该插件的 PluginLoader 类当前如下所示:
namespace Pidac.MvvmCross.Plugins.Location
{
public class PluginLoader : IMvxConfigurablePluginLoader
{
private bool _loaded;
public static readonly PluginLoader Instance = new PluginLoader();
public void EnsureLoaded()
{
if (_loaded)
return;
_loaded = true;
var locationWatcher = new MockGeoLocationWatcher();
var data = @"<?xml version='1.0' encoding='utf-8'?>
<WindowsPhoneEmulator xmlns='http://schemas.microsoft.com/WindowsPhoneEmulator/2009/08/SensorData'>
<SensorData>
<Header version='1' />
<GpsData latitude='48.619934106826' longitude='-84.5247359841114' />
<GpsData latitude='48.6852544862377' longitude='-83.9864059059864' />
<GpsData latitude='48.8445703681025' longitude='-83.7337203591114' />
<GpsData latitude='48.8662561090809' longitude='-83.2393355934864' />
<GpsData latitude='49.0825970371386' longitude='-83.0415816872364' />
<GpsData latitude='49.2621642999055' longitude='-82.7229781716114' />
<GpsData latitude='49.2621642999055' longitude='-82.6021285622364' />
<GpsData latitude='49.2047736379815' longitude='-82.3054977028614' />
</SensorData>
</WindowsPhoneEmulator>";
locationWatcher.SensorLocationData = data;
Mvx.RegisterSingleton(typeof(IMvxGeoLocationWatcher), locationWatcher);
}
public void Configure(IMvxPluginConfiguration configuration)
{
}
}
public class MockLocationWatcherConfiguration : IMvxPluginConfiguration
{
public static readonly MockLocationWatcherConfiguration Default = new MockLocationWatcherConfiguration();
// ideally, we should use this property to point to a file or string containing location data
// this should be configurable outside of code base.
public string SensorLocationData { get; set; }
}
}
我想通过 MockLocationWatcherConfiguration 的实例将当前硬编码到名为“data”的变量中的传感器数据传递,但不知道在调用 IMvxConfigurablePluginLoader.Configure(configuration) 之前 MvvmCross 框架期望在哪里加载此插件的配置。理想情况下,我应该通过配置指定这一点。
我查看了Json 插件的 PluginLoaded 实现,但仍然无法确定在 IMvxConfigurablePluginLoader.Configure 中尝试强制转换之前检索配置的位置。
任何想法或指针将不胜感激。
TIA。