Exemplo n.º 1
0
 void loader_Prompt(object sender, MessagePromptEventArgs e)
 {
     if (this.Prompt != null)
     {
         this.Prompt(sender, e);
     }
 }
Exemplo n.º 2
0
 private static void Loader_Prompt(object sender, MessagePromptEventArgs e)
 {
     if (Prompt != null)
     {
         Prompt(sender, e);
     }
 }
Exemplo n.º 3
0
 private void FingerPrint_Prompt(object sender, MessagePromptEventArgs e)
 {
     // TODO: 不再出现此对话框。不过重试有个次数限制,同一位置失败多次后总要出现对话框才好
     if (e.Actions == "yes,no,cancel")
     {
         DialogResult result = MessageBox.Show(this,
                                               e.MessageText + "\r\n\r\n是否重试操作?\r\n\r\n(是: 重试;  否: 跳过本次操作,继续后面的操作; 取消: 停止全部操作)",
                                               "ReportForm",
                                               MessageBoxButtons.YesNoCancel,
                                               MessageBoxIcon.Question,
                                               MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Yes)
         {
             e.ResultAction = "yes";
         }
         else if (result == DialogResult.Cancel)
         {
             e.ResultAction = "cancel";
         }
         else
         {
             e.ResultAction = "no";
         }
     }
 }
        // 2017/6/16
        void m_loader_Prompt(object sender, MessagePromptEventArgs e)
        {
            MessagePromptEventHandler handler = this.Prompt;

            if (handler != null)
            {
                handler(sender, e);
            }
        }
Exemplo n.º 5
0
        void loader_Prompt(object sender, MessagePromptEventArgs e)
        {
            // TODO: 不再出现此对话框。不过重试有个次数限制,同一位置失败多次后总要出现对话框才好
            if (e.Actions == "yes,no,cancel")
            {
#if NO
                DialogResult result = MessageBox.Show(this,
                                                      e.MessageText + "\r\n\r\n是否重试操作?\r\n\r\n(是: 重试;  否: 跳过本次操作,继续后面的操作; 取消: 停止全部操作)",
                                                      "ReportForm",
                                                      MessageBoxButtons.YesNoCancel,
                                                      MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    e.ResultAction = "yes";
                }
                else if (result == DialogResult.Cancel)
                {
                    e.ResultAction = "cancel";
                }
                else
                {
                    e.ResultAction = "no";
                }
#endif
                DialogResult result = AutoCloseMessageBox.Show(this,
                                                               e.MessageText + "\r\n\r\n将自动重试操作\r\n\r\n(点右上角关闭按钮可以中断批处理)",
                                                               20 * 1000,
                                                               "OperLogStatisForm");
                if (result == DialogResult.Cancel)
                {
                    e.ResultAction = "no";
                }
                else
                {
                    e.ResultAction = "yes";
                }
            }
        }
Exemplo n.º 6
0
        // 处理一小批指纹数据的装入
        // parameters:
        static void GetSomeFingerprintData(
            LibraryChannel channel,
            List <string> lines,
            CancellationToken token,
            out List <DigitalPlatform.LibraryClient.localhost.Record> records)
        {
            // strError = "";

            records = new List <DigitalPlatform.LibraryClient.localhost.Record>();

            for (; ;)
            {
                token.ThrowIfCancellationRequested();

                DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null;

                string[] paths = new string[lines.Count];
                lines.CopyTo(paths);
REDO_GETRECORDS:
                long lRet = channel.GetBrowseRecords(
                    null,
                    paths,
                    "id,cols,format:cfgs/browse_fingerprint",
                    out searchresults,
                    out string strError);
                if (lRet == -1)
                {
#if NO
                    DialogResult temp_result = MessageBox.Show(this,
                                                               strError + "\r\n\r\n是否重试?",
                                                               "ReaderSearchForm",
                                                               MessageBoxButtons.RetryCancel,
                                                               MessageBoxIcon.Question,
                                                               MessageBoxDefaultButton.Button1);
                    if (temp_result == DialogResult.Retry)
                    {
                        goto REDO_GETRECORDS;
                    }
                    return(-1);
#endif

                    if (Prompt != null)
                    {
                        MessagePromptEventArgs e = new MessagePromptEventArgs
                        {
                            // e.MessageText = "获得书目记录 '"+strCommand+"' ("+StringUtil.MakePathList(format_list)+") 时发生错误: " + strError;
                            MessageText = strError + "\r\n\r\n是否重试?",
                            Actions     = "yes,no,cancel"
                        };
                        Prompt(channel, e);
                        if (e.ResultAction == "cancel")
                        {
                            throw new ChannelException(channel.ErrorCode, strError);
                        }
                        else if (e.ResultAction == "yes")
                        {
                            goto REDO_GETRECORDS;
                        }
                        else
                        {
                            // no 也是抛出异常。因为继续下一批代价太大
                            throw new ChannelException(channel.ErrorCode, strError);
                        }
                    }
                    else
                    {
                        throw new ChannelException(channel.ErrorCode, strError);
                    }
                }

                records.AddRange(searchresults);

                // 去掉已经做过的一部分
                lines.RemoveRange(0, searchresults.Length);

                if (lines.Count == 0)
                {
                    break;
                }
            }
        }
Exemplo n.º 7
0
 public void Loader_Prompt(object sender, MessagePromptEventArgs e)
 {
     if (Prompt != null)
         Prompt(sender, e);
 }
