public void Subscribe(IObservable <ITweetItem> items, Action <ITweetItem> optionalActionOnSubscribe = null)
        {
            optionalActionOnSubscribe = optionalActionOnSubscribe ?? (_ => { });

            IsBusy = true;
            _subscription.DisposeIfNotNull();
            _subscription = items
                            .SubscribeOnThreadPool()
                            .ObserveOnDispatcher()
                            .Do(_ => IsBusy = false)
                            .Do(x => optionalActionOnSubscribe(x))
                            .Subscribe(x => Tweets.Append(x), () => IsBusy = false);

            ((IActivate)this).Activate();
        }
 public void DisposeSubscriptions()
 {
     _nameTextChangedSubscription.DisposeIfNotNull();
     _emailTextChangedSubscription.DisposeIfNotNull();
     _passwordTextChangedSubscription.DisposeIfNotNull();
     _repeatablePasswordTextChangedSubscription.DisposeIfNotNull();
 }
Example #3
0
        public TimelinesViewModel(AppInfo appInfo, TwitterClient client, IWindowManager windowManager, Func <TweetsPanelViewModel> timelineFactory)
        {
            Lists = new ObservableCollection <List>();

            _appInfo         = appInfo;
            _client          = client;
            _windowManager   = windowManager;
            _timelineFactory = timelineFactory;

            _homeline             = timelineFactory();
            _homeline.DisplayName = "Home";

            _mentionline             = timelineFactory();
            _mentionline.DisplayName = "Mentions";

            _messageline             = timelineFactory();
            _messageline.DisplayName = "Messages";

            IsBusy = true;

            Observable.FromEventPattern <NotifyCollectionChangedEventArgs>(Items, "CollectionChanged")
            .Where(x => x.EventArgs.OldItems != null)
            .SelectMany(x => x.EventArgs.OldItems.Cast <TweetsPanelViewModel>())
            .Where(_ => !Items.Any(t => t.Tag is string[]))     // streaming columns
            .Subscribe(_ => _streamingSubscription.DisposeIfNotNull());

            string user   = '******' + _appInfo.User.ScreenName;
            var    stream = _client.GetStreamingStatuses().Publish();

            _homeline.Subscribe(stream.Where(t => !t.Text.Contains(user)));
            _mentionline.Subscribe(stream.Where(t => t.Text.Contains(user)));
            _subscriptions.Add(stream.Connect());

            ShowHome     = true;
            ShowMentions = true;
            ShowMessages = false;
            IsBusy       = false;

            _subscriptions.Add(_client.GetPollingRateLimitStatus().DispatcherSubscribe(rl => RateLimitStatus = rl));
            _subscriptions.Add(_client.GetLists(_appInfo.User.ScreenName).DispatcherSubscribe(x => Lists.Add(x)));

            if (!string.IsNullOrEmpty(AppSettings.LastSearchTerms))
            {
                SearchText = AppSettings.LastSearchTerms;
                StartStreaming(SearchText);
            }
        }
Example #4
0
        public void When_DisposeIfNotNull_is_called_with_null()
        {
            // Arrange.
            IDisposable disposable = null;

            // Act.
            Action action = () =>
                            disposable.DisposeIfNotNull();

            // Assert.
            action.ShouldNotThrow();
        }
Example #5
0
        public static IDisposable AddTo(this IDisposable self, Component obj)
        {
            if (self == null)
            {
                return(self);
            }
            if (!obj)
            {
                self.DisposeIfNotNull();
                return(self);
            }
            var c = GetOrAdd(obj);

            c.AddDisposable(self);
            return(self);
        }
Example #6
0
        public static void TryDispose(this object obj)
        {
            IDisposable disposable = obj as IDisposable;

            disposable.DisposeIfNotNull();
        }
Example #7
0
 public void DisposeSubscriptions()
 {
     _searchTextChangedSubscription.DisposeIfNotNull();
 }