public void Start()
        {
            PeriodicTask periodicTask = new PeriodicTask(Constants.SETTINGS.LIVE_TILE_AGENT);

            WP_to_WP.Shared.Services.UiSettings Settings = new WP_to_WP.Shared.Services.UiSettings();

            periodicTask.Description = Settings.AppName() + " Task";
            periodicTask.ExpirationTime = System.DateTime.Now.AddDays(10);

            if (Exists())
            {
                ScheduledActionService.Remove(Constants.SETTINGS.LIVE_TILE_AGENT);
            }

            try
            {
                ScheduledActionService.Add(periodicTask);

            #if DEBUG
                ScheduledActionService.LaunchForTest(Constants.SETTINGS.LIVE_TILE_AGENT, TimeSpan.FromMinutes(20));
            #endif

            }
            catch (InvalidOperationException ex)
            {
                if (ex.Message.Contains("BNS Error: The action is disabled"))
                {
                    // MessageBox.Show("Background agents for this application have been disabled by the user.");
                }

            }
        }
        public void Start()
        {
            PeriodicTask periodicTask = new PeriodicTask(Constants.SETTINGS.LIVE_TILE_AGENT);

            WP_to_WP.Shared.Services.UiSettings Settings = new WP_to_WP.Shared.Services.UiSettings();

            periodicTask.Description    = Settings.AppName() + " Task";
            periodicTask.ExpirationTime = System.DateTime.Now.AddDays(10);

            if (Exists())
            {
                ScheduledActionService.Remove(Constants.SETTINGS.LIVE_TILE_AGENT);
            }

            try
            {
                ScheduledActionService.Add(periodicTask);

#if DEBUG
                ScheduledActionService.LaunchForTest(Constants.SETTINGS.LIVE_TILE_AGENT, TimeSpan.FromMinutes(20));
#endif
            }
            catch (InvalidOperationException ex)
            {
                if (ex.Message.Contains("BNS Error: The action is disabled"))
                {
                    // MessageBox.Show("Background agents for this application have been disabled by the user.");
                }
            }
        }
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        protected async override void OnInvoke(ScheduledTask task)
        {
            //TODO: Add code to perform your task in background

            WP_to_WP.Shared.Services.UiSettings settings = new WP_to_WP.Shared.Services.UiSettings();

            WP_to_WP.Shared.Services.UiStorage storage = new WP_to_WP.Shared.Services.UiStorage();

            Domain.Services.AgentService service = new Domain.Services.AgentService(storage, settings);

            var result = await service.GetUpdates("112", storage);


            if (result.Count > 0)
            {

                string toastMessage = string.Format(International.Translations.NewPosts, result.Count);

                ShellToast toast = new ShellToast();
                toast.Title = settings.AppName();
                toast.Content = toastMessage;
                toast.Show();

                if (ShellTile.ActiveTiles.Any())
                {
                    var tile = ShellTile.ActiveTiles.FirstOrDefault(o => o.NavigationUri == new Uri("/Home.xaml", UriKind.RelativeOrAbsolute));
                    var flipTileData = new RadFlipTileData
                    {
                        Count = result.Count,
                        Title = Domain.AppBase.Current.Config.AppName,
                        IsTransparencySupported = true,
                        //Title = International.Translations.AppName,
                        BackTitle = result[0].Title,
                        BackgroundImage = new Uri("/Assets/FlipCycleTileSmall_159_159.png", UriKind.RelativeOrAbsolute),
                        WideBackgroundImage = new Uri("/Assets/FlipCycleTitleLarge_691_336.png", UriKind.RelativeOrAbsolute),

                     
                        WideBackBackgroundImage = new Uri(result[0].Url, UriKind.RelativeOrAbsolute),
                        BackBackgroundImage = new Uri(result[0].Url, UriKind.RelativeOrAbsolute)

                    };


                    //List<Uri> images = new List<Uri>();
                    //RadCycleTileData RadTile = new RadCycleTileData();

                    //int start = 0;
                    //int max = 10;


                    //for (int i = 0; i < 9; i++)
                    //{
                    //    images.Add(null);

                    //}

                    //foreach (var item in result)
                    //{
                    //    images[start] = new Uri(item.Url, UriKind.Absolute);
                    //    start++;
                    //    if (start >= max)
                    //        break;

                    //}



                    //IEnumerable<Uri> CycleImages = images;

                    //RadTile.CycleImages = CycleImages;

                    LiveTileHelper.UpdateTile(tile, flipTileData);


                }
            }



            NotifyComplete();
        }
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        protected async override void OnInvoke(ScheduledTask task)
        {
            //TODO: Add code to perform your task in background

            WP_to_WP.Shared.Services.UiSettings settings = new WP_to_WP.Shared.Services.UiSettings();

            WP_to_WP.Shared.Services.UiStorage storage = new WP_to_WP.Shared.Services.UiStorage();

            Domain.Services.AgentService service = new Domain.Services.AgentService(storage, settings);

            var result = await service.GetUpdates("112", storage);


            if (result.Count > 0)
            {
                string toastMessage = string.Format(International.Translations.NewPosts, result.Count);

                ShellToast toast = new ShellToast();
                toast.Title   = settings.AppName();
                toast.Content = toastMessage;
                toast.Show();

                if (ShellTile.ActiveTiles.Any())
                {
                    var tile         = ShellTile.ActiveTiles.FirstOrDefault(o => o.NavigationUri == new Uri("/Home.xaml", UriKind.RelativeOrAbsolute));
                    var flipTileData = new RadFlipTileData
                    {
                        Count = result.Count,
                        Title = Domain.AppBase.Current.Config.AppName,
                        IsTransparencySupported = true,
                        //Title = International.Translations.AppName,
                        BackTitle           = result[0].Title,
                        BackgroundImage     = new Uri("/Assets/FlipCycleTileSmall_159_159.png", UriKind.RelativeOrAbsolute),
                        WideBackgroundImage = new Uri("/Assets/FlipCycleTitleLarge_691_336.png", UriKind.RelativeOrAbsolute),


                        WideBackBackgroundImage = new Uri(result[0].Url, UriKind.RelativeOrAbsolute),
                        BackBackgroundImage     = new Uri(result[0].Url, UriKind.RelativeOrAbsolute)
                    };


                    //List<Uri> images = new List<Uri>();
                    //RadCycleTileData RadTile = new RadCycleTileData();

                    //int start = 0;
                    //int max = 10;


                    //for (int i = 0; i < 9; i++)
                    //{
                    //    images.Add(null);

                    //}

                    //foreach (var item in result)
                    //{
                    //    images[start] = new Uri(item.Url, UriKind.Absolute);
                    //    start++;
                    //    if (start >= max)
                    //        break;

                    //}



                    //IEnumerable<Uri> CycleImages = images;

                    //RadTile.CycleImages = CycleImages;

                    LiveTileHelper.UpdateTile(tile, flipTileData);
                }
            }



            NotifyComplete();
        }