Exemplo n.º 8
0
        public IEnumerator GetEnumerator()
        {
            List <string> batch = new List <string>();

            for (int index = 0; index < m_barcodes.Count; index++)
            {
                string s = m_barcodes[index];

                if (string.IsNullOrEmpty(s) == true)
                {
                    throw new Exception("册条码号字符串不允许为空 (index=" + index.ToString() + ")");
                }

                batch.Add(s);

                // 每100个一批,或者最后一次
                if (batch.Count >= 100 ||
                    (index == m_barcodes.Count - 1 && batch.Count > 0))
                {
REDO_GETITEMINFO:
                    string strBiblio = "";
                    string strResult = "";
                    string strError  = "";
                    long   lRet      = this.Channel.GetItemInfo(
                        this.Stop,
                        "@barcode-list:" + StringUtil.MakePathList(batch),
                        "get-path-list",
                        out strResult,
                        "", // strBiblioType,
                        out strBiblio,
                        out strError);
                    if (lRet == -1)
                    {
                        if (this.Prompt != null)
                        {
                            MessagePromptEventArgs e = new MessagePromptEventArgs();
                            e.MessageText = "通过册条码号获得记录路径时发生错误: " + strError;
                            e.Actions     = "yes,no,cancel";
                            this.Prompt(this, e);
                            if (e.ResultAction == "cancel")
                            {
                                throw new Exception(strError);
                            }
                            else if (e.ResultAction == "yes")
                            {
                                if (this.Stop != null)
                                {
                                    this.Stop.Continue();
                                }
                                goto REDO_GETITEMINFO;
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            throw new ChannelException(Channel.ErrorCode, strError);
                        }
                    }

                    List <string> recpaths = StringUtil.SplitList(strResult);

                    if (batch.Count != recpaths.Count)
                    {
                        strError = "batch.Count != recpaths.Count";
                        throw new Exception(strError);
                    }
                    Debug.Assert(batch.Count == recpaths.Count, "");

                    int i = 0;
                    foreach (string recpath in recpaths)
                    {
                        EntityItem item = new EntityItem();
                        item.Barcode = batch[i];

                        if (string.IsNullOrEmpty(recpath) == false &&
                            recpath[0] == '!')
                        {
                            item.ErrorInfo = recpath.Substring(1);
                        }
                        else
                        {
                            item.RecPath = recpath;
                        }
                        i++;

                        yield return(item);
                    }

                    batch.Clear();
                }
            }
        }
Exemplo n.º 9
0
        public IEnumerator GetEnumerator()
        {
            string strError = "";
            int    nRet     = 0;

            long lRet = 0;

            if ((this.LogType & dp2Circulation.LogType.AccessLog) != 0 &&
                (this.LogType & dp2Circulation.LogType.OperLog) != 0)
            {
                throw new ArgumentException("OperLogItemLoader 的 LogType 只能使用一种类型");
            }

            if (this.Stop != null && this.estimate != null)
            {
                this.Stop.SetMessage("正在装入日志文件 " + this.FileName + " 中的记录。"
                                     + "剩余时间 " + ProgressEstimate.Format(estimate.Estimate(lProgressValue)) + " 已经过时间 " + ProgressEstimate.Format(estimate.delta_passed));
            }

            string strXml = "";
            long   lAttachmentTotalLength = 0;

            byte[] attachment_data = null;

            long lFileSize = 0;

            if (lServerFileSize == -1)
            {
                long _lServerFileSize = 0;

                string strStyle = "level-" + Level.ToString();
                if ((this.LogType & dp2Circulation.LogType.AccessLog) != 0)
                {
                    strStyle += ",accessLog";
                }

                // 获得服务器端日志文件尺寸
                lRet = this.Channel.GetOperLog(
                    this.Stop,
                    this.FileName,
                    -1, // lIndex,
                    -1, // lHint,
                    strStyle,
                    "", // strFilter
                    out strXml,
                    out _lServerFileSize,
                    0,  // lAttachmentFragmentStart,
                    0,  // nAttachmentFramengLength,
                    out attachment_data,
                    out lAttachmentTotalLength,
                    out strError);
                // 2015/11/25
                if (lRet == -1)
                {
                    throw new Exception(strError);
                }
                this.lServerFileSize = _lServerFileSize;

                if (lRet == 0)
                {
                    yield break;
                }
                // 2015/11/25
                if (_lServerFileSize == -1)
                {
                    yield break;    // 此类型的日志尚未启用
                }
            }

            Stream stream           = null;
            bool   bCacheFileExist  = false;
            bool   bRemoveCacheFile = false; // 是否要自动删除未全部完成的本地缓存文件

            bool bAutoCache = this.AutoCache;

            if (bAutoCache == true)
            {
                string strFileName = this.FileName;
                if ((this.LogType & dp2Circulation.LogType.AccessLog) != 0)
                {
                    strFileName = this.FileName + ".a";
                }

                nRet = PrepareCacheFile(
                    this.CacheDir,
                    strFileName,    // this.FileName,
                    lServerFileSize,
                    out bCacheFileExist,
                    out stream,
                    out strError);
                if (nRet == -1)
                {
                    throw new Exception(strError);
                }

                if (bCacheFileExist == false && stream != null)
                {
                    bRemoveCacheFile = true;
                }
            }

            try
            {
                if (bCacheFileExist == true)
                {
                    lFileSize = stream.Length;
                }
                else
                {
                    lFileSize = lServerFileSize;
                }

                // stop.SetProgressRange(0, lTotalSize);

                if (String.IsNullOrEmpty(Range) == true)
                {
                    Range = "0-" + (long.MaxValue - 1).ToString();    // "0-9999999999";
                }
                RangeList rl = new RangeList(Range);

                for (int i = 0; i < rl.Count; i++)
                {
                    RangeItem ri = (RangeItem)rl[i];

                    // 让 100- 这样的 range 可以使用
                    if (ri.lLength == -1)
                    {
                        ri.lLength = long.MaxValue - ri.lStart;
                    }

                    OperLogInfo[] records       = null;
                    long          lStartRecords = 0;

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

                        if (this.Stop != null && this.Stop.State != 0)
                        {
                            strError = "用户中断";
                            throw new Exception(strError);
                            // yield break; ?
                        }

                        if (lIndex == ri.lStart)
                        {
                            lHint = -1;
                        }
                        else
                        {
                            lHint = lHintNext;
                        }

                        if (bCacheFileExist == true)
                        {
                            if (lHint == -1)
                            {
                                // return:
                                //      -1  error
                                //      0   成功
                                //      1   到达文件末尾或者超出
                                nRet = LocationRecord(stream,
                                                      lIndex,
                                                      out strError);
                                if (nRet == -1)
                                {
                                    throw new Exception(strError);
                                }
                            }
                            else
                            {
                                // 根据暗示找到
                                if (lHint == stream.Length)
                                {
                                    break;
                                }

                                if (lHint > stream.Length)
                                {
                                    strError = "lHint参数值不正确";
                                    throw new Exception(strError);
                                }
                                if (stream.Position != lHint)
                                {
                                    stream.Seek(lHint, SeekOrigin.Begin);
                                }
                            }

                            nRet = ReadCachedEnventLog(
                                stream,
                                out strXml,
                                out lAttachmentTotalLength,
                                out strError);
                            if (nRet == -1)
                            {
                                throw new Exception(strError);
                            }
                            lHintNext = stream.Position;
                        }
                        else
                        {
                            if (records == null || lIndex /*- ri.lStart*/ >= lStartRecords + records.Length)
                            {
                                int nCount = -1;
                                if (ri.lLength >= Int32.MaxValue)
                                {
                                    nCount = -1;    // 500;   // -1;
                                }
                                else
                                {
                                    nCount = (int)ri.lLength;   // Math.Min(500, (int)ri.lLength);
                                }
                                string strStyle = "level-" + Level.ToString();
                                if ((this.LogType & dp2Circulation.LogType.AccessLog) != 0)
                                {
                                    strStyle += ",accessLog";
                                }
REDO:
                                // 获得日志
                                // return:
                                //      -1  error
                                //      0   file not found
                                //      1   succeed
                                //      2   超过范围,本次调用无效
                                lRet = this.Channel.GetOperLogs(
                                    this.Stop,
                                    this.FileName,
                                    lIndex,
                                    lHint,
                                    nCount,
                                    strStyle,
                                    this.Filter, // strFilter
                                    out records,
                                    out strError);
                                if (lRet == -1)
                                {
#if NO
                                    DialogResult result = MessageBox.Show(owner,
                                                                          "获取日志信息 (" + this.FileName + " " + lIndex.ToString() + ") 的操作发生错误: " + strError + "\r\n\r\n是否重试操作?\r\n\r\n(是: 重试;  否: 跳过本次操作,继续后面的操作; 放弃: 停止全部操作)",
                                                                          "OperLogItemLoader",
                                                                          MessageBoxButtons.YesNoCancel,
                                                                          MessageBoxIcon.Question,
                                                                          MessageBoxDefaultButton.Button1);
                                    if (result == DialogResult.Yes)
                                    {
                                        goto REDO;
                                    }
                                    if (result == DialogResult.Cancel)
                                    {
                                        throw new Exception(strError);
                                    }
                                    else
                                    {
                                        // TODO: 是否要在listview中装入一条表示出错的行?
                                        lHintNext = -1;
                                        continue;
                                    }
#endif
                                    if (this.Prompt != null)
                                    {
                                        MessagePromptEventArgs e = new MessagePromptEventArgs();
                                        e.MessageText = "获取 " + this._logType.ToString() + " 日志信息 (" + this.FileName + " " + lIndex.ToString() + ") 的操作发生错误: " + strError;
                                        e.Actions     = "yes,no,cancel";
                                        this.Prompt(this, e);
                                        if (e.ResultAction == "cancel")
                                        {
                                            throw new Exception(strError);
                                        }
                                        else if (e.ResultAction == "yes")
                                        {
                                            if (this.Stop != null)
                                            {
                                                this.Stop.Continue();
                                            }
                                            goto REDO;
                                        }
                                        else
                                        {
                                            lHintNext = -1;
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception(strError);
                                    }
                                }
                                if (lRet == 0)
                                {
                                    yield break;
                                }

                                if (lRet == 2)
                                {
                                    break;
                                }

                                // records数组表示的起点位置
                                lStartRecords = lIndex /* - ri.lStart*/;
                            }
                            OperLogInfo info = records[lIndex - lStartRecords];

                            strXml    = info.Xml;
                            lHintNext = info.HintNext;
                            lAttachmentTotalLength = info.AttachmentLength;

                            // 写入本地缓存的日志文件
                            if (stream != null)
                            {
                                try
                                {
                                    WriteCachedEnventLog(
                                        stream,
                                        strXml,
                                        lAttachmentTotalLength);
                                }
                                catch (Exception ex)
                                {
                                    strError = "写入本地缓存文件的时候出错: " + ex.Message;
                                    throw new Exception(strError);
                                }
                            }
                        }

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

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

                                if (this.Stop != null && this.estimate != null)
                                {
                                    this.Stop.SetProgressRange(0, lSize);
                                    estimate.SetRange(0, lSize);
                                }
                            }

                            this.Stop.SetProgressValue(lProgressValue + lHintNext);
                        }

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

                        {
                            OperLogItem item = new OperLogItem();
                            item.Xml   = strXml;
                            item.Index = lIndex;
                            item.Date  = this.FileName.Substring(0, 8);
                            yield return(item);
                        }
                    }
                }

                // 创建本地缓存的日志文件的metadata文件
                if (bCacheFileExist == false && stream != null)
                {
                    string strFileName = this.FileName;
                    if ((this.LogType & dp2Circulation.LogType.AccessLog) != 0)
                    {
                        strFileName = this.FileName + ".a";
                    }

                    nRet = CreateCacheMetadataFile(
                        this.CacheDir,
                        strFileName,    // this.FileName,
                        lServerFileSize,
                        out strError);
                    if (nRet == -1)
                    {
                        throw new Exception(strError);
                    }
                }

                bRemoveCacheFile = false;   // 不删除
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }

                if (bRemoveCacheFile == true)
                {
                    string strFileName = this.FileName;
                    if ((this.LogType & dp2Circulation.LogType.AccessLog) != 0)
                    {
                        strFileName = this.FileName + ".a";
                    }

                    string strError1 = "";
                    nRet = DeleteCacheFile(
                        this.CacheDir,
                        strFileName,    // this.FileName,
                        out strError1);
                    if (nRet == -1)
                    {
                        // MessageBox.Show(owner, strError1);
                        if (this.Prompt != null)
                        {
                            MessagePromptEventArgs e = new MessagePromptEventArgs();
                            e.MessageText = strError1;
                            e.Actions     = "ok";
                            this.Prompt(this, e);
                        }
                    }
                }
            }

            lProgressValue += lFileSize;
        }
