示例#1
0
            public RoomReference AddReference(PeerBase ownerPeer)
            {
                var reference = new RoomReference(_roomFactory, Room, ownerPeer);

                _references.Add(reference.Id, reference);

                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat(
                        "Created room instance reference: roomName={0}, referenceCount={1}",
                        Room.Name,
                        ReferenceCount);
                }

                if (_logQueue.Log.IsDebugEnabled)
                {
                    _logQueue.Add(
                        new LogEntry(
                            "AddReference",
                            string.Format(
                                "RoomName={0}, ReferenceCount={1}, OwnerPeer={2}",
                                Room.Name,
                                ReferenceCount,
                                ownerPeer)));
                }

                return(reference);
            }
示例#2
0
        public void LogRequest(string oldUrl, string referrer)
        {
            int bufferSize = Configuration.Configuration.BufferSize;

            if (LogQueue.Count > 0 && LogQueue.Count >= bufferSize)
            {
                lock (LogQueue)
                {
                    try
                    {
                        if (LogQueue.Count >= bufferSize)
                        {
                            LogRequests(LogQueue);
                        }
                        LogQueue = new List <LogEvent>();
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("An error occured while trying to log 404 errors. ", ex);
                        LogQueue = new List <LogEvent>();
                    }
                }
            }
            LogQueue.Add(new LogEvent(oldUrl, DateTime.Now, referrer));
        }
示例#3
0
        public static int RemoveUnusedImages(long envelopeId, string caseName)
        {
            int removedImages = 0;

            var caseFolder = AddInfoHelper.CaseAddInfoFolder(envelopeId);
            var imageList  = GetImageList(caseFolder, _cfg.ImageExts).Select(x => new CaseImage(AddInfoHelper.CaseAddInfoPath(envelopeId, x.FileName))).ToList();

            foreach (var il in imageList)
            {
                if (il.Image.StartsWith(caseName))
                {
                    il.Found = true;
                }
            }

            foreach (var il in imageList)
            {
                if (!il.Found)
                {
                    if (FileHelper.DeleteFile(AddInfoHelper.CaseAddInfoPath(envelopeId, il.Image)))
                    {
                        ++removedImages;
                    }
                    else
                    {
                        _log.Add(TAG, FileHelper.LastError);
                    }
                }
            }

            return(removedImages);
        }
示例#4
0
        public void AddLogMessage(IComponentControl componentControl, LogMessage logMessage)
        {
            if (componentControl == null)
            {
                return;
            }
            if (logMessage == null)
            {
                return;
            }
            if (Disabled)
            {
                return;
            }
            var webLogs = new WebLogMessage()
            {
                Attemps          = 0,
                ComponentControl = componentControl,
                CreateDate       = DateTime.Now,
                Order            = Order,
                Date             = logMessage.Date,
                Level            = logMessage.Level,
                Message          = logMessage.Message,
                Context          = logMessage.Context,
                Properties       = logMessage.Properties
            };

            webLogs.Size = GetMessageSize(webLogs);
            LogQueue.Add(webLogs);
            Order++;

            OnAddLogMessage?.Invoke(componentControl, logMessage);
        }
示例#5
0
        /// <summary>
        /// 获取指定对象的父对象层级,排序为:自身到根节点
        /// </summary>
        /// <param name="trans"></param>
        /// <returns></returns>
        public static List <Transform> getParentLevel(this Transform trans)
        {
            List <Transform> parent_level = null;

            if (trans)
            {
                parent_level = new List <Transform>();
                if (trans.root.name.Equals(trans.name))
                {
                    parent_level.Add(trans);
                }
                else
                {
                    Transform trans_temp = trans;
                    while (!trans_temp.Equals(trans.root))
                    {
                        parent_level.Add(trans_temp);
                        trans_temp = trans_temp.parent;
                    }
                    parent_level.Add(trans_temp);
                }
            }
            else
            {
                LogQueue.Add("警告:需要获取的父节点层级的对象为空!");
            }
            return(parent_level);
        }
        public static void Send(string str)
        {
            if (string.IsNullOrEmpty(TokenKey))
            {
                throw new ArgumentException("Please call Init() first.");
            }

            LogQueue.Add(str.Replace("\n", "\n" + TokenKey));
        }
