Пример #1
0
        public static void Log(params object[] objs)
        {
            var str = $"{DateTime.Now:yyMMdd-HHmmss-ff}>>{objs.Aggregate((o, o1) => $"{o}\r\n{o1}")}";

            Debug.WriteLine(str);
            LogAction?.Invoke(str);
        }
Пример #2
0
        public CustomFile SetDataFromPath(string path)
        {
            try
            {
                //if (!Exists(path))
                //{

                //    System.IO.File.Create(path);

                //    //throw new Exception(string.Format("The file : '{0}' doesnt exists", path));
                //}

                SetPathToRead(path);
                SetPathToWrite(path);

                Data = ReadAllBytes(path);

                SetExtension(System.IO.Path.GetExtension(path));

                SetName(System.IO.Path.GetFileNameWithoutExtension(path));

                FileInfo = new FileInfo(path);
            }
            catch (Exception ex)
            {
                LogAction?.Invoke(ex);
            }

            return(this);
        }
Пример #3
0
        internal static void Log(
            LogAction action,
            LogError errAction,
            Type loggerType,
            Exception error,
            string message,
            object[] args,
            string memberName,
            string sourceFile,
            int sourceLine)
        {
            string trace = LogTraceMessage(
                loggerType,
                error,
                message,
                memberName,
                sourceFile,
                sourceLine);

            if (errAction != null && error != null)
            {
                errAction.Invoke(error, trace, args);
            }
            else
            {
                action.Invoke(trace, args);
            }
        }
Пример #4
0
        public void Run(Action action, long count, string assembly, string method, Type type = null, string comment = null)
        {
            GC.Collect(3, GCCollectionMode.Forced, true);
            var startMem = GC.GetTotalMemory(false);
            var gen0     = GC.CollectionCount(0);
            var gen1     = GC.CollectionCount(1);
            var gen2     = GC.CollectionCount(2);
            var gen3     = GC.CollectionCount(3);
            var sw       = Stopwatch.StartNew();

            action.Invoke();
            sw.Stop();
            var peakMem = GC.GetTotalMemory(false) - startMem;

            GC.Collect(3, GCCollectionMode.Forced, true);
            var endMem = GC.GetTotalMemory(false) - startMem;
            var ops    = (1000L * count / sw.ElapsedMilliseconds);

            gen0 = GC.CollectionCount(0) - gen0;
            gen1 = GC.CollectionCount(1) - gen1;
            gen2 = GC.CollectionCount(2) - gen2;
            gen3 = GC.CollectionCount(3) - gen3;
            // assembly, method, time in msecs, mops, totalMem, peakMem, gen0, gen1, gen2, gen3,typeName, comment
            _logAction.Invoke(assembly, method, sw.ElapsedMilliseconds, Math.Round(ops / 1000000.0, 2),
                              Math.Round(endMem / 1000000.0, 2), Math.Round(peakMem / 1000000.0, 2), gen0, gen1, gen2, gen3, type == null ? "" : type.Name,
                              comment);
        }
Пример #5
0
        private void LogInfo(string log)
        {
            string huiche = @"
";

            LogAction?.Invoke(log);
            log += log + huiche;
        }
Пример #6
0
        /// <summary>
        /// Read the log file until EOF
        /// </summary>
        private void ReadToEof(object state = null)
        {
            string s;

            while ((s = _sr.ReadLine()) != null)
            {
                LogAction.Invoke(s);
            }
        }
Пример #7
0
        /// <summary>
        /// Logs the message.
        /// </summary>
        /// <param name="message">The <see cref="MessageItem"/> to log.</param>
        /// <returns>The resulting <see cref="JsonEntityMergeResult"/>.</returns>
        public JsonEntityMergeResult Log(MessageItem message)
        {
            if (TreatWarningsAsErrors && message.Type == MessageType.Warning)
            {
                message.Type = MessageType.Error;
            }

            LogAction?.Invoke(message);
            return(message.Type == MessageType.Error ? JsonEntityMergeResult.Error : JsonEntityMergeResult.SuccessNoChanges);
        }