Exemplo n.º 10
0
        public IEnumerator GetEnumerator()
        {

            List<string> batch = new List<string>();
            for (int index = 0; index < m_barcodes.Count; index++)
            {
                string s = m_barcodes[index];

                if (string.IsNullOrEmpty(s) == true)
                    throw new Exception("册条码号字符串不允许为空 (index="+index.ToString()+")");

                batch.Add(s);

                // 每100个一批,或者最后一次
                if (batch.Count >= 100 ||
                    (index == m_barcodes.Count - 1 && batch.Count > 0))
                {
                REDO_GETITEMINFO:
                    string strBiblio = "";
                    string strResult = "";
                    string strError = "";
                    long lRet = this.Channel.GetItemInfo(
                        this.Stop,
                        "@barcode-list:" + StringUtil.MakePathList(batch),
                        "get-path-list",
                        out strResult,
                        "", // strBiblioType,
                        out strBiblio,
                        out strError);
                    if (lRet == -1)
                    {
                        if (this.Prompt != null)
                        {
                            MessagePromptEventArgs e = new MessagePromptEventArgs();
                            e.MessageText = "通过册条码号获得记录路径时发生错误: " + strError;
                            e.Actions = "yes,no,cancel";
                            this.Prompt(this, e);
                            if (e.ResultAction == "cancel")
                                throw new Exception(strError);
                            else if (e.ResultAction == "yes")
                            {
                                if (this.Stop != null)
                                    this.Stop.Continue();
                                goto REDO_GETITEMINFO;
                            }
                            else
                            {
                            }
                        }
                        else
                            throw new ChannelException(Channel.ErrorCode, strError);
                    }

                    List<string> recpaths = StringUtil.SplitList(strResult);

                    if (batch.Count != recpaths.Count)
                    {
                        strError = "batch.Count != recpaths.Count";
                        throw new Exception(strError);
                    }
                    Debug.Assert(batch.Count == recpaths.Count, "");

                    int i = 0;
                    foreach (string recpath in recpaths)
                    {
                        EntityItem item = new EntityItem();
                        item.Barcode = batch[i];

                        if (string.IsNullOrEmpty(recpath) == false
                            && recpath[0] == '!')
                            item.ErrorInfo = recpath.Substring(1);
                        else
                            item.RecPath = recpath;
                        i++;

                        yield return item;
                    }

                    batch.Clear();
                }
            }
        }
Exemplo n.º 11
0
     void loader_Prompt(object sender, MessagePromptEventArgs e)
     {
         // TODO: 不再出现此对话框。不过重试有个次数限制,同一位置失败多次后总要出现对话框才好
         if (e.Actions == "yes,no,cancel")
         {
             DialogResult result = MessageBox.Show(this,
 e.MessageText + "\r\n\r\n是否重试操作?\r\n\r\n(是: 重试;  否: 跳过本次操作,继续后面的操作; 取消: 停止全部操作)",
 "ReportForm",
 MessageBoxButtons.YesNoCancel,
 MessageBoxIcon.Question,
 MessageBoxDefaultButton.Button1);
             if (result == DialogResult.Yes)
                 e.ResultAction = "yes";
             else if (result == DialogResult.Cancel)
                 e.ResultAction = "cancel";
             else
                 e.ResultAction = "no";
         }
     }
Exemplo n.º 12
0
 void m_loader_Prompt(object sender, MessagePromptEventArgs e)
 {
     if (this.Prompt != null)
         this.Prompt(sender, e);
 }
