public IObservable <IData> Run(IData initialData) { return(Observable.Create <IData>( observer => { var state = _factory.FromData(initialData); var states = new BehaviorSubject <IState>(state); // First create a stream of changes by ... IConnectableObservable <IChange> changes = states // ... enter the current state ... .Select(state => state.Enter()) // ... subscribing to the change observable ... .Switch() // ... and ensure only a single shared subscription is made to the change observable ... .Publish(); IObservable <IData> data = changes.OfType <IData>(); // Then, for each transition type, select the new state... IObservable <IState> transitions = changes .OfType <ITransition>() .Select(_ => _factory.FromData(initialData)) .ObserveOn(Scheduler.CurrentThread); return new CompositeDisposable( transitions.Subscribe(states), data.Subscribe(observer), changes.Connect(), states ); } )); }
public void Subscribe <T>(Action <T> action) where T : TBase { var disposable = subscriptions.OfType <T>().Subscribe(action); delegateSubscriptionMap.TryAdd(action, disposable); }
public void RegisterHandler <T>([NotNull] Action <T> action) where T : IStatusBarMessage { if (action == null) { throw new ArgumentNullException(nameof(action)); } _connectableObservable.OfType <T>() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(action); }
/// <summary> /// コンストラクタです。 /// </summary> /// <param name="client">Twitter クライアント。</param> /// <param name="type">タイムラインの種類。</param> public TimeLineTwitter(TwitdonTwitterClient client, Define.TwitterTimeLineType type) { this.client = client; this.type = type; var name = $"{Utilities.TwitterTimeLineTypeToString(type)} "; TimeLineName = $"{name}{client.AccountName}"; streaming = client.Streaming; OnGetStatusMessage = streaming.OfType <StatusMessage>(); statuses = new List <TimeLineStatus>(Define.StatusesCapacity); fetchedStatuses = new Queue <TwitdonTwitterStatus>(); }
public Publisher(ILogger <Publisher> logger, Connection connection, GroupOptions groupOptions) { _logger = logger; _connection = connection; _groupOptions = groupOptions; _onlineMessages = new Messages() .Stream .BufferUntil(connection.State, gateStreamMessageIndex => { var shouldBuffer = gateStreamMessageIndex % 2 != 0; if (shouldBuffer) { _logger.LogWarning("Buffering until connection becomes available: {Url}", connection.Url); } else { _logger.LogWarning("Releasing buffer"); } return(shouldBuffer); }) .Publish(); var eventLoop = new EventLoopScheduler(); _textsReceived = _onlineMessages .OfType <TextReceived>() .ObserveOn(eventLoop) .Do(x => Retry(() => Send(x)).Wait()); _terminates = _onlineMessages .OfType <SessionTerminated>() .ObserveOn(eventLoop) .Do(x => Retry(() => Terminate(x)).Wait()); }
public async Task Initialize() { await _serviceEndpoint.Initialize(); _consumerSubscription = new CompositeDisposable( _messageObservable.OfType <With.Message.IRegister>().Do(Instrument.Harmonize.Action.Register).Subscribe(message => _serviceEndpoint.Register(message.Entity.Identity)), _messageObservable.OfType <With.Message.IDeregister>().Do(Instrument.Harmonize.Action.Deregister).Subscribe(message => _serviceEndpoint.Deregister(message.Entity)), _messageObservable.OfType <With.Message.IAdd>().Do(Instrument.Harmonize.Action.Add).Subscribe(message => _serviceEndpoint.Add(message.Component.Identity)), _messageObservable.OfType <With.Message.IRemove>().Do(Instrument.Harmonize.Action.Remove).Subscribe(message => _serviceEndpoint.Remove(message.Component)), _messageObservable.OfType <With.Message.IObserve>().Do(Instrument.Harmonize.Action.Observe).Subscribe(message => _serviceEndpoint.AddObserver(message.Entity, message.Observable, message.Observer)), _messageObservable.OfType <With.Message.IIgnore>().Do(Instrument.Harmonize.Action.Ignore).Subscribe(message => _serviceEndpoint.RemoveObserver(message.Entity, message.Observable, message.Observer)) ); }
private Task <T> Send <T>(IRequest request) where T : IResponse { Instrumentation.Command.Endpoint.Request(request); string requestString = AddKey(request.AsString()); Instrumentation.Command.Endpoint.Send(requestString); byte[] datagram = Encoding.ASCII.GetBytes(requestString); Task <T> result = _responses.OfType <T>() .ThrowWhen <T>(RequestFailed, response => RequestException(request, response)) .Timeout(_requestTimeout) .Take(1) .ToTask(); _udpSend.Send(datagram, datagram.Length, _remoteEndpoint); return(result); }
//ストリーミング private async void streamingtest() { try { tweet2 = ViewModel2.TweetTimeline; sm_stream = tokens.Streaming.UserAsObservable().Publish(); sm_stream.OfType <StatusMessage>().Subscribe(x => streamLoad(x)); disposable = sm_stream.Connect(); //testBlock.Text = "接続中です"; var xx = ViewModel.streamCount(); int tw_count = int.Parse(xx); await Task.Delay(tw_count * 60000); disposable.Dispose(); streamButton.IsChecked = false; //testBlock.Text = "接続終了"; } catch (Exception ex) { } }
//ストリーミング public async void streamingtest(ObservableCollection <TweetClass.TweetInfo> tweet) { try { sm_stream = tokens.Streaming.UserAsObservable().Publish(); sm_stream.OfType <StatusMessage>().Subscribe(x => streamLoad(x, tweet)); disposable = sm_stream.Connect(); //testBlock.Text = "接続中です"; var xx = ViewModel.streamCount(); int tw_count = int.Parse(xx); //toast(tw_count.ToString()); await Task.Delay(tw_count * 600); disposable.Dispose(); //streamButton.IsChecked = false; //testBlock.Text = "接続終了"; } catch (Exception ex) { } }
public IObservable <TEvent> ReceiveEvents <TEvent>() where TEvent : IEvent { return(_deserializedEvents.OfType <TEvent>()); }
public void RegisterHandler <T>(Action <T> handleAction) where T : IJob { _connectableObservable.OfType <T>().Subscribe(handleAction); }