Ejemplo n.º 1
0
        public string StoreStrategyLogEvent(StrategyEventLogDTO strategyEventLogDTO)
        {
            try
            {
                var accountId = GetAccountIdWithApiKey(strategyEventLogDTO.ApiKey);
                var guid      = Guid.NewGuid().ToString();

                string sql = "INSERT INTO strategy_log_event (id,account_id,log_event_date,log_message,log_message_type,order_id,strategy_name) " +
                             "VALUES (@id, @accId,@eventDate,@message,@messageType,@orderId,@strategyName)";
                using (var connection = new SqlConnection(GetConnectionString()))
                {
                    var affectedRows = connection.Execute(sql, new
                    {
                        id           = guid,
                        accId        = accountId,
                        eventDate    = DateTime.Now,
                        message      = strategyEventLogDTO.LogMessage,
                        strategyName = strategyEventLogDTO.StrategyName,
                        messageType  = strategyEventLogDTO.LogMessageType,
                        orderId      = strategyEventLogDTO.OrderId
                    });
                }

                return(guid);
            }
            catch (Exception exp)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public void WebPush(StrategyEventLogDTO strategyEventLogDTO)
        {
            try
            {
                var message = new PushMessage(CreateJsonStringFromLogEvent(strategyEventLogDTO));
                var userId  = dbService.GetUserIdWithAccountApiKey(strategyEventLogDTO.ApiKey);
                if (userId != null)
                {
                    var subscriptions = dbService.TryGetUserWebPushNotifications(userId);
                    foreach (var sub in subscriptions)
                    {
                        var pushSub = GetPushSubscriptionForDbSubscription(sub);

                        var result = _pushClient.RequestPushMessageDeliveryAsync(pushSub, message);
                        result.Wait();

                        System.Diagnostics.Debug.WriteLine("Web push notification sent :" + pushSub.Endpoint);
                    }
                }
            } catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine("Exception occurred : " + exp.Message);
            }
        }
Ejemplo n.º 3
0
        private string CreateJsonStringFromLogEvent(StrategyEventLogDTO strategyEvent)
        {
            var jsonString = " {\"notification\": {\"title\": \"Forexwatch log event\",\"body\": \" " + strategyEvent.LogMessageType + " :" + strategyEvent.LogMessage + "\" }}";

            return(jsonString);
        }