Exemplo n.º 13
0
        public IEnumerator GetEnumerator()
        {
            string strError = "";
            int nRet = 0;

            long lRet = 0;

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

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

            long lFileSize = 0;
            if (lServerFileSize == -1)
            {
                long _lServerFileSize = 0;

                // 获得服务器端日志文件尺寸
                lRet = this.Channel.GetOperLog(
                    this.Stop,
                    this.FileName,
                    -1,    // lIndex,
                    -1, // lHint,
                        "level-" + nLevel.ToString(),
                        "", // strFilter
                    out strXml,
                    out _lServerFileSize,
                    0,  // lAttachmentFragmentStart,
                    0,  // nAttachmentFramengLength,
                    out attachment_data,
                    out lAttachmentTotalLength,
                    out strError);

                this.lServerFileSize = _lServerFileSize;

                if (lRet == 0)
                    yield break;
            }

            Stream stream = null;
            bool bCacheFileExist = false;
            bool bRemoveCacheFile = false;  // 是否要自动删除未全部完成的本地缓存文件

            bool bAutoCache = this.AutoCache;

            if (bAutoCache == true)
            {
                nRet = PrepareCacheFile(
                    this.CacheDir,
                    this.FileName,
                    lServerFileSize,
                    out bCacheFileExist,
                    out stream,
                    out strError);
                if (nRet == -1)
                    throw new Exception(strError);

                if (bCacheFileExist == false && stream != null)
                    bRemoveCacheFile = true;
            }

            try
            {
                if (bCacheFileExist == true)
                    lFileSize = stream.Length;
                else
                    lFileSize = lServerFileSize;

                // stop.SetProgressRange(0, lTotalSize);

                if (String.IsNullOrEmpty(Range) == true)
                    Range = "0-" + (long.MaxValue - 1).ToString();    // "0-9999999999";

                RangeList rl = new RangeList(Range);

                for (int i = 0; i < rl.Count; i++)
                {
                    RangeItem ri = (RangeItem)rl[i];

                    // 让 100- 这样的 range 可以使用
                    if (ri.lLength == -1)
                        ri.lLength = long.MaxValue - ri.lStart;

                    OperLogInfo[] records = null;
                    long lStartRecords = 0;

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

                        if (this.Stop != null && this.Stop.State != 0)
                        {
                            strError = "用户中断";
                            throw new Exception(strError);
                            // yield break; ?
                        }


                        if (lIndex == ri.lStart)
                            lHint = -1;
                        else
                            lHint = lHintNext;

                        if (bCacheFileExist == true)
                        {
                            if (lHint == -1)
                            {
                                // return:
                                //      -1  error
                                //      0   成功
                                //      1   到达文件末尾或者超出
                                nRet = LocationRecord(stream,
                    lIndex,
                    out strError);
                                if (nRet == -1)
                                    throw new Exception(strError);
                            }
                            else
                            {
                                // 根据暗示找到
                                if (lHint == stream.Length)
                                    break;

                                if (lHint > stream.Length)
                                {
                                    strError = "lHint参数值不正确";
                                    throw new Exception(strError);
                                }
                                if (stream.Position != lHint)
                                    stream.Seek(lHint, SeekOrigin.Begin);
                            }

                            nRet = ReadCachedEnventLog(
                                stream,
                                out strXml,
                                out lAttachmentTotalLength,
                                out strError);
                            if (nRet == -1)
                                throw new Exception(strError);
                            lHintNext = stream.Position;

                        }
                        else
                        {
                            if (records == null || lIndex /*- ri.lStart*/ >= lStartRecords + records.Length)
                            {
                                int nCount = -1;
                                if (ri.lLength >= Int32.MaxValue)
                                    nCount = -1;    // 500;   // -1;
                                else
                                    nCount = (int)ri.lLength;   // Math.Min(500, (int)ri.lLength);

                            REDO:
                                // 获得日志
                                // return:
                                //      -1  error
                                //      0   file not found
                                //      1   succeed
                                //      2   超过范围,本次调用无效
                                lRet = this.Channel.GetOperLogs(
                                    this.Stop,
                                    this.FileName,
                                    lIndex,
                                    lHint,
                                    nCount,
                                    "level-" + nLevel.ToString(),
                                    this.Filter, // strFilter
                                    out records,
                                    out strError);
                                if (lRet == -1)
                                {
#if NO
                                    DialogResult result = MessageBox.Show(owner,
    "获取日志信息 ("+this.FileName + " " +lIndex.ToString() + ") 的操作发生错误: " + strError + "\r\n\r\n是否重试操作?\r\n\r\n(是: 重试;  否: 跳过本次操作,继续后面的操作; 放弃: 停止全部操作)",
    "OperLogItemLoader",
    MessageBoxButtons.YesNoCancel,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button1);
                                    if (result == DialogResult.Yes)
                                        goto REDO;
                                    if (result == DialogResult.Cancel)
                                        throw new Exception(strError);
                                    else
                                    {
                                        // TODO: 是否要在listview中装入一条表示出错的行?
                                        lHintNext = -1;
                                        continue;
                                    }
#endif
                                    if (this.Prompt != null)
                                    {
                                        MessagePromptEventArgs e = new MessagePromptEventArgs();
                                        e.MessageText = "获取日志信息 ("+this.FileName + " " +lIndex.ToString() + ") 的操作发生错误: " + strError;
                                        e.Actions = "yes,no,cancel";
                                        this.Prompt(this, e);
                                        if (e.ResultAction == "cancel")
                                            throw new Exception(strError);
                                        else if (e.ResultAction == "yes")
                                        {
                                            if (this.Stop != null)
                                                this.Stop.Continue();
                                            goto REDO;
                                        }
                                        else
                                        {
                                            lHintNext = -1;
                                            continue;
                                        }
                                    }
                                    else
                                        throw new Exception(strError);
                                }
                                if (lRet == 0)
                                    yield break;

                                if (lRet == 2)
                                    break;

                                // records数组表示的起点位置
                                lStartRecords = lIndex /* - ri.lStart*/;
                            }
                            OperLogInfo info = records[lIndex - lStartRecords];

                            strXml = info.Xml;
                            lHintNext = info.HintNext;
                            lAttachmentTotalLength = info.AttachmentLength;

                            // 写入本地缓存的日志文件
                            if (stream != null)
                            {
                                try
                                {
                                    WriteCachedEnventLog(
                                        stream,
                                        strXml,
                                        lAttachmentTotalLength);
                                }
                                catch (Exception ex)
                                {
                                    strError = "写入本地缓存文件的时候出错: " + ex.Message;
                                    throw new Exception(strError);
                                }
                            }
                        }

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

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

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

                            this.Stop.SetProgressValue(lProgressValue + lHintNext);
                        }

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

                        {
                            OperLogItem item = new OperLogItem();
                            item.Xml = strXml;
                            item.Index = lIndex;
                            item.Date = this.FileName.Substring(0, 8);
                            yield return item;
                        }

                    }
                }

                // 创建本地缓存的日志文件的metadata文件
                if (bCacheFileExist == false && stream != null)
                {
                    nRet = CreateCacheMetadataFile(
                        this.CacheDir,
                        this.FileName,
                        lServerFileSize,
                        out strError);
                    if (nRet == -1)
                        throw new Exception(strError);
                }

                bRemoveCacheFile = false;   // 不删除
            }
            finally
            {
                if (stream != null)
                    stream.Close();

                if (bRemoveCacheFile == true)
                {
                    string strError1 = "";
                    nRet = DeleteCacheFile(
                        this.CacheDir,
                        this.FileName,
                        out strError1);
                    if (nRet == -1)
                    {
                        // MessageBox.Show(owner, strError1);
                        if (this.Prompt != null)
                        {
                            MessagePromptEventArgs e = new MessagePromptEventArgs();
                            e.MessageText = strError1;
                            e.Actions = "ok";
                            this.Prompt(this, e);
                        }
                    }
                }
            }

            lProgressValue += lFileSize;
        }