示例#7
0
 protected internal override bool BeforeLog(LogEntry logEntry)
 {
     lock (LogQueue)
     {
         LogQueue.Add(new KeyValuePair <Logger, LogEntry>(this.Logger, logEntry));
     }
     ThreadSignal.Set();
     return(true);
 }
示例#8
0
 public static void Error(string msg, params object[] par)
 {
     if (!ErrorLogEnabled)
     {
         return;
     }
     LogQueue.Add(string.Format("{0} ERR {1}\r\n", DateTime.UtcNow.ToString(TimeStampFormat),
                                // need to check because {} symbols might break Format call
                                (par == null || par.Length == 0) ? msg : string.Format(msg, par)));
 }
示例#9
0
 /// <summary>
 /// MP3文件转WAV文件
 /// </summary>
 /// <param name="ori_file_path">原MP3文件路径</param>
 /// <param name="_savePath">转成wav文件后的存储路径</param>
 public static void MP3_TO_WAV(string ori_file_path, string _savePath)
 {
     LogQueue.Add("开始转换:" + ori_file_path);
     if (File.Exists(ori_file_path))
     {
         LogQueue.Add("正在转换:" + ori_file_path);
         var stream = File.Open(ori_file_path, FileMode.Open);
         var reader = new Mp3FileReader(stream);
         WaveFileWriter.CreateWaveFile(_savePath, reader);
     }
 }
示例#10
0
 /// <summary>
 /// 添加状态
 /// </summary>
 /// <param name="state_id">状态ID</param>
 /// <param name="state"></param>
 public virtual void Add(object state_id, IStateBase state)
 {
     if (!states.ContainsValue(state))
     {
         states.Add(state_id, state);
     }
     else
     {
         LogQueue.Add(string.Format("提醒:{0}已存在...", state.ToString()));
     }
 }
示例#11
0
 /// <summary>
 /// 删除一个状态
 /// </summary>
 /// <param name="state"></param>
 public void Remove(IStateBase state)
 {
     if (states.ContainsValue(state))
     {
         states.Remove(state);
     }
     else
     {
         LogQueue.Add(string.Format("提醒:{0}不存在...", state.ToString()));
     }
 }
示例#12
0
 /// <summary>
 /// 删除一个状态
 /// </summary>
 public void Remove(object id)
 {
     if (states.ContainsKey(id))
     {
         states.Remove(id);
     }
     else
     {
         LogQueue.Add(string.Format("提醒:{0}不存在...", id.ToString()));
     }
 }
        public static void Send(string str, params object[] obj)
        {
            if (string.IsNullOrEmpty(TokenKey))
            {
                throw new ArgumentException("Please call Init() first.");
            }

            var finalStr = string.Format(str, obj);

            LogQueue.Add(finalStr.Replace("\n", "\n" + TokenKey));
        }
 /// <summary>
 /// 添加状态
 /// </summary>
 /// <param name="state"></param>
 public void Add(StateBase <StateID> state)
 {
     if (!states.ContainsValue(state))
     {
         states.Add(state.ID, state);
     }
     else
     {
         LogQueue.Add(string.Format("提醒:{0}已存在...", state.ToString()));
     }
 }
示例#15
0
        /// <summary>
        /// Log a caught exception
        /// </summary>
        public void LogException(LogLevel level, Exception ex, string message, params object[] formatParameters)
        {
            if (level < ActiveLevel)
            {
                return;
            }

            var logMessage = new LogMessage(this, _hostName, level, ex, message, formatParameters)
            {
                LogTarget = _targetLog
            };

            LogQueue.Add(logMessage);
        }
示例#16
0
        /// <summary>
        /// 获取字典中指定Value值的下标
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="dic"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int getIndexOf <K, V>(this Dictionary <K, V> dic, V value)
        {
            int index = -1;

            if (dic.ContainsValue(value))
            {
                index = dic.getValues().IndexOf(value);
            }
            else
            {
                LogQueue.Add(string.Format("提醒:{0}不存在...", value.ToString()));
            }
            return(index);
        }
