Ejemplo n.º 1
0
        public static void Log(string msg)
        {
#if UNITY_EDITOR
            if (!EditorSetting.debug)
            {
                return;
            }
#endif
            msg = "【TheMatrix Debug】" + msg;
            Debug.Log(msg);
            OnLog?.Invoke(msg);
        }
Ejemplo n.º 2
0
        public static void Log(string message)
        {
#if UNITY_EDITOR
            if (!TheMatrix.EditorSetting.debug)
            {
                return;
            }
#endif
            message = "【" + TypeName + "】" + message;
            Debug.Log(message);
            OnLog?.Invoke(message);
        }
Ejemplo n.º 3
0
 internal static void Warning(
     string message,
     string callerClassFullName                 = "",
     [CallerFilePath] string callerFilePath     = "",
     [CallerMemberName] string callerMemberName = "",
     [CallerLineNumber] int callerLineNumber    = 0)
 {
     lock (SyncLock)
     {
         OnLog?.Invoke(new LogEventArgs(LogLevel.Warning, message, callerClassFullName, callerFilePath, callerMemberName, callerLineNumber));
     }
 }
Ejemplo n.º 4
0
        private Task InvalidIdFormatLog(string exceptionMessage)
        {
            var logArgs = new LogMessageEventArgs
            {
                LogType = MqLogType.InvalidIdFormat,
                Reason  = exceptionMessage
            };

            OnLog?.Invoke(null, logArgs);

            return(Task.CompletedTask);
        }
Ejemplo n.º 5
0
        /*
         * vw_advance_frame_callback --
         *
         * Notification from GGPO we should step foward exactly 1 frame
         * during a rollback.
         */

        static bool Vw_advance_frame_callback(int flags)
        {
            OnLog?.Invoke($"vw_begin_game_callback {flags}");

            // Make sure we fetch new inputs from GGPO and use those to update the game state
            // instead of reading from the keyboard.
            ulong[] inputs = new ulong[MAX_SHIPS];
            ReportFailure(GGPO.SynchronizeInput(ggpo, inputs, MAX_SHIPS, out var disconnect_flags));

            AdvanceFrame(inputs, disconnect_flags);
            return(true);
        }
Ejemplo n.º 6
0
        public int ReceivePacket()
        {
            try
            {
                int ret;
                buffer = new byte[1024];
                while (true)
                {
                    socket.ReceiveTimeout = 3000;
                    try
                    {
                        ret = socket.Receive(buffer, 1024, SocketFlags.None);
                    }
                    catch (SocketException e)
                    {
                        if (e.ErrorCode == 10060)
                        {
                            ret = -1;
                            OnLog.Invoke("recv", "failed to connect to remote host", false);
                        }
                        else
                        {
                            throw e;
                        }
                    }
                    if (ret < 0)
                    {
                        OnLog.Invoke("recv", "recv() failed", false);
                        return(-2);
                    }

                    if (buffer[0] == 0x4D)
                    {
                        if (buffer[1] == 0x15)
                        {
                            OnLog.Invoke("login", "! Others logined.", false);
                            InnerSource = "账户在其他地方登录。";
                            return(-5);
                        }

                        continue;
                    }

                    break;
                }
                return(ret);
            }
            catch (ObjectDisposedException)
            {
                InnerSource = "Socket被异常关闭。";
                return(-5);
            }
        }
Ejemplo n.º 7
0
        private Task MessageNotInflightLog(string exceptionMessage)
        {
            var logArgs = new LogMessageEventArgs
            {
                LogType = MqLogType.MessageNotInflight,
                Reason  = exceptionMessage
            };

            OnLog?.Invoke(null, logArgs);

            return(Task.CompletedTask);
        }
Ejemplo n.º 8
0
        private void ConsumerClient_OnConsumeError(object sender, Message e)
        {
            var message = e.Deserialize <Null, string>(null, StringDeserializer);
            var logArgs = new LogMessageEventArgs
            {
                LogType = KafkaLogType.ConsumeError,
                Reason  = $@"An error occurred during consume the message; Topic:'{e.Topic}',
                            Message:'{message.Value}', Reason:'{e.Error}'."
            };

            OnLog?.Invoke(sender, logArgs);
        }