Exemplo n.º 14
0
        public IEnumerator GetEnumerator()
        {
            string strError = "";
            int    nRet     = 0;

            if ((this.LogType & dp2Circulation.LogType.AccessLog) != 0 &&
                (this.LogType & dp2Circulation.LogType.OperLog) != 0)
            {
                throw new ArgumentException("OperLogLoader 的 LogType 只能使用一种类型");
            }

            if (string.IsNullOrEmpty(this.CacheDir) == false)
            {
                PathUtil.CreateDirIfNeed(this.CacheDir);
            }

            // ProgressEstimate estimate = new ProgressEstimate();
            bool bAutoCache = this.AutoCache;

            if (bAutoCache == true)
            {
                long lServerFileSize = 0;
                long lCacheFileSize  = 0;
                // 象征性获得一个日志文件的尺寸,主要目的是为了触发一次通道登录
                // return:
                //      -2  此类型的日志尚未启用
                //      -1  error
                //      0   file not found
                //      1   found
                nRet = GetFileSize(
                    this.Stop,
                    this.Channel,
                    this.CacheDir,
                    "20121001.log",
                    this.LogType,
                    out lServerFileSize,
                    out lCacheFileSize,
                    out strError);
                if (nRet == -1)
                {
                    throw new Exception(strError);
                }
                // 2015/11/25
                if (nRet == -2)
                {
                    yield break;    // 此类型的日志尚未启用
                }
                // 检查日志文件缓存目录的版本是否和当前用户的信息一致
                // return:
                //      -1  出错
                //      0   一致
                //      1   不一致
                nRet = DetectCacheVersionFile(
                    this.CacheDir,
                    "version.xml",
                    this.Channel.LibraryCodeList,
                    this.Channel.Url,
                    out strError);
                if (nRet == -1)
                {
                    throw new Exception(strError);
                }
                if (nRet == 1)
                {
REDO:
                    // 清空当前缓存目录
                    nRet = Global.DeleteDataDir(
                        null, // owner,
                        this.CacheDir,
                        out strError);
                    if (nRet == -1)
                    {
                        if (this.Prompt != null)
                        {
                            MessagePromptEventArgs e = new MessagePromptEventArgs();
                            e.MessageText = "清空当前缓存目录时发生错误: " + strError;
                            e.Actions     = "yes,no,cancel";
                            this.Prompt(this, e);
                            if (e.ResultAction == "cancel")
                            {
                                throw new Exception(strError);
                            }
                            else if (e.ResultAction == "yes")
                            {
                                goto REDO;
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            throw new Exception(strError);
                        }
                    }
#if NO
                    if (nRet == -1)
                    {
                        throw new Exception(strError);
                    }
#endif

                    PathUtil.CreateDirIfNeed(this.CacheDir);  // 重新创建目录

                    // 创建版本文件
                    nRet = CreateCacheVersionFile(
                        this.CacheDir,
                        "version.xml",
                        this.Channel.LibraryCodeList,
                        this.Channel.Url,
                        out strError);
                    if (nRet == -1)
                    {
                        throw new Exception(strError);
                    }
                }
            }

            long          lTotalSize = 0;
            List <string> lines      = new List <string>(); // 经过处理后排除了不存在的文件名
            List <string> ranges     = new List <string>();
            List <long>   sizes      = new List <long>();

            this.Stop.SetMessage("正在准备获得日志文件尺寸 ...");
            foreach (string strLine in this.FileNames)
            {
                Application.DoEvents();

                if (this.Stop != null && this.Stop.State != 0)
                {
                    strError = "用户中断";
                    throw new Exception(strError);
                    // yield break; ?
                }

                if (String.IsNullOrEmpty(strLine) == true)
                {
                    continue;
                }

                string strFilename = strLine.Trim();
                // 去掉注释
                nRet = strFilename.IndexOf("#");
                if (nRet != -1)
                {
                    strFilename = strFilename.Substring(0, nRet).Trim();
                }

                if (String.IsNullOrEmpty(strFilename) == true)
                {
                    continue;
                }

                string strLogFilename = "";
                string strRange       = "";

                nRet = strFilename.IndexOf(":");
                if (nRet != -1)
                {
                    strLogFilename = strFilename.Substring(0, nRet).Trim();
                    strRange       = strFilename.Substring(nRet + 1).Trim();
                }
                else
                {
                    strLogFilename = strFilename.Trim();
                    strRange       = "";
                }

                if (strLogFilename.Length == 8)
                {
                    strLogFilename += ".log";
                }
REDO_GETSIZE:
                long lServerFileSize = 0;
                long lCacheFileSize = 0;
                // 获得一个日志文件的尺寸
                //      -2  此类型的日志尚未启用
                //      -1  error
                //      0   file not found
                //      1   found
                nRet = GetFileSize(
                    this.Stop,
                    this.Channel,
                    this.CacheDir,
                    strLogFilename,
                    this.LogType,
                    out lServerFileSize,
                    out lCacheFileSize,
                    out strError);
                if (nRet == -1)
                {
                    // throw new Exception(strError);

                    if (this.Prompt != null)
                    {
                        MessagePromptEventArgs e = new MessagePromptEventArgs();
                        e.MessageText = "获取日志文件 " + strLogFilename + " 尺寸的操作发生错误: " + strError;
                        e.Actions     = "yes,no,cancel";
                        this.Prompt(this, e);
                        if (e.ResultAction == "cancel")
                        {
                            throw new Exception(strError);
                        }
                        else if (e.ResultAction == "yes")
                        {
                            if (this.Stop != null)
                            {
                                this.Stop.Continue();
                            }
                            goto REDO_GETSIZE;
                        }
                        else
                        {
                            // ??
                            continue;
                        }
                    }
                    else
                    {
                        throw new Exception(strError);
                    }
                }

                if (nRet == 0)
                {
                    continue;
                }

                if (lServerFileSize == 0)
                {
                    continue;   // 0字节的文件当作不存在处理
                }
                // 2015/11/25
                if (lServerFileSize == -1)
                {
                    yield break;    // 此类型的日志尚未启用
                }
                Debug.Assert(lServerFileSize >= 0, "");

                if (bAutoCache == true)
                {
                    if (lCacheFileSize > 0)
                    {
                        lTotalSize += lCacheFileSize;
                    }
                    else
                    {
                        lTotalSize += lServerFileSize;
                    }
                }
                else
                {
                    lTotalSize += lServerFileSize;
                }

                // lines.Add(strFilename);
                lines.Add(strLogFilename);
                ranges.Add(strRange);

                // 记忆每个文件的尺寸,后面就不用获取了?
                sizes.Add(lServerFileSize);
            }

            long lDoneSize = 0;

            if (this.ProgressStart == -1)
            {
                lDoneSize = lTotalSize;
            }
            else
            {
                lDoneSize = this.ProgressStart;
            }

            lTotalSize += lDoneSize;

            if (this.Stop != null)
            {
                this.Stop.SetProgressRange(0, lTotalSize);
            }

            estimate.SetRange(lDoneSize, lTotalSize);
            estimate.StartEstimate();

            for (int i = 0; i < lines.Count; i++)
            {
                Application.DoEvents();

                if (this.Stop != null && this.Stop.State != 0)
                {
                    strError = "用户中断";
                    throw new Exception(strError);
                    // yield break; ?
                }

                string strLine  = lines[i];
                string strRange = ranges[i];

                string strLogFilename = strLine;
#if NO
                string strLogFilename = "";
                string strRange       = "";

                nRet = strLine.IndexOf(":");
                if (nRet != -1)
                {
                    strLogFilename = strLine.Substring(0, nRet).Trim();
                    strRange       = strLine.Substring(nRet + 1).Trim();
                }
                else
                {
                    strLogFilename = strLine.Trim();
                    strRange       = "";
                }
#endif

                {
                    OperLogItemLoader loader = new OperLogItemLoader();
                    loader.Stop    = this.Stop;
                    loader.Channel = this.Channel;
                    // loader.owner = this.owner;
                    loader.estimate        = this.estimate;
                    loader.FileName        = strLogFilename;
                    loader.Level           = this.Level;
                    loader.lServerFileSize = sizes[i];
                    loader.Range           = strRange;
                    loader.AutoCache       = this.AutoCache;
                    loader.lProgressValue  = lDoneSize;
                    loader.lSize           = lTotalSize;
                    loader.Filter          = this.Filter;
                    loader.LogType         = this.LogType;

                    loader.Prompt -= new MessagePromptEventHandler(loader_Prompt);
                    loader.Prompt += new MessagePromptEventHandler(loader_Prompt);

                    foreach (OperLogItem item in loader)
                    {
                        yield return(item);
                    }

                    lDoneSize  = loader.lProgressValue;
                    lTotalSize = loader.lSize;
                }
            }
        }
Exemplo n.º 15
0
        // 同步
        // 注:中途遇到异常(例如 Loader 抛出异常),可能会丢失 INSERT_BATCH 条以内的日志记录写入 operlog 表
        // parameters:
        //      strLastDate   处理中断或者结束时返回最后处理过的日期
        //      last_index  处理或中断返回时最后处理过的位置。以后继续处理的时候可以从这个偏移开始
        // return:
        //      -1  出错
        //      0   中断
        //      1   完成
        public static ReplicationResult DoReplication(
            LibraryChannel channel,
            string strStartDate,
            string strEndDate,
            LogType logType,
            CancellationToken token)
        {
            string strLastDate = "";
            long   last_index  = -1; // -1 表示尚未处理

            // bool bUserChanged = false;

            // strStartDate 里面可能会包含 ":1-100" 这样的附加成分
            StringUtil.ParseTwoPart(strStartDate,
                                    ":",
                                    out string strLeft,
                                    out string strRight);
            strStartDate = strLeft;

            if (string.IsNullOrEmpty(strStartDate) == true)
            {
                return(new ReplicationResult
                {
                    Value = -1,
                    ErrorInfo = "DoReplication() 出错: strStartDate 参数值不应为空"
                });
            }

            try
            {
                List <string> dates = null;
                int           nRet  = OperLogLoader.MakeLogFileNames(strStartDate,
                                                                     strEndDate,
                                                                     true, // 是否包含扩展名 ".log"
                                                                     out dates,
                                                                     out string strWarning,
                                                                     out string strError);
                if (nRet == -1)
                {
                    return(new ReplicationResult
                    {
                        Value = -1,
                        ErrorInfo = strError
                    });
                }

                if (dates.Count > 0 && string.IsNullOrEmpty(strRight) == false)
                {
                    dates[0] = dates[0] + ":" + strRight;
                }

                channel.Timeout = new TimeSpan(0, 1, 0);   // 一分钟


                // using (SQLiteConnection connection = new SQLiteConnection(this._connectionString))
                {
                    ProgressEstimate estimate = new ProgressEstimate();

                    OperLogLoader loader = new OperLogLoader
                    {
                        Channel = channel,
                        Stop    = null, //  this.Progress;
                                        // loader.owner = this;
                        Estimate  = estimate,
                        Dates     = dates,
                        Level     = 2, // Program.MainForm.OperLogLevel;
                        AutoCache = false,
                        CacheDir  = "",
                        LogType   = logType,
                        Filter    = "setReaderInfo"
                    };

                    loader.Prompt += Loader_Prompt;
                    try
                    {
                        // int nRecCount = 0;

                        string strLastItemDate = "";

                        long lLastItemIndex = -1;
                        foreach (OperLogItem item in loader)
                        {
                            token.ThrowIfCancellationRequested();

                            //if (stop != null)
                            //    stop.SetMessage("正在同步 " + item.Date + " " + item.Index.ToString() + " " + estimate.Text + "...");

                            if (string.IsNullOrEmpty(item.Xml) == true)
                            {
                                goto CONTINUE;
                            }

                            XmlDocument dom = new XmlDocument();
                            try
                            {
                                dom.LoadXml(item.Xml);
                            }
                            catch (Exception ex)
                            {
#if NO
                                DialogResult result = System.Windows.Forms.DialogResult.No;
                                strError = logType.ToString() + "日志记录 " + item.Date + " " + item.Index.ToString() + " XML 装入 DOM 的时候发生错误: " + ex.Message;
                                string strText = strError;

                                this.Invoke((Action)(() =>
                                {
                                    result = MessageBox.Show(this,
                                                             strText + "\r\n\r\n是否跳过此条记录继续处理?",
                                                             "ReportForm",
                                                             MessageBoxButtons.YesNo,
                                                             MessageBoxIcon.Question,
                                                             MessageBoxDefaultButton.Button1);
                                }));

                                if (result == System.Windows.Forms.DialogResult.No)
                                {
                                    return(-1);
                                }

                                // 记入日志,继续处理
                                this.GetErrorInfoForm().WriteHtml(strError + "\r\n");
                                continue;
#endif

                                if (Prompt != null)
                                {
                                    strError = logType.ToString() + "日志记录 " + item.Date + " " + item.Index.ToString() + " XML 装入 DOM 的时候发生错误: " + ex.Message;
                                    MessagePromptEventArgs e = new MessagePromptEventArgs
                                    {
                                        MessageText     = strError + "\r\n\r\n是否跳过此条继续处理?\r\n\r\n(确定: 跳过;  取消: 停止全部操作)",
                                        IncludeOperText = true,
                                        // + "\r\n\r\n是否跳过此条继续处理?",
                                        Actions = "yes,cancel"
                                    };
                                    Prompt(channel, e);
                                    if (e.ResultAction == "cancel")
                                    {
                                        throw new ChannelException(channel.ErrorCode, strError);
                                    }
                                    else if (e.ResultAction == "yes")
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        // no 也是抛出异常。因为继续下一批代价太大
                                        throw new ChannelException(channel.ErrorCode, strError);
                                    }
                                }
                                else
                                {
                                    throw new ChannelException(channel.ErrorCode, strError);
                                }
                            }

                            string strOperation = DomUtil.GetElementText(dom.DocumentElement, "operation");
                            if (strOperation == "setReaderInfo")
                            {
                                nRet = TraceSetReaderInfo(
                                    dom,
                                    out strError);
                            }
                            else
                            {
                                continue;
                            }

                            if (nRet == -1)
                            {
                                strError = "同步 " + item.Date + " " + item.Index.ToString() + " 时出错: " + strError;

                                if (Prompt != null)
                                {
                                    MessagePromptEventArgs e = new MessagePromptEventArgs
                                    {
                                        MessageText     = strError + "\r\n\r\n是否跳过此条继续处理?\r\n\r\n(确定: 跳过;  取消: 停止全部操作)",
                                        IncludeOperText = true,
                                        // + "\r\n\r\n是否跳过此条继续处理?",
                                        Actions = "yes,cancel"
                                    };
                                    Prompt(channel, e);
                                    if (e.ResultAction == "cancel")
                                    {
                                        throw new Exception(strError);
                                    }
                                    else if (e.ResultAction == "yes")
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        // no 也是抛出异常。因为继续下一批代价太大
                                        throw new Exception(strError);
                                    }
                                }
                                else
                                {
                                    throw new ChannelException(channel.ErrorCode, strError);
                                }
                            }

                            // lProcessCount++;
CONTINUE:
                            // 便于循环外获得这些值
                            strLastItemDate = item.Date;
                            lLastItemIndex  = item.Index + 1;

                            // index = 0;  // 第一个日志文件后面的,都从头开始了
                        }
                        // 记忆
                        strLastDate = strLastItemDate;
                        last_index  = lLastItemIndex;
                    }
                    finally
                    {
                        loader.Prompt -= Loader_Prompt;
                    }
                }

                return(new ReplicationResult
                {
                    Value = last_index == -1 ? 0 : 1,
                    LastDate = strLastDate,
                    LastIndex = last_index
                });
            }
            catch (Exception ex)
            {
                string strError = "ReportForm DoReplication() exception: " + ExceptionUtil.GetDebugText(ex);
                return(new ReplicationResult {
                    Value = -1, ErrorInfo = strError
                });
            }
        }
