/// <summary> /// 获取频道列表 /// </summary> /// <returns></returns> public async Task <List <Channel> > GetChannelList() { string filename = "channelList.json"; ResultDataTemplate <List <Channel> > channelResult = new ResultDataTemplate <List <Channel> >(); channelResult.Result = await FileHelper.Current.ReadObjectAsync <List <Channel> >(filename); if (channelResult.Result == null) { PostDataTemplate <AllChannelListRequest> postData = new PostDataTemplate <AllChannelListRequest>() { deviceId = DeviceInformationHelper.GetDeviceId(), request = new AllChannelListRequest() { type = "0" } }; channelResult = await PostJson <PostDataTemplate <AllChannelListRequest>, ResultDataTemplate <List <Channel> > >(ServiceUri.AllChannel, postData); if (channelResult != null && channelResult.Result != null) { await FileHelper.Current.WriteObjectAsync(channelResult.Result, filename); } } channelResult.Result.Insert(0, new Channel { IsTop = "False", NodeId = 0, NodeName = "头条" }); return(channelResult.Result); }
/// <summary> /// 获取新闻列表 /// </summary> /// <param name="nodeId">频道ID</param> /// <param name="pageIndex">页码</param> /// <returns></returns> public async Task <List <Essay> > GetEssayList(int nodeId, int pageIndex) { string filename = "essayList_" + nodeId + "_" + pageIndex + ".json"; ResultDataTemplate <List <Essay> > essayResult = new ResultDataTemplate <List <Essay> >(); if (!ConnectionHelper.IsInternetAvailable) //无网络 { essayResult.Result = await FileHelper.Current.ReadObjectAsync <List <Essay> >(filename); } else { PostDataTemplate <AllChannelListRequest> postData = new PostDataTemplate <AllChannelListRequest>() { deviceId = DeviceInformationHelper.GetDeviceId(), request = new AllChannelListRequest() { elementsCountPerPage = 20, nodeIds = nodeId, pageIndex = pageIndex, parentNodeId = "news", type = "null", } }; essayResult = await PostJson <PostDataTemplate <AllChannelListRequest>, ResultDataTemplate <List <Essay> > >(ServiceUri.AllChannelList, postData); if (essayResult != null && essayResult.Result != null) { await FileHelper.Current.WriteObjectAsync(essayResult.Result, filename); } } return(essayResult?.Result); }
private static void Prepare() { lock (_lockObject) { if (!_prepared) { UnityScreenSizeProvider.Initialize(); DeviceInformationHelper.SetScreenSizeProviderFactory(new UnityScreenSizeProviderFactory()); #if ENABLE_IL2CPP #pragma warning disable 612 /** * Workaround for known IL2CPP issue. * See https://issuetracker.unity3d.com/issues/il2cpp-use-of-windows-dot-foundation-dot-collections-dot-propertyset-throws-a-notsupportedexception-on-uwp * * NotSupportedException: Cannot call method * 'System.Boolean System.Runtime.InteropServices.WindowsRuntime.IMapToIDictionaryAdapter`2::System.Collections.Generic.IDictionary`2.TryGetValue(TKey,TValue&)'. * IL2CPP does not yet support calling this projected method. */ UnityApplicationSettings.Initialize(); UWPAppCenter.SetApplicationSettingsFactory(new UnityApplicationSettingsFactory()); /** * Workaround for another IL2CPP issue. * System.Net.Http.HttpClient doesn't work properly so, replace to unity specific implementation. */ UWPAppCenter.SetChannelGroupFactory(new UnityChannelGroupFactory()); #pragma warning restore 612 #endif _prepared = true; } } }
/// <summary> /// 阅读文章 /// 适用于新闻 和 攻略 /// </summary> /// <param name="contentId">文章Id</param> /// <returns></returns> public async Task <News> GetEssay(string contentId) { string filename = "news_" + contentId + ".json"; ResultDataTemplate <News> newsResult = new ResultDataTemplate <News>(); if (!ConnectionHelper.IsInternetAvailable) //无网络 { newsResult.Result = await FileHelper.Current.ReadObjectAsync <News>(filename); } else { PostDataTemplate <AllChannelListRequest> postData = new PostDataTemplate <AllChannelListRequest>() { request = new AllChannelListRequest { contentId = contentId, pageIndex = 1 }, deviceId = DeviceInformationHelper.GetDeviceId() }; newsResult = await PostJson <PostDataTemplate <AllChannelListRequest>, ResultDataTemplate <News> >(ServiceUri.TwoArticle, postData); if (newsResult != null && newsResult.Result != null) { await FileHelper.Current.WriteObjectAsync <News>(newsResult.Result, filename); } } return(newsResult?.Result); }
private static void Prepare() { lock (_lockObject) { if (!_prepared) { UnityScreenSizeProvider.Initialize(); DeviceInformationHelper.SetScreenSizeProviderFactory(new UnityScreenSizeProviderFactory()); /** * Workaround for known IL2CPP issue. * Currently it is not required, but since this workaround stores settings in separate file, * and not generic unity mechanism, a migration is required to transition users who store data in old file to built-in mechanism. * See https://issuetracker.unity3d.com/issues/il2cpp-use-of-windows-dot-foundation-dot-collections-dot-propertyset-throws-a-notsupportedexception-on-uwp * * NotSupportedException: Cannot call method * 'System.Boolean System.Runtime.InteropServices.WindowsRuntime.IMapToIDictionaryAdapter`2::System.Collections.Generic.IDictionary`2.TryGetValue(TKey,TValue&)'. * IL2CPP does not yet support calling this projected method. * TODO: Can be removed after migration for settings is added. */ UnityApplicationSettings.Initialize(); UWPAppCenter.SetApplicationSettingsFactory(new UnityApplicationSettingsFactory()); _prepared = true; } } }
public void VerifyDeviceInfoWhenManagmentClassNotAvailable() { var deviceInformation = new DeviceInformationHelper(); var factory = new MockManagmentClassFactory(); deviceInformation.SetManagmentClassFactory(factory); var device = Task.Run(() => deviceInformation.GetDeviceInformationAsync()).Result; }
/// <summary> /// Sets the two-letter ISO country code to send to the backend. /// </summary> /// <param name="countryCode">The two-letter ISO country code. See <see href="https://www.iso.org/obp/ui/#search"/> for more information.</param> public static void SetCountryCode(string countryCode) { if (countryCode != null && countryCode.Length != 2) { AppCenterLog.Error(AppCenterLog.LogTag, "App Center accepts only the two-letter ISO country code."); return; } DeviceInformationHelper.SetCountryCode(countryCode); }
public void SetWrapperSdk() { string wrapperName = $"expectedName {Guid.NewGuid()}"; string wrapperVersion = $"expectedVersion {Guid.NewGuid()}"; string releaseLabel = $"expectedLabel {Guid.NewGuid()}"; string updateDevKey = $"expectedUpdateDevKey {Guid.NewGuid()}"; string updatePackageHash = $"expectedHash {Guid.NewGuid()}"; string runtimeVersion = $"expectedRuntimeVersion {Guid.NewGuid()}"; WrapperSdk wrapperSdk = new WrapperSdk(wrapperName, wrapperVersion, runtimeVersion, releaseLabel, updateDevKey, updatePackageHash); DeviceInformationHelper.SetWrapperSdk(wrapperSdk); var deviceInformationHelper = new DeviceInformationHelper(); var device = deviceInformationHelper.GetDeviceInformationAsync().RunNotAsync(); Assert.AreEqual(wrapperName, device.WrapperSdkName); Assert.AreEqual(wrapperVersion, device.WrapperSdkVersion); Assert.AreEqual(releaseLabel, device.LiveUpdateReleaseLabel); Assert.AreEqual(updateDevKey, device.LiveUpdateDeploymentKey); Assert.AreEqual(updatePackageHash, device.LiveUpdatePackageHash); Assert.AreEqual(runtimeVersion, device.WrapperRuntimeVersion); }
public void VerifyScreenSizeProvider() { const string testScreenSize = "screen_size"; var informationInvalidated = false; var screenSizeProviderMock = new Mock <IScreenSizeProvider>(); var screenSizeProviderFactoryMock = new Mock <IScreenSizeProviderFactory>(); screenSizeProviderMock.Setup(provider => provider.ScreenSize).Returns(testScreenSize); screenSizeProviderFactoryMock.Setup(factory => factory.CreateScreenSizeProvider()).Returns(screenSizeProviderMock.Object); DeviceInformationHelper.SetScreenSizeProviderFactory(screenSizeProviderFactoryMock.Object); // Screen size is returned from screen size provider var device = Task.Run(() => new DeviceInformationHelper().GetDeviceInformationAsync()).Result; Assert.AreEqual(device.ScreenSize, testScreenSize); // InformationInvalidated is invoked when ScreenSizeChanged event is raised DeviceInformationHelper.InformationInvalidated += (sender, args) => { informationInvalidated = true; }; screenSizeProviderMock.Raise(provider => provider.ScreenSizeChanged += null, EventArgs.Empty); Assert.IsTrue(informationInvalidated); }
public void SetCountryCode() { // Mock event handler. var mockInformationInvalidated = new Mock <EventHandler>(); // Initialize device information helper. DeviceInformationHelper.InformationInvalidated += mockInformationInvalidated.Object; var deviceInformationHelper = new DeviceInformationHelper(); var device = deviceInformationHelper.GetDeviceInformationAsync().RunNotAsync(); Assert.IsNull(device.CarrierCountry); // Valid country code. var validCountryCode = "US"; AppCenter.SetCountryCode(validCountryCode); device = deviceInformationHelper.GetDeviceInformationAsync().RunNotAsync(); Assert.AreEqual(device.CarrierCountry, validCountryCode); mockInformationInvalidated.Verify(_ => _(It.IsAny <object>(), It.IsAny <EventArgs>()), Times.Once); // Invalid country code. var invalidCountryCode = "US1"; AppCenter.SetCountryCode(invalidCountryCode); device = deviceInformationHelper.GetDeviceInformationAsync().RunNotAsync(); // The code has not been updated and the event has not been called. Assert.AreEqual(device.CarrierCountry, validCountryCode); mockInformationInvalidated.Verify(_ => _(It.IsAny <object>(), It.IsAny <EventArgs>()), Times.Once); // Reset country code. AppCenter.SetCountryCode(null); device = deviceInformationHelper.GetDeviceInformationAsync().RunNotAsync(); Assert.IsNull(device.CarrierCountry); mockInformationInvalidated.Verify(_ => _(It.IsAny <object>(), It.IsAny <EventArgs>()), Times.Exactly(2)); // Clean. DeviceInformationHelper.InformationInvalidated -= mockInformationInvalidated.Object; }
/// <summary> /// A wrapper SDK can use this method to pass extra information to device properties. /// </summary> /// <param name="wrapperSdk">Wrapper SDK information.</param> public static void SetWrapperSdk(WrapperSdk wrapperSdk) { DeviceInformationHelper.SetWrapperSdk(wrapperSdk); }
public ViewModelBase() { IsDesktop = DeviceInformationHelper.IsDesktop(); }