示例#17
0
        /// <summary>
        /// 通过ID获取一个状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        protected virtual IStateBase getSate(object id)
        {
            IStateBase _state = default(IStateBase);

            if (states.ContainsKey(id))
            {
                states.TryGetValue(id, out _state);
            }
            else
            {
                LogQueue.Add(string.Format("提醒:状态机中并不存在ID为{0}的状态", id.ToString()));
            }
            return(_state);
        }
示例#18
0
        /// <summary>
        /// 获取字典中指定Key值的下标
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="dic"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int getIndexOf <K, V>(this Dictionary <K, V> dic, K key)
        {
            int index = -1;

            if (dic.ContainsKey(key))
            {
                index = dic.getKeys().IndexOf(key);
            }
            else
            {
                LogQueue.Add(string.Format("提醒:{0}不存在...", key.ToString()));
            }
            return(index);
        }
示例#19
0
        public async Task AddLog(LogItem logItem, bool writeLog = true)
        {
            try
            {
                await LogQueueLock.WaitAsync();

                if (CompactLog)
                {
                    var lastLogItem = LogQueue.LastOrDefault();
                    if (
                        LogMessageTypeEnum.Progress == logItem.Type &&
                        LogMessageTypeEnum.Progress == lastLogItem?.Type
                        )
                    {
                        LogQueue.Remove(lastLogItem);
                    }
                }

                LogQueue.Add(logItem);
                if (LogQueue.Count() > LogQueueSize)
                {
                    LogQueue.RemoveAt(0);
                }
            }
            finally
            {
                LogQueueLock.Release();
            }

            if (writeLog && null != WriteLog)
            {
                var totalLog = await GetLog();

                try
                {
                    if (null != WriteLog)
                    {
                        await WriteLog(totalLog);
                    }
                }
                catch (Exception e)
                {
                    try
                    {
                        Console.WriteLine($"failed to {nameof(WriteLog)}, exception message: {e.Message}");
                    }
                    catch { }
                }
            }
        }
示例#20
0
        public static void Trace(string msg,
                                 [CallerMemberName] string memberName    = "",
                                 [CallerFilePath] string sourceFilePath  = "",
                                 [CallerLineNumber] int sourceLineNumber = 0)
        {
            if (!TraceLogEnabled)
            {
                return;
            }

            LogQueue.Add(string.Format("{0} TRC {1}:{2}[{3}] {4}\r\n", DateTime.UtcNow.ToString(TimeStampFormat),
                                       Path.GetFileName(sourceFilePath), memberName,
                                       sourceLineNumber, msg));
        }
        /// <summary>
        /// 通过ID获取一个状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private StateBase <StateID> getSate(StateID id)
        {
            StateBase <StateID> _state = default(StateBase <StateID>);

            if (states.ContainsKey(id))
            {
                states.TryGetValue(id, out _state);
            }
            else
            {
                LogQueue.Add(string.Format("提醒:状态机中并不存在ID为{0}的状态", id.ToString()));
            }
            return(_state);
        }
示例#22
0
 /// <summary>
 /// 移除指定Value值
 /// </summary>
 /// <typeparam name="K"></typeparam>
 /// <typeparam name="V"></typeparam>
 /// <param name="dic"></param>
 public static void Remove <K, V>(this Dictionary <K, V> dic, V value)
 {
     if (dic.ContainsValue(value))
     {
         K key = default(K);
         foreach (var item in dic)
         {
             if (item.Value.Equals(value))
             {
                 key = item.Key;
                 break;
             }
         }
         dic.Remove(key);
     }
     else
     {
         LogQueue.Add(string.Format("提醒:{0}不存在...", value.ToString()));
     }
 }
示例#23
0
        public ExcelReader(string excelPath)
        {
            _excelPath = excelPath;
            if (!string.IsNullOrEmpty(_excelPath))
            {
                FileStream       stream      = File.Open(_excelPath, FileMode.Open, FileAccess.Read);
                IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

                if (excelReader.ResultsCount > 0)
                {
                    _excelData = excelReader.AsDataSet();
                    _dataTable = _excelData.Tables;
                    _rows      = _dataTable[0].Rows;
                    _colus     = _dataTable[0].Columns;
                    _rowCount  = _rows.Count;
                    _coluCount = _colus.Count;

                    if (excelReader != null)
                    {
                        excelReader.Close();
                    }
                    if (stream != null)
                    {
                        stream.Close();
                    }
                }
                else
                {
                    LogQueue.Add("表格读取错误...");
                }
            }
            else
            {
                LogQueue.Add("表格存储路径错误...");
            }
        }