Exemplo n.º 16
0
        public void Prompt(Form owner, MessagePromptEventArgs e)
        {
            if (e.Actions == "yes,no,cancel")
            {
                DialogResult result = DialogResult.Yes;
                if (_hide_dialog == false)
                {
                    owner.Invoke((Action)(() =>
                    {
                        result = MessageDialog.Show(owner,
                                                    e.MessageText +
                                                    (e.IncludeOperText == false ? "\r\n\r\n(重试) 重试操作;(跳过) 跳过本条继续处理后面的书目记录; (中断) 中断处理" : ""),
                                                    MessageBoxButtons.YesNoCancel,
                                                    MessageBoxDefaultButton.Button1,
                                                    "此后不再出现本对话框",
                                                    ref _hide_dialog,
                                                    e.ButtonCaptions != null ? e.ButtonCaptions : new string[] { "重试", "跳过", "中断" },
                                                    10);
                    }));
                    _hide_dialog_count = 0;

                    if (result == DialogResult.Yes)
                    {
                        _retry_count++;
                        if (_retry_count >= _max_retry)
                        {
                            result       = DialogResult.Cancel;
                            _retry_count = 0;
                        }
                    }
                }
                else
                {
                    _hide_dialog_count++;
                    if (_hide_dialog_count > 10)
                    {
                        _hide_dialog = false;
                    }
                }

                if (result == DialogResult.Yes)
                {
                    e.ResultAction = "yes";
                }
                else if (result == DialogResult.Cancel)
                {
                    e.ResultAction = "cancel";
                }
                else
                {
                    e.ResultAction = "no";
                }
            }

            if (e.Actions == "yes,cancel")
            {
                DialogResult result = DialogResult.Yes;
                if (_hide_dialog == false)
                {
                    owner.Invoke((Action)(() =>
                    {
                        result = MessageDialog.Show(owner,
                                                    e.MessageText +
                                                    (e.IncludeOperText == false ? "\r\n\r\n是否跳过本条继续后面操作?\r\n\r\n(跳过: 跳过并继续; 中断: 停止全部操作)" : ""),
                                                    MessageBoxButtons.OKCancel,
                                                    MessageBoxDefaultButton.Button1,
                                                    "此后不再出现本对话框",
                                                    ref _hide_dialog,
                                                    e.ButtonCaptions != null ? e.ButtonCaptions : new string[] { "跳过", "中断" },
                                                    10);
                    }));
                    _hide_dialog_count = 0;

                    if (result == DialogResult.OK)
                    {
                        _retry_count++;
                        if (_retry_count >= _max_retry)
                        {
                            result       = DialogResult.Cancel;
                            _retry_count = 0;
                        }
                    }
                }
                else
                {
                    _hide_dialog_count++;
                    if (_hide_dialog_count > 10)
                    {
                        _hide_dialog = false;
                    }
                }

                if (result == DialogResult.OK)
                {
                    e.ResultAction = "yes";
                }
                else
                {
                    e.ResultAction = "cancel";
                }
            }

            /*
             * // TODO: 自动延时以后重试
             * this.Invoke((Action)(() =>
             * {
             *  if (e.Actions == "yes,cancel")
             *  {
             *      DialogResult result = MessageBox.Show(this,
             * e.MessageText +
             * (e.IncludeOperText == false ? "\r\n\r\n是否跳过本条继续后面操作?\r\n\r\n(确定: 跳过并继续; 取消: 停止全部操作)" : ""),
             * "MainForm",
             * MessageBoxButtons.OKCancel,
             * MessageBoxIcon.Question,
             * MessageBoxDefaultButton.Button1);
             *      if (result == DialogResult.OK)
             *          e.ResultAction = "yes";
             *      else // if (result == DialogResult.Cancel)
             *          e.ResultAction = "cancel";
             *      return;
             *  }
             *
             *  // TODO: 不再出现此对话框。不过重试有个次数限制,同一位置失败多次后总要出现对话框才好
             *  if (e.Actions == "yes,no,cancel")
             *  {
             *      DialogResult result = MessageBox.Show(this,
             * e.MessageText +
             * (e.IncludeOperText == false ? "\r\n\r\n是否重试操作?\r\n\r\n(是: 重试;  否: 跳过本次操作,继续后面的操作; 取消: 停止全部操作)" : ""),
             * "MainForm",
             * MessageBoxButtons.YesNoCancel,
             * MessageBoxIcon.Question,
             * MessageBoxDefaultButton.Button1);
             *      if (result == DialogResult.Yes)
             *          e.ResultAction = "yes";
             *      else if (result == DialogResult.Cancel)
             *          e.ResultAction = "cancel";
             *      else
             *          e.ResultAction = "no";
             *  }
             * }));
             */
        }
