Пример #1
0
        // parameters:
        //      nCount  本次希望获取的记录数。如果==-1,表示希望尽可能多地获取
        //      strStyle    如果不包含 supervisor,则本函数会自动过滤掉日志记录中读者记录的 password 字段
        // return:
        //      -1  error
        //      0   file not found
        //      1   succeed
        //      2   超过范围,本次调用无效
        public int GetOperLogs(
            string strLibraryCodeList,
            string strFileName,
            long lIndex,
            long lHint,
            int nCount,
            string strStyle,
            string strFilter,
            out OperLogInfo[] records,
            out string strError)
        {
            records = null;
            strError = "";
            List<OperLogInfo> results = new List<OperLogInfo>();

            if (StringUtil.IsInList("getfilenames", strStyle) == true)
            {
                DirectoryInfo di = new DirectoryInfo(this.m_strDirectory);
                FileInfo[] fis = di.GetFiles("????????.log");

                if (fis.Length == 0)
                    return 0;   // 一个文件也没有

                // 日期小者在前
                Array.Sort(fis, new FileInfoCompare(true));

                int nStart = (int)lIndex;
                int nEnd = fis.Length;
                if (nCount == -1)
                    nEnd = fis.Length;
                else
                    nEnd = Math.Min(nStart + nCount, fis.Length);

                // 一次不让超过最大数量
                if (nEnd - nStart > MAX_FILENAME_COUNT)
                    nEnd = nStart + MAX_FILENAME_COUNT;
                for (int i = nStart; i < nEnd; i++)
                {
                    OperLogInfo info = new OperLogInfo();
                    info.Index = i;
                    info.Xml = fis[i].Name;
                    info.AttachmentLength = fis[i].Length;
                    results.Add(info);
                }

                records = new OperLogInfo[results.Count];
                results.CopyTo(records);
                return fis.Length;  // 返回事项总数
            }

            int nPackageLength = 0;

            string strXml = "";
            long lAttachmentLength = 0;
            long lHintNext = -1;
            for (int i = 0; i < nCount || nCount == -1; i++)
            {
                // return:
                //      -1  error
                //      0   file not found
                //      1   succeed
                //      2   超过范围
                int nRet = GetOperLog(
                    strLibraryCodeList,
                    strFileName,
                    lIndex,
                    lHint,
                    strStyle,
                    strFilter,
                    out lHintNext,
                    out strXml,
                    out lAttachmentLength,
                    out strError);
                if (nRet == -1)
                    return -1;
                if (nRet == 0)
                    return 0;
                if (nRet == 2)
                {
                    if (i == 0)
                        return 2;   // 本次调用无效
                    break;
                }

                nPackageLength += strXml.Length + 100;  // 边角尺寸

                if (nPackageLength > 500 * 1024
                    && i > 0)
                    break;

                OperLogInfo info = new OperLogInfo();
                info.Index = lIndex;
                info.HintNext = lHintNext;
                info.Xml = strXml;
                info.AttachmentLength = lAttachmentLength;
                results.Add(info);

                lIndex++;
                lHint = lHintNext;
            }

            records = new OperLogInfo[results.Count];
            results.CopyTo(records);
            return 1;
        }
Пример #2
0
        // parameters:
        //      nCount  本次希望获取的记录数。如果==-1,表示希望尽可能多地获取
        // return:
        //      -1  error
        //      0   file not found
        //      1   succeed
        //      2   超过范围,本次调用无效
        public int GetOperLogs(
            string strLibraryCodeList,
            string strFileName,
            long lIndex,
            long lHint,
            int nCount,
            string strStyle,
            string strFilter,
            out OperLogInfo[] records,
            out string strError)
        {
            records = null;
            strError = "";
            List<OperLogInfo> results = new List<OperLogInfo>();

            if (StringUtil.IsInList("getfilenames", strStyle) == true)
            {
                int hit_count = 0;
                List<ValueCount> dates = ListDates(0, MAX_FILENAME_COUNT, out hit_count);
                int nStart = (int)lIndex;
                int nEnd = dates.Count;
                if (nCount == -1)
                    nEnd = dates.Count;
                else
                    nEnd = Math.Min(nStart + nCount, dates.Count);

                // 一次不让超过最大数量
                if (nEnd - nStart > MAX_FILENAME_COUNT)
                    nEnd = nStart + MAX_FILENAME_COUNT;

                for (int i = nStart; i < nEnd; i++)
                {
                    ValueCount item = dates[i];
                    OperLogInfo info = new OperLogInfo();
                    info.Index = i;
                    info.Xml = item.Value + ".log";
                    info.AttachmentLength = item.Count;
                    results.Add(info);
                }

#if NO
                records = new OperLogInfo[results.Count];
                results.CopyTo(records);
#endif
                records = results.ToArray();
                return (int)lIndex + hit_count;
#if NO
                DirectoryInfo di = new DirectoryInfo(this.m_strDirectory);
                FileInfo[] fis = di.GetFiles("????????.log");

                if (fis.Length == 0)
                    return 0;   // 一个文件也没有

                // 日期小者在前
                Array.Sort(fis, new FileInfoCompare(true));

                int nStart = (int)lIndex;
                int nEnd = fis.Length;
                if (nCount == -1)
                    nEnd = fis.Length;
                else
                    nEnd = Math.Min(nStart + nCount, fis.Length);

                // 一次不让超过最大数量
                if (nEnd - nStart > MAX_FILENAME_COUNT)
                    nEnd = nStart + MAX_FILENAME_COUNT;
                for (int i = nStart; i < nEnd; i++)
                {
                    OperLogInfo info = new OperLogInfo();
                    info.Index = i;
                    info.Xml = fis[i].Name;
                    info.AttachmentLength = fis[i].Length;
                    results.Add(info);
                }

                records = new OperLogInfo[results.Count];
                results.CopyTo(records);
                return 1;
#endif
            }

            if (string.IsNullOrEmpty(strFileName) == true
                || strFileName.Length < 8)
            {
                strError = "strFileName 参数值不能为空,或者长度小于 8 字符";
                return -1;
            }

            string date = strFileName.Substring(0, 8);
            IEnumerable<AccessLogItem> collection = Find(date, (int)lIndex);
            if (collection == null)
                return 0;
            List<OperLogInfo> infos = new List<OperLogInfo>();
            foreach (AccessLogItem item in collection)
            {
                OperLogInfo info = new OperLogInfo();
                info.AttachmentLength = 0;
                info.HintNext = 0;
                info.Index = lIndex++;
                info.Xml = GetXml(item);
                infos.Add(info);
            }
            if (infos.Count == 0)
                return 2;

            records = infos.ToArray();
            return 1;
        }