Beispiel #1
0
        public async void CreateTile()
        {
            try
            {
                if (IsolatedStorageFile.GetUserStoreForApplication().FileExists("upcomming.json"))
                {
                    using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        using (IsolatedStorageFileStream stream = isoStore.OpenFile("upcomming.json", FileMode.Open))
                        {
                            var             ser = new DataContractJsonSerializer(typeof(TraktCalendar[]));
                            TraktCalendar[] cal = (TraktCalendar[])ser.ReadObject(stream);

                            if (cal.Length == 0)
                            {
                                createNoUpcommingTile();
                            }
                            else
                            {
                                TraktCalendarEpisode nextEpisode = null;

                                await DownloadRequiredWallpapers(cal);

                                if (AppUser.Instance.LiveTileType == LiveTileType.Random)
                                {
                                    nextEpisode = LookupRandomNextEpisode(cal, nextEpisode);
                                }
                                else
                                {
                                    nextEpisode = LookupNextEpisode(cal, nextEpisode);
                                }

                                if (nextEpisode != null)
                                {
                                    CreateEpisodeTile(nextEpisode);
                                }
                                else
                                {
                                    createNoUpcommingTile();
                                    UpdateUpcomming();
                                }
                            }
                        }
                    }
                }
                else
                {
                    createNoUpcommingTile();
                    UpdateUpcomming();
                }
            }
            catch (IsolatedStorageException)
            {
                createNoUpcommingTile();
            }
        }
Beispiel #2
0
        private void CreateEpisodeTile(TraktCalendarEpisode nextEpisode)
        {
            ShellTile appTile = ShellTile.ActiveTiles.First();

            if (appTile != null)
            {
                if (doesFileExist(nextEpisode.Show.tvdb_id + "background.jpg"))
                {
                    FlipTileData newTileData = new FlipTileData();
                    newTileData.BackContent = nextEpisode.Show.Title + ", " + nextEpisode.Episode.Season + "x" + nextEpisode.Episode.Number;
                    newTileData.BackTitle   = ((nextEpisode.Date.DayOfYear == DateTime.UtcNow.DayOfYear) ? ("Today, " + nextEpisode.Episode.FirstAiredAsDate.ToShortTimeString()) : (nextEpisode.Episode.FirstAiredAsDate.ToShortDateString()));


                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        copyImageToShellContent(nextEpisode.Show.tvdb_id + "background.jpg", nextEpisode.Show.tvdb_id);
                        LockscreenHelper.UpdateLockScreen("ms-appdata:///Local/" + nextEpisode.Show.tvdb_id + "background.jpg");
                        newTileData.BackgroundImage =
                            new Uri("isostore:/Shared/ShellContent/wptraktbg" + nextEpisode.Show.tvdb_id + ".jpg", UriKind.Absolute);
                        newTileData.WideBackgroundImage =
                            new Uri("isostore:/Shared/ShellContent/wptraktbg" + nextEpisode.Show.tvdb_id + ".jpg", UriKind.Absolute);
                        newTileData.SmallBackgroundImage = new Uri("isostore:/Shared/ShellContent/wptraktbg" + nextEpisode.Show.tvdb_id + ".jpg", UriKind.Absolute);
                        newTileData.WideBackContent      = nextEpisode.Show.Title + ", " + nextEpisode.Episode.Season + "x" + nextEpisode.Episode.Number + "\r\n" + nextEpisode.Episode.Title + "\r\n" + ((nextEpisode.Date.DayOfYear == DateTime.UtcNow.DayOfYear) ? ("Today, " + nextEpisode.Episode.FirstAiredAsDate.ToShortTimeString()) : (nextEpisode.Episode.FirstAiredAsDate.ToShortDateString())) + " ( " + nextEpisode.Show.Network + " )";
                        appTile.Update(newTileData);

                        NotifyComplete();
                    });
                }
                else
                {
                    FlipTileData newTileData = new FlipTileData();
                    newTileData.BackContent = nextEpisode.Show.Title + ", " + nextEpisode.Episode.Season + "x" + nextEpisode.Episode.Number;
                    newTileData.BackTitle   = ((nextEpisode.Date.DayOfYear == DateTime.UtcNow.DayOfYear) ? ("Today, " + nextEpisode.Episode.FirstAiredAsDate.ToShortTimeString()) : (nextEpisode.Episode.FirstAiredAsDate.ToShortDateString()));


                    newTileData.BackgroundImage      = new Uri("appdata:background.png");
                    newTileData.WideBackgroundImage  = new Uri("appdata:WideBackground.png");
                    newTileData.SmallBackgroundImage = new Uri("appdata:background.png");
                    newTileData.WideBackContent      = nextEpisode.Show.Title + ", " + nextEpisode.Episode.Season + "x" + nextEpisode.Episode.Number + "\r\n" + nextEpisode.Episode.Title + "\r\n" + ((nextEpisode.Date.DayOfYear == DateTime.UtcNow.DayOfYear) ? ("Today, " + nextEpisode.Episode.FirstAiredAsDate.ToShortTimeString()) : (nextEpisode.Episode.FirstAiredAsDate.ToShortDateString())) + " ( " + nextEpisode.Show.Network + " )";
                    appTile.Update(newTileData);


                    NotifyComplete();
                }
            }
        }
Beispiel #3
0
        private static TraktCalendarEpisode LookupNextEpisode(TraktCalendar[] cal, TraktCalendarEpisode nextEpisode)
        {
            List <TraktCalendarEpisode> upcommingEpisodes = new List <TraktCalendarEpisode>();


            foreach (TraktCalendar calendar in cal)
            {
                DateTime calDate = DateTime.Parse(calendar.Date);

                if ((DateTime.UtcNow.Year <= calDate.Year) && (DateTime.UtcNow.Month <= calDate.Month) && (DateTime.UtcNow.DayOfYear <= calDate.DayOfYear))
                {
                    if ((calDate - DateTime.Now).Days > 7)
                    {
                        break;
                    }
                    Int32 next = new Random().Next(0, calendar.Episodes.Length);
                    TraktCalendarEpisode newItem = calendar.Episodes[next];
                    newItem.Date = calDate;
                    return(newItem);
                }
            }

            return(null);
        }
Beispiel #4
0
        private static TraktCalendarEpisode LookupRandomNextEpisode(TraktCalendar[] cal, TraktCalendarEpisode nextEpisode)
        {
            List <TraktCalendarEpisode> upcommingEpisodes = new List <TraktCalendarEpisode>();


            foreach (TraktCalendar calendar in cal)
            {
                DateTime calDate = DateTime.Parse(calendar.Date);

                if ((DateTime.UtcNow.Year <= calDate.Year) && (DateTime.UtcNow.Month <= calDate.Month) && (DateTime.UtcNow.DayOfYear <= calDate.DayOfYear))
                {
                    if ((calDate - DateTime.Now).Days > 7)
                    {
                        break;
                    }

                    foreach (TraktCalendarEpisode episode in calendar.Episodes)
                    {
                        episode.Date = calDate;
                        upcommingEpisodes.Add(episode);
                    }
                }
            }
            try
            {
                nextEpisode = upcommingEpisodes[new Random().Next(0, upcommingEpisodes.Count)];
            }
            catch (ArgumentOutOfRangeException) { return(null); }
            return(nextEpisode);
        }