Exemple #1
0
        private async Task UpdateSubscriptionStatusAsync(TvDbSeries series)
        {
            var subs         = await subscribed.Value;
            var isSubscribed = subs.Any(s => series.Id == s.Id);

            series.IsSubscribed = isSubscribed;
        }
Exemple #2
0
        public void Save(TvDbSeries series)
        {
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                var directory = string.Format(@"{0}\{1}", SubscriptionsFolderName, series.Id);

                using (new MutexLock(directory))
                {
                    if (!storage.DirectoryExists(directory))
                    {
                        storage.CreateDirectory(directory);
                    }
                }

                var filename = string.Format(@"{0}\data.xml", directory);

                using (new MutexLock(filename))
                {
                    using (var file = new IsolatedStorageFileStream(filename, FileMode.Create, storage))
                    {
                        try
                        {
                            Serializer.Serialize(file, series);
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.Message);
                            OnStorageFailure(
                                new StorageFailureEventArgs(
                                    "Failed to save data to local storage. Any modifications or updates will be lost, sorry! :("));
                        }
                    }
                }
            }
        }
Exemple #3
0
 public async Task SaveAsync(TvDbSeries series)
 {
     using (await ioLock.DisposableWaitAsync())
     {
         await Task.Factory.StartNew(() => storageManager.Save(series));
     }
 }
Exemple #4
0
 public async Task UnsubscribeAsync(TvDbSeries series)
 {
     using (await ioLock.DisposableWaitAsync())
     {
         var subscriptions = await subscribed.Value;
         subscriptions.RemoveAllThatMatch(m => series.Id == m.Id);
         series.IsSubscribed = false;
         OnUnsubscribed(new SubscriptionChangedEventArgs(series));
         await Task.Factory.StartNew(() => storageManager.Remove(series));
     }
 }
Exemple #5
0
 public async Task SubscribeAsync(TvDbSeries series)
 {
     using (await ioLock.DisposableWaitAsync())
     {
         var subscriptions = await subscribed.Value;
         subscriptions.Add(series);
         series.IsSubscribed = true;
         OnSubscribed(new SubscriptionChangedEventArgs(series));
         await Task.Factory.StartNew(() => storageManager.Save(series));
     }
 }
Exemple #6
0
        public void Remove(TvDbSeries series)
        {
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                var filename = string.Format(@"{0}\{1}\data.xml", SubscriptionsFolderName, series.Id);

                using (new MutexLock(filename))
                {
                    if (!storage.FileExists(filename))
                    {
                        return;
                    }

                    storage.DeleteFile(filename);
                }
            }
        }
Exemple #7
0
        private async Task UpdateSeriesIfNecessaryAsync(TvDbSeries series)
        {
            bool ownsTask = false;
            Task update   = null;

            using (await ioLock.DisposableWaitAsync())
            {
                if (updates.ContainsKey(series))
                {
                    update = updates[series];
                }

                var needsUpdating = (series.Updated == null) || (DateTime.Now - series.Updated > TimeSpan.FromHours(3));
                if (needsUpdating)
                {
                    update = UpdateSeriesAsync(series);
                    updates.Add(series, update);
                    ownsTask = true;
                }
            }
            if (update != null)
            {
                await update;
                if (ownsTask)
                {
                    using (await ioLock.DisposableWaitAsync())
                    {
                        updates.Remove(series);
                        if (series.IsSubscribed)
                        {
                            storageManager.Save(series);
                        }
                    }
                }
            }
        }
Exemple #8
0
 public void SaveSeen(TvDbSeries series)
 {
     Save(series);
 }
Exemple #9
0
        public async Task UnmarkSeenAsync(TvDbSeries series, TvDbSeriesEpisode episode)
        {
            episode.IsSeen = false;

            await SaveAsync(series);
        }
Exemple #10
0
        public async Task MarkSeenAsync(TvDbSeries series, TvDbSeriesEpisode episode)
        {
            episode.IsSeen = true;

            await SaveAsync(series);
        }
Exemple #11
0
 private Task UpdateSeriesAsync(TvDbSeries series)
 {
     return(Task.WhenAll(new[] { tvDb.UpdateData(series), UpdateSubscriptionStatusAsync(series) }));
 }
Exemple #12
0
 public SubscriptionChangedEventArgs(TvDbSeries series)
 {
     Series = series;
 }
 public SeriesDisplayWindow(TvDbSeries series)
 {
     this.series = series;
     InitializeComponent();
     this.searchResultsListBox.ItemsSource = new List<TvDbSeries> { series };
 }