Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleMessageProcessor" /> class.
 /// </summary>
 /// <param name="dispatcher">
 /// A <see cref="IEntityDispatcher{ISportEvent}" /> whose dispatched entities will be processed by the current instance.
 /// </param>
 /// <param name="name">The name of the session/processor</param>
 /// <param name="log">A <see cref="ILogger" /> instance used for logging</param>
 public SimpleMessageProcessor(IEntityDispatcher <ISportEvent> dispatcher, string name = null, ILog log = null)
 {
     _dispatcher  = dispatcher;
     _log         = log ?? SdkLoggerFactory.GetLogger(typeof(SimpleMessageProcessor));
     FeedMessages = new ConcurrentBag <FMessage>();
     Name         = name ?? ((IOddsFeedSession)dispatcher).Name;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SpecificEntityProcessor{T}"/> class
        /// </summary>
        /// <param name="dispatcher">A <see cref="ISpecificEntityDispatcher{T}"/> used to obtain SDK messages</param>
        /// <param name="sportEntityWriter">A <see cref="SportEntityWriter"/> used to write the sport entities data</param>
        /// <param name="marketWriter">A <see cref="MarketWriter"/> used to write market and outcome data</param>
        /// <param name="log">A <see cref="ILogger"/> instance used for logging</param>
        public SpecificEntityProcessor(ISpecificEntityDispatcher <T> dispatcher, SportEntityWriter sportEntityWriter = null, MarketWriter marketWriter = null, ILogger log = null)
        {
            Guard.Argument(dispatcher, nameof(dispatcher)).NotNull();
            Guard.Argument(log, nameof(log)).NotNull();

            _log               = log ?? SdkLoggerFactory.GetLogger(typeof(SpecificEntityProcessor <T>)); // new NullLogger<SpecificEntityProcessor<T>>();
            _dispatcher        = dispatcher;
            _sportEntityWriter = sportEntityWriter;
            _marketWriter      = marketWriter;
        }
 /// <summary>
 /// Converts the provided int <code>value</code> to the member of the specified enum, or returns <code>defaultValue</code>
 /// </summary>
 /// <typeparam name="T">The type of enum to which to convert the <code>value</code></typeparam>
 /// <param name="value">The value in the feed message</param>
 /// <param name="defaultValue">A <see cref="T"/> member to be returned if unknown <code>value</code></param>
 /// <returns>The <code>value</code> converted to enum <see cref="T"/> member</returns>
 public static T GetEnumValue <T>(int value, T defaultValue) where T : struct, IConvertible
 {
     try
     {
         return(GetEnumValue <T>(value));
     }
     catch
     {
         var log = SdkLoggerFactory.GetLogger(typeof(MessageMapperHelper));
         log.LogError($"Enum value [{value}] not available for enum {typeof(T)}.");
         // ignored
     }
     return(defaultValue);
 }
        public static void RegisterTypes(this IUnityContainer container, ISdkConfiguration userConfig, ILoggerFactory loggerFactory, IMetricsRoot metricsRoot)
        {
            Guard.Argument(container, nameof(container)).NotNull();
            Guard.Argument(userConfig, nameof(userConfig)).NotNull();

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            if (loggerFactory != null)
            {
                var _ = new SdkLoggerFactory(loggerFactory);
            }
            _log = SdkLoggerFactory.GetLogger(typeof(SdkUnityBootstrapper));

            if (metricsRoot == null)
            {
                _metricsRoot = new MetricsBuilder()
                               .Configuration.Configure(
                    options =>
                {
                    options.DefaultContextLabel = "UF SDK .NET Core";
                    options.Enabled             = true;
                    options.ReportingEnabled    = true;
                })
                               .OutputMetrics.AsPlainText()
                               .Build();
            }
            else
            {
                _metricsRoot = metricsRoot;
            }
            container.RegisterInstance(_metricsRoot, new ContainerControlledLifetimeManager());

            RegisterBaseClasses(container, userConfig);

            RegisterRabbitMqTypes(container, userConfig, _environment);

            RegisterTicketSenders(container);

            RegisterMarketDescriptionCache(container, userConfig);

            RegisterSdkStatisticsWriter(container);

            RegisterMtsAuthService(container, userConfig);

            RegisterClientApi(container, userConfig);

            RegisterReportManager(container, userConfig);

            RegisterCustomBet(container);
        }
Ejemplo n.º 5
0
        private static void PrintLogManagerStatus()
        {
            Console.WriteLine($"Number of loggers: {LogManager.GetCurrentLoggers().Length}");
            foreach (var l in LogManager.GetCurrentLoggers())
            {
                Console.WriteLine($"\tLogger: {l.Logger.Name}");
                foreach (var a in l.Logger.Repository.GetAppenders())
                {
                    Console.WriteLine($"\t\t Appender: {a.Name}");
                }
            }
            Console.WriteLine($"Number of repositories: {LogManager.GetAllRepositories().Length}");
            foreach (var l in LogManager.GetAllRepositories())
            {
                Console.WriteLine($"\tRepository: {l.Name}");
            }

            Console.WriteLine(Environment.NewLine);

            var logDefault         = SdkLoggerFactory.GetLogger(typeof(SdkLogTest), SdkCommon.TestData.SdkTestLogRepositoryName);
            var logCache           = SdkLoggerFactory.GetLoggerForCache(typeof(SdkLogTest), SdkCommon.TestData.SdkTestLogRepositoryName);
            var logClientIteration = SdkLoggerFactory.GetLoggerForClientInteraction(typeof(SdkLogTest), SdkCommon.TestData.SdkTestLogRepositoryName);
            var logFeedTraffic     = SdkLoggerFactory.GetLoggerForFeedTraffic(typeof(SdkLogTest), SdkCommon.TestData.SdkTestLogRepositoryName);
            var logRestTraffic     = SdkLoggerFactory.GetLoggerForRestTraffic(typeof(SdkLogTest), SdkCommon.TestData.SdkTestLogRepositoryName);
            var logStatsTraffic    = SdkLoggerFactory.GetLoggerForStats(typeof(SdkLogTest), SdkCommon.TestData.SdkTestLogRepositoryName);

            LogPrint(logDefault);
            LogPrint(logCache);
            LogPrint(logClientIteration);
            LogPrint(logFeedTraffic);
            LogPrint(logRestTraffic);
            LogPrint(logStatsTraffic);

            //for (int i = 0; i < 10000; i++)
            //{
            //    LogPrint(logRestTraffic);
            //}
        }
Ejemplo n.º 6
0
        /// <summary>When overridden in a derived class, invokes the method that is specified in the provided <see cref="T:System.Runtime.Remoting.Messaging.IMessage" /> on the remote object that is represented by the current instance.</summary>
        /// <returns>The message returned by the invoked method, containing the return value and any out or ref parameters.</returns>
        /// <param name="msg">A <see cref="T:System.Runtime.Remoting.Messaging.IMessage" /> that contains a <see cref="T:System.Collections.IDictionary" /> of information about the method call. </param>
        public override IMessage Invoke(IMessage msg)
        {
            var logEnabled = false;

            var methodCall = msg as IMethodCallMessage;

            if (methodCall == null)
            {
                throw new ArgumentException("Input parameter 'msg' not valid IMethodCallMessage.");
            }
            var methodInfo = methodCall.MethodBase as MethodInfo;

            if (methodInfo == null)
            {
                throw new ArgumentException("Input parameter 'msg' does not have MethodBase as MethodInfo.");
            }

            var logger = SdkLoggerFactory.GetLogger(methodCall.MethodBase.ReflectedType, SdkLoggerFactory.SdkLogRepositoryName, _defaultLoggerType);

            if (_filter != null && _filter(methodInfo))
            {
                logEnabled = true;
            }

            if (!logEnabled || _canOverrideLoggerType)
            {
                var attributes = methodInfo.GetCustomAttributes(true).ToList();
                if (methodInfo.DeclaringType != null)
                {
                    attributes.AddRange(methodInfo.DeclaringType.GetCustomAttributes(true));
                }

                if (attributes.Count > 0)
                {
                    foreach (var t in attributes)
                    {
                        if (!(t is LogAttribute))
                        {
                            continue;
                        }
                        logEnabled = true;
                        if (_canOverrideLoggerType)
                        {
                            logger = SdkLoggerFactory.GetLogger(methodCall.MethodBase.ReflectedType, SdkLoggerFactory.SdkLogRepositoryName, ((LogAttribute)t).LoggerType);
                        }
                        break;
                    }
                }
            }

            var watch = new Stopwatch();

            watch.Start();

            try
            {
                if (methodCall.MethodName == "GetType")
                {
                    logEnabled = false;
                }
                if (logEnabled)
                {
                    logger.Info($"Starting executing '{methodCall.MethodName}' ...");
                }
                if (logEnabled && methodCall.InArgCount > 0)
                {
                    logger.Debug($"{methodCall.MethodName} arguments:");
                    for (var i = 0; i < methodCall.InArgCount; i++)
                    {
                        logger.Debug($"\t{((Type[]) methodCall.MethodSignature)[i].Name}={methodCall.InArgs[i]}");
                    }
                }

                var result = methodInfo.Invoke(_decorated, methodCall.InArgs); // MAIN EXECUTION

                var task = result as Task;
                if (task != null)
                {
                    var perm = new LogProxyPerm
                    {
                        LogEnabled = logEnabled,
                        Logger     = logger,
                        MethodCall = methodCall,
                        MethodInfo = methodInfo,
                        Result     = result,
                        Watch      = watch
                    };
                    _proxyPerms.Add(task.Id, perm);
                    if (logEnabled)
                    {
                        logger.Debug($"TaskId:{task.Id} is executing and we wait to finish ...");
                    }
                    task.ContinueWith(TaskExecutionFinished);
                    return(new ReturnMessage(result, null, 0, methodCall.LogicalCallContext, methodCall));
                }

                FinishExecution(logEnabled, methodCall, methodInfo, result?.GetType().Name, result, logger, watch);
                return(new ReturnMessage(result, null, 0, methodCall.LogicalCallContext, methodCall));
            }
            catch (Exception e)
            {
                watch.Stop();
                if (logEnabled)
                {
                    logger.Error($"Exception during executing '{methodCall.MethodName}': {Environment.NewLine}", e);
                }
                return(new ReturnMessage(e, methodCall));
            }
        }
Ejemplo n.º 7
0
 public void Init()
 {
     _log = SdkLoggerFactory.GetLogger(typeof(EntityPrinterTest));
 }