コード例 #1
0
        public static IValidatedProperty <string> Validate <T>(
            this IProperty <Optional <T> > self,
            Func <T, string> toString,
            Func <string, IValidationResult <T> > fromString)
        {
            var validationError = new BehaviorSubject <Optional <string> >(Optional.None());

            return(new ValidatedProperty <string>
            {
                Value = self.SelectPerElement(toString).Or(""),
                IsReadOnly = self.IsReadOnly,
                ValidationError = validationError.Merge(self.Select(v => Optional.None <string>())),
                Writer = (v, save) => fromString(v).MatchWith(
                    (T t) =>
                {
                    self.Write(Optional.Some(t));
                    validationError.OnNext(Optional.None <string>());
                    return false;
                },
                    (string e) =>
                {
                    self.Write(Optional.None());
                    validationError.OnNext(Optional.Some(e));
                    return false;
                }),
            });
        }
コード例 #2
0
        public RecommendationsContainer(IStorageService storageService)
        {
            _storageService = storageService;

            Changes = _subject.Merge(Observable.FromAsync(GetAsync))
                      .Catch(Observable.Return <RecommendationsList>(null))
                      .Synchronize()
                      .DistinctUntilChanged()
                      .Replay(1)
                      .RefCount();
        }
コード例 #3
0
        public Folder(IAccount server, string name, string shortName, string separator, bool hasChildren, bool canHaveMessages)
        {
            server_    = server;
            name_      = name;
            shortName_ = shortName;
            separator_ = separator;

            if (hasChildren)
            {
                subFolders_ = new BehaviorSubject <IEnumerable <Folder> >(new Folder[] { });
            }

            canHaveMessages_ = canHaveMessages;
            if (canHaveMessages)
            {
                filterIds_ = new BehaviorSubject <IEnumerable <int> >(null);

                messages_ = new BehaviorSubject <IEnumerable <MessageHeader> >(new MessageHeader[] { });

                Messages     = messages_.Throttle(TimeSpan.FromMilliseconds(100), Dependencies.TimeScheduler);
                ViewMessages = Observable.CombineLatest(Messages, filterIds_, FilterMessages);

                exists_ = new BehaviorSubject <int>(0);
                recent_ = new BehaviorSubject <int>(0);
                unseen_ = new BehaviorSubject <int>(0);

                var msgCount = Messages.Select(msgs => msgs.Count());

                // Take the value as either the number of messages in the list or
                // just what the server has set for the folder.
                Exists = exists_.Merge(msgCount);


                var msgsUnRead = Messages.
                                 Select((msgs) =>
                {
                    // Build an observable list of all of the unread values.

                    return(Observable.CombineLatest(msgs.Select(msg => msg.UnRead)));
                }).Switch().     // .. and only listen to the newest one.
                                 Select(unreads =>
                {
                    // .. then count up the unread values in it.

                    return(unreads.Where(unread => unread == true).Count());
                });

                // Take the value as either the number of messages with Unread set
                // or just what the server has set for the folder.
                Unseen = unseen_.Merge(msgsUnRead);
            }
        }