public static Task<ReadableArticleViewModel> LoadAtLeastOne(ISimpleHttpService httpService, string url, string linkId)
 {
     TaskCompletionSource<ReadableArticleViewModel> result = new TaskCompletionSource<ReadableArticleViewModel>();
     var articleViewModel = new ReadableArticleViewModel { ArticleUrl = url, ArticleParts = new ObservableCollection<object>(), LinkId = linkId, ContentIsFocused = true };
     LoadOneImpl(httpService, url, articleViewModel.ArticleParts).ContinueWith(async (task) =>
         {
             try
             {
                 if (task.IsCompleted)
                 {
                     Tuple<string, string> tpl = await task;
                     var nextPage = tpl.Item1;
                     articleViewModel.Title = tpl.Item2;
                     result.SetResult(articleViewModel);
                     if (!string.IsNullOrEmpty(nextPage))
                     {
                         var remainingParts = await Task.Run(() => LoadFullyImpl(httpService, nextPage));
                         foreach (var part in remainingParts.Item2)
                         {
                             
                             articleViewModel.ArticleParts.Add(part);
                         }
                     }
                 }
                 else if (task.Exception != null)
                     result.SetException(task.Exception);
             }
             catch (Exception ex)
             {
                 result.SetException(ex);
             }
         }, TaskScheduler.FromCurrentSynchronizationContext());
     return result.Task;
     
 }
Esempio n. 2
0
        private static object MakeSerializable(ReadableArticleViewModel vm)
        {
            if (SimpleIoc.Default.IsRegistered<ReadableArticleViewModel>())
            {
                SimpleIoc.Default.Unregister<ReadableArticleViewModel>();
            }

            SimpleIoc.Default.Register<ReadableArticleViewModel>(() => vm, true);
            return Tuple.Create(vm.ArticleUrl, vm.LinkId);
        }