public OperationsProjection( IWampHostedRealm realm, ISessionCache sessionCache) { _subject = realm?.Services.GetSubject(Topic); _sessionCache = sessionCache; }
protected override async Task RunAsync(IWampChannel channel) { await channel.Open().ConfigureAwait(false); await Task.Yield(); IWampSubject topic = channel.RealmProxy.Services.GetSubject("com.myapp.topic1"); IObservable <int> timer = Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)).Select((x, i) => i); WampEvent TopicSelector(int value) { return(new WampEvent() { Arguments = new object[] { value }, Options = new PublishOptions() { DiscloseMe = true } }); } using (IDisposable disposable = timer.Select(value => TopicSelector(value)).Subscribe(topic)) { Console.WriteLine("Hit enter to stop publishing"); Console.ReadLine(); } Console.WriteLine("Stopped publishing"); Console.ReadLine(); }
public ConfirmationCommandHandler( IWampHostedRealm realm, ISessionCache sessionCache) { _subject = realm?.Services.GetSubject(Topic); _sessionCache = sessionCache; }
public ISubject <TTuple> GetSubject <TTuple>(string topicUri, IWampEventValueTupleConverter <TTuple> converter) { IWampSubject subject = GetSubject(topicUri); WampTupleTopicSubject <TTuple> result = new WampTupleTopicSubject <TTuple>(subject, converter); return(result); }
public WampTopicSubject(IWampSubject subject) { mSubject = subject; mObservable = subject.Where(x => x.Arguments != null && x.Arguments.Any()) .Select(x => x.Arguments[0].Deserialize <T>()); }
public WampTupleTopicSubject(IWampSubject subject, IWampEventValueTupleConverter <TTuple> converter) { mSubject = subject; mConverter = converter; mObservable = mSubject.Select(x => mConverter.ToTuple(x)); }
public ISubject <TEvent> GetSubject <TEvent>(string topicUri) { IWampSubject subject = GetSubject(topicUri); WampTopicSubject <TEvent> result = new WampTopicSubject <TEvent>(subject); return(result); }
public HistoryExportProjection( ILog log, IWampHostedRealm realm, ISessionCache sessionCache) { _log = log; _subject = realm?.Services.GetSubject(Topic); _sessionCache = sessionCache; }
public OrdersPublisher( [NotNull] IClientAccountClient clientAccountClient, [NotNull] IOrdersConverter ordersConverter, [NotNull] ISessionCache sessionCache, [NotNull] IWampHostedRealm realm) { _clientAccountClient = clientAccountClient ?? throw new ArgumentNullException(nameof(clientAccountClient)); _ordersConverter = ordersConverter ?? throw new ArgumentNullException(nameof(ordersConverter)); _sessionCache = sessionCache ?? throw new ArgumentNullException(nameof(sessionCache)); _subject = realm?.Services.GetSubject(Topic) ?? throw new ArgumentNullException(nameof(realm)); }
public TradesSubscriber( [NotNull] ILog log, [NotNull] IRabbitMqSubscribeHelper rabbitMqSubscribeHelper, [NotNull] string connectionString, [NotNull] IWampHostedRealm realm, [NotNull] ISessionCache sessionCache) { _log = log ?? throw new ArgumentNullException(nameof(log)); _sessionCache = sessionCache ?? throw new ArgumentNullException(nameof(sessionCache)); _rabbitMqSubscribeHelper = rabbitMqSubscribeHelper ?? throw new ArgumentNullException(nameof(rabbitMqSubscribeHelper)); _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString)); _subject = realm.Services.GetSubject("trades"); }
public BalancesConsumer( [NotNull] ILog log, [NotNull] RabbitMqSettings settings, [NotNull] IWampHostedRealm realm, [NotNull] ISessionCache sessionCache, [NotNull] IClientToWalletMapper clientToWalletMapper, [NotNull] IRabbitMqSubscribeHelper rabbitMqSubscribeHelper) { _log = log ?? throw new ArgumentNullException(nameof(log)); _sessionCache = sessionCache ?? throw new ArgumentNullException(nameof(sessionCache)); _rabbitMqSubscribeHelper = rabbitMqSubscribeHelper ?? throw new ArgumentNullException(nameof(rabbitMqSubscribeHelper)); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _clientToWalletMapper = clientToWalletMapper ?? throw new ArgumentNullException(nameof(clientToWalletMapper)); _subject = realm.Services.GetSubject(TopicUri); }
protected override async Task RunAsync(IWampChannel channel) { await channel.Open().ConfigureAwait(false); await Task.Yield(); IWampSubject heartbeatSubject = channel.RealmProxy.Services.GetSubject("com.myapp.heartbeat"); var topic2Subject = channel.RealmProxy.Services.GetSubject("com.myapp.topic2", new Topic2TupleConverter()); IObservable <int> timer = Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)).Select((x, i) => i); Random random = new Random(); WampEvent emptyEvent = new WampEvent(); using (IDisposable heartbeatDisposable = timer.Select(value => emptyEvent).Subscribe(heartbeatSubject)) { (int number1, int number2, string c, MyClass d) Topic2Selector(int value) { return(number1 : random.Next(0, 100), number2 : 23, c : "Hello", d : new MyClass() { Counter = value, Foo = new int[] { 1, 2, 3 } }); } using (IDisposable topic2Disposable = timer.Select(value => Topic2Selector(value)).Subscribe(topic2Subject)) { Console.WriteLine("Hit enter to stop publishing"); Console.ReadLine(); } } Console.WriteLine("Stopped publishing"); Console.ReadLine(); }
private void DisconnectFromWAMPRouter() { if (channel != null) { try { channel.Close(); channel = null; OpenFaceSubject = null; //EyeDataSubject = null; } catch (Exception ex) { //OutputMessage(ex.Message); } } IsBroadcastingToWAMP = false; }
protected override async Task RunAsync(IWampChannel channel) { await channel.Open().ConfigureAwait(false); await Task.Yield(); IWampSubject topic = channel.RealmProxy.Services.GetSubject("com.myapp.topic1"); using (IDisposable disposable = topic.Subscribe(value => Console.WriteLine($"Got event, publication ID {value.PublicationId}, publisher {value.Details.Publisher}: {value.Arguments[0].Deserialize<int>()}"), ex => Console.WriteLine($"An error has occurred {ex}"))) { Console.WriteLine("Hit enter to unsubscribe"); Console.ReadLine(); } Console.WriteLine("Unsubscribed"); Console.ReadLine(); }
public LimitOrdersConsumer(ILogFactory logFactory, RabbitMqSettings settings, IWampHostedRealm realm, ISessionRepository sessionRepository) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (logFactory == null) { throw new ArgumentNullException(nameof(logFactory)); } _sessionRepository = sessionRepository ?? throw new ArgumentNullException(nameof(sessionRepository)); _subject = realm.Services.GetSubject(TopicUri); try { var subscriptionSettings = new RabbitMqSubscriptionSettings { ConnectionString = settings.ConnectionString, QueueName = $"{settings.ExchangeName}.{QueueName}", ExchangeName = settings.ExchangeName, IsDurable = QueueDurable }; var strategy = new DefaultErrorHandlingStrategy(logFactory, subscriptionSettings); _subscriber = new RabbitMqSubscriber <LimitOrderMessage>(logFactory, subscriptionSettings, strategy) .SetMessageDeserializer(new JsonMessageDeserializer <LimitOrderMessage>()) .SetMessageReadStrategy(new MessageReadWithTemporaryQueueStrategy()) .Subscribe(ProcessLimitOrder) .Start(); } catch (Exception ex) { var log = logFactory.CreateLog(this); log.Error(ex); throw; } }
protected override async Task RunAsync(IWampChannel channel) { await channel.Open().ConfigureAwait(false); await Task.Yield(); IWampSubject heartbeatSubject = channel.RealmProxy.Services.GetSubject("com.myapp.heartbeat"); var topic2Subject = channel.RealmProxy.Services.GetSubject("com.myapp.topic2", new Topic2TupleConverter()); using (IDisposable heartbeatDisposable = heartbeatSubject.Subscribe(value => Console.WriteLine($"Got heartbeat (publication ID {value.PublicationId})"), ex => Console.WriteLine($"An error has occurred {ex}"))) { void Topic2EventHandler((int number1, int number2, string c, MyClass d) value) { (int number1, int number2, string c, MyClass d) = value; Console.WriteLine($@"Got event: number1:{number1}, number2:{number2}, c:""{c}"", d:{{{d}}}"); } void Topic2ErrorHandler(Exception exception) { Console.WriteLine($"An error has occurred {exception}"); } using (IDisposable topic2Disposable = topic2Subject.Subscribe(Topic2EventHandler, Topic2ErrorHandler)) { Console.WriteLine("Hit enter to unsubscribe"); Console.ReadLine(); } } Console.WriteLine("Unsubscribed"); Console.ReadLine(); }
private bool ConnectToRouter() { if (channel != null) { try { //DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory(); //channel = channelFactory.CreateJsonChannel(WAMPRouterAdress, WAMPRealm); Task openTask = channel.Open(); openTask.Wait(5000); IWampRealmProxy realmProxy = channel.RealmProxy; //EyeDataSubject = realmProxy.Services.GetSubject(EyeDataTopic); //HeadDataSubject = realmProxy.Services.GetSubject(HeadDataTopic); OpenFaceSubject = realmProxy.Services.GetSubject(OpenFaceTopic); return(true); } catch (Exception ex) { counter++; Thread.Sleep(2000); if (counter <= 30) { ConnectToRouter(); } else { //this.Invoke(new Action<object, bool>(OnFinishConnectProcess), this, false); } return(false); } } return(false); }
async private void StreamBtn_Click(object sender, EventArgs e) { if (!IsStreamingToWAMP) { //maybe check if the connection before start wamp string CrossbarAddress = CrossbarIPTextBox.Text + "/ws"; string CrossbarRealm = RealmTextbox.Text; //This was the old code, might have to do some kind of hybrid depending on the url written. /*DefaultWampChannelFactory channelFactory = new DefaultWampChannelFactory(); * IWampChannel channel = channelFactory.CreateJsonChannel("wss://syn.ife.no/crossbarproxy/ws", CrossbarRealm); //CrossbarAddress * * channel.Open().Wait(); * //Task openTask = channel.Open() * //openTask.Wait(5000);*/ //if (CrossbarAddress.Contains("wss://")){ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //} WampChannelFactory factory = new WampChannelFactory(); IWampChannel channel = factory.ConnectToRealm(CrossbarRealm) .WebSocketTransport(new Uri(CrossbarAddress + "/ws")) .JsonSerialization() .Build(); IWampRealmProxy realmProxy = channel.RealmProxy; channel.RealmProxy.Monitor.ConnectionEstablished += (sender_inner, arg) => { Console.WriteLine("connected session with ID " + arg.SessionId); dynamic details = arg.WelcomeDetails.OriginalValue.Deserialize <dynamic>(); Console.WriteLine("authenticated using method '{0}' and provider '{1}'", details.authmethod, details.authprovider); Console.WriteLine("authenticated with authid '{0}' and authrole '{1}'", details.authid, details.authrole); }; channel.RealmProxy.Monitor.ConnectionBroken += (sender_inner, arg) => { dynamic details = arg.Details.OriginalValue.Deserialize <dynamic>(); Console.WriteLine("disconnected " + arg.Reason + " " + details.reason + details); Console.WriteLine("disconnected " + arg.Reason); }; await channel.Open().ConfigureAwait(false); WAMPSubject = realmProxy.Services.GetSubject("RETDataSample"); SelectedTracker.GazeDataReceived += HandleGazeData; IsStreamingToWAMP = true; WAMPThread = new Thread(() => { while (IsStreamingToWAMP) { try { while (GazeEventQueue.Any()) { GazeDataEventArgs gazeEvent; GazeEventQueue.TryDequeue(out gazeEvent); float gazeX = 0; float gazeY = 0; if (gazeEvent.LeftEye.GazePoint.Validity == Validity.Valid && gazeEvent.RightEye.GazePoint.Validity == Validity.Valid) { gazeX = (gazeEvent.LeftEye.GazePoint.PositionOnDisplayArea.X + gazeEvent.RightEye.GazePoint.PositionOnDisplayArea.X) / 2; gazeY = (gazeEvent.LeftEye.GazePoint.PositionOnDisplayArea.Y + gazeEvent.RightEye.GazePoint.PositionOnDisplayArea.Y) / 2; } else if (gazeEvent.LeftEye.GazePoint.Validity == Validity.Valid) { gazeX = gazeEvent.LeftEye.GazePoint.PositionOnDisplayArea.X; gazeY = gazeEvent.LeftEye.GazePoint.PositionOnDisplayArea.Y; } else if (gazeEvent.RightEye.GazePoint.Validity == Validity.Valid) { gazeX = gazeEvent.RightEye.GazePoint.PositionOnDisplayArea.X; gazeY = gazeEvent.RightEye.GazePoint.PositionOnDisplayArea.Y; } if (gazeEvent.LeftEye.Pupil.PupilDiameter != -1 || gazeEvent.RightEye.Pupil.PupilDiameter != -1) { CurrentPupilDiameters[0] = Double.IsNaN(gazeEvent.LeftEye.Pupil.PupilDiameter) ? -1 : gazeEvent.LeftEye.Pupil.PupilDiameter; CurrentPupilDiameters[1] = Double.IsNaN(gazeEvent.RightEye.Pupil.PupilDiameter) ? -1 : gazeEvent.RightEye.Pupil.PupilDiameter; } WampEvent evt = new WampEvent(); evt.Arguments = new object[] { SelectedTracker.SerialNumber, new object[] { CurrentPupilDiameters[0], gazeEvent.LeftEye.GazePoint.PositionOnDisplayArea.X, gazeEvent.LeftEye.GazePoint.PositionOnDisplayArea.Y, CurrentPupilDiameters[1], gazeEvent.RightEye.GazePoint.PositionOnDisplayArea.X, gazeEvent.RightEye.GazePoint.PositionOnDisplayArea.Y, gazeEvent.LeftEye.GazeOrigin.PositionInUserCoordinates.X, gazeEvent.LeftEye.GazeOrigin.PositionInUserCoordinates.Y, gazeEvent.LeftEye.GazeOrigin.PositionInUserCoordinates.Z, gazeEvent.RightEye.GazeOrigin.PositionInUserCoordinates.X, gazeEvent.RightEye.GazeOrigin.PositionInUserCoordinates.Y, gazeEvent.RightEye.GazeOrigin.PositionInUserCoordinates.Z, gazeX, gazeY } }; WAMPSubject.OnNext(evt); } } catch (Exception exp) { //do nothing, skip Console.Write(exp); } } }); WAMPThread.Start(); if (StreamBtn.InvokeRequired) { StreamBtn.BeginInvoke((MethodInvoker) delegate() { this.StreamBtn.Text = "Stop"; }); } else { StreamBtn.Text = "Stop"; } } else { IsStreamingToWAMP = false; SelectedTracker.GazeDataReceived -= HandleGazeData; if (StreamBtn.InvokeRequired) { StreamBtn.BeginInvoke((MethodInvoker) delegate() { this.StreamBtn.Text = "Stream"; }); } else { StreamBtn.Text = "Stream"; } WAMPThread.Join(); } }