Пример #8
0
    static void Main(string[] args)
    {
        string host = "188.40.137.215";
        int    port = 23323;

        //string host = "99.229.37.128";
        // int port = 9990;
        RPCTest = DoSomething;

        RPCTest.Invoke(5, 4);
        byte    rpcID;
        RPCTest test  = new RPCTest(2);
        RPCTest test2 = new RPCTest(4);
        Type    type  = typeof(RPCTest);
        int     x1    = 5;
        int     x2    = 3;

        object[] obj = { 1, 2 };

        MethodInfo[] methods = type.GetMethods();

        for (int i = 0; i < methods.Count(); i++)
        {
            if (methods[i].IsDefined(typeof(MMORPC), out rpcID))
            {
                Console.WriteLine("Registerd Method with RPC ID =  " + rpcID);
                methods[i].Invoke(test, obj);
            }
        }
        Console.WriteLine("Connected to Server [Host = " + host + " ] [Port = " + port + Environment.NewLine);
        clientCore.InitializeClient(host, port);

        clientCore.onMovementSync  += OnMovementSync;
        clientCore.onChatResponse  += onChatResponse;
        clientCore.onLoginResponse += OnLoginResponse;
        clientCore.Connect();
        Thread thread = new Thread(new ThreadStart(KeyListen));

        thread.Start();
        while (true)
        {
            switch (Console.ReadLine().ToLower())
            {
            case "l": tbLogin_Click(); break;

            case "m": new Thread(new ThreadStart(SpamMovePackets)).Start(); break;
            }
        }
    }
Пример #9
0
        private DataGateKey GetDataGate(string key)
        {
            var gkey = _ms.GetDataKey(key);

            //如果是多数据库,则需要在*Keys.json中配置数据库连接名称ConnName

            //注意这里在单个生命周期内_db只能有一个
            if (DB == null)
            {
                DB     = DBFactory.CreateDBHelper(gkey.ConnName ?? "Default");
                DB.Log = (sql, ps) =>
                {
                    LogAction?.Invoke(gkey, sql, ps);
                };
            }
            gkey.DataService = this; //将DB对象传递给可能的DataGate前后切面数据处理程序
            return(gkey);
        }
Пример #10
0
        public bool CreateNewIfNotExists(string path)
        {
            try
            {
                if (!System.IO.File.Exists(path))
                {
                    using (FileStream fs = File.Create(path))
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                LogAction?.Invoke(ex);

                return(false);
            }

            return(true);
        }
Пример #11
0
        public void RunTransaction(Action <MySqlCommand> Command, LogAction dbgCallback = null)
        {
            try
            {
                CloseReaders();

                var transaction = _connection.BeginTransaction();
                var executor    = new MySqlCommand()
                {
                    Transaction = transaction,
                    Connection  = _connection
                };
                executor.EnableCaching = false;

                try
                {
                    Command(executor);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    var error = "Error running transaction. Rolling back. Error: " + ex + Environment.NewLine + "Command: " + executor.CommandText;
                    _logFile.WriteLine(error);
                    dbgCallback?.Invoke(error);
                }
                finally
                {
                    transaction.Dispose();
                    executor.Dispose();
                }
            }
            catch (InvalidOperationException)
            {
                _logFile.WriteLine("Lost connection (InvalidOperation). Reconnecting.");
                Connect();
                System.Threading.Thread.Sleep(1000);
                RunTransaction(Command);
            }
        }
Пример #12
0
 public void RaiseLog(string message, DateTime timestamp)
 {
     LogAction?.Invoke(new LogMessage(this, message, timestamp));
 }
Пример #13
0
 /// <summary>
 /// Writes a log entry if <see cref="LogAction"/> is not null.
 /// </summary>
 /// <param name="message"></param>
 /// <param name="callerMemberName"></param>
 protected void WriteLog(string message, [CallerMemberName] string callerMemberName = "unknown")
 {
     LogAction?.Invoke($"{GetType().FullName} \t {callerMemberName} \t {message}");
 }
Пример #14
0
		private void Log(string msg, PhotoModel item = null)
		{
			Debug.WriteLine(msg);
			LogAction?.Invoke(msg);
			item?.AddMessage(msg);
		}
Пример #15
0
 public static void Info(string format, string arg0)
 {
     infoAction?.Invoke(string.Format(format, arg0));
 }
Пример #16
0
 public static void Error(object obj)
 {
     errorAction?.Invoke(obj);
 }
Пример #17
0
 public static void Warning(object obj)
 {
     warningAction?.Invoke(obj);
 }
Пример #18
0
 public void RaiseDie()
 {
     Died?.Invoke();
     LogAction?.Invoke(new LogMessage(this, "Корабль сбит", DateTime.Now));
 }
Пример #19
0
 public static void Log(InfoType infoType, string format, params object[] args)
 {
     LogAction?.Invoke(infoType, string.Format(format, args));
 }
Пример #20
0
 public static void Log(InfoType infoType, string info)
 {
     LogAction?.Invoke(infoType, info);
 }
Пример #21
0
 public void Log(MessageLevel level, string message, params object[] args) =>
 LogAction?.Invoke(level, message, args);
Пример #22
0
 public static void Log(object obj)
 {
     logAction?.Invoke(obj);
 }
 public static void Log(string message) => LogAction?.Invoke(message);