Exemplo n.º 1
0
        public bool Filter(ToastLoggerLogObject logData)
        {
            if (ToastLoggerSettings.Instance.isLogDuplicateFilter == false)
            {
                return(true);
            }

            long currentTime = ToastUtil.GetEpochMilliSeconds();

            _compareDuplicateInfos.RemoveAll(info => info.CreateTime < (currentTime - ToastLoggerSettings.Instance.filterDuplicateLogExpiredTimeSeconds * 1000));

            ToastLoggerDuplicateInfo duplicateInfo = new ToastLoggerDuplicateInfo();

            duplicateInfo.SetLogData(logData);

            foreach (var item in _compareDuplicateInfos)
            {
                if (item.Key == duplicateInfo.Key)
                {
                    return(false);
                }
            }

            if (_compareDuplicateInfos.Count >= _capacity)
            {
                _compareDuplicateInfos.RemoveAt(0);
            }

            _compareDuplicateInfos.Add(duplicateInfo);

            return(true);
        }
        public int compareTo(ToastLoggerDuplicateInfo info)
        {
            if (CreateTime < info.CreateTime)
            {
                return(-1);
            }
            else if (CreateTime > info.CreateTime)
            {
                return(1);
            }

            return(0);
        }