Ejemplo n.º 9
0
 public void Log(string message)
 {
     try
     {
         Console.WriteLine(message);
         OnLog?.Invoke(message);
     }
     catch (Exception ex)
     {
         Log(ex.Message);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 发送读码命令
        /// </summary>
        public void TriggerOn(int index)
        {
            string Command = Config.Trigger[index].Command;

            if (string.IsNullOrEmpty(Command))
            {
                return;
            }
            visionClient.SendAsync(Command);
            OnLog?.Invoke($"SEND:{Command}");
            LogRead.Log.Info($"发送读码命令:{Command}");
        }
Ejemplo n.º 11
0
 public async Task Log(WorkflowLogLevel level, string message)
 {
     try
     {
         await OnLog?.Invoke(level, message);
     }
     catch (Exception ex)
     {
         OnLog = null;
         Context.Log(WorkflowLogLevel.Warning, "Realtime processing has failed:\n" + ex.Message + "\nLog streaming has been disabled.");
     }
 }
Ejemplo n.º 12
0
        private void LogCallback(IntPtr rk, int level, string fac, string buf)
        {
            var name = Util.Marshal.PtrToStringUTF8(LibRdKafka.name(rk));

            if (OnLog == null)
            {
                // Log to stderr by default if no logger is specified.
                Loggers.ConsoleLogger(this, new LogMessage(name, level, fac, buf));
                return;
            }

            OnLog.Invoke(this, new LogMessage(name, level, fac, buf));
        }
Ejemplo n.º 13
0
 public static void Message(string str,
                            [CallerMemberName] string member        = null,
                            [CallerFilePath] string sourceFilePat   = null,
                            [CallerLineNumber] int sourceLineNumber = 0)
 {
     if (OnLog != null)
     {
         lock (OnLog)
         {
             OnLog.Invoke(Level.Message, $"{str}\n", member, sourceFilePat, sourceLineNumber);
         }
     }
 }
Ejemplo n.º 14
0
        private void LogCaller(LoggerEventArgs args)
        {
            string eMessage = String.Empty;

            if (args.Exception != null)
            {
                eMessage = args.Exception.Message;
            }

            AddLog(new Log(args.LogType, args.Message, (Exception)args.Exception));

            OnLog?.Invoke(this, args);
        }
Ejemplo n.º 15
0
 internal static void Error(
     string message,
     Exception?exception                        = null,
     string callerClassFullName                 = "",
     [CallerFilePath] string callerFilePath     = "",
     [CallerMemberName] string callerMemberName = "",
     [CallerLineNumber] int callerLineNumber    = 0)
 {
     lock (SyncLock)
     {
         OnLog?.Invoke(new LogEventArgs(LogLevel.Error, message, callerClassFullName, callerFilePath, callerMemberName, callerLineNumber, exception));
     }
 }
Ejemplo n.º 16
0
        protected void WriteStackTraceToLog(Exception exception, IEnumerable <StackFrame> callStack)
        {
            OnLog?.Invoke($"Unhandled exception. {exception.GetType().FullName}: {exception.Message}");
            var first = true;

            foreach (var sf in callStack)
            {
                var msg = (first ? " ---> " : "   at ") + sf.ToStringWithBestSourceLocation();
                OnLog?.Invoke(msg);
                first = false;
            }
            OnLog?.Invoke("");
        }
Ejemplo n.º 17
0
        public Consumer(
            IEnumerable <KeyValuePair <string, object> > config,
            IDeserializer <TKey> keyDeserializer,
            IDeserializer <TValue> valueDeserializer)
        {
            KeyDeserializer   = keyDeserializer;
            ValueDeserializer = valueDeserializer;

            // TODO: allow deserializers to be set in the producer config IEnumerable<KeyValuePair<string, object>>.

            if (KeyDeserializer == null)
            {
                if (typeof(TKey) != typeof(Null))
                {
                    throw new ArgumentNullException("Key deserializer must be specified.");
                }
                // TKey == Null -> cast is always valid.
                KeyDeserializer = (IDeserializer <TKey>) new NullDeserializer();
            }

            if (ValueDeserializer == null)
            {
                if (typeof(TValue) != typeof(Null))
                {
                    throw new ArgumentNullException("Value deserializer must be specified.");
                }
                // TValue == Null -> cast is always valid.
                ValueDeserializer = (IDeserializer <TValue>) new NullDeserializer();
            }

            consumer                       = new Consumer(config);
            consumer.OnLog                += (sender, e) => OnLog?.Invoke(sender, e);
            consumer.OnError              += (sender, e) => OnError?.Invoke(sender, e);
            consumer.OnStatistics         += (sender, e) => OnStatistics?.Invoke(sender, e);
            consumer.OnPartitionsAssigned += (sender, e) => OnPartitionsAssigned?.Invoke(sender, e);
            consumer.OnPartitionsRevoked  += (sender, e) => OnPartitionsRevoked?.Invoke(sender, e);
            consumer.OnOffsetCommit       += (sender, e) => OnOffsetCommit?.Invoke(sender, e);
            // TODO: bypass this.consumer for this event to optimize perf.
            consumer.OnMessage += (sender, e) => OnMessage?.Invoke(sender,
                                                                   new Message <TKey, TValue> (
                                                                       e.Topic,
                                                                       e.Partition,
                                                                       e.Offset,
                                                                       KeyDeserializer.Deserialize(e.Key),
                                                                       ValueDeserializer.Deserialize(e.Value),
                                                                       e.Timestamp,
                                                                       e.Error
                                                                       )
                                                                   );
            consumer.OnPartitionEOF += (sender, e) => OnPartitionEOF?.Invoke(sender, e);
        }
Ejemplo n.º 18
0
        /*
         * vw_save_game_state_callback --
         *
         * Save the current state to a buffer and return it to GGPO via the
         * buffer and len parameters.
         */

        static unsafe bool Vw_save_game_state_callback(void **buffer, int *length, int *checksum, int frame)
        {
            OnLog?.Invoke($"vw_save_game_state_callback {frame}");
            Debug.Assert(gs != null);
            var bytes = GameState.ToBytes(gs);

            *   checksum = Helper.CalcFletcher32(bytes);
            *   length   = bytes.Length;
            var ptr      = Helper.ToPtr(bytes);

            *buffer = ptr;
            cache[(long)ptr] = bytes;
            return(true);
        }
Ejemplo n.º 19
0
        public void Log(LogEntry entry)
        {
            if (Level < entry.Level)
            {
                return;
            }

            Task.Run(delegate
            {
                OnLog?.Invoke(this, entry);
            });

            Console.WriteLine($"[{entry.Level}][{entry.DateTime}] {entry.Message}");
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="configuration">The test-bed adapter configuration information</param>
        internal AbstractProducer(Configuration configuration)
        {
            _configuration = configuration;
            _producer      = new ProducerBuilder <EDXLDistribution, T>(_configuration.ProducerConfig)
                             .SetKeySerializer(new AvroSerializer <EDXLDistribution>(configuration.SchemaRegistryClient))
                             .SetValueSerializer(new AvroSerializer <T>(configuration.SchemaRegistryClient))
                             // Raised on critical errors, e.g. connection failures or all brokers down.
                             .SetErrorHandler((sender, error) => OnError?.Invoke(sender, error))
                             // Raised when there is information that should be logged.
                             .SetLogHandler((sender, log) => OnLog?.Invoke(sender, log))
                             .Build();

            _messageQueue = new Queue <KeyValuePair <T, string> >();
        }
Ejemplo n.º 21
0
        private void Log(string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                return;
            }

            OnLog?.Invoke(this, new LogEventArgs(message));

            if (IsWriteLogToFile)
            {
                _dataLogger.Log(message);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 委托回报
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="pInputOrder">委托信息</param>
        /// <param name="pRspInfo">错误信息</param>
        /// <param name="nRequestID"></param>
        /// <param name="bIsLast"></param>
        public void OnRspOrderInsert_ <T1, T2>(T1 pInputOrder, T2 pRspInfo, int nRequestID, bool bIsLast)
        {
            object obj   = pRspInfo;
            var    error = (ErrorInfo)obj;

            if (error.ErrorID == 0)
            {
                OnLog?.Invoke($"委托成功回报:{error.ErrorMsg}");
            }
            else
            {
                OnLog?.Invoke($"委托失败回报:{error.ErrorMsg}");
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 查询投资者响应
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="pInvestor"></param>
        /// <param name="pRspInfo"></param>
        /// <param name="nRequestID"></param>
        /// <param name="bIsLast"></param>
        public void OnRspQryInvestor_ <T1, T2>(T1 pInvestor, T2 pRspInfo, int nRequestID, bool bIsLast)
        {
            object obj   = pRspInfo;
            var    error = (ErrorInfo)obj;

            if (error.ErrorID == 0)
            {
                OnLog?.Invoke($"查询投资者成功:{error.ErrorMsg}");
            }
            else
            {
                OnLog?.Invoke($"查询投资者失败:{error.ErrorMsg}");
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 行情账号登出回报
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="onUserLogOut"></param>
        /// <param name="error"></param>
        /// <param name="n"></param>
        /// <param name="b"></param>
        public void OnRspUserLogout_ <T1, T2>(T1 onUserLogOut, T2 error, int n, bool b)
        {
            object    obj     = error;
            ErrorInfo error_d = (ErrorInfo)obj;

            if (error_d.ErrorID == 0)
            {
                OnLog?.Invoke($"CTP行情账号登出成功");
            }
            else
            {
                OnLog?.Invoke($"CTP行情账号登出失败,错误信息:{error_d.ErrorMsg}");
            }
        }
Ejemplo n.º 25
0
        private static void WriteToLog(string message, LogLevel level)
        {
            LogColor color = _theme?.GetColor(level)
                             ?? new LogColor();

            Console.ForegroundColor = color.Foreground
                                      ?? ConsoleColor.White;
            Console.BackgroundColor = color.Background
                                      ?? ConsoleColor.Black;

            OnLog?.Invoke($"{_createHeader(level)} {message}", level);

            Console.ResetColor();
        }
Ejemplo n.º 26
0
        public void Connect(string serverAddress = "10.0.1.1:13000")
        {
            ServerAddress = serverAddress;
            string result = string.Empty;

            // Create DnsEndPoint. The hostName and port are passed in to this method.
            string[]    address   = ServerAddress.Split(':');
            int         port      = 13000;
            DnsEndPoint hostEntry = new DnsEndPoint(address[0], address.Length == 2 ? int.Parse(address[1], System.Globalization.NumberFormatInfo.InvariantInfo) : port);

            // cleanup any previous connection
            if (_socket != null && _socket.Connected)
            {
                _socket.Dispose();
                OnConnect?.Invoke(this, new ConnectedEventArgs(false));
            }

            // Create a stream-based, TCP socket using the InterNetwork Address Family.
            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            // Create a SocketAsyncEventArgs object to be used in the connection request
            SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

            socketEventArg.RemoteEndPoint = hostEntry;

            // Inline event handler for the Completed event.
            // Note: This event handler was implemented inline in order to make this method self-contained.
            socketEventArg.Completed += new EventHandler <SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
            {
                if (e.SocketError == SocketError.Success)
                {
                    OnConnect?.Invoke(this, new ConnectedEventArgs(true));
                }

                OnLog?.Invoke(this, new LogEventArgs("Server response: " + e.SocketError.ToString()));

                // listen
                SocketAsyncEventArgs traceEventArg = new SocketAsyncEventArgs();
                traceEventArg.RemoteEndPoint       = hostEntry;
                ResetBuffer(traceEventArg);
                traceEventArg.Completed += SocketReceive;
                _socket.ReceiveAsync(traceEventArg);
            });

            OnLog?.Invoke(this, new LogEventArgs(string.Format("Connecting {0}:{1}", hostEntry.Host, hostEntry.Port)));

            // Make an asynchronous Connect request over the socket
            _socket.ConnectAsync(socketEventArg);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Creates a new log entry.
        /// </summary>
        /// <param name="message">
        /// The message of this log entry.
        /// </param>
        /// <param name="level">
        /// The log level describes the importance of an log entry.
        /// If its lower than the logFilter-level, which was set in the constructor, the log entry wont be shown in the console.
        /// </param>
        /// <param name="memberName">
        /// Filled by the compiler. Ignore this field.
        /// </param>
        /// <param name="sourceFilePath">
        /// Filled by the compiler. Ignore this field.
        /// </param>
        /// <param name="sourceLineNumber">
        /// Filled by the compiler. Ignore this field.
        /// </param>
        public void Log(string message, LogLevel level = LogLevel.Info,
                        [System.Runtime.CompilerServices.CallerMemberName] string memberName    = "",
                        [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath  = "",
                        [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
        {
            String clazz = Path.GetFileNameWithoutExtension(sourceFilePath);

            var entry = new LogEntry(message, level, clazz, memberName, sourceLineNumber);

            OnLog?.Invoke(entry);
            if (level >= LogFilter)
            {
                OnLogFiltered?.Invoke(entry);
            }
        }
Ejemplo n.º 28
0
        public void AddCustomResolver(Type type, Func <CustomResolverArgs, object> func)
        {
            if (customResolvers.ContainsKey(type))
            {
                OnLog?.Invoke($"[ERROR] There is already a custom resolver for type '{type.FullName}'");
                return;
            }
            if (func == null)
            {
                OnLog?.Invoke($"[ERROR] Null arg {nameof(func)}.");
                return;
            }

            customResolvers.Add(type, func);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Logs a line to this logger.
        /// </summary>
        /// <param name="msg">The contents of this log.</param>
        /// <param name="type">The type of log.</param>
        public void Log(string msg, DiscoreLogLevel type)
        {
            if (type >= MinimumLevel)
            {
                if (!string.IsNullOrWhiteSpace(Prefix))
                {
                    // Prefix
                    msg = $"[{Prefix}] {msg}";
                }

                try { OnLog?.Invoke(this, new DiscoreLogEventArgs(new DiscoreLogMessage(msg, type, DateTime.Now))); }
                // Log methods need to be guaranteed to never throw exceptions.
                catch { }
            }
        }
Ejemplo n.º 30
0
        public void OnRspUserLogout_ <T1, T2>(T1 pUserLogout, T2 pRspInfo, int nRequestID, bool bIsLast)
        {
            ///登出回报
            object obj   = pRspInfo;
            var    error = (ErrorInfo)obj;

            if (error.ErrorID == 0)
            {
                OnLog?.Invoke($"CTP交易账户登出成功:{error.ErrorMsg}");
            }
            else
            {
                OnLog?.Invoke($"CTP交易账户登出失败:{error.ErrorMsg}");
            }
        }