Exemplo n.º 17
0
        // 通用版本
        List <ItemInfo> GetItemInfos(string strDbType,
                                     string strHowToGetItemRecord,
                                     ref List <ItemInfo> item_infos)
        {
            // 优化速度
            if (item_infos != null)
            {
                return(item_infos);
            }

            // 如果当前书目库下没有包含实体库,调用会抛出异常。特殊处理
            // TODO: 是否需要用hashtable优化速度?
            string strBiblioDBName = Global.GetDbName(this.CurrentRecPath);
            string strItemDbName   = "";

            if (strDbType == "item")
            {
                strItemDbName = this.BiblioStatisForm.MainForm.GetItemDbName(strBiblioDBName);
            }
            else if (strDbType == "order")
            {
                strItemDbName = this.BiblioStatisForm.MainForm.GetOrderDbName(strBiblioDBName);
            }
            else if (strDbType == "issue")
            {
                strItemDbName = this.BiblioStatisForm.MainForm.GetIssueDbName(strBiblioDBName);
            }
            else if (strDbType == "comment")
            {
                strItemDbName = this.BiblioStatisForm.MainForm.GetCommentDbName(strBiblioDBName);
            }
            else
            {
                throw new Exception("未知的 strDbType '" + strDbType + "'");
            }

            if (String.IsNullOrEmpty(strItemDbName) == true)
            {
                return(new List <ItemInfo>());    // 返回一个空的数组
            }
            item_infos = new List <ItemInfo>();

            long lPerCount    = 100; // 每批获得多少个
            long lStart       = 0;
            long lResultCount = 0;
            long lCount       = -1;

            for (; ;)
            {
                string strStyle = "";
                if (strHowToGetItemRecord == "delay")
                {
                    strStyle = "onlygetpath";
                }
                else if (strHowToGetItemRecord == "first")
                {
                    strStyle = "onlygetpath,getfirstxml";
                }

                EntityInfo[] infos    = null;
                string       strError = "";
                long         lRet     = 0;

REDO:

                if (strDbType == "item")
                {
                    lRet = this.BiblioStatisForm.Channel.GetEntities(
                        null,
                        this.CurrentRecPath,
                        lStart,
                        lCount,
                        strStyle,
                        "zh",
                        out infos,
                        out strError);
                }
                else if (strDbType == "order")
                {
                    lRet = this.BiblioStatisForm.Channel.GetOrders(
                        null,
                        this.CurrentRecPath,
                        lStart,
                        lCount,
                        strStyle,
                        "zh",
                        out infos,
                        out strError);
                }
                else if (strDbType == "issue")
                {
                    lRet = this.BiblioStatisForm.Channel.GetIssues(
                        null,
                        this.CurrentRecPath,
                        lStart,
                        lCount,
                        strStyle,
                        "zh",
                        out infos,
                        out strError);
                }
                else if (strDbType == "comment")
                {
                    lRet = this.BiblioStatisForm.Channel.GetComments(
                        null,
                        this.CurrentRecPath,
                        lStart,
                        lCount,
                        strStyle,
                        "zh",
                        out infos,
                        out strError);
                }

                if (lRet == -1)
                {
                    // 2018/6/6
                    if (this.Prompt != null)
                    {
                        MessagePromptEventArgs e = new MessagePromptEventArgs
                        {
                            MessageText = "获得 " + strDbType + " 记录时发生错误: " + strError,
                            Actions     = "yes,no,cancel"
                        };
                        this.Prompt(this, e);
                        if (e.ResultAction == "cancel")
                        {
                            throw new ChannelException(this.BiblioStatisForm.Channel.ErrorCode, strError);
                        }
                        else if (e.ResultAction == "yes")
                        {
                            goto REDO;
                        }
                        else
                        {
                            // no 也是抛出异常。因为继续下一批代价太大
                            throw new ChannelException(this.BiblioStatisForm.Channel.ErrorCode, strError);
                        }
                    }
                    else
                    {
                        throw new ChannelException(this.BiblioStatisForm.Channel.ErrorCode, strError);
                    }
                }

                lResultCount = lRet;    // 2009/11/23

                if (infos == null)
                {
                    return(item_infos);
                }

                for (int i = 0; i < infos.Length; i++)
                {
                    EntityInfo info   = infos[i];
                    string     strXml = info.OldRecord;

                    /*
                     * if (String.IsNullOrEmpty(strXml) == true)
                     *  continue;
                     * */

                    ItemInfo item_info = new ItemInfo(strDbType);
                    item_info.Container = this;
                    item_info.RecPath   = info.OldRecPath;
                    item_info.Timestamp = info.OldTimestamp;
                    item_info.OldRecord = strXml;

                    item_infos.Add(item_info);
                }

                lStart += infos.Length;
                if (lStart >= lResultCount)
                {
                    break;
                }

                if (lCount == -1)
                {
                    lCount = lPerCount;
                }

                if (lStart + lCount > lResultCount)
                {
                    lCount = lResultCount - lStart;
                }
            } // end of for

            return(item_infos);
        }
