コード例 #1
0
 public OperationStateBase(OperationError error, double progress, bool isCancelled, ModelSource source = ModelSource.Unknown, ModelIdentifierBase id = null, double resultProgress = 0)
 {
     Error            = error;
     Progress         = progress;
     IsCancelled      = isCancelled;
     ResultSource     = source;
     ResultIdentifier = id;
     ResultProgress   = resultProgress;
 }
コード例 #2
0
        protected override void WriteImplementation(ModelIdentifierBase id, UpdateContainer update, ModelSource target, IObserver <IOperationState <object> > operation, CancellationToken ct = default)
        {
            if (id is BbcArticleIdentifier articleId)
            {
                var original = (NewsArticle)update.Original;
                var updated  = (NewsArticle)update.Updated;

                if (updated.Title != original.Title)
                {
                    Debug.WriteLine("Title updated from '" + original.Title + "' to '" + updated.Title);
                }

                operation.OnCompleteResult(id, id, 100);
            }
        }
コード例 #3
0
        protected override void ParseImplementation(ModelIdentifierBase id, Stream data, IObserver <IOperationState <object> > target)
        {
            var progress = 1.0;

            target.OnNextProgress(progress);

            var doc = XDocument.Load(data);

            progress = 20;

            // TODO: Try to get existing list from repository
            var list = new List <NewsArticle>();

            target.OnIncompleteResult(list, AllArticlesId, progress, 10);

            var items        = doc.Descendants("item").ToList();
            var itemProgress = (100.0 - progress) / (items.Count() + 1);

            foreach (var item in items)
            {
                var link    = item.Element("link").Value;
                var article = new NewsArticle
                {
                    Url   = new Uri(link),
                    Title = item.Element("title").Value
                };

                var thisId = new BbcArticleIdentifier(article);

                progress = thisId.Equals(id) ? 100 : progress + itemProgress;

                target.OnCompleteResult(article, thisId, progress);
                list.Add(article);
            }

            progress += itemProgress;
            target.OnCompleteResult(list, AllArticlesId, progress);

            if (progress < 100)
            {
                target.OnNextProgress(100);
            }

            target.OnCompleted();
        }
コード例 #4
0
        public IObservable <IOperationState <Stream> > Load(ModelIdentifierBase id)
        {
            return(Observable.Generate(0, p => p <= 100, p => ++ p,
                                       p => new OperationState <Stream>(
                                           p == 100
                        ? new MemoryStream(
                                               Encoding.UTF8.GetBytes("Article from server"),
                                               false
                                               )
                        : null,
                                           p
                                           ),
                                       p => TimeSpan.FromMilliseconds(50)));

            /*
             * if (source == ModelSource.Disk) {
             *  return Observable.Generate(0, p => p <= 100, p => ++p,
             *      p => new OperationState<Stream>(p == 100 ? Encoding.UTF8.GetBytes("Article from disk").AsBuffer() : null, p),
             *      p => TimeSpan.FromMilliseconds(1));
             * } else {
             * }*/
        }
コード例 #5
0
 public OperationState(T result = null, double progress = 0, OperationError error = null, bool isCancelled = false, ModelSource source = ModelSource.Unknown, ModelIdentifierBase id = null, double resultProgress = 0) : base(error, progress, isCancelled, source, id, resultProgress)
 {
     Result = result;
 }
コード例 #6
0
 protected override void ParseImplementation(ModelIdentifierBase id, Stream data, IObserver <IOperationState <object> > target, CancellationToken ct)
 {
     // Use the parser for this model
     new BbcParser().Parse(id, data, target);
 }
コード例 #7
0
 protected override void LoadImplementation(ModelIdentifierBase id, IObserver <IOperationState <Stream> > target, CancellationToken ct)
 {
     // Check that this model is supposed to be loaded from the bbc
     new NetworkRequestHander().Get(new Uri("http://feeds.bbci.co.uk/news/rss.xml"), target);
 }