Esempio n. 1
0
        // 装入一个日志文件中的若干记录
        // return:
        //      -1  error
        //      0   file not found
        //      1   found
        int LoadSomeRecords(string strLogFileName,
            string strRange,
            ref long lProgressValue,
            ref long lSize,
            out string strError)
        {
            strError = "";

            stop.SetMessage("正在装入日志文件 " + strLogFileName + " 中的记录。"
                + "剩余时间 " + ProgressEstimate.Format(this.estimate.Estimate(lProgressValue)) + " 已经过时间 " + ProgressEstimate.Format(this.estimate.delta_passed));

            string strXml = "";
            long lAttachmentTotalLength = 0;
            byte[] attachment_data = null;

            long lFileSize = 0;

            // 获得日志文件尺寸
            long lRet = Channel.GetOperLog(
                stop,
                strLogFileName,
                -1,    // lIndex,
                -1, // lHint,
                out strXml,
                out lFileSize,
                0,  // lAttachmentFragmentStart,
                0,  // nAttachmentFramengLength,
                out attachment_data,
                out lAttachmentTotalLength,
                out strError);
            // 2010/12/13
            if (lRet == 0)
                return 0;

            // stop.SetProgressRange(0, lTotalSize);

            if (String.IsNullOrEmpty(strRange) == true)
                strRange = "0-9999999999";

            RangeList rl = new RangeList(strRange);

#if DELAY_UPDATE
            this.listView_records.BeginUpdate();
#endif
            try
            {
                for (int i = 0; i < rl.Count; i++)
                {
                    RangeItem ri = (RangeItem)rl[i];

                    long lHint = -1;
                    long lHintNext = -1;
                    for (long lIndex = ri.lStart; lIndex < ri.lStart + ri.lLength; lIndex++)
                    {
                        Application.DoEvents();

                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                strError = "用户中断1";
                                goto ERROR1;
                            }
                        }

                        lHint = lHintNext;

                        // 获得日志
                        // result.Value
                        //      -1  error
                        //      0   file not found
                        //      1   succeed
                        //      2   超过范围
                        lRet = Channel.GetOperLog(
                            stop,
                            strLogFileName,
                            lIndex,
                            lHint,
                            out strXml,
                            out lHintNext,
                            0,  // lAttachmentFragmentStart,
                            0,  // nAttachmentFramengLength,
                            out attachment_data,
                            out lAttachmentTotalLength,
                            out strError);
                        if (lRet == -1)
                            goto ERROR1;
                        if (lRet == 0)
                            return 0;

                        if (lRet == 2)
                            break;

#if NO
                            // 2011/12/30
                            // 日志记录可能动态地增加了,超过了原先为ProgressBar设置的范围
                            if (lFizeTotalSize < (int)lHintNext)
                            {
                                lFizeTotalSize = lHintNext;

                                stop.SetProgressRange(0, lFizeTotalSize);
                            }
#endif
                        // 校正
                        if (lProgressValue + lHintNext > lSize)
                        {
                            lSize = lProgressValue + lHintNext;

                            stop.SetProgressRange(0, lSize);
                            this.estimate.SetRange(0, lSize);
                        }

                            stop.SetProgressValue(lProgressValue + lHintNext);

                        if (lIndex % 100 == 0)
                        {
                            stop.SetMessage("正在装入日志文件 " + strLogFileName + " 中的记录 "+lIndex.ToString()+" 。"
    + "剩余时间 " + ProgressEstimate.Format(this.estimate.Estimate(lProgressValue + lHintNext)) + " 已经过时间 " + ProgressEstimate.Format(this.estimate.delta_passed));
                        }

                        if (string.IsNullOrEmpty(strXml) == false)
                        {
                            OperLogItemInfo info = new OperLogItemInfo();

                            if (this.StoreInTempFile == true)
                            {
                                // 创建临时文件
                                string strTempFileName = Path.GetTempFileName();
                                Stream stream = File.Create(strTempFileName);

                                // 写入xml内容
                                byte[] buffer = Encoding.UTF8.GetBytes(strXml);
                                stream.Write(buffer, 0, buffer.Length);

                                stream.Close();

                                m_tempFileNames.Add(strTempFileName);
                                info.IndexOfTempFilename = m_tempFileNames.Count - 1;
                            }
                            else
                            {
                                info.Hint = lHint;
                            }
                            ListViewItem item = new ListViewItem(strLogFileName, 0);
                            item.SubItems.Add(lIndex.ToString());  // 序号从0开始计数
                            this.listView_records.Items.Add(item);
                            item.Tag = info;

                            int nRet = FillListViewItem(item,
                                strXml,
                                lAttachmentTotalLength,
                                out strError);
                            if (nRet == -1)
                                goto ERROR1;
                        }
                    }
                }

                lProgressValue += lFileSize;
            }
            finally
            {
#if DELAY_UPDATE
                this.listView_records.EndUpdate();
#endif
            }

            return 1;
        ERROR1:
            return -1;
        }
Esempio n. 2
0
        int DoRecord(string strLogFileName,
            string strXml,
            bool bInCacheFile,
            long lHint,
            long lIndex,
            long lAttachmentTotalLength,
            object param,
            out string strError)
        {
            strError = "";

            if (string.IsNullOrEmpty(strXml) == true)
                return 0;

            OperLogItemInfo info = new OperLogItemInfo();

            if (this.StoreInTempFile == true)
            {
                // 创建临时文件
                string strTempFileName = Path.GetTempFileName();
                using (Stream stream = File.Create(strTempFileName))
                {
                    // 写入xml内容
                    byte[] buffer = Encoding.UTF8.GetBytes(strXml);
                    stream.Write(buffer, 0, buffer.Length);
                }

                m_tempFileNames.Add(strTempFileName);
                info.IndexOfTempFilename = m_tempFileNames.Count - 1;
            }
            else
            {
                info.Hint = lHint;
                info.InCacheFile = bInCacheFile;
            }
            ListViewItem item = new ListViewItem(strLogFileName, 0);
            ListViewUtil.ChangeItemText(item, COLUMN_INDEX, lIndex.ToString());
            // item.SubItems.Add(lIndex.ToString());  // 序号从0开始计数
            this.listView_records.Items.Add(item);
            item.Tag = info;

            int nRet = FillListViewItem(item,
                strXml,
                lAttachmentTotalLength,
                out strError);
            if (nRet == -1)
                return -1;

            if ((lIndex % 100) == 0)
                this.listView_records.ForceUpdate();

            return 0;
        }