示例#24
0
        protected override void ExecuteOperation(
            PlayerPeer peer,
            OperationRequest operationRequest,
            SendParameters sendParameters)
        {
            try
            {
                base.ExecuteOperation(peer, operationRequest, sendParameters);

                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("Executing operation {0}", (OperationCode)operationRequest.OperationCode);
                }

                switch ((OperationCode)operationRequest.OperationCode)
                {
                case OperationCode.Join:
                {
                    var joinRequest = new JoinRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(joinRequest, sendParameters) == false)
                    {
                        return;
                    }

                    if (LogQueue.Log.IsDebugEnabled)
                    {
                        LogQueue.Add(
                            new LogEntry(
                                "ExecuteOperation: " + (OperationCode)operationRequest.OperationCode,
                                "Peer=" + peer.ConnectionId));
                    }

                    joinRequest.OnStart();
                    HandleJoinOperation(peer, joinRequest, sendParameters);
                    joinRequest.OnComplete();
                    break;
                }

                case OperationCode.Leave:
                {
                    var leaveOperation = new LeaveRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(leaveOperation, sendParameters) == false)
                    {
                        return;
                    }

                    if (LogQueue.Log.IsDebugEnabled)
                    {
                        LogQueue.Add(
                            new LogEntry(
                                "ExecuteOperation: " + (OperationCode)operationRequest.OperationCode,
                                "Peer=" + peer.ConnectionId));
                    }

                    leaveOperation.OnStart();
                    HandleLeaveOperation(peer, leaveOperation, sendParameters);
                    leaveOperation.OnComplete();
                    break;
                }

                case OperationCode.CustomOp:
                    // todo: here implemented custom logic
                    // get handler for opp
                    break;

                case OperationCode.RaiseEvent:
                {
                    var raiseEventOperation = new RaiseEventRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(raiseEventOperation, sendParameters) == false)
                    {
                        return;
                    }

                    raiseEventOperation.OnStart();
                    HandleRaiseEventOperation(peer, raiseEventOperation, sendParameters);
                    raiseEventOperation.OnComplete();
                    break;
                }

                case OperationCode.GetProperties:
                {
                    var getPropertiesOperation = new GetPropertiesRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(getPropertiesOperation, sendParameters) == false)
                    {
                        return;
                    }

                    getPropertiesOperation.OnStart();
                    HandleGetPropertiesOperation(peer, getPropertiesOperation, sendParameters);
                    getPropertiesOperation.OnComplete();
                    break;
                }

                case OperationCode.SetProperties:
                {
                    var setPropertiesOperation = new SetPropertiesRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(setPropertiesOperation, sendParameters) == false)
                    {
                        return;
                    }

                    setPropertiesOperation.OnStart();
                    HandleSetPropertiesOperation(peer, setPropertiesOperation, sendParameters);
                    setPropertiesOperation.OnComplete();
                    break;
                }

                case OperationCode.Ping:
                {
                    peer.SendOperationResponse(
                        new OperationResponse {
                            OperationCode = operationRequest.OperationCode
                        },
                        sendParameters);
                    break;
                }

                case OperationCode.ChangeGroups:
                {
                    var changeGroupsOperation = new ChangeGroups(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(changeGroupsOperation, sendParameters) == false)
                    {
                        return;
                    }

                    changeGroupsOperation.OnStart();
                    HandleChangeGroupsOperation(peer, changeGroupsOperation, sendParameters);
                    changeGroupsOperation.OnComplete();
                    break;
                }

                default:
                {
                    var message = $"Unknown operation code {(OperationCode)operationRequest.OperationCode}";
                    peer.SendOperationResponse(
                        new OperationResponse
                        {
                            OperationCode = operationRequest.OperationCode,
                            ReturnCode    = -1,
                            DebugMessage  = message
                        },
                        sendParameters);

                    if (Log.IsWarnEnabled)
                    {
                        Log.Warn(message);
                    }
                }

                break;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }