public async Task<bool> UpdateTileNotifications() { MetroEventSource.Log.Info("Setting Tile Notifications Started"); await DeleteOldImages(); TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true); AppSettings settings = new AppSettings(); ApiClient client = new ApiClient(); ServerListItem server = settings.GetServer(); if(server == null) { return false; } List<MediaItem> items = await client.GetResentItems(); foreach(MediaItem item in items) { string itemImage = "http://" + server + "/mediabrowser/Items/" + item.Id + "/Images/Thumb?Width=310&Height=150"; string name = item.Name; string imageName = "TileImage-" + item.Id + ".jpg"; // get image data and save it byte[] image = await client.GetImage(item.Id, "Thumb", 310, 150, "jpg"); if(image != null) { var storageFileTask = await ApplicationData.Current.LocalFolder.CreateFileAsync(imageName, CreationCollisionOption.ReplaceExisting); await FileIO.WriteBytesAsync(storageFileTask, image); XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Image); //XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150ImageAndText01); //XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text"); //tileTextAttributes[0].InnerText = name; XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image"); ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appdata:///local/" + imageName); ((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "item thumb"); TileNotification tileNotification = new TileNotification(tileXml); tileNotification.ExpirationTime = DateTimeOffset.UtcNow.AddDays(90); TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); } } MetroEventSource.Log.Info("Setting Tile Notifications Ended"); return true; }
private async void OnResume(object sender, object e) { MetroEventSource.Log.Info("App Resuming"); socketManager.CloseWebSocket(); await socketManager.SetupWebSocket(); ApiClient apiClient = new ApiClient(); try { await apiClient.SetCapabilities(); } catch (Exception exp) { //App.AddNotification(new Notification() { Title = "Set Capabilities Error", Message = exp.Message }); } }
public async static void ReInitializeWebSocket() { socketManager.CloseWebSocket(); await socketManager.SetupWebSocket(); ApiClient apiClient = new ApiClient(); try { await apiClient.SetCapabilities(); } catch (Exception exp) { MetroEventSource.Log.Info("Set Capabilities Error - " + exp.Message); //App.AddNotification(new Notification() { Title = "Set Capabilities Error", Message = exp.Message }); } }
private async void mainWebPage_LoadCompleted(object sender, NavigationEventArgs e) { // extract the luser and security token info bool canSetRemote = false; // extractte user data try { AppSettings settings = new AppSettings(); string[] userIdCall = { "if(typeof Dashboard != 'undefined'){Dashboard.getCurrentUserId()}" }; string userIdData = await mainWebPage.InvokeScriptAsync("eval", userIdCall); settings.SaveUserId(userIdData); string[] accessTokenCall = { "if(typeof ApiClient != 'undefined'){ApiClient.accessToken()}" }; string accessTokenData = await mainWebPage.InvokeScriptAsync("eval", accessTokenCall); settings.SaveAccessToken(accessTokenData); if(string.IsNullOrEmpty(userIdData) == false && string.IsNullOrEmpty(accessTokenData) == false) { canSetRemote = true; } } catch (Exception exp) { MetroEventSource.Log.Info("Error getting user data : " + exp.ToString()); App.AddNotification(new Notification() { Title = "Error Extracting Current User Info", Message = exp.Message }); } if (canSetRemote == false) { return; // cant set remote so return } // now set the remote control target try { // try to call set player in client ApiClient client = new ApiClient(); SessionInfo session = await client.GetSessionInfo(); string userId = null; if (session != null) { string itemObj = "{\"deviceName\":\"Smart Player\",\"id\":\"" + session.Id + "\",\"name\":\"BMP\",\"playableMediaTypes\":\"Video\",\"supportedCommands\":\"PlayNow\"}"; string[] args = { "MediaController.setActivePlayer(\"Remote Control\", " + itemObj + ")" }; await mainWebPage.InvokeScriptAsync("eval", args); } } catch(Exception exp) { App.AddNotification(new Notification() { Title = "Error Setting Remote Control Target", Message = exp.Message }); } }