コード例 #1
0
        private void SendOperationStatus(Guid clientId, Guid operationId, OperationStatus status,
                                         string errorCode = null, string errorMessage = null)
        {
            var sessionIds = _sessionCache.GetSessionIds(clientId.ToString());

            if (sessionIds.Length == 0)
            {
                return;
            }

            _subject.OnNext(new WampEvent
            {
                Options = new PublishOptions {
                    Eligible = sessionIds
                },
                Arguments = new object[]
                {
                    new OperationStatusChangedMessage
                    {
                        Status       = status,
                        OperationId  = operationId,
                        ErrorCode    = errorCode,
                        ErrorMessage = errorMessage
                    }
                }
            });
        }
コード例 #2
0
        public async Task <CommandHandlingResult> Handle(RequestConfirmationCommand command, IEventPublisher eventPublisher)
        {
            var sessionIds = _sessionCache.GetSessionIds(command.ClientId.ToString());

            if (sessionIds.Length == 0)
            {
                return(CommandHandlingResult.Ok());
            }

            _subject.OnNext(new WampEvent
            {
                Options = new PublishOptions {
                    Eligible = sessionIds
                },
                Arguments = new object[]
                {
                    new OperationStatusChangedMessage
                    {
                        Status      = OperationStatus.ConfirmationRequested,
                        OperationId = command.OperationId
                    }
                }
            });

            return(CommandHandlingResult.Ok());
        }
コード例 #3
0
        private async Task ProcessLimitOrder(LimitOrderMessage ordersUpdateMessage)
        {
            await ordersUpdateMessage.Orders.ParallelForEachAsync(async order =>
            {
                if (Guid.TryParse(order.Order.ExternalId, out Guid orderId))
                {
                    var sessionIds = _sessionRepository.GetSessionIds(order.Order.ClientId);
                    if (sessionIds.Length == 0)
                    {
                        return;
                    }

                    var notifyResponse = new LimitOrderUpdateEvent
                    {
                        Order = new Order
                        {
                            Id              = orderId,
                            Status          = order.Order.Status,
                            AssetPairId     = order.Order.AssetPairId,
                            Volume          = order.Order.Volume,
                            Price           = order.Order.Price,
                            RemainingVolume = order.Order.RemainingVolume,
                            LastMatchTime   = order.Order.LastMatchTime
                        },
                        Trades = order.Trades.Select(x => new Trade
                        {
                            Asset          = x.Asset,
                            Volume         = x.Volume,
                            Price          = x.Price,
                            Timestamp      = x.Timestamp,
                            OppositeAsset  = x.OppositeAsset,
                            OppositeVolume = x.OppositeVolume
                        }).ToArray()
                    };

                    _subject.OnNext(new WampEvent
                    {
                        Options = new PublishOptions
                        {
                            Eligible = sessionIds
                        },
                        Arguments = new object[] { notifyResponse }
                    });
                }
            }).ConfigureAwait(false);
        }
コード例 #4
0
        private void PublishOrdersToClient(string clientId, Order[] orders)
        {
            var sessionIds = _sessionCache.GetSessionIds(clientId);

            if (sessionIds.Length == 0)
            {
                return;
            }

            _subject.OnNext(new WampEvent
            {
                Options = new PublishOptions {
                    Eligible = sessionIds
                },
                Arguments = new [] { orders }
            });
        }
コード例 #5
0
        private async Task Process(BalanceUpdateEventModel message)
        {
            if (!message.Balances.Any())
            {
                return;
            }

            try
            {
                foreach (var balance in message.Balances)
                {
                    var meWalletId = balance.Id;

                    var(clientId, walletId) = await _clientToWalletMapper.GetClientIdAndWalletIdAsync(meWalletId);

                    var sessionIds = _sessionCache.GetSessionIds(clientId);
                    if (sessionIds.Length == 0)
                    {
                        continue;
                    }

                    _subject.OnNext(new WampEvent
                    {
                        Options = new PublishOptions
                        {
                            Eligible = sessionIds
                        },
                        Arguments = new object[] { new BalanceUpdateMessage
                                                   {
                                                       WalletId = walletId,
                                                       Asset    = balance.Asset,
                                                       Balance  = balance.NewBalance,
                                                       Reserved = balance.NewReserved ?? default(double)
                                                   } }
                    });
                }
            }
            catch (Exception e)
            {
                _log.WriteError(nameof(BalancesConsumer), message, e);
                throw;
            }
        }
コード例 #6
0
        public Task Handle(ClientHistoryExportedEvent evt)
        {
            var sessionIds = _sessionCache.GetSessionIds(evt.ClientId);

            if (sessionIds.Length == 0)
            {
                return(Task.CompletedTask);
            }

            _subject.OnNext(new WampEvent
            {
                Options = new PublishOptions {
                    Eligible = sessionIds
                },
                Arguments = new object[] { new HistoryExportGeneratedMessage {
                                               Id = evt.Id, Url = evt.Uri
                                           } }
            });

            return(Task.CompletedTask);
        }
コード例 #7
0
        private async Task ProcessTradeAsync(List <TradeLogItem> messages)
        {
            if (!messages.Any())
            {
                return;
            }

            var messagesByUser = messages.GroupBy(x => x.UserId);

            try
            {
                foreach (var userTrades in messagesByUser)
                {
                    var sessionIds = _sessionCache.GetSessionIds(userTrades.First().UserId);
                    if (sessionIds.Length == 0)
                    {
                        return;
                    }

                    _subject.OnNext(new WampEvent
                    {
                        Options = new PublishOptions {
                            Eligible = sessionIds
                        },
                        Arguments = new object[] { userTrades.ToList() }
                    });
                }
            }
            catch (Exception ex)
            {
                _log.WriteWarning(nameof(ProcessTradeAsync), messages, "Failed to process trade", ex);
                throw;
            }

            await Task.CompletedTask;
        }
コード例 #8
0
        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();
            }
        }
コード例 #9
0
        public void OnNext(TTuple value)
        {
            IWampEvent wampEvent = mConverter.ToEvent(value);

            mSubject.OnNext(wampEvent);
        }
コード例 #10
0
 public void OnNext(T value)
 {
     mSubject.OnNext(new WampEvent {
         Arguments = new object[] { value }
     });
 }