예제 #1
0
        /// <summary>
        /// Constructs a new instance of the <see cref="MtsSdk"/> class
        /// </summary>
        /// <param name="config">A <see cref="ISdkConfiguration"/> instance representing feed configuration</param>
        /// <param name="loggerFactory">A <see cref="ILoggerFactory"/> used to create <see cref="ILogger"/> used within sdk</param>
        /// <param name="metricsRoot">A <see cref="IMetricsRoot"/> used to provide metrics within sdk</param>
        public MtsSdk(ISdkConfiguration config, ILoggerFactory loggerFactory = null, IMetricsRoot metricsRoot = null)
        {
            Guard.Argument(config, nameof(config)).NotNull();

            LogInit();

            _isDisposed = false;
            _isOpened   = 0;

            _unityContainer = new UnityContainer();
            _unityContainer.RegisterTypes(config, loggerFactory, metricsRoot);
            _config = _unityContainer.Resolve <ISdkConfigurationInternal>();

            _executionLog   = SdkLoggerFactory.GetLoggerForExecution(typeof(MtsSdk));
            _interactionLog = SdkLoggerFactory.GetLoggerForExecution(typeof(MtsSdk));

            LogInit();

            _metricsRoot          = _unityContainer.Resolve <IMetricsRoot>();
            _metricsLogger        = SdkLoggerFactory.GetLoggerForStats(typeof(MtsSdk));
            _metricsTaskScheduler = new AppMetricsTaskScheduler(
                TimeSpan.FromSeconds(_config.StatisticsTimeout),
                async() => { await LogMetricsAsync(); });


            _connectionValidator = _unityContainer.Resolve <ConnectionValidator>();

            BuilderFactory          = _unityContainer.Resolve <IBuilderFactory>();
            _ticketPublisherFactory = _unityContainer.Resolve <ITicketSenderFactory>();

            _entitiesMapper = _unityContainer.Resolve <EntitiesMapper>();

            _rabbitMqMessageReceiverForTickets           = _unityContainer.Resolve <IRabbitMqMessageReceiver>("TicketResponseMessageReceiver");
            _rabbitMqMessageReceiverForTicketCancels     = _unityContainer.Resolve <IRabbitMqMessageReceiver>("TicketCancelResponseMessageReceiver");
            _rabbitMqMessageReceiverForTicketCashouts    = _unityContainer.Resolve <IRabbitMqMessageReceiver>("TicketCashoutResponseMessageReceiver");
            _rabbitMqMessageReceiverForTicketNonSrSettle = _unityContainer.Resolve <IRabbitMqMessageReceiver>("TicketNonSrSettleResponseMessageReceiver");

            ClientApi        = _unityContainer.Resolve <IMtsClientApi>();
            CustomBetManager = _unityContainer.Resolve <ICustomBetManager>();
            ConnectionStatus = _unityContainer.Resolve <IConnectionStatus>();
            ReportManager    = _unityContainer.Resolve <IReportManager>();

            _autoResetEventsForBlockingRequests        = new ConcurrentDictionary <string, AutoResetEvent>();
            _responsesFromBlockingRequests             = new ConcurrentDictionary <string, ISdkTicket>();
            _ticketsForNonBlockingRequests             = new MemoryCache("TicketsForNonBlockingRequests");
            _lockForTicketsForNonBlockingRequestsCache = new object();

            foreach (var t in Enum.GetValues(typeof(SdkTicketType)))
            {
                var publisher = _ticketPublisherFactory.GetTicketSender((SdkTicketType)t);
                if (publisher != null)
                {
                    publisher.TicketSendFailed += PublisherOnTicketSendFailed;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Constructs a new instance of the <see cref="MtsSdk"/> class
        /// </summary>
        /// <param name="config">A <see cref="ISdkConfiguration"/> instance representing feed configuration</param>
        public MtsSdk(ISdkConfiguration config)
        {
            Guard.Argument(config, nameof(config)).NotNull();

            LogInit();

            _isDisposed = false;
            _isOpened   = 0;

            _unityContainer = new UnityContainer();
            SdkUnityBootstrapper.RegisterTypes(_unityContainer, config);

            _config = _unityContainer.Resolve <ISdkConfigurationInternal>();
            _connectionValidator = _unityContainer.Resolve <ConnectionValidator>();

            BuilderFactory          = _unityContainer.Resolve <IBuilderFactory>();
            _ticketPublisherFactory = _unityContainer.Resolve <ITicketSenderFactory>();

            _entitiesMapper = _unityContainer.Resolve <EntitiesMapper>();

            _rabbitMqMessageReceiverForTickets           = _unityContainer.Resolve <IRabbitMqMessageReceiver>("TicketResponseMessageReceiver");
            _rabbitMqMessageReceiverForTicketCancels     = _unityContainer.Resolve <IRabbitMqMessageReceiver>("TicketCancelResponseMessageReceiver");
            _rabbitMqMessageReceiverForTicketCashouts    = _unityContainer.Resolve <IRabbitMqMessageReceiver>("TicketCashoutResponseMessageReceiver");
            _rabbitMqMessageReceiverForTicketNonSrSettle = _unityContainer.Resolve <IRabbitMqMessageReceiver>("TicketNonSrSettleResponseMessageReceiver");

            ClientApi        = _unityContainer.Resolve <IMtsClientApi>();
            CustomBetManager = _unityContainer.Resolve <ICustomBetManager>();
            ConnectionStatus = _unityContainer.Resolve <IConnectionStatus>();
            ReportManager    = _unityContainer.Resolve <IReportManager>();

            _autoResetEventsForBlockingRequests        = new ConcurrentDictionary <string, AutoResetEvent>();
            _responsesFromBlockingRequests             = new ConcurrentDictionary <string, ISdkTicket>();
            _ticketsForNonBlockingRequests             = new MemoryCache("TicketsForNonBlockingRequests");
            _lockForTicketsForNonBlockingRequestsCache = new object();

            foreach (var t in Enum.GetValues(typeof(SdkTicketType)))
            {
                var publisher = _ticketPublisherFactory.GetTicketSender((SdkTicketType)t);
                if (publisher != null)
                {
                    publisher.TicketSendFailed += PublisherOnTicketSendFailed;
                }
            }
        }