Exemplo n.º 18
0
        public IEnumerator GetEnumerator()
        {
            string strError = "";
            int nRet = 0;

            if (string.IsNullOrEmpty(this.CacheDir) == false)
                PathUtil.CreateDirIfNeed(this.CacheDir);

            // ProgressEstimate estimate = new ProgressEstimate();
            bool bAutoCache = this.AutoCache;

            if (bAutoCache == true)
            {
                long lServerFileSize = 0;
                long lCacheFileSize = 0;
                // 象征性获得一个日志文件的尺寸,主要目的是为了触发一次通道登录
                // return:
                //      -1  error
                //      0   file not found
                //      1   found
                nRet = GetFileSize(
                    this.Stop,
                    this.Channel,
                    this.CacheDir,
                    "20121001.log",
                    out lServerFileSize,
                    out lCacheFileSize,
                    out strError);
                if (nRet == -1)
                    throw new Exception(strError);

                // 检查日志文件缓存目录的版本是否和当前用户的信息一致
                // return:
                //      -1  出错
                //      0   一致
                //      1   不一致
                nRet = DetectCacheVersionFile(
                    this.CacheDir,
                    "version.xml",
                    this.Channel.LibraryCodeList,
                    this.Channel.Url,
                    out strError);
                if (nRet == -1)
                    throw new Exception(strError);
                if (nRet == 1)
                {
                REDO:
                    // 清空当前缓存目录
                    nRet = Global.DeleteDataDir(
                        null, // owner,
                        this.CacheDir,
                        out strError);
                    if (nRet == -1)
                    {
                        if (this.Prompt != null)
                        {
                            MessagePromptEventArgs e = new MessagePromptEventArgs();
                            e.MessageText = "清空当前缓存目录时发生错误: " + strError;
                            e.Actions = "yes,no,cancel";
                            this.Prompt(this, e);
                            if (e.ResultAction == "cancel")
                                throw new Exception(strError);
                            else if (e.ResultAction == "yes")
                                goto REDO;
                            else
                            {
                            }
                        }
                        else
                            throw new Exception(strError);
                    }
#if NO
                    if (nRet == -1)
                        throw new Exception(strError);
#endif

                    PathUtil.CreateDirIfNeed(this.CacheDir);  // 重新创建目录

                    // 创建版本文件
                    nRet = CreateCacheVersionFile(
                        this.CacheDir,
                        "version.xml",
                        this.Channel.LibraryCodeList,
                        this.Channel.Url,
                        out strError);
                    if (nRet == -1)
                        throw new Exception(strError);
                }

            }

            long lTotalSize = 0;
            List<string> lines = new List<string>();    // 经过处理后排除了不存在的文件名
            List<string> ranges = new List<string>();
            List<long> sizes = new List<long>();
            this.Stop.SetMessage("正在准备获得日志文件尺寸 ...");
            foreach (string strLine in this.FileNames)
            {
                Application.DoEvents();

                if (this.Stop != null && this.Stop.State != 0)
                {
                    strError = "用户中断";
                    throw new Exception(strError);
                    // yield break; ?
                }

                if (String.IsNullOrEmpty(strLine) == true)
                    continue;

                string strFilename = strLine.Trim();
                // 去掉注释
                nRet = strFilename.IndexOf("#");
                if (nRet != -1)
                    strFilename = strFilename.Substring(0, nRet).Trim();

                if (String.IsNullOrEmpty(strFilename) == true)
                    continue;

                string strLogFilename = "";
                string strRange = "";

                nRet = strFilename.IndexOf(":");
                if (nRet != -1)
                {
                    strLogFilename = strFilename.Substring(0, nRet).Trim();
                    strRange = strFilename.Substring(nRet + 1).Trim();
                }
                else
                {
                    strLogFilename = strFilename.Trim();
                    strRange = "";
                }

                if (strLogFilename.Length == 8)
                    strLogFilename += ".log";
            REDO_GETSIZE:
                long lServerFileSize = 0;
                long lCacheFileSize = 0;
                // 获得一个日志文件的尺寸
                // return:
                //      -1  error
                //      0   file not found
                //      1   found
                nRet = GetFileSize(
                    this.Stop,
                    this.Channel,
                    this.CacheDir,
                    strLogFilename,
                    out lServerFileSize,
                    out lCacheFileSize,
                    out strError);
                if (nRet == -1)
                {
                    // throw new Exception(strError);

                    if (this.Prompt != null)
                    {
                        MessagePromptEventArgs e = new MessagePromptEventArgs();
                        e.MessageText = "获取日志文件 " + strLogFilename + " 尺寸的操作发生错误: " + strError;
                        e.Actions = "yes,no,cancel";
                        this.Prompt(this, e);
                        if (e.ResultAction == "cancel")
                            throw new Exception(strError);
                        else if (e.ResultAction == "yes")
                        {
                            if (this.Stop != null)
                                this.Stop.Continue();
                            goto REDO_GETSIZE;
                        }
                        else
                        {
                            // ??
                            continue;
                        }
                    }
                    else
                        throw new Exception(strError);
                }

                if (nRet == 0)
                    continue;

                if (lServerFileSize == 0)
                    continue;   // 0字节的文件当作不存在处理

                Debug.Assert(lServerFileSize >= 0, "");

                if (bAutoCache == true)
                {
                    if (lCacheFileSize > 0)
                        lTotalSize += lCacheFileSize;
                    else
                        lTotalSize += lServerFileSize;
                }
                else
                {
                    lTotalSize += lServerFileSize;
                }

                // lines.Add(strFilename);
                lines.Add(strLogFilename);
                ranges.Add(strRange);

                // 记忆每个文件的尺寸,后面就不用获取了?
                sizes.Add(lServerFileSize);
            }

            long lDoneSize = 0;

            if (this.ProgressStart == -1)
                lDoneSize = lTotalSize;
            else
                lDoneSize = this.ProgressStart;

            lTotalSize += lDoneSize;

            if (this.Stop != null)
            {
                this.Stop.SetProgressRange(0, lTotalSize);
            }

            estimate.SetRange(lDoneSize, lTotalSize);
            estimate.StartEstimate();

            for (int i = 0; i < lines.Count; i++)
            {
                Application.DoEvents();

                if (this.Stop != null && this.Stop.State != 0)
                {
                    strError = "用户中断";
                    throw new Exception(strError);
                    // yield break; ?
                }

                string strLine = lines[i];
                string strRange = ranges[i];

                string strLogFilename = strLine;
#if NO
                string strLogFilename = "";
                string strRange = "";

                nRet = strLine.IndexOf(":");
                if (nRet != -1)
                {
                    strLogFilename = strLine.Substring(0, nRet).Trim();
                    strRange = strLine.Substring(nRet + 1).Trim();
                }
                else
                {
                    strLogFilename = strLine.Trim();
                    strRange = "";
                }
#endif

                // begin
                {
                    OperLogItemLoader loader = new OperLogItemLoader();
                    loader.Stop = this.Stop;
                    loader.Channel = this.Channel;
                    // loader.owner = this.owner;
                    loader.estimate = this.estimate;
                    loader.FileName = strLogFilename;
                    loader.nLevel = this.nLevel;
                    loader.lServerFileSize = sizes[i];
                    loader.Range = strRange;
                    loader.AutoCache = this.AutoCache;
                    loader.lProgressValue = lDoneSize;
                    loader.lSize = lTotalSize;
                    loader.Filter = this.Filter;

                    loader.Prompt -= new MessagePromptEventHandler(loader_Prompt);
                    loader.Prompt += new MessagePromptEventHandler(loader_Prompt);

                    foreach (OperLogItem item in loader)
                    {
                        yield return item;
                    }

                    lDoneSize = loader.lProgressValue;
                    lTotalSize = loader.lSize;
                }
                // end

            }



        }