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 });
            }
        }
        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;
        }
        public static int SetupAudioBitrate(ComboBox comboBox)
        {
            List<ComboBoxData> audioBitrateItems = new List<ComboBoxData>();
            audioBitrateItems.Add(new ComboBoxData() { DataName = "720 K", DataValueInt = 720000 });
            audioBitrateItems.Add(new ComboBoxData() { DataName = "448 K", DataValueInt = 448000 });
            audioBitrateItems.Add(new ComboBoxData() { DataName = "320 K", DataValueInt = 320000 });
            audioBitrateItems.Add(new ComboBoxData() { DataName = "256 K", DataValueInt = 256000 });
            audioBitrateItems.Add(new ComboBoxData() { DataName = "196 K", DataValueInt = 196000 });
            audioBitrateItems.Add(new ComboBoxData() { DataName = "128 K", DataValueInt = 128000 });
            audioBitrateItems.Add(new ComboBoxData() { DataName = "96 K", DataValueInt = 96000 });
            audioBitrateItems.Add(new ComboBoxData() { DataName = "64 K", DataValueInt = 64000 });
            comboBox.ItemsSource = audioBitrateItems;

            AppSettings settings = new AppSettings();
            int audioBitrateSetting = settings.GetAppSettingInt("audio_bitrate");
            if (audioBitrateSetting == -1)
            {
                audioBitrateSetting = 128000;
            }
            comboBox.SelectedItem = audioBitrateItems[GetSelectedIntItem(audioBitrateItems, audioBitrateSetting)];

            return audioBitrateSetting;
        }
        public static int SetupAudioChannel(ComboBox comboBox)
        {
            List<ComboBoxData> audioChannelList = new List<ComboBoxData>();
            audioChannelList.Add(new ComboBoxData() { DataName = "1", DataValueInt = 1 });
            audioChannelList.Add(new ComboBoxData() { DataName = "2", DataValueInt = 2 });
            audioChannelList.Add(new ComboBoxData() { DataName = "3", DataValueInt = 3 });
            audioChannelList.Add(new ComboBoxData() { DataName = "4", DataValueInt = 4 });
            audioChannelList.Add(new ComboBoxData() { DataName = "5", DataValueInt = 5 });
            audioChannelList.Add(new ComboBoxData() { DataName = "6", DataValueInt = 6 });
            comboBox.ItemsSource = audioChannelList;

            AppSettings settings = new AppSettings();
            int audioChannelsSetting = settings.GetAppSettingInt("audio_channels");
            if (audioChannelsSetting == -1)
            {
                audioChannelsSetting = 6;
            }
            comboBox.SelectedItem = audioChannelList[GetSelectedIntItem(audioChannelList, audioChannelsSetting)];

            return audioChannelsSetting;
        }
        public static int SetupVideoMaxWidth(ComboBox comboBox)
        {
            List<ComboBoxData> videoMaxWidthItems = new List<ComboBoxData>();
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "1920", DataValueInt = 1920 });
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "1600", DataValueInt = 1600 });
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "1440", DataValueInt = 1440 });
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "1280", DataValueInt = 1280 });
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "1024", DataValueInt = 1024 });
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "800", DataValueInt = 800 });
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "720", DataValueInt = 720 });
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "640", DataValueInt = 640 });
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "560", DataValueInt = 560 });
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "480", DataValueInt = 480 });
            videoMaxWidthItems.Add(new ComboBoxData() { DataName = "376", DataValueInt = 376 });
            comboBox.ItemsSource = videoMaxWidthItems;

            AppSettings settings = new AppSettings();
            int videoMaxWidthSetting = settings.GetAppSettingInt("video_max_width");
            if (videoMaxWidthSetting == -1)
            {
                videoMaxWidthSetting = 1920;
            }
            comboBox.SelectedItem = videoMaxWidthItems[GetSelectedIntItem(videoMaxWidthItems, videoMaxWidthSetting)];

            return videoMaxWidthSetting;
        }
        public static int SetupVideoBitrate(ComboBox comboBox)
        {
            List<ComboBoxData> videoBitrateItems = new List<ComboBoxData>();
            videoBitrateItems.Add(new ComboBoxData() { DataName = "100 M", DataValueInt = 100000000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "50 M", DataValueInt = 50000000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "20 M", DataValueInt = 20000000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "15 M", DataValueInt = 15000000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "10 M", DataValueInt = 10000000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "7.5 M", DataValueInt = 7500000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "5.0 M", DataValueInt = 5000000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "4.0 M", DataValueInt = 4000000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "3.0 M", DataValueInt = 3000000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "2.5 M", DataValueInt = 2500000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "2.0 M", DataValueInt = 2000000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "1.5 M", DataValueInt = 1500000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "1.0 M", DataValueInt = 1000000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "750 K", DataValueInt = 750000 });
            videoBitrateItems.Add(new ComboBoxData() { DataName = "500 K", DataValueInt = 500000 });
            comboBox.ItemsSource = videoBitrateItems;

            AppSettings settings = new AppSettings();
            int videoBitrateSetting = settings.GetAppSettingInt("video_bitrate");
            if (videoBitrateSetting == -1)
            {
                videoBitrateSetting = 10000000;
            }
            comboBox.SelectedItem = videoBitrateItems[GetSelectedIntItem(videoBitrateItems, videoBitrateSetting)];

            return videoBitrateSetting;
        }
        public static string SetupEnableStreamCopy(ComboBox comboBox)
        {
            List<ComboBoxData> enableStreamCopyList = new List<ComboBoxData>();
            enableStreamCopyList.Add(new ComboBoxData() { DataName = "YES", DataValueString = "true" });
            enableStreamCopyList.Add(new ComboBoxData() { DataName = "NO", DataValueString = "false" });
            comboBox.ItemsSource = enableStreamCopyList;

            AppSettings settings = new AppSettings();
            string selectedEnableStreamCopy = settings.GetAppSettingString("stream_copy");
            if (string.IsNullOrWhiteSpace(selectedEnableStreamCopy))
            {
                selectedEnableStreamCopy = "true";
            }
            comboBox.SelectedItem = enableStreamCopyList[GetSelectedStringItem(enableStreamCopyList, selectedEnableStreamCopy)];

            return selectedEnableStreamCopy;
        }
        public static string SetupAudioCodec(ComboBox comboBox)
        {
            List<ComboBoxData> audioCodecList = new List<ComboBoxData>();
            audioCodecList.Add(new ComboBoxData() { DataName = "AC3", DataValueString = "ac3" });
            audioCodecList.Add(new ComboBoxData() { DataName = "AAC", DataValueString = "aac" });
            audioCodecList.Add(new ComboBoxData() { DataName = "AAC, AC3", DataValueString = "aac,ac3" });
            comboBox.ItemsSource = audioCodecList;

            AppSettings settings = new AppSettings();
            string selectedAudioCodec = settings.GetAppSettingString("audio_codec");
            if (string.IsNullOrWhiteSpace(selectedAudioCodec))
            {
                selectedAudioCodec = "aac,ac3";
            }
            comboBox.SelectedItem = audioCodecList[GetSelectedStringItem(audioCodecList, selectedAudioCodec)];

            return selectedAudioCodec;
        }