Exemplo n.º 1
0
        /// <summary>
        /// 当日志文件不止一个时, 初始化组件运行所需参数
        /// </summary>
        /// <param name="listFileName"></param>
        public void LoadLogger(IList <string> listFileName)
        {
            JsonList tempJsonList = new JsonList();

            foreach (string fileName in listFileName)
            {
                int index  = fileName.IndexOf('_');
                int symbol = 0;
                if (index != -1)
                {
                    int endIndex = fileName.IndexOf('.');
                    symbol = int.Parse(fileName.Substring(index + 1, endIndex - index - 1));
                }

                DateTime dt = DateTime.Parse(fileName.Substring(0, 10));
                index = tempJsonList.GetIndexByKey(tempJsonList, dt);
                if (index != -1)
                {
                    if (tempJsonList[index].Value < symbol)
                    {
                        tempJsonList[index].Value = symbol;
                    }
                }
                else
                {
                    tempJsonList.Add(new Json <DateTime, int>(dt, symbol));
                }
            }

            int maxIndex = 0, minIndex = 0;

            for (int i = 1; i != tempJsonList.Count; i++)
            {
                if (tempJsonList[minIndex].Key > tempJsonList[i].Key)
                {
                    minIndex = i;
                }

                if (tempJsonList[maxIndex].Key < tempJsonList[i].Key)
                {
                    maxIndex = i;
                }
            }

            logEntity.CurrentFileName = tempJsonList[maxIndex].Key.ToString("yyyy-MM-dd") + (tempJsonList[maxIndex].Value == 0 ? "" : "_" + tempJsonList[maxIndex].Value) + ".log";
            logEntity.FileSymbol      = tempJsonList[maxIndex].Value;
            logEntity.LastFileDate    = tempJsonList[maxIndex].Key;
            logEntity.FirstFileDate   = tempJsonList[minIndex].Key;

            tempJsonList.Clear();
            tempJsonList = null;
        }
Exemplo n.º 2
0
        public int GetIndexByKey(JsonList jsonList, DateTime key)
        {
            int i = 0;

            foreach (Json <DateTime, int> json in jsonList)
            {
                if (json.Key == key)
                {
                    return(i);
                }

                i++;
            }

            return(-1);
        }