Example #1
0
 public void PrepareSearch(string strText)
 {
     if (stop != null)
     {
         stop.OnStop += new StopEventHandler(this.DoStop);
         stop.Initial(strText);
         stop.BeginLoop();
     }
 }
Example #2
0
 /// <summary>
 /// 开始检索循环
 /// </summary>
 /// <param name="strMessage">循环期间要显示在状态行的提示信息</param>
 public void BeginLoop(string strMessage)
 {
     if (stop != null)
     {
         stop.OnStop += new StopEventHandler(this.DoStop);
         stop.Initial(strMessage);
         stop.BeginLoop();
     }
 }
Example #3
0
        // 检索
        // return:
        //      -1  出错
        //      0   没有找到
        //      >0  命中的条数
        int Search(
            string strDbName,
            string strKey,
            string strMatchStyle,
            int nMax,
            ref List <string> results,
            out string strError)
        {
            strError = "";

            lock (this._stop)
            {
                LibraryChannel channel = Program.MainForm.GetChannel();

                _stop.OnStop += new StopEventHandler(this.DoStop);
                _stop.Initial("正在检索词条 '" + strKey + "' ...");
                _stop.BeginLoop();
                try
                {
                    int nRet = Program.MainForm.SearchDictionary(
                        channel,
                        this._stop,
                        strDbName,
                        strKey,
                        strMatchStyle,
                        nMax,
                        ref results,
                        out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }
                    if (nRet == 0)
                    {
                        strError = "词条 '" + strKey + "' 在 " + strDbName + "库中没有找到";
                        return(0);
                    }

                    return(nRet);
                }
                finally
                {
                    _stop.EndLoop();
                    _stop.OnStop -= new StopEventHandler(this.DoStop);
                    _stop.Initial("");

                    Program.MainForm.ReturnChannel(channel);
                }
            }
        }
Example #4
0
        // return:
        //      -1  出错
        //      0   放弃处理
        //      1   正常结束
        public int DoRecPathLines()
        {
            this.tabControl_input.SelectedTab = this.tabPage_paths;

            this.EnableControls(false);
            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("");
            stop.BeginLoop();
            this.Update();
            this.MainForm.Update();

            try
            {
                return(DoTextLines());
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
                stop.HideProgress();

                this.EnableControls(true);
            }
        }
Example #5
0
File: MyForm.cs Project: gvhung/dp2
        /// <summary>
        /// 开始一个循环
        /// </summary>
        /// <param name="strStyle">风格。如果包含 "halfstop",表示停止按钮使用温和中断方式 </param>
        /// <param name="strMessage">要在状态行显示的消息文字</param>
        public void BeginLoop(string strStyle   = "",
                              string strMessage = "")
        {
            if (StringUtil.IsInList("halfstop", strStyle) == true)
            {
                stop.Style = StopStyle.EnableHalfStop;
            }

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial(strMessage);
            stop.BeginLoop();
        }
Example #6
0
        // 检索出实体库全部可用的馆藏地名称
        int SearchAllLocation(
    LibraryChannel channel,
    Stop stop,
    out string strError)
        {
            strError = "";

            long lTotalCount = 0;

            this.listView_records.Items.Clear();

            // EnableControls(false);
            stop.OnStop += new StopEventHandler(channel.DoStop);
            stop.Initial("正在列出全部馆藏地 ...");
            stop.BeginLoop();

            try
            {
                for (int i = 0; i < 2; i++)
                {
                    long lRet = Channel.SearchItem(
        stop,
        "<all>",
        "", // strBatchNo
        -1,
        "馆藏地点",
        i == 0 ? "left" : "exact",  // 第二次为检索空值
        "zh",
        "batchno",   // strResultSetName
        "", // "desc",
        "keycount", // strOutputStyle
        out strError);
                    if (lRet == 0)
                    {
#if NO
                        strError = "not found";
                        return 0;   // not found
#endif 
                        continue;
                    }
                    if (lRet == -1)
                        return -1;

                    long lHitCount = lRet;

                    long lStart = 0;
                    long lCount = lHitCount;
                    DigitalPlatform.CirculationClient.localhost.Record[] searchresults = null;

                    // 装入浏览格式
                    for (; ; )
                    {
                        Application.DoEvents();	// 出让界面控制权

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

                        lRet = channel.GetSearchResult(
                            stop,
                            "batchno",   // strResultSetName
                            lStart,
                            lCount,
                            "keycount",
                            "zh",
                            out searchresults,
                            out strError);
                        if (lRet == -1)
                        {
                            strError = "GetSearchResult() error: " + strError;
                            return -1;
                        }

                        if (lRet == 0)
                        {
                            // MessageBox.Show(this, "未命中");
                            continue;
                        }

                        // 处理浏览结果
                        foreach (Record record in searchresults)
                        {
                            if (record.Cols == null)
                            {
                                strError = "请更新应用服务器和数据库内核到最新版本,才能使用列出馆藏地的功能";
                                return -1;
                            }

                            if (this._libraryCodeList.Count > 0 
                                && MatchLibraryCode(this._libraryCodeList, record.Path) == false)
                                continue;

                            // 跳过数字为 0 的事项
                            if (record.Cols.Length > 0 && record.Cols[0] == "0")
                                continue;

                            ListViewItem item = new ListViewItem();
                            item.Text = string.IsNullOrEmpty(record.Path) == false ? record.Path : "[空]";
                            ListViewUtil.ChangeItemText(item, 1, record.Cols[0]);

                            this.listView_records.Items.Add(item);
                        }

                        lStart += searchresults.Length;
                        lCount -= searchresults.Length;

                        stop.SetMessage("共命中 " + (lTotalCount + lHitCount).ToString() + " 条,已装入 " + (lTotalCount + lStart).ToString() + " 条");

                        if (lStart >= lHitCount || lCount <= 0)
                            break;
                    }

                    lTotalCount += lHitCount;
                }

                if (lTotalCount == 0)
                {
                    strError = "not found";
                    return 0;
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(channel.DoStop);
                stop.Initial("");

                // EnableControls(true);
            }
            return 1;
        }
Example #7
0
        int ProcessSelectedRecords(Delegate_processLog func,
            out string strError)
        {
            strError = "";

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选定要处理的行";
                return -1;
            }

            Stop stop = new DigitalPlatform.Stop();
            stop.Register(MainForm.stopManager, true);	// 和容器关联

            stop.OnStop += new StopEventHandler(this.DoStopPrint);
            stop.Initial("正在处理日志记录 ...");
            stop.BeginLoop();

            try
            {
                stop.SetProgressRange(0, this.listView_records.SelectedItems.Count);
                int i = 0;
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    Application.DoEvents();

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

                    OperLogItemInfo info = (OperLogItemInfo)item.Tag;

                    string strLogFileName = ListViewUtil.GetItemText(item, COLUMN_FILENAME);
                    string strIndex = ListViewUtil.GetItemText(item, COLUMN_INDEX);

                    string strXml = "";
                    // 从服务器获得
                    // return:
                    //      -1  出错
                    //      0   正常
                    //      1   用户中断
                    int nRet = GetXml(item,
            out strXml,
            out strError);
                    if (nRet == 1)
                        return -1;
                    if (nRet == -1)
                        return -1;

                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strXml);
                    }
                    catch (Exception ex)
                    {
                        strError = "装载日志记录 '" + strLogFileName + ":" + strIndex + "' XML 到 DOM 时发生错误: " + ex.Message;
                        return -1;
                    }

                    if (func != null)
                    {
                        if (func(strLogFileName,
                            Convert.ToInt32(strIndex),
                dom,
                null) == false)
                            break;
                    }

                    stop.SetProgressValue(i + 1);
                    i++;
                }

                return 0;
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStopPrint);
                stop.Initial("处理完成");
                stop.HideProgress();

                if (stop != null) // 脱离关联
                {
                    stop.Unregister();	// 和容器关联
                    stop = null;
                }
            }
        }
Example #8
0
        public override int RunScript(string strProjectName,
                                      string strProjectLocate,
                                      string strInitialParamString,
                                      out string strError,
                                      out string strWarning)
        {
            strWarning = "";

            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在执行脚本 ...");
            stop.BeginLoop();

            this.Update();
            Program.MainForm.Update();

            _dllPaths.Clear();
            _dllPaths.Add(strProjectLocate);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            try
            {
                int nRet = 0;
                strError = "";

                this.objStatis    = null;
                this.AssemblyMain = null;

                // 2009/11/5
                // 防止以前残留的打开的文件依然没有关闭
                Global.ForceGarbageCollection();

                nRet = PrepareScript(strProjectName,
                                     strProjectLocate,
                                     out objStatis,
                                     out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                if (strInitialParamString == "test_compile")
                {
                    return(0);
                }

                objStatis.ProjectDir    = strProjectLocate;
                objStatis.Console       = this.Console;
                objStatis.InputFilename = this._openMarcFileDialog.FileName;

                // 执行脚本的OnInitial()

                // 触发Script中OnInitial()代码
                // OnInitial()和OnBegin的本质区别, 在于OnInitial()适合检查和设置面板参数
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnInitial(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                    {
                        goto END1;
                    }
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                // 触发Script中OnBegin()代码
                // OnBegin()中仍然有修改MainForm面板的自由
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnBegin(this, args);
                    if (args.Continue == ContinueType.SkipAll)
                    {
                        goto END1;
                    }
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                // 循环
                nRet = DoLoop(out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                if (nRet == 1)
                {
                    goto END1;  // TODO: SkipAll如何执行? 是否连OnEnd也不执行了?
                }
END1:
                // 触发Script的OnEnd()代码
                if (objStatis != null)
                {
                    StatisEventArgs args = new StatisEventArgs();
                    objStatis.OnEnd(this, args);
                    if (args.Continue == ContinueType.Error)
                    {
                        strError = args.ParamString;
                        goto ERROR1;
                    }
                }

                return(0);

ERROR1:
                return(-1);
            }
            catch (Exception ex)
            {
                strError = "脚本执行过程抛出异常: \r\n" + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                if (objStatis != null)
                {
                    objStatis.FreeResources();
                }

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                this.AssemblyMain = null;

                EnableControls(true);
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            }
        }
Example #9
0
        //
        /// <summary>
        /// 恢复应急日志文件到服务器
        /// </summary>
        public void Recover()
        {
            string strError = "";
            int    nRet     = 0;

            string strLogFileName = this.LogFileName;
            int    nLineCount     = 0;

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在初始化浏览器组件 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            EnableControls(false);

            Global.WriteHtml(this.webBrowser_operationInfo,
                             "开始恢复。\r\n");


            try
            {
                using (StreamReader sr = new StreamReader(strLogFileName, true))
                {
                    for (; ;)
                    {
                        string strLine = sr.ReadLine();
                        if (strLine == null)
                        {
                            break;
                        }

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

                        string strXml = "";
                        nRet = BuildRecoverXml(
                            strLine,
                            out strXml,
                            out strError);
                        if (nRet == -1)
                        {
                            goto ERROR1;
                        }

                        long lRet = this.Channel.UrgentRecover(
                            stop,
                            strXml,
                            out strError);
                        if (lRet == -1)
                        {
                            DialogResult result = MessageBox.Show(this,
                                                                  "行\r\n" + strLine + "\r\n恢复到数据库时出错:" + strError + "。\r\n\r\n要中断处理么? ",
                                                                  "UrgentChargingForm",
                                                                  MessageBoxButtons.YesNo,
                                                                  MessageBoxIcon.Question,
                                                                  MessageBoxDefaultButton.Button2);
                            if (result == DialogResult.Yes)
                            {
                                goto ERROR1;
                            }

                            Global.WriteHtml(this.webBrowser_operationInfo,
                                             strLine + " *** error: " + strError + "\r\n");
                            goto CONTINUE_1;
                        }

                        Global.WriteHtml(this.webBrowser_operationInfo,
                                         strLine + "\r\n");
CONTINUE_1:
                        Global.ScrollToEnd(this.webBrowser_operationInfo);
                        nLineCount++;
                    }
                }
            }
            catch (FileNotFoundException)
            {
                strError = "文件 " + strLogFileName + "不存在。";
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = "读取文件过程出错: " + ex.Message;
                goto ERROR1;
            }
            finally
            {
                EnableControls(true);

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }

            Global.WriteHtml(this.webBrowser_operationInfo,
                             "恢复完成。共处理记录 " + nLineCount + " 个。 \r\n");
            Global.WriteHtml(this.webBrowser_operationInfo,
                             "注意打开数据目录,改名保存 " + this.LogFileName + " 文件,避免将来不小心重复恢复。\r\n");

            API.PostMessage(this.Handle, WM_SCROLLTOEND, 0, 0);
            return;

ERROR1:
            MessageBox.Show(this, strError);
            return;
        }
Example #10
0
        private void button_dp2library_changePassword_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.textBox_dp2library_userName.Text == "")
            {
                MessageBox.Show(this, "尚未输入用户名。");
                this.textBox_dp2library_userName.Focus();
                return;
            }

            if (this.textBox_dp2library_newPassword.Text != this.textBox_dp2library_confirmNewPassword.Text)
            {
                MessageBox.Show(this, "新密码 和 确认新密码不一致。请重新输入。");
                this.textBox_dp2library_newPassword.Focus();
                return;
            }

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在修改 dp2library 用户密码 ...");
            stop.BeginLoop();

            this.EnableControls(false);

            this.Update();
            this.MainForm.Update();


            try
            {
                long lRet = 0;

                // 获得server url
                if (String.IsNullOrEmpty(this.LibraryServerName) == true)
                {
                    strError = "尚未指定服务器名";
                    goto ERROR1;
                }
                dp2Server server = this.MainForm.Servers.GetServerByName(this.LibraryServerName);
                if (server == null)
                {
                    strError = "服务器名为 '" + this.LibraryServerName + "' 的服务器不存在...";
                    goto ERROR1;
                }

                string strServerUrl = server.Url;

                this.Channel = this.Channels.GetChannel(strServerUrl);


                // 非强制修改密码,即本人修改
                if (this.checkBox_dp2library_force.Checked == false)
                {
                    // return:
                    //      -1  error
                    //      0   登录未成功
                    //      1   登录成功
                    lRet = Channel.Login(this.textBox_dp2library_userName.Text,
                                         this.textBox_dp2library_oldPassword.Text,
                                         "location=dp2Catalog,type=worker,client=dp2catalog|" + Program.ClientVersion,

                                         /*
                                          * "",
                                          * false,
                                          * */
                                         out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }

                    if (lRet == 0)
                    {
                        strError = "旧密码不正确";
                        goto ERROR1;
                    }

                    try
                    {
                        lRet = Channel.ChangeUserPassword(
                            stop,
                            this.textBox_dp2library_userName.Text,
                            this.textBox_dp2library_oldPassword.Text,
                            this.textBox_dp2library_newPassword.Text,
                            out strError);
                        if (lRet == -1)
                        {
                            goto ERROR1;
                        }
                    }
                    finally
                    {
                        string strError_1 = "";
                        Channel.Logout(out strError_1);
                    }
                }

                // 强制修改密码
                if (this.checkBox_dp2library_force.Checked == true)
                {
                    UserInfo info = new UserInfo();
                    info.UserName = this.textBox_dp2library_userName.Text;
                    info.Password = this.textBox_dp2library_newPassword.Text;
                    // 当action为"resetpassword"时,则info.ResetPassword状态不起作用,无论怎样都要修改密码。resetpassword并不修改其他信息,也就是说info中除了Password/UserName以外其他成员的值无效。
                    lRet = Channel.SetUser(
                        stop,
                        "resetpassword",
                        info,
                        out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }
                }
            }
            finally
            {
                this.EnableControls(true);

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }

            MessageBox.Show(this, "dp2library 用户 '" + this.textBox_dp2library_userName.Text + "' 密码修改成功。");

            this.textBox_dp2library_userName.SelectAll();
            this.textBox_dp2library_userName.Focus();
            return;

ERROR1:
            MessageBox.Show(this, strError);

            // 焦点重新定位到密码输入域
            this.textBox_dp2library_oldPassword.Focus();
            this.textBox_dp2library_oldPassword.SelectAll();
        }
Example #11
0
        // 工作线程每一轮循环的实质性工作
        public override void Worker()
        {
            try
            {
                int nOldCount            = 0;
                List <SummaryTask> tasks = new List <SummaryTask>();
                // List<SummaryTask> remove_tasks = new List<SummaryTask>();
                if (this.m_lock.TryEnterReadLock(m_nLockTimeout) == false)
                {
                    throw new LockException("锁定尝试中超时");
                }
                try
                {
                    nOldCount = this._tasks.Count;
                    foreach (SummaryTask task in this._tasks)
                    {
                        tasks.Add(task);
                    }
                }
                finally
                {
                    this.m_lock.ExitReadLock();
                }

                if (tasks.Count > 0)
                {
#if NO
                    stop.OnStop += new StopEventHandler(this.DoStop);
                    stop.Initial("进行一轮获取摘要的处理...");
                    stop.BeginLoop();
#endif
                    try
                    {
                        foreach (SummaryTask task in tasks)
                        {
                            if (this.Stopped == true)
                            {
                                // this.Container.SetColorList();  // 促使“任务已经暂停”显示出来
                                return;
                            }

#if NO
                            if (stop != null && stop.State != 0)
                            {
                                this.Stopped = true;
                                // this.Container.SetColorList();  // 促使“任务已经暂停”显示出来
                                return;
                            }
#endif

                            if (task.State == "finish")
                            {
                                continue;
                            }

                            // bool bStop = false;
                            // 执行任务
                            if (task.Action == "get_item_summary")
                            {
                                LoadItemSummary(task);
                            }
                        }
                    }
                    finally
                    {
#if NO
                        stop.EndLoop();
                        stop.OnStop -= new StopEventHandler(this.DoStop);
                        stop.Initial("");
#endif
                    }
                }

                //bool bChanged = false;
                if (tasks.Count > 0)
                {
                    if (this.m_lock.TryEnterWriteLock(m_nLockTimeout) == false)
                    {
                        throw new LockException("锁定尝试中超时");
                    }
                    try
                    {
                        foreach (SummaryTask task in tasks)
                        {
                            RemoveTask(task, false);
                        }
                    }
                    finally
                    {
                        this.m_lock.ExitWriteLock();
                    }
                }
            }
            catch (Exception ex)
            {
                string strText = "SummaryList Worker() 出现异常: " + ExceptionUtil.GetDebugText(ex);
                MainForm.TryWriteErrorLog(strText);
                if (this.Container != null)
                {
                    this.Container.ShowMessage(strText, "red", true);
                }
            }
        }
Example #12
0
        // 装入全部日历名
        int FillCalendarNames(out string strError)
        {
            this.comboBox_calendarName.Items.Clear();

            EnableControls(false, true);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在获得全部日历名 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            try
            {
                int           nStart = 0;
                int           nCount = 100;
                List <string> names  = new List <string>();

                while (true)
                {
                    CalenderInfo[] infos = null;

                    long lRet = Channel.GetCalendar(
                        stop,
                        "list",
                        "",
                        nStart,
                        nCount,
                        out infos,
                        out strError);
                    if (lRet == -1)
                    {
                        goto ERROR1;
                    }
                    if (lRet == 0)
                    {
                        break;
                    }

                    //
                    for (int i = 0; i < infos.Length; i++)
                    {
                        names.Add(infos[i].Name);
                    }

                    nStart += infos.Length;
                    if (nStart >= lRet)
                    {
                        break;
                    }
                }

                names.Sort(new CalencarNameComparer());
                foreach (string s in names)
                {
                    this.comboBox_calendarName.Items.Add(s);
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                EnableControls(true, true);
            }

            return(1);

ERROR1:
            return(-1);
        }
Example #13
0
        private void button_reader_changePassword_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.textBox_reader_barcode.Text == "")
            {
                MessageBox.Show(this, "尚未输入读者证条码号。");
                this.textBox_reader_barcode.Focus();
                return;
            }

            if (this.textBox_reader_newPassword.Text != this.textBox_reader_confirmNewPassword.Text)
            {
                MessageBox.Show(this, "新密码 和 确认新密码不一致。请重新输入。");
                this.textBox_reader_newPassword.Focus();
                return;
            }

            bool bOldPasswordEnabled = this.textBox_reader_oldPassword.Enabled;

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在修改读者密码 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            this.EnableControls(false);

            try
            {
                long lRet = Channel.ChangeReaderPassword(
                    stop,
                    this.textBox_reader_barcode.Text,
                    bOldPasswordEnabled == false ? null : this.textBox_reader_oldPassword.Text,
                    this.textBox_reader_newPassword.Text,
                    out strError);
                if (lRet == 0)
                {
                    goto ERROR1;
                }
                if (lRet == -1)
                {
                    goto ERROR1;
                }
            }
            finally
            {
                this.EnableControls(true);

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }

            MessageBox.Show(this, "读者密码已经被成功修改。");

            this.textBox_reader_barcode.SelectAll();
            this.textBox_reader_barcode.Focus();
            return;

ERROR1:
            MessageBox.Show(this, strError);

            // 焦点重新定位到密码输入域
            this.textBox_reader_oldPassword.Focus();
            this.textBox_reader_oldPassword.SelectAll();
        }
Example #14
0
        // 工作线程每一轮循环的实质性工作
        public override void Worker()
        {
            int nOldCount                    = 0;
            List <ChargingTask> tasks        = new List <ChargingTask>();
            List <ChargingTask> remove_tasks = new List <ChargingTask>();

            if (this.m_lock.TryEnterReadLock(m_nLockTimeout) == false)
            {
                throw new LockException("锁定尝试中超时");
            }
            try
            {
                nOldCount = this._tasks.Count;
                foreach (ChargingTask task in this._tasks)
                {
                    if (task.State == "")
                    {
                        tasks.Add(task);
                    }

#if NO
                    if (task.State == "finish" &&
                        task.Action == "load_reader_info" &&
                        task.ReaderBarcode != this.CurrentReaderBarcode)
                    {
                        remove_tasks.Add(task);
                    }
#endif
                }
            }
            finally
            {
                this.m_lock.ExitReadLock();
            }

            if (tasks.Count > 0)
            {
                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("进行一轮任务处理...");
                stop.BeginLoop();
                try
                {
                    foreach (ChargingTask task in tasks)
                    {
                        if (this.Stopped == true)
                        {
                            this.Container.SetColorList();  // 促使“任务已经暂停”显示出来
                            return;
                        }

                        if (stop != null && stop.State != 0)
                        {
                            this.Stopped = true;
                            this.Container.SetColorList();  // 促使“任务已经暂停”显示出来
                            return;
                        }

                        // bool bStop = false;
                        // 执行任务
                        if (task.Action == "load_reader_info")
                        {
                            LoadReaderInfo(task);
                        }
                        else if (task.Action == "borrow" ||
                                 task.Action == "renew" ||
                                 task.Action == "verify_renew")
                        {
                            Borrow(task);
                        }
                        else if (task.Action == "return" ||
                                 task.Action == "verify_return" ||
                                 task.Action == "lost" ||
                                 task.Action == "verify_lost" ||
                                 task.Action == "inventory" ||
                                 task.Action == "read" ||
                                 task.Action == "boxing")
                        {
                            Return(task);
                        }

                        stop.SetMessage("");
                    }
                }
                finally
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");
                }
            }

            //bool bChanged = false;
            if (remove_tasks.Count > 0)
            {
                if (this.m_lock.TryEnterWriteLock(m_nLockTimeout) == false)
                {
                    throw new LockException("锁定尝试中超时");
                }
                try
                {
                    //if (this._tasks.Count != nOldCount)
                    //    bChanged = true;

                    foreach (ChargingTask task in remove_tasks)
                    {
                        RemoveTask(task, false);
                    }
                }
                finally
                {
                    this.m_lock.ExitWriteLock();
                }
            }

            /*
             * if (bChanged == true)
             *  this.Activate();
             * */
        }
Example #15
0
        // 根据读者证条码号,装入读者记录
        // parameters:
        //      edit    读者编辑控件。可以==null
        //      webbHtml    用于显示HTML的WebBrowser控件。可以==null
        //      webbXml   用于显示XML的WebBrowser控件。可以==null
        // return:
        //      0   cancelled
        internal int LoadRecord(ref string strBarcode,
                                ReaderEditControl edit,
                                WebExternalHost external_html,
                                // WebBrowser webbHtml,
                                WebBrowser webbXml)
        {
            string strError = "";
            int    nRet     = 0;

            if (edit != null &&
                edit.Changed == true)
            {
                // 警告尚未保存
                DialogResult result = MessageBox.Show(this,
                                                      "当前有信息被修改后尚未保存。若此时装载新内容,现有未保存信息将丢失。\r\n\r\n确实要根据证条码号重新装载内容? ",
                                                      "ActivateForm",
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button2);
                if (result != DialogResult.Yes)
                {
                    return(0);   // cancelled
                }
            }

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在初始化浏览器组件 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            EnableControls(false);

            if (edit != null)
            {
                edit.Clear();
            }
#if NO
            if (webbHtml != null)
            {
                Global.ClearHtmlPage(webbHtml,
                                     this.MainForm.DataDir);
            }
#endif
            if (external_html != null)
            {
                external_html.ClearHtmlPage();
            }

            if (webbXml != null)
            {
                Global.ClearHtmlPage(webbXml,
                                     this.MainForm.DataDir);
            }

            try
            {
                byte[] baTimestamp = null;
                string strRecPath  = "";

                int nRedoCount = 0;
REDO:
                stop.SetMessage("正在装入读者记录 " + strBarcode + " ...");

                string[] results = null;

                long lRet = Channel.GetReaderInfo(
                    stop,
                    strBarcode,
                    "xml,html",
                    out results,
                    out strRecPath,
                    out baTimestamp,
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }

                if (lRet == 0)
                {
                    goto ERROR1;
                }

                if (lRet > 1)
                {
                    // 如果重试后依然发生重复
                    if (nRedoCount > 0)
                    {
                        strError = "条码 " + strBarcode + " 命中记录 " + lRet.ToString() + " 条,放弃装入读者记录。\r\n\r\n注意这是一个严重错误,请系统管理员尽快排除。";
                        goto ERROR1;    // 当出错处理
                    }
                    SelectPatronDialog dlg = new SelectPatronDialog();

                    dlg.Overflow = StringUtil.SplitList(strRecPath).Count < lRet;
                    nRet         = dlg.Initial(
                        this.MainForm,
                        //this.Channel,
                        //this.stop,
                        StringUtil.SplitList(strRecPath),
                        "请选择一个读者记录",
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                    // TODO: 保存窗口内的尺寸状态
                    this.MainForm.AppInfo.LinkFormState(dlg, "ActivateForm_SelectPatronDialog_state");
                    dlg.ShowDialog(this);
                    this.MainForm.AppInfo.UnlinkFormState(dlg);

                    if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        strError = "放弃选择";
                        return(0);
                    }

                    // strBarcode = dlg.SelectedBarcode;
                    strBarcode = "@path:" + dlg.SelectedRecPath;   // 2015/11/16

                    nRedoCount++;
                    goto REDO;
                }



                // this.ReaderBarcode = strBarcode;

                if (results == null || results.Length < 2)
                {
                    strError = "返回的results不正常。";
                    goto ERROR1;
                }

                string strXml = "";
                strXml = results[0];
                string strHtml = results[1];

                if (edit != null)
                {
                    nRet = edit.SetData(
                        strXml,
                        strRecPath,
                        baTimestamp,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }

                if (webbXml != null)
                {
                    /*
                     * SetXmlToWebbrowser(webbXml,
                     *  strXml);
                     * */
                    Global.SetXmlToWebbrowser(webbXml,
                                              this.MainForm.DataDir,
                                              "xml",
                                              strXml);
                }

                // this.m_strSetAction = "change";

#if NO
                if (webbHtml != null)
                {
                    Global.SetHtmlString(webbHtml,
                                         strHtml,
                                         this.MainForm.DataDir,
                                         "activateform_html");
                }
#endif

                if (external_html != null)
                {
                    external_html.SetHtmlString(strHtml, "activateform_html");
                }
            }
            finally
            {
                EnableControls(true);

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }

            return(1);

ERROR1:
            MessageBox.Show(this, strError);
            return(-1);
        }
Example #16
0
        // 汉字字符串转换为拼音。新版本
        // 如果函数中已经MessageBox报错,则strError第一字符会为空格
        /// <summary>
        /// 汉字字符串转换为拼音,智能方式
        /// </summary>
        /// <param name="owner">用于函数中 MessageBox 和对话框 的宿主窗口</param>
        /// <param name="strText">输入字符串</param>
        /// <param name="style">转换为拼音的风格</param>
        /// <param name="strDuoyinStyle">是否自动选择多音字。auto/first 的一个或者组合。如果为 auto,first 表示优先按照智能拼音选择,没有智能拼音的,选择第一个</param>
        /// <param name="strPinyin">返回拼音字符串</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>-1: 出错; 0: 用户希望中断; 1: 正常; 2: 结果字符串中有没有找到拼音的汉字</returns>
        public int SmartHanziTextToPinyin(
            IWin32Window owner,
            string strText,
            PinyinStyle style,
            string strDuoyinStyle,  // bool bAutoSel,
            out string strPinyin,
            out string strError)
        {
            strPinyin = "";
            strError = "";

            bool bAuto = StringUtil.IsInList("auto", strDuoyinStyle);
            bool bFirst = StringUtil.IsInList("first", strDuoyinStyle);

            bool bNotFoundPinyin = false;   // 是否出现过没有找到拼音、只能把汉字放入结果字符串的情况

            Stop new_stop = new DigitalPlatform.Stop();
            new_stop.Register(this.stopManager, true);	// 和容器关联
            new_stop.OnStop += new StopEventHandler(new_stop_OnStop);
            new_stop.Initial("正在获得 '" + strText + "' 的拼音信息 (从服务器 " + this.PinyinServerUrl + ")...");
            new_stop.BeginLoop();

            m_gcatClient = null;
            try
            {

                m_gcatClient = GcatNew.CreateChannel(this.PinyinServerUrl);

            REDO_GETPINYIN:
                //int nStatus = -1;	// 前面一个字符的类型 -1:前面没有字符 0:普通英文字母 1:空格 2:汉字
                string strPinyinXml = "";
                // return:
                //      -2  strID验证失败
                //      -1  出错
                //      0   成功
                int nRet = GcatNew.GetPinyin(
                    new_stop,
                    m_gcatClient,
                    m_strPinyinGcatID,
                    strText,
                    out strPinyinXml,
                    out strError);
                if (nRet == -1)
                {
                    if (new_stop != null && new_stop.State != 0)
                        return 0;

                    DialogResult result = MessageBox.Show(owner,
    "从服务器 '" + this.PinyinServerUrl + "' 获取拼音的过程出错:\r\n" + strError + "\r\n\r\n是否要临时改为使用本机加拼音功能? \r\n\r\n(注:临时改用本机拼音的状态在程序退出时不会保留。如果要永久改用本机拼音方式,请使用主菜单的“参数配置”命令,将“服务器”属性页的“拼音服务器URL”内容清空)",
    "EntityForm",
    MessageBoxButtons.YesNo,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button2);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        this.ForceUseLocalPinyinFunc = true;
                        strError = "将改用本机拼音,请重新操作一次。(本次操作出错: " + strError + ")";
                        return -1;
                    }
                    strError = " " + strError;
                    return -1;
                }

                if (nRet == -2)
                {
                    IdLoginDialog login_dlg = new IdLoginDialog();
                    login_dlg.Text = "获得拼音 -- "
                        + ((string.IsNullOrEmpty(this.m_strPinyinGcatID) == true) ? "请输入ID" : strError);
                    login_dlg.ID = this.m_strPinyinGcatID;
                    login_dlg.SaveID = this.m_bSavePinyinGcatID;
                    login_dlg.StartPosition = FormStartPosition.CenterScreen;
                    if (login_dlg.ShowDialog(owner) == DialogResult.Cancel)
                    {
                        return 0;
                    }

                    this.m_strPinyinGcatID = login_dlg.ID;
                    this.m_bSavePinyinGcatID = login_dlg.SaveID;
                    goto REDO_GETPINYIN;
                }

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strPinyinXml);
                }
                catch (Exception ex)
                {
                    strError = "strPinyinXml装载到XMLDOM时出错: " + ex.Message;
                    return -1;
                }

                foreach (XmlNode nodeWord in dom.DocumentElement.ChildNodes)
                {
                    if (nodeWord.NodeType == XmlNodeType.Text)
                    {
                        SelPinyinDlg.AppendText(ref strPinyin, nodeWord.InnerText);
                        //nStatus = 0;
                        continue;
                    }

                    if (nodeWord.NodeType != XmlNodeType.Element)
                        continue;

                    string strWordPinyin = DomUtil.GetAttr(nodeWord, "p");
                    if (string.IsNullOrEmpty(strWordPinyin) == false)
                        strWordPinyin = strWordPinyin.Trim();

                    // 目前只取多套读音的第一套
                    nRet = strWordPinyin.IndexOf(";");
                    if (nRet != -1)
                        strWordPinyin = strWordPinyin.Substring(0, nRet).Trim();

                    string[] pinyin_parts = strWordPinyin.Split(new char[] { ' ' });
                    int index = 0;
                    // 让选择多音字
                    foreach (XmlNode nodeChar in nodeWord.ChildNodes)
                    {
                        if (nodeChar.NodeType == XmlNodeType.Text)
                        {
                            SelPinyinDlg.AppendText(ref strPinyin, nodeChar.InnerText);
                            //nStatus = 0;
                            continue;
                        }

                        string strHanzi = nodeChar.InnerText;
                        string strCharPinyins = DomUtil.GetAttr(nodeChar, "p");

                        if (String.IsNullOrEmpty(strCharPinyins) == true)
                        {
                            strPinyin += strHanzi;
                            //nStatus = 0;
                            index++;
                            continue;
                        }

                        if (strCharPinyins.IndexOf(";") == -1)
                        {
                            DomUtil.SetAttr(nodeChar, "sel", strCharPinyins);
                            SelPinyinDlg.AppendPinyin(ref strPinyin,
                                SelPinyinDlg.ConvertSinglePinyinByStyle(
                                    strCharPinyins,
                                    style)
                                    );
                            //nStatus = 2;
                            index++;
                            continue;
                        }

#if _TEST_PINYIN
                        // 调试!
                        string[] parts = strCharPinyins.Split(new char[] {';'});
                        {
                            DomUtil.SetAttr(nodeChar, "sel", parts[0]);
                            AppendPinyin(ref strPinyin, parts[0]);
                            nStatus = 2;
                            index++;
                            continue;
                        }
#endif


                        string strSampleText = "";
                        int nOffs = -1;
                        SelPinyinDlg.GetOffs(dom.DocumentElement,
                            nodeChar,
                            out strSampleText,
                            out nOffs);

                        {	// 如果是多个拼音
                            SelPinyinDlg dlg = new SelPinyinDlg();
                            //float ratio_single = dlg.listBox_multiPinyin.Font.SizeInPoints / dlg.Font.SizeInPoints;
                            //float ratio_sample = dlg.textBox_sampleText.Font.SizeInPoints / dlg.Font.SizeInPoints;
                            MainForm.SetControlFont(dlg, this.Font, false);
                            // 维持字体的原有大小比例关系
                            //dlg.listBox_multiPinyin.Font = new Font(dlg.Font.FontFamily, ratio_single * dlg.Font.SizeInPoints, GraphicsUnit.Point);
                            //dlg.textBox_sampleText.Font = new Font(dlg.Font.FontFamily, ratio_sample * dlg.Font.SizeInPoints, GraphicsUnit.Point);
                            // 这个对话框比较特殊 MainForm.SetControlFont(dlg, this.Font, false);

                            dlg.Text = "请选择汉字 '" + strHanzi + "' 的拼音 (来自服务器 " + this.PinyinServerUrl + ")";
                            dlg.SampleText = strSampleText;
                            dlg.Offset = nOffs;
                            dlg.Pinyins = strCharPinyins;
                            if (index < pinyin_parts.Length)
                                dlg.ActivePinyin = pinyin_parts[index];
                            dlg.Hanzi = strHanzi;

#if NO
                            if (bAutoSel == true
                                && string.IsNullOrEmpty(dlg.ActivePinyin) == false)
                            {
                                dlg.ResultPinyin = dlg.ActivePinyin;
                                dlg.DialogResult = DialogResult.OK;
                            }
                            else
                            {
                                this.AppInfo.LinkFormState(dlg, "SelPinyinDlg_state");

                                dlg.ShowDialog(owner);

                                this.AppInfo.UnlinkFormState(dlg);
                            }
#endif
                            if (bAuto == true
    && string.IsNullOrEmpty(dlg.ActivePinyin) == false)
                            {
                                dlg.ResultPinyin = dlg.ActivePinyin;
                                dlg.DialogResult = DialogResult.OK;
                            }
                            else if (bFirst == true
                                && string.IsNullOrEmpty(dlg.Pinyins) == false)
                            {
                                dlg.ResultPinyin = SelPinyinDlg.GetFirstPinyin(dlg.Pinyins);
                                dlg.DialogResult = DialogResult.OK;
                            }
                            else
                            {
                                this.AppInfo.LinkFormState(dlg, "SelPinyinDlg_state");

                                dlg.ShowDialog(owner);

                                this.AppInfo.UnlinkFormState(dlg);
                            }

                            Debug.Assert(DialogResult.Cancel != DialogResult.Abort, "推断");

                            if (dlg.DialogResult == DialogResult.Abort)
                            {
                                return 0;   // 用户希望整个中断
                            }

                            DomUtil.SetAttr(nodeChar, "sel", dlg.ResultPinyin);

                            if (dlg.DialogResult == DialogResult.Cancel)
                            {
                                SelPinyinDlg.AppendText(ref strPinyin, strHanzi);
                                //nStatus = 2;
                                bNotFoundPinyin = true;
                            }
                            else if (dlg.DialogResult == DialogResult.OK)
                            {
                                SelPinyinDlg.AppendPinyin(ref strPinyin,
                                    SelPinyinDlg.ConvertSinglePinyinByStyle(
                                    dlg.ResultPinyin,
                                    style)
                                    );
                                //nStatus = 2;
                            }
                            else
                            {
                                Debug.Assert(false, "SelPinyinDlg返回时出现意外的DialogResult值");
                            }

                            index++;
                        }
                    }
                }

#if _TEST_PINYIN
#else
                // 2014/10/22
                // 删除 word 下的 Text 节点
                XmlNodeList text_nodes = dom.DocumentElement.SelectNodes("word/text()");
                foreach (XmlNode node in text_nodes)
                {
                    Debug.Assert(node.NodeType == XmlNodeType.Text, "");
                    node.ParentNode.RemoveChild(node);
                }

                // 把没有p属性的<char>元素去掉,以便上传
                XmlNodeList nodes = dom.DocumentElement.SelectNodes("//char");
                foreach (XmlNode node in nodes)
                {
                    string strP = DomUtil.GetAttr(node, "p");
                    string strSelValue = DomUtil.GetAttr(node, "sel");  // 2013/9/13

                    if (string.IsNullOrEmpty(strP) == true
                        || string.IsNullOrEmpty(strSelValue) == true)
                    {
                        XmlNode parent = node.ParentNode;
                        parent.RemoveChild(node);

                        // 把空的<word>元素删除
                        if (parent.Name == "word"
                            && parent.ChildNodes.Count == 0
                            && parent.ParentNode != null)
                        {
                            parent.ParentNode.RemoveChild(parent);
                        }
                    }

                    // TODO: 一个拼音,没有其他选择的,是否就不上载了?
                    // 注意,前端负责新创建的拼音仍需上载;只是当初原样从服务器过来的,不用上载了
                }

                if (dom.DocumentElement.ChildNodes.Count > 0)
                {
                    // return:
                    //      -2  strID验证失败
                    //      -1  出错
                    //      0   成功
                    nRet = GcatNew.SetPinyin(
                        new_stop,
                        m_gcatClient,
                        "",
                        dom.DocumentElement.OuterXml,
                        out strError);
                    if (nRet == -1)
                    {
                        if (new_stop != null && new_stop.State != 0)
                            return 0;
                        return -1;
                    }
                }
#endif

                if (bNotFoundPinyin == false)
                    return 1;   // 正常结束

                return 2;   // 结果字符串中有没有找到拼音的汉字
            }
            finally
            {
                new_stop.EndLoop();
                new_stop.OnStop -= new StopEventHandler(new_stop_OnStop);
                new_stop.Initial("");
                new_stop.Unregister();
                if (m_gcatClient != null)
                {
                    m_gcatClient.Close();
                    m_gcatClient = null;
                }
            }
        }
Example #17
0
        // 启动批处理任务
        int StartBatchTask(string strTaskName,
                           out string strError)
        {
            strError = "";

            BatchTaskStartInfo startinfo = new BatchTaskStartInfo();

            if (strTaskName == "日志恢复")
            {
                StartLogRecoverDlg dlg = new StartLogRecoverDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "dp2Library 同步")
            {
                StartReplicationDlg dlg = new StartReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "重建检索点")
            {
                StartRebuildKeysDlg dlg = new StartRebuildKeysDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "预约到书管理")
            {
                StartArriveMonitorDlg dlg = new StartArriveMonitorDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }

            /*
             * else if (strTaskName == "跟踪DTLP数据库")
             * {
             * StartTraceDtlpDlg dlg = new StartTraceDtlpDlg();
             * MainForm.SetControlFont(dlg, this.Font, false);
             * dlg.StartInfo = startinfo;
             * dlg.ShowDialog(this);
             * if (dlg.DialogResult != DialogResult.OK)
             * {
             *  strError = "用户放弃启动";
             *  return -1;
             * }
             * }
             * */
            else if (strTaskName == "正元一卡通读者信息同步")
            {
                StartZhengyuanReplicationDlg dlg = new StartZhengyuanReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "迪科远望一卡通读者信息同步")
            {
                StartDkywReplicationDlg dlg = new StartDkywReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                startinfo.Start = "!breakpoint";    // 一开始就有适当的缺省值,避免从头开始跟踪
                dlg.StartInfo   = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }
            else if (strTaskName == "读者信息同步")
            {
#if NO
                StartPatronReplicationDlg dlg = new StartPatronReplicationDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                startinfo.Start = "!breakpoint";    // 一开始就有适当的缺省值,避免从头开始跟踪
                dlg.StartInfo   = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
#endif
                startinfo.Start = "activate";   // 表示立即启动,忽略服务器原有定时启动参数
            }
            else if (strTaskName == "超期通知")
            {
                startinfo.Start = "activate";   // 表示立即启动,忽略服务器原有定时启动参数
            }
            else if (strTaskName == "创建 MongoDB 日志库")
            {
                StartLogRecoverDlg dlg = new StartLogRecoverDlg();
                MainForm.SetControlFont(dlg, this.Font, false);
                dlg.Text      = "启动 创建 MongoDB 日志库 任务";
                dlg.TaskName  = "创建 MongoDB 日志库";
                dlg.StartInfo = startinfo;
                dlg.ShowDialog(this);
                if (dlg.DialogResult != DialogResult.OK)
                {
                    strError = "用户放弃启动";
                    return(-1);
                }
            }

            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                EnableControls(false);

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在"
                             + "启动"
                             + "任务 '" + strTaskName + "' ...");
                stop.BeginLoop();

                this.Update();
                this.MainForm.Update();

                try
                {
                    BatchTaskInfo param = new BatchTaskInfo();
                    param.StartInfo = startinfo;

                    BatchTaskInfo resultInfo = null;

                    // return:
                    //      -1  出错
                    //      0   启动成功
                    //      1   调用前任务已经处于执行状态,本次调用激活了这个任务
                    long lRet = Channel.BatchTask(
                        stop,
                        strTaskName,
                        "start",
                        param,
                        out resultInfo,
                        out strError);
                    if (lRet == -1 || lRet == 1)
                    {
                        goto ERROR1;
                    }

                    if (resultInfo != null)
                    {
                        Global.WriteHtml(this.webBrowser_info,
                                         GetResultText(resultInfo.ResultText));
                        ScrollToEnd();
                    }

                    this.label_progress.Text = resultInfo.ProgressText;
                }
                finally
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");

                    EnableControls(true);
                }

                return(1);

ERROR1:
                return(-1);
            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }
        }
Example #18
0
        //
        // return:
        //      -1  error
        //      0   not found
        //      1   found
        /// <summary>
        /// 根据册条码号,装入册记录和书目记录
        /// </summary>
        /// <param name="bEnableControls">是否在处理过程中禁止界面元素</param>
        /// <param name="strBarcode">册条码号</param>
        /// <param name="strError">返回出错信息</param>
        /// <returns>
        ///      -1  出错
        ///      0   没有找到
        ///      1   找到
        /// </returns>
        public int LoadRecord(
            bool bEnableControls,
            string strBarcode,
            out string strError)
        {
            strError = "";

            if (bEnableControls == true)
            {
                EnableControls(false);

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在初始化浏览器组件 ...");
                stop.BeginLoop();


                this.Update();
                this.MainForm.Update();
            }

            this.entityEditControl1.Clear();

            this.m_webExternalHost_biblio.StopPrevious();
            this.webBrowser_biblio.Stop();

            Global.ClearHtmlPage(this.webBrowser_biblio,
                                 this.MainForm.DataDir);

            this.textBox_message.Text = "";

            stop.SetMessage("正在装入册记录 " + strBarcode + " ...");


            try
            {
                string strItemText   = "";
                string strBiblioText = "";

                string strItemRecPath   = "";
                string strBiblioRecPath = "";

                byte[] item_timestamp = null;

                long lRet = Channel.GetItemInfo(
                    stop,
                    strBarcode,
                    "xml",
                    out strItemText,
                    out strItemRecPath,
                    out item_timestamp,
                    "html",
                    out strBiblioText,
                    out strBiblioRecPath,
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }
                if (lRet == 0)
                {
                    return(0);
                }

                if (lRet > 1)
                {
                    strError = "册条码号 " + strBarcode + " 发现被下列多个册记录所使用: \r\n" + strItemRecPath + "\r\n\r\n这是一个严重错误,请求助于系统管理员尽快排除。";
                    goto ERROR1;
                }

                this.BiblioRecPath = strBiblioRecPath;

                int nRet = this.entityEditControl1.SetData(strItemText,
                                                           strItemRecPath,
                                                           item_timestamp,
                                                           out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
                Debug.Assert(this.entityEditControl1.Changed == false, "");

                this.entityEditControl1.SetReadOnly("librarian");

#if NO
                Global.SetHtmlString(this.webBrowser_biblio,
                                     strBiblioText,
                                     this.MainForm.DataDir,
                                     "quickchangeentityform_biblio");
#endif
                this.m_webExternalHost_biblio.SetHtmlString(strBiblioText,
                                                            "quickchangeentityform_biblio");

                this.textBox_message.Text = "册记录路径: " + strItemRecPath + " ;其从属的种(书目)记录路径: " + strBiblioRecPath;
            }
            finally
            {
                if (bEnableControls == true)
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");

                    EnableControls(true);
                }
            }

            return(1);

ERROR1:
            strError = "装载册条码号为 " + strBarcode + "的记录发生错误: " + strError;
            // MessageBox.Show(this, strError);
            return(-1);
        }
Example #19
0
        // 获得批次号表
        // parameters:
        //      strPubType  出版物类型。为 图书/连续出版物/(空) 之一
        internal static void GetBatchNoTable(GetKeyCountListEventArgs e,
            IWin32Window owner,
            string strPubType,  // 出版物类型
            string strType,
            Stop stop,
            LibraryChannel Channel)
        {
            string strError = "";
            long lRet = 0;


            if (e.KeyCounts == null)
                e.KeyCounts = new List<KeyCount>();

            string strName = "";
            if (strType == "order")
                strName = "订购";
            else if (strType == "item")
                strName = "册";
            else if (strType == "biblio")
                strName = "编目";
            else
                throw new Exception("未知的strType '" + strType + "' 值");

            // EnableControls(false);
            stop.OnStop += new StopEventHandler(Channel.DoStop);
            stop.Initial("正在列出全部" + strName + "批次号 ...");
            stop.BeginLoop();

            try
            {
                int nPerMax = 2000; // 一次检索命中的最大条数限制
                string strLang = "zh";

                string strDbName = "<all>";
                if (strPubType == "图书")
                    strDbName = "<all book>";
                else if (strPubType == "连续出版物")
                    strDbName = "<all series>";
                else
                    strDbName = "<all>";

                if (strType == "order")
                {
                    lRet = Channel.SearchOrder(
                        stop,
                        strDbName,  // "<all>",
                        "", // strBatchNo
                        nPerMax,   // -1,
                        "批次号",
                        "left",
                        strLang,
                        "batchno",   // strResultSetName
                        "desc",
                        "keycount", // strOutputStyle
                        out strError);
                }
                else if (strType == "biblio")
                {
                    string strQueryXml = "";

                    lRet = Channel.SearchBiblio(
                        stop,
                        strDbName,  // "<all>",    // 尽管可以用 this.comboBox_inputBiblioDbName.Text, 以便获得和少数书目库相关的批次号实例,但是容易造成误会:因为数据库名列表刷新后,这里却不会刷新?
                        "", // strBatchNo,
                        nPerMax,   // -1,    // nPerMax
                        "batchno",
                        "left",
                        strLang,
                        "batchno",   // strResultSetName
                        "desc",
                        "keycount", // strOutputStyle
                        "",
                        out strQueryXml,
                        out strError);
                }
                else if (strType == "item")
                {

                    lRet = Channel.SearchItem(
                        stop,
                        strDbName,   // "<all>",
                        "", // strBatchNo
                        nPerMax,  // -1,
                        "批次号",
                        "left",
                        strLang,
                        "batchno",   // strResultSetName
                        "desc",
                        "keycount", // strOutputStyle
                        out strError);
                }
                else
                {
                    Debug.Assert(false, "");
                }


                if (lRet == -1)
                    goto ERROR1;

                if (lRet == 0)
                {
                    strError = "没有找到任何" + strName + "批次号检索点";
                    return;
                }

                long lHitCount = lRet;

                long lStart = 0;
                long lCount = lHitCount;
                DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null;

                // 装入浏览格式
                for (; ; )
                {
                    Application.DoEvents();	// 出让界面控制权

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

                    lRet = Channel.GetSearchResult(
                        stop,
                        "batchno",   // strResultSetName
                        lStart,
                        lCount,
                        "keycount",
                        strLang,
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        strError = "GetSearchResult() error: " + strError;
                        goto ERROR1;
                    }

                    if (lRet == 0)
                    {
                        // MessageBox.Show(this, "未命中");
                        return;
                    }

                    // 处理浏览结果
                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        if (searchresults[i].Cols == null)
                        {
                            strError = "请更新应用服务器和数据库内核到最新版本,才能使用列出" + strName + "批次号的功能";
                            goto ERROR1;
                        }

                        KeyCount keycount = new KeyCount();
                        keycount.Key = searchresults[i].Path;
                        keycount.Count = Convert.ToInt32(searchresults[i].Cols[0]);
                        e.KeyCounts.Add(keycount);
                    }

                    lStart += searchresults.Length;
                    lCount -= searchresults.Length;

                    stop.SetMessage("共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条");

                    if (lStart >= lHitCount || lCount <= 0)
                        break;
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(Channel.DoStop);
                stop.Initial("");

                // EnableControls(true);
            }
            return;
        ERROR1:
            MessageBox.Show(owner, strError);
        }
Example #20
0
        static int DownloadObject(Stop stop,
            LibraryChannel channel,
            string strResPath,
            string strOutputFileName,
            out string strError)
        {
            strError = "";

            PathUtil.CreateDirIfNeed(Path.GetDirectoryName(strOutputFileName));

            TimeSpan old_timeout = channel.Timeout;
            channel.Timeout = new TimeSpan(0, 5, 0);

            if (stop != null)
                stop.Initial("正在下载对象 " + strResPath);
            try
            {
                byte[] baOutputTimeStamp = null;
                string strMetaData = "";
                string strOutputPath = "";

                long lRet = channel.GetRes(
                    stop,
                    strResPath,
                    strOutputFileName,
                    out strMetaData,
                    out baOutputTimeStamp,
                    out strOutputPath,
                    out strError);
                if (lRet == -1)
                {
                    strError = "下载对象 '" + strResPath + "' 到文件失败,原因: " + strError;
                    return -1;
                }
                return 0;
            }
            finally
            {
                channel.Timeout = old_timeout;
                if (stop != null)
                    stop.Initial("");
            }
        }
Example #21
0
        // 汉字字符串转换为拼音
        // 如果函数中已经MessageBox报错,则strError第一字符会为空格
        // return:
        //      -1  出错
        //      0   用户希望中断
        //      1   正常
        public int SmartHanziTextToPinyin(
            string strText,
            PinyinStyle style,
            out string strPinyin,
            out string strError)
        {
            strPinyin = "";
            strError = "";

            Stop new_stop = new DigitalPlatform.Stop();
            new_stop.Register(MainForm.stopManager, true);	// 和容器关联
            new_stop.OnStop += new StopEventHandler(new_stop_OnStop);
            new_stop.Initial("正在获得 '" + strText + "' 的拼音信息 (从服务器 " + this.MainForm.PinyinServerUrl + ")...");
            new_stop.BeginLoop();

            m_gcatClient = null;
            try
            {

                m_gcatClient = GcatNew.CreateChannel(this.MainForm.PinyinServerUrl);

            REDO_GETPINYIN:
                int nStatus = -1;	// 前面一个字符的类型 -1:前面没有字符 0:普通英文字母 1:空格 2:汉字
                string strPinyinXml = "";
                // return:
                //      -2  strID验证失败
                //      -1  出错
                //      0   成功
                int nRet = GcatNew.GetPinyin(
                    new_stop,
                    m_gcatClient,
                    m_strPinyinGcatID,
                    strText,
                    out strPinyinXml,
                    out strError);
                if (nRet == -1)
                {
                    DialogResult result = MessageBox.Show(this,
    "从服务器 '" + this.MainForm.PinyinServerUrl + "' 获取拼音的过程出错:\r\n" + strError + "\r\n\r\n是否要临时改为使用本机加拼音功能? \r\n\r\n(注:临时改用本机拼音的状态在程序退出时不会保留。如果要永久改用本机拼音方式,请使用主菜单的“参数配置”命令,将“服务器”属性页的“拼音服务器URL”内容清空)",
    "EntityForm",
    MessageBoxButtons.YesNo,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button2);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        this.MainForm.ForceUseLocalPinyinFunc = true;
                        strError = "将改用本机拼音,请重新操作一次。(本次操作出错: " + strError + ")";
                        return -1;
                    }
                    strError = " " + strError;
                    return -1;
                }

                if (nRet == -2)
                {
                    IdLoginDialog login_dlg = new IdLoginDialog();
                    login_dlg.Text = "获得拼音 -- "
                        + ((string.IsNullOrEmpty(this.m_strPinyinGcatID) == true) ? "请输入ID" : strError);
                    login_dlg.ID = this.m_strPinyinGcatID;
                    login_dlg.SaveID = this.m_bSavePinyinGcatID;
                    login_dlg.StartPosition = FormStartPosition.CenterScreen;
                    if (login_dlg.ShowDialog(this) == DialogResult.Cancel)
                    {
                        return 0;
                    }

                    this.m_strPinyinGcatID = login_dlg.ID;
                    this.m_bSavePinyinGcatID = login_dlg.SaveID;
                    goto REDO_GETPINYIN;
                }

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strPinyinXml);
                }
                catch (Exception ex)
                {
                    strError = "strPinyinXml装载到XMLDOM时出错: " + ex.Message;
                    return -1;
                }

                foreach (XmlNode nodeWord in dom.DocumentElement.ChildNodes)
                {
                    if (nodeWord.NodeType == XmlNodeType.Text)
                    {
                        SelPinyinDlg.AppendText(ref strPinyin, nodeWord.InnerText);
                        nStatus = 0;
                        continue;
                    }

                    if (nodeWord.NodeType != XmlNodeType.Element)
                        continue;

                    string strWordPinyin = DomUtil.GetAttr(nodeWord, "p");
                    if (string.IsNullOrEmpty(strWordPinyin) == false)
                        strWordPinyin = strWordPinyin.Trim();

                    // 目前只取多套读音的第一套
                    nRet = strWordPinyin.IndexOf(";");
                    if (nRet != -1)
                        strWordPinyin = strWordPinyin.Substring(0, nRet).Trim();

                    string[] pinyin_parts = strWordPinyin.Split(new char[] { ' ' });
                    int index = 0;
                    // 让选择多音字
                    foreach (XmlNode nodeChar in nodeWord.ChildNodes)
                    {
                        if (nodeChar.NodeType == XmlNodeType.Text)
                        {
                            SelPinyinDlg.AppendText(ref strPinyin, nodeChar.InnerText);
                            nStatus = 0;
                            continue;
                        }

                        string strHanzi = nodeChar.InnerText;
                        string strCharPinyins = DomUtil.GetAttr(nodeChar, "p");

                        if (String.IsNullOrEmpty(strCharPinyins) == true)
                        {
                            strPinyin += strHanzi;
                            nStatus = 0;
                            index++;
                            continue;
                        }

                        if (strCharPinyins.IndexOf(";") == -1)
                        {
                            DomUtil.SetAttr(nodeChar, "sel", strCharPinyins);
                            SelPinyinDlg.AppendPinyin(ref strPinyin,
                                SelPinyinDlg.ConvertSinglePinyinByStyle(
                                    strCharPinyins,
                                    style)
                                    );
                            nStatus = 2;
                            index++;
                            continue;
                        }

#if _TEST_PINYIN
                        // 调试!
                        string[] parts = strCharPinyins.Split(new char[] {';'});
                        {
                            DomUtil.SetAttr(nodeChar, "sel", parts[0]);
                            AppendPinyin(ref strPinyin, parts[0]);
                            nStatus = 2;
                            index++;
                            continue;
                        }
#endif


                        string strSampleText = "";
                        int nOffs = -1;
                        SelPinyinDlg.GetOffs(dom.DocumentElement,
                            nodeChar,
                out strSampleText,
                out nOffs);

                        {	// 如果是多个拼音
                            SelPinyinDlg dlg = new SelPinyinDlg();
                            float ratio_single = dlg.listBox_multiPinyin.Font.SizeInPoints / dlg.Font.SizeInPoints;
                            float ratio_sample = dlg.textBox_sampleText.Font.SizeInPoints / dlg.Font.SizeInPoints;
                            GuiUtil.SetControlFont(dlg, this.Font, false);
                            // 维持字体的原有大小比例关系
                            dlg.listBox_multiPinyin.Font = new Font(dlg.Font.FontFamily, ratio_single * dlg.Font.SizeInPoints, GraphicsUnit.Point);
                            dlg.textBox_sampleText.Font = new Font(dlg.Font.FontFamily, ratio_sample * dlg.Font.SizeInPoints, GraphicsUnit.Point);
                            // 这个对话框比较特殊 GuiUtil.SetControlFont(dlg, this.Font, false);

                            dlg.Text = "请选择汉字 '" + strHanzi + "' 的拼音 (来自服务器 " + this.MainForm.PinyinServerUrl + ")";
                            dlg.SampleText = strSampleText;
                            dlg.Offset = nOffs;
                            dlg.Pinyins = strCharPinyins;
                            if (index < pinyin_parts.Length)
                                dlg.ActivePinyin = pinyin_parts[index];
                            dlg.Hanzi = strHanzi;

                            MainForm.AppInfo.LinkFormState(dlg, "SelPinyinDlg_state");

                            dlg.ShowDialog(this);

                            MainForm.AppInfo.UnlinkFormState(dlg);

                            Debug.Assert(DialogResult.Cancel != DialogResult.Abort, "推断");

                            if (dlg.DialogResult == DialogResult.Abort)
                            {
                                return 0;   // 用户希望整个中断
                            }

                            DomUtil.SetAttr(nodeChar, "sel", dlg.ResultPinyin);

                            if (dlg.DialogResult == DialogResult.Cancel)
                            {
                                SelPinyinDlg.AppendText(ref strPinyin, strHanzi);
                                nStatus = 2;
                            }
                            else if (dlg.DialogResult == DialogResult.OK)
                            {
                                SelPinyinDlg.AppendPinyin(ref strPinyin,
                                    SelPinyinDlg.ConvertSinglePinyinByStyle(
                                    dlg.ResultPinyin,
                                    style)
                                    );
                                nStatus = 2;
                            }
                            else
                            {
                                Debug.Assert(false, "SelPinyinDlg返回时出现意外的DialogResult值");
                            }

                            index++;
                        }

                    }
                }

#if _TEST_PINYIN
#else
                // return:
                //      -2  strID验证失败
                //      -1  出错
                //      0   成功
                nRet = GcatNew.SetPinyin(
                    new_stop,
                    m_gcatClient,
                    "",
                    dom.DocumentElement.OuterXml,
                    out strError);
                if (nRet == -1)
                    return -1;
#endif

                return 1;
            }
            finally
            {
                new_stop.EndLoop();
                new_stop.OnStop -= new StopEventHandler(new_stop_OnStop);
                new_stop.Initial("");
                new_stop.Unregister();
                if (m_gcatClient != null)
                {
                    m_gcatClient.Close();
                    m_gcatClient = null;
                }
            }
        }
Example #22
0
        // 获得publisher等实用库的库名
        public int GetUtilDbName(
            Stop stop,
            string strServerName,
            string strServerUrl,
            string strFuncName, // "publisher"
            out string strUtilDbName,
            out string strError)
        {
            strUtilDbName = "";
            strError = "";

            bool bInitialStop = false;
            if (stop == null)
            {
                stop = this.stop;

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在获得服务器 " + strServerUrl + " 的信息 ...");
                stop.BeginLoop();

                bInitialStop = true;
            }

            dp2ServerInfo info = null;

            try
            {
                info = this.MainForm.ServerInfos.GetServerInfo(stop,
                    this.m_bInSearching,
                    this.Channels,
                    strServerName,
                    strServerUrl,
                    this.MainForm.TestMode,
                    out strError);
                if (info == null)
                    return -1;
            }
            finally
            {
                if (bInitialStop == true)
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");
                }
            }

            for (int i = 0; i < info.UtilDbProperties.Count; i++)
            {
                UtilDbProperty prop = info.UtilDbProperties[i];
                if (prop.Type == "publisher")
                {
                    strUtilDbName = prop.DbName;
                    return 1;
                }

            }

            return 0;    // not found
        }
Example #23
0
        private void button_set_Click(object sender, EventArgs e)
        {
            string strError = "";

            DialogResult result = MessageBox.Show(this,
                                                  "确实要把服务器时钟设置为 '" + this.TimeStringForDisplay + "' ?\r\n\r\n警告:如果服务器时间设置得不正确,会对很多流通操作产生不利影响",
                                                  "ClockForm",
                                                  MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Question,
                                                  MessageBoxDefaultButton.Button2);

            if (result != DialogResult.Yes)
            {
                return;
            }

            LibraryChannel channel = this.GetChannel();

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在设置服务器当前时钟为 " + this.RFC1123TimeString + " ...");
            stop.BeginLoop();

            this.EnableControls(false);

            // int value = Interlocked.Increment(ref this.m_nIn);

            try
            {
#if NO
                if (value > 1)
                {
                    strError = "通道正在被另一操作使用,当前操作被放弃";
                    goto ERROR1;   // 防止重入
                }
#endif

                long lRet = channel.SetClock(
                    stop,
                    this.RFC1123TimeString,
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }
            }
            finally
            {
                // Interlocked.Decrement(ref this.m_nIn);

                this.EnableControls(true);

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                this.ReturnChannel(channel);
            }

            // MessageBox.Show(this, "时钟设置成功");
            this.ShowMessage("时钟设置成功", "green", true);
            return;

ERROR1:
            //MessageBox.Show(this, strError);
            //return;
            this.ShowMessage(strError, "red", true);
        }
Example #24
0
        int BuildCharsetTable(out string strError)
        {
            strError = "";


            CharsetTable charsettable_e2u = new CharsetTable();
            CharsetTable charsettable_u2e = new CharsetTable();

            charsettable_e2u.Open(true);
            charsettable_u2e.Open(true);


            if (this.textBox_unihanFilenames.Text == "")
            {
                strError = "尚未指定输入文件名";
                return(-1);
            }

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.SetMessage("正在创建码表文件 ...");
            stop.BeginLoop();

            EnableControls(false);

            this.Update();
            this.MainForm.Update();

            try
            {
                for (int i = 0; i < this.textBox_unihanFilenames.Lines.Length; i++)
                {
                    StreamReader sr = null;
                    try
                    {
                        sr = new StreamReader(this.textBox_unihanFilenames.Lines[i]);
                    }
                    catch (Exception ex)
                    {
                        strError = "文件 " + this.textBox_unihanFilenames.Lines[i] + " 打开失败: " + ex.Message;
                        return(-1);
                    }

                    this.MainForm.ToolStripProgressBar.Minimum = 0;
                    this.MainForm.ToolStripProgressBar.Maximum = (int)sr.BaseStream.Length;
                    this.MainForm.ToolStripProgressBar.Value   = 0;



                    try
                    {
                        for (; ;)
                        {
                            Application.DoEvents();     // 出让界面控制权

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

                            string strLine = sr.ReadLine();
                            if (strLine == null)
                            {
                                break;
                            }

                            if (strLine.Length < 1)
                            {
                                goto CONTINUE;
                            }

                            // 注释行
                            if (strLine[0] == '#')
                            {
                                goto CONTINUE;
                            }

                            int nRet = strLine.IndexOf("\t", 0);
                            if (nRet == -1)
                            {
                                goto CONTINUE;  // 格式有问题
                            }
                            string strPart1 = strLine.Substring(0, nRet).Trim();

                            strLine = strLine.Substring(nRet + 1);

                            nRet = strLine.IndexOf("\t", 0);
                            if (nRet == -1)
                            {
                                goto CONTINUE;  // 格式有问题
                            }
                            string strPart2 = strLine.Substring(0, nRet).Trim();
                            string strPart3 = strLine.Substring(nRet + 1).Trim();

                            strPart1 = strPart1.Substring(2);   // 去掉'U+'

                            if (strPart2 != "kEACC")
                            {
                                goto CONTINUE;  // 不相关的行
                            }
                            strLine = strPart1 + "\t" + strPart3;

                            CharsetItem item = new CharsetItem();
                            item.Content = strLine;
                            charsettable_u2e.Add(item);

                            strLine = strPart3 + "\t" + strPart1;

                            item         = new CharsetItem();
                            item.Content = strLine;
                            charsettable_e2u.Add(item); // ANSI字符集

                            stop.SetMessage(strLine);

CONTINUE:
                            // 显示进度条
                            this.MainForm.ToolStripProgressBar.Value = (int)sr.BaseStream.Position;
                        }
                    }
                    finally
                    {
                        sr.Close();
                    }
                }


                stop.SetMessage("正在复制和排序...");

                string strDataFileName  = "";
                string strIndexFileName = "";

                if (String.IsNullOrEmpty(this.textBox_e2uFilename.Text) == false)
                {
                    charsettable_e2u.Sort();
                    charsettable_e2u.Detach(out strDataFileName,
                                            out strIndexFileName);

                    File.Delete(this.textBox_e2uFilename.Text);
                    File.Move(strDataFileName,
                              this.textBox_e2uFilename.Text);

                    File.Delete(this.textBox_e2uFilename.Text + ".index");
                    File.Move(strIndexFileName,
                              this.textBox_e2uFilename.Text + ".index");
                }

                //

                if (String.IsNullOrEmpty(this.textBox_u2eFilename.Text) == false)
                {
                    charsettable_u2e.Sort();
                    charsettable_u2e.Detach(out strDataFileName,
                                            out strIndexFileName);

                    File.Delete(this.textBox_u2eFilename.Text);
                    File.Move(strDataFileName,
                              this.textBox_u2eFilename.Text);

                    File.Delete(this.textBox_u2eFilename.Text + ".index");
                    File.Move(strIndexFileName,
                              this.textBox_u2eFilename.Text + ".index");
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                EnableControls(true);
            }

            return(0);
        }
Example #25
0
        // 获得一条MARC记录
        // 注:如果this.DtlpChannel被占用,启动启用新的通道
        // TODO: 尚未处理启用新通道时启用新Stop的课题
        // parameters:
        //      strPath 记录路径。格式为"localhost/中文图书/ctlno/1"
        //      strDirection    方向。为 prev/next/current之一。current可以缺省。
        //      strOutputPath   [out]返回的实际路径。格式和strPath相同。
        // return:
        //      -1  error 包括not found
        //      0   found
        //      1   为诊断记录
        int InternalGetOneRecord(
            string strStyle,
            string strPath,
            string strDirection,
            out string strMARC,
            out string strOutputPath,
            out string strOutStyle,
            out byte[] baTimestamp,
            out DigitalPlatform.Z3950.Record record,
            out Encoding currrentEncoding,
            out string strError)
        {
            strMARC = "";
            record = null;
            strError = "";
            currrentEncoding = this.CurrentEncoding;
            baTimestamp = null;
            strOutStyle = "marc";
            strOutputPath = ""; // TODO: 需要参考dp1batch看获得outputpath的方法

            if (strStyle != "marc")
            {
                strError = "DtlpSearchForm只支持获取MARC格式记录";
                return -1;
            }

            int nRet = 0;

            int nStyle = DtlpChannel.XX_STYLE; // 获得详细记录

            if (strDirection == "prev")
                nStyle |= DtlpChannel.PREV_RECORD;
            else if (strDirection == "next")
                nStyle |= DtlpChannel.NEXT_RECORD;

            /*
            // 将路径转换为内核可以接受的正规形态
            string strPath = DigitalPlatform.DTLP.Global.ModifyDtlpRecPath(strPath,
                "ctlno");
             * */
            Stop temp_stop = this.stop;
            DtlpChannel channel = null;

            bool bNewChannel = false;
            if (this.m_nInSearching == 0)
                channel = this.DtlpChannel;
            else
            {
                channel = this.DtlpChannels.CreateChannel(0);
                bNewChannel = true;

                temp_stop = new Stop();
                temp_stop.Tag = channel;
                temp_stop.Register(MainForm.stopManager, true);	// 和容器关联

                temp_stop.OnStop += new StopEventHandler(this.DoNewStop);
                temp_stop.Initial("正在初始化浏览器组件 ...");
                temp_stop.BeginLoop();

            }

                byte[] baPackage = null;
            Encoding encoding = null;
            try
            {

                nRet = channel.Search(strPath,
                    nStyle,
                    out baPackage);
                if (nRet == -1)
                {
                    int errorcode = channel.GetLastErrno();

                    if (errorcode == DtlpChannel.GL_NOTEXIST
                        && (strDirection == "prev" || strDirection == "next"))
                    {
                        if (strDirection == "prev")
                            strError = "到头";
                        else if (strDirection == "next")
                            strError = "到尾";
                        goto ERROR1;
                    }
                    strError = "检索出错:\r\n"
                        + "检索式: " + strPath + "\r\n"
                        + "错误码: " + errorcode + "\r\n"
                        + "错误信息: " + channel.GetErrorString(errorcode) + "\r\n";
                    goto ERROR1;
                }

                encoding = channel.GetPathEncoding(strPath);
            }
            finally
            {
                if (bNewChannel == true)
                {
                    temp_stop.EndLoop();
                    temp_stop.OnStop -= new StopEventHandler(this.DoNewStop);
                    temp_stop.Initial("");

                    this.DtlpChannels.DestroyChannel(channel);
                    channel = null;


                    temp_stop.Unregister();	// 和容器关联
                    temp_stop = null;
                }
            }
            Package package = new Package();
            package.LoadPackage(baPackage,
                encoding);
            nRet = package.Parse(PackageFormat.Binary);
            if (nRet == -1)
            {
                strError = "Package::Parse() error";
                goto ERROR1;
            }

            strOutputPath = package.GetFirstPath();

            byte[] content = null;
            nRet = package.GetFirstBin(out content);
            if (nRet == -1)
            {
                strError = "Package::GetFirstBin() error";
                goto ERROR1;
            }

            if (content == null
                || content.Length < 9)
            {
                strError = "content length < 9";
                goto ERROR1;
            }

            baTimestamp = new byte[9];
            Array.Copy(content, baTimestamp, 9);

            byte[] marc = new byte[content.Length - 9];
            Array.Copy(content,
                9,
                marc,
                0,
                content.Length - 9);

            // strMARC = this.CurrentEncoding.GetString(marc);
            strMARC = encoding.GetString(marc);

            // 去掉最后若干连续的29字符或者0字符
            // 2008/3/11
            int nDelta = 0;
            for (int i = strMARC.Length - 1; i > 24; i--)
            {
                char ch = strMARC[i];
                if (ch == 0 || ch == 29)
                    nDelta++;
                else
                    break;
            }

            if (nDelta > 0)
                strMARC = strMARC.Substring(0, strMARC.Length - nDelta);

            // 自动识别MARC格式
            string strOutMarcSyntax = "";
            // 探测记录的MARC格式 unimarc / usmarc / reader
            // return:
            //      0   没有探测出来。strMarcSyntax为空
            //      1   探测出来了
            nRet = MarcUtil.DetectMarcSyntax(strMARC,
                out strOutMarcSyntax);
            if (strOutMarcSyntax == "")
                strOutMarcSyntax = "unimarc";

            record = new DigitalPlatform.Z3950.Record();
            if (strOutMarcSyntax == "unimarc" || strOutMarcSyntax == "")
                record.m_strSyntaxOID = "1.2.840.10003.5.1";
            else if (strOutMarcSyntax == "usmarc")
                record.m_strSyntaxOID = "1.2.840.10003.5.10";
            else if (strOutMarcSyntax == "dt1000reader")
                record.m_strSyntaxOID = "1.2.840.10003.5.dt1000reader";
            else
            {
                /*
                strError = "未知的MARC syntax '" + strOutMarcSyntax + "'";
                goto ERROR1;
                 * */
                // TODO: 可以出现菜单选择
            }

            return 0;
        ERROR1:
            return -1;
        }
Example #26
0
        // 获得一条MARC/XML记录
        // return:
        //      -1  error 包括not found
        //      0   found
        //      1   为诊断记录
        public int GetOneRecord(
            string strStyle,
            int nTest,
            string strPathParam,
            string strParameters,   // bool bHilightBrowseLine,
            out string strSavePath,
            out string strRecord,
            out string strXmlFragment,
            out string strOutStyle,
            out byte[] baTimestamp,
            out long lVersion,
            out DigitalPlatform.Z3950.Record record,
            out Encoding currrentEncoding,
            out LoginInfo logininfo,
            out string strError)
        {
            strXmlFragment   = "";
            strRecord        = "";
            record           = null;
            strError         = "";
            currrentEncoding = this.CurrentEncoding;
            baTimestamp      = null;
            strSavePath      = "";
            strOutStyle      = "marc";
            logininfo        = new LoginInfo();
            lVersion         = 0;

            // 防止重入
            if (m_bInSearch == true)
            {
                strError = "当前窗口正在被一个未结束的长操作使用,无法获得记录。请稍后再试。";
                return(-1);
            }

            if (strStyle != "marc" && strStyle != "xml")
            {
                strError = "DupForm只支持获取MARC格式记录和xml格式记录,不支持 '" + strStyle + "' 格式的记录";
                return(-1);
            }
            int nRet = 0;

            int    index        = -1;
            string strPath      = "";
            string strDirection = "";

            nRet = Global.ParsePathParam(strPathParam,
                                         out index,
                                         out strPath,
                                         out strDirection,
                                         out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            if (index == -1)
            {
                strError = "暂时不支持没有 index 的用法";
                return(-1);
            }

            bool bHilightBrowseLine = StringUtil.IsInList("hilight_browse_line", strParameters);

            if (index >= this.listView_browse.Items.Count)
            {
                strError = "越过结果集尾部";
                return(-1);
            }
            ListViewItem curItem = this.listView_browse.Items[index];

            if (bHilightBrowseLine == true)
            {
                // 修改listview中事项的选定状态
                for (int i = 0; i < this.listView_browse.SelectedItems.Count; i++)
                {
                    this.listView_browse.SelectedItems[i].Selected = false;
                }

                curItem.Selected = true;
                curItem.EnsureVisible();
            }

            string strPurePath   = curItem.Text;
            string strServerName = this.LibraryServerName;

            strPath = strPurePath + "@" + this.LibraryServerName;

            strSavePath = this.CurrentProtocol + ":" + strPath;

            // 拉上一个dp2检索窗,好办事
            dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

            if (dp2_searchform == null)
            {
                strError = "没有打开的dp2检索窗,无法GetOneRecordSyntax()";
                return(-1);
            }

            // 获得server url
            string strServerUrl = dp2_searchform.GetServerUrl(strServerName);

            if (strServerUrl == null)
            {
                strError = "没有找到服务器名 '" + strServerName + "' 对应的URL";
                return(-1);
            }

            this.Channel = this.Channels.GetChannel(strServerUrl);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在初始化浏览器组件 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            try
            {
                stop.SetMessage("正在装入书目记录 " + strPath + " ...");

                string[] formats = null;
                formats    = new string[1];
                formats[0] = "xml";

                string[] results = null;

                long lRet = Channel.GetBiblioInfos(
                    stop,
                    strPurePath,
                    "",
                    formats,
                    out results,
                    out baTimestamp,
                    out strError);
                if (lRet == 0)
                {
                    strError = "路径为 '" + strPath + "' 的书目记录没有找到 ...";
                    goto ERROR1;   // not found
                }

                if (lRet == -1)
                {
                    goto ERROR1;
                }

                // this.BiblioTimestamp = baTimestamp;

                if (results == null)
                {
                    strError = "results == null";
                    goto ERROR1;
                }
                if (results.Length != formats.Length)
                {
                    strError = "result.Length != formats.Length";
                    goto ERROR1;
                }

                string strXml = results[0];

                if (strStyle == "marc")
                {
                    string strMarcSyntax    = "";
                    string strOutMarcSyntax = "";
                    // 从数据记录中获得MARC格式
                    nRet = MarcUtil.Xml2Marc(strXml,
                                             true,
                                             strMarcSyntax,
                                             out strOutMarcSyntax,
                                             out strRecord,
                                             out strError);
                    if (nRet == -1)
                    {
                        strError = "XML转换到MARC记录时出错: " + strError;
                        goto ERROR1;
                    }


                    // 获得书目以外的其它XML片断
                    nRet = dp2SearchForm.GetXmlFragment(strXml,
                                                        out strXmlFragment,
                                                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }
                else
                {
                    strRecord   = strXml;
                    strOutStyle = strStyle;
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }
            return(0);

ERROR1:
            return(-1);
        }
Example #27
0
        // listview imageindex 0:尚未初始化 1:已经初始化 2:出错

        // 工作线程每一轮循环的实质性工作
        void Worker()
        {
            try
            {
                string strError = "";

                for (int i = this.m_nTail; i < this.listView_list.Items.Count; i++)
                {
                    // ListViewItem item = this.listView_list.Items[i];
                    ListViewItem item = GetItem(i);

                    if (item.ImageIndex == 1)
                    {
                        continue;
                    }

                    // string strBarcode = item.Text;
                    ReaderInfo info       = (ReaderInfo)item.Tag;
                    string     strBarcode = info.ReaderBarcode;

                    stop.OnStop += new StopEventHandler(this.DoStop);
                    stop.Initial("正在初始化浏览器组件 ...");
                    stop.BeginLoop();

                    string strTypeList = "xml";
                    int    nTypeCount  = 1;

                    if (this.checkBox_displayReaderDetailInfo.Checked == true)
                    {
                        strTypeList += ",html";

                        if (StringUtil.CompareVersion(this.MainForm.ServerVersion, "2.25") >= 0)
                        {
                            strTypeList += ":noborrowhistory";
                        }

                        nTypeCount = 2;
                    }

                    try
                    {
                        string[] results = null;
                        long     lRet    = Channel.PassGate(stop,
                                                            strBarcode,
                                                            this.textBox_gateName.Text, // strGateName
                                                            strTypeList,
                                                            out results,
                                                            out strError);
                        if (lRet == -1)
                        {
                            OnError(item, strError);
                            goto CONTINUE;
                        }

                        // this.textBox_counter.Text = lRet.ToString();
                        SetCounterText(lRet);

                        if (results.Length != nTypeCount)
                        {
                            strError = "results error...";
                            OnError(item, strError);
                            goto CONTINUE;
                        }

                        string strXml = results[0];

                        string strReaderName = "";
                        string strState      = "";
                        int    nRet          = GetRecordInfo(strXml,
                                                             out strReaderName,
                                                             out strState,
                                                             out strError);
                        if (nRet == -1)
                        {
                            OnError(item, strError);
                            goto CONTINUE;
                        }

                        info.ReaderName = strReaderName;

                        if (this.checkBox_hideReaderName.Checked == true)
                        {
                            string strText = "";
                            // item.SubItems[1].Text = strText.PadLeft(strReaderName.Length, '*');
                            SetItemText(item, 1, strText.PadLeft(strReaderName.Length, '*'));
                        }
                        else
                        {
                            // item.SubItems[1].Text = strReaderName;
                            SetItemText(item, 1, strReaderName);
                        }

                        // item.SubItems[2].Text = strState;
                        SetItemText(item, 2, strState);

                        // item.ImageIndex = 1;    // error
                        SetItemImageIndex(item, 1);

                        if (this.checkBox_displayReaderDetailInfo.Checked == true &&
                            results.Length == 2)
                        {
                            this.m_webExternalHost.StopPrevious();
                            this.webBrowser_readerInfo.Stop();

                            // this.HtmlString = results[1];

                            // API.PostMessage(this.Handle, WM_SETHTML, 0, 0);
                            StartSetHtml(results[1]);
                        }
                    }
                    finally
                    {
                        stop.EndLoop();
                        stop.OnStop -= new StopEventHandler(this.DoStop);
                        stop.Initial("");
                    }

CONTINUE:
                    this.m_nTail = i;
                }
            }
            catch (Exception ex)
            {
                string strErrorText = "PassGateForm Worker() 出现异常: " + ExceptionUtil.GetDebugText(ex);
                this.MainForm.WriteErrorLog(strErrorText);
            }
        }
Example #28
0
        // 获得一个书目库名列表
        // parameters:
        //      stop    如果!=null,表示使用这个stop,它已经OnStop +=
        //              如果==null,表示会自动使用this.stop,并自动OnStop+=
        // return:
        //      -1  error
        //      0   OK
        int GetBiblioDbNames(
            Stop stop,
            string strServerName,
            string strServerUrl,
            out List<string> dbnames,
            out string strError)
        {
            dbnames  = new List<string>();
            strError = "";

            bool bInitialStop = false;
            if (stop == null)
            {
                stop = this.stop;

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在获得服务器 " + strServerUrl + " 的信息 ...");
                stop.BeginLoop();

                bInitialStop = true;
            }

            dp2ServerInfo info = null;

            try
            {
                info = this.MainForm.ServerInfos.GetServerInfo(stop,
                    false,
                    this.Channels,
                    strServerName,
                    strServerUrl,
                    this.MainForm.TestMode,
                    out strError);
                if (info == null)
                    return -1;
            }
            finally
            {
                if (bInitialStop == true)
                {
                    stop.EndLoop();
                    stop.OnStop -= new StopEventHandler(this.DoStop);
                    stop.Initial("");
                }
            }

            for (int i = 0; i < info.BiblioDbProperties.Count; i++)
            {
                BiblioDbProperty prop = info.BiblioDbProperties[i];

                dbnames.Add(prop.DbName);
            }

            return 0;
        }
Example #29
0
        // strStart, // 起始路径, ""表示根
        Package GetOneLevelDirPackage(string strStart)
        {
            int nRet;

            byte [] baPackage = null;

            // bool bSetDefault = false;	// 表示是否使用过缺省帐户

            //bool bFirstLogin = true;

            Package package = new Package();

            // CWaitCursor cursor;
            if (Channel == null)
            {
                Channel = channelarray.CreateChannel(0);
            }

            Debug.Assert(Channel != null, "channel尚未初始化");

            Cursor.Current = Cursors.WaitCursor;
            if (Stop != null)
            {
                Stop.OnStop += new StopEventHandler(this.DoStop);
                Stop.SetMessage("正在列目录 '" + strStart + "' ...");
                Stop.BeginLoop();
            }
            try
            {
                nRet = Channel.Dir(strStart,
                                   out baPackage);
            }
            finally
            {
                if (Stop != null)
                {
                    Stop.EndLoop();
                    Stop.OnStop -= new StopEventHandler(this.DoStop);
                    Stop.Initial("");
                }

                Cursor.Current = Cursors.Default;
            }

            if (nRet == -1)
            {
                Channel.ErrorBox(this,
                                 "restree",
                                 "列目录发生错误");

                goto ERROR1;
            }


            package.LoadPackage(baPackage, Channel.GetPathEncoding(strStart));
            package.Parse(PackageFormat.String);

            return(package);

ERROR1:
            return(null);
        }
Example #30
0
        // 打印
        private void button_print_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (Control.ModifierKeys == Keys.Control)
            {
                this.m_bShowDialog = true;  // 强制出现打印对话框
            }
            else
            {
                this.m_bShowDialog = false;
            }

            RangeList rl = null;    // rl==null表示全部打印

            if (String.IsNullOrEmpty(this.textBox_printRange.Text) == false)
            {
                try
                {
                    rl = new RangeList(this.textBox_printRange.Text);
                }
                catch (Exception ex)
                {
                    strError = "打印范围字符串格式错误: " + ex.Message;
                    goto ERROR1;
                }
            }

            int nCopies = 1;

            try
            {
                nCopies = Convert.ToInt32(this.textBox_copies.Text);
            }
            catch
            {
                strError = "份数值格式错误";
                goto ERROR1;
            }

            EnableControls(false);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在打印 ...");
            stop.BeginLoop();
            this.Update();
            Program.MainForm.Update();

            int nPrinted = 0;

            try
            {
                this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
                this.eventPrintComplete.Reset();

                // Debug.Assert(false, "");

                for (int c = 0; c < nCopies; c++)
                {
                    // 打印表格各页
                    for (int i = 0; i < this.Filenames.Count; i++)
                    {
                        Application.DoEvents(); // 出让界面控制权


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


                        if (rl == null ||
                            rl.IsInRange(i + 1, false) == true)
                        {
                            // MessageBox.Show(this, "once");
                            nPrinted++;

                            stop.SetMessage("正在打印第 " + (i + 1).ToString() + " 页...");

                            this.m_nCurrenPageNo = i;

                            this.LoadPageFile();    // 通过completed事件来驱动打印。

                            while (true)
                            {
                                Application.DoEvents(); // 出让界面控制权
                                if (eventPrintComplete.WaitOne(100, true) == true)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }

                this.webBrowser1.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("打印完成。共打印 " + nPrinted.ToString() + "页。");

                EnableControls(true);
            }

            if (nPrinted == 0)
            {
                MessageBox.Show(this, "您所指定的打印页码范围 '"
                                + this.textBox_printRange.Text + "' 没有找到匹配的页。");
            }

            return;

ERROR1:
            MessageBox.Show(this, strError);
            return;
        }
Example #31
0
        private void button_test_channelAttack_Click(object sender, EventArgs e)
        {

            _stop = new DigitalPlatform.Stop();
            _stop.Register(this.MainForm.stopManager, true);	// 和容器关联

            _stop.OnStop += new StopEventHandler(this.DoStop);
            _stop.Style = StopStyle.EnableHalfStop;
            _stop.Initial("正在测试耗费通道 ...");
            _stop.BeginLoop();

            this.button_test_channelAttack.Enabled = false;
            this.numericUpDown_test_tryChannelCount.Enabled = false;
            try
            {
                for (int i = 0; i < this.numericUpDown_test_tryChannelCount.Value; i++ )
                {
                    Application.DoEvents();

                    if (_stop != null && _stop.State != 0)
                        break;

                    LibraryChannel channel = new LibraryChannel();
                    channel.Url = this.MainForm.LibraryServerUrl;

                    channel.BeforeLogin -= new DigitalPlatform.CirculationClient.BeforeLoginEventHandle(Channel_BeforeLogin);
                    channel.BeforeLogin += new DigitalPlatform.CirculationClient.BeforeLoginEventHandle(Channel_BeforeLogin);

                    string strValue = "";
                    string strError = "";
                    long lRet = channel.GetSystemParameter(_stop,
                        "library",
                        "name",
                        out strValue,
                        out strError);
#if NO
                    if (lRet == -1)
                    {
                        if (channel.ErrorCode == DigitalPlatform.CirculationClient.localhost.ErrorCode.OutofSession)
                            break;
                    }
#endif

                    _stop.SetMessage(i.ToString());
                }
            }
            finally
            {
                this.numericUpDown_test_tryChannelCount.Enabled = true;
                this.button_test_channelAttack.Enabled = true;

                _stop.EndLoop();
                _stop.OnStop -= new StopEventHandler(this.DoStop);
                _stop.Initial("");

                if (_stop != null) // 脱离关联
                {
                    _stop.Unregister();	// 和容器关联
                    _stop = null;
                }
            }
        }
Example #32
0
        // 打印解释内容
        void menu_printHtml_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.listView_records.SelectedItems.Count == 0)
            {
                strError = "尚未选定要打印的行";
                goto ERROR1;
            }

            List<string> filenames = new List<string>();
            string strFileNamePrefix = this.MainForm.DataDir + "\\~operlog_print_";
            string strFilename = strFileNamePrefix + (1).ToString() + ".html";
            filenames.Add(strFilename);

            File.Delete(strFilename);

            StreamUtil.WriteText(strFilename,
    "<html>" +
    GetHeadString(false) +
    "<body>");

            Stop stop = new DigitalPlatform.Stop();
            stop.Register(MainForm.stopManager, true);	// 和容器关联

            stop.OnStop += new StopEventHandler(this.DoStopPrint);
            stop.Initial("正在创建打印页面 ...");
            stop.BeginLoop();

            m_webExternalHost = new WebExternalHost();
            m_webExternalHost.Initial(this.MainForm, null);
            m_webExternalHost.IsInLoop = true;

            this.GetSummary += new GetSummaryEventHandler(OperLogForm_GetSummary);
            try
            {
                stop.SetProgressRange(0, this.listView_records.SelectedItems.Count);
                int i = 0;
                foreach (ListViewItem item in this.listView_records.SelectedItems)
                {
                    Application.DoEvents();

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

                    OperLogItemInfo info = (OperLogItemInfo)item.Tag;

                    string strLogFileName = ListViewUtil.GetItemText(item, COLUMN_FILENAME);
                    string strIndex = ListViewUtil.GetItemText(item, COLUMN_INDEX);

                    string strXml = "";
                    // 从服务器获得
                    // return:
                    //      -1  出错
                    //      0   正常
                    //      1   用户中断
                    int nRet = GetXml(item,
            out strXml,
            out strError);
                    if (nRet == 1)
                        return;
                    if (nRet == -1)

                        goto ERROR1;

                    Global.SetXmlString(this.webBrowser_xml,
    strXml,
    this.MainForm.DataDir,
    "operlogexml");

                    string strHtml = "";
                    // 创建解释日志记录内容的 HTML 字符串
                    // return:
                    //      -1  出错
                    //      0   成功
                    //      1   未知的操作类型
                    nRet = GetHtmlString(strXml,
                        false,
                        out strHtml,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 1)
                        strHtml = strError;

                    StreamUtil.WriteText(strFilename,
        "<p class='record_title'>" + strLogFileName + " : " + strIndex + "</p>" + strHtml);

                    stop.SetProgressValue(i + 1);
                    i++;
                }
            }
            finally
            {
                this.GetSummary -= new GetSummaryEventHandler(OperLogForm_GetSummary);
                if (m_webExternalHost != null)
                {
                    m_webExternalHost.IsInLoop = false;
                    m_webExternalHost.Destroy();
                    m_webExternalHost = null;
                }

                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStopPrint);
                stop.Initial("打印页面创建完成");
                stop.HideProgress();

                if (stop != null) // 脱离关联
                {
                    stop.Unregister();	// 和容器关联
                    stop = null;
                }
            }

            StreamUtil.WriteText(strFilename,
"</body></html>");

            // TODO: 浏览器控件连接javascript host
            HtmlPrintForm printform = new HtmlPrintForm();

            printform.Text = "打印解释内容";
            printform.MainForm = this.MainForm;
            printform.Filenames = filenames;

            this.MainForm.AppInfo.LinkFormState(printform, "operlogform_printform_state");
            printform.ShowDialog(this);
            this.MainForm.AppInfo.UnlinkFormState(printform);

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Example #33
0
        private void button_test_loginAttack_Click(object sender, EventArgs e)
        {
            LibraryChannel channel = new LibraryChannel();
            channel.Url = this.MainForm.LibraryServerUrl;

            channel.BeforeLogin -= new DigitalPlatform.CirculationClient.BeforeLoginEventHandle(Channel_BeforeLogin);
            channel.BeforeLogin += new DigitalPlatform.CirculationClient.BeforeLoginEventHandle(Channel_BeforeLogin);


            _stop = new DigitalPlatform.Stop();
            _stop.Register(this.MainForm.stopManager, true);	// 和容器关联

            _stop.OnStop += new StopEventHandler(this.DoStop);
            _stop.Style = StopStyle.EnableHalfStop;
            _stop.Initial("正在试探密码 ...");
            _stop.BeginLoop();

            this.button_test_loginAttack.Enabled = false;
            this.numericUpDown_test_tryChannelCount.Enabled = false;
            try
            {
                for (int i = 0; i < this.numericUpDown_test_tryChannelCount.Value; i++)
                {
                    Application.DoEvents();

                    if (_stop != null && _stop.State != 0)
                        break;


                    string strUserName = "******";
                    string strPassword = i.ToString();

                    string strRights = "";
                    string strLibraryCode = "";
                    string strOutputUserName = "";
                    string strError = "";
                    long lRet = channel.Login(
                        strUserName,
                        strPassword,
                        "",
                        out strOutputUserName,
                        out strRights,
                        out strLibraryCode,
                        out strError);
#if NO
                    if (lRet == -1)
                    {
                        if (channel.ErrorCode == DigitalPlatform.CirculationClient.localhost.ErrorCode.OutofSession)
                            break;
                    }
#endif

                    _stop.SetMessage(i.ToString() + " username="******" password="******" lRet = " + lRet.ToString() + " " + strError);
                }
            }
            finally
            {
                this.numericUpDown_test_tryChannelCount.Enabled = true;
                this.button_test_loginAttack.Enabled = true;

                _stop.EndLoop();
                _stop.OnStop -= new StopEventHandler(this.DoStop);
                _stop.Initial("");

                if (_stop != null) // 脱离关联
                {
                    _stop.Unregister();	// 和容器关联
                    _stop = null;
                }
            }

        }
Example #34
0
        // 检索出盘点库内全部批次号名称
        int SearchAllBatchNo(
            LibraryChannel channel,
            Stop stop,
            string strInventoryDbName,
            out string strError)
        {
            strError = "";

            this.listView_records.Items.Clear();

            // EnableControls(false);
            stop.OnStop += new StopEventHandler(channel.DoStop);
            stop.Initial("正在列出全部批次号 ...");
            stop.BeginLoop();

            try
            {
                // 构造检索式
                StringBuilder text = new StringBuilder();

                text.Append("<target list='"
                        + StringUtil.GetXmlStringSimple(strInventoryDbName + ":" + "批次号")
                        + "'>");
                // 当前是否为全局用户
                bool bGlobalUser = this._libraryCodeList.Count == 0 || this._libraryCodeList.IndexOf("") != -1;
                    // 全局用户只认列表中 "" 一个值。这样可以检索出全部批次号,包括各个分馆的
                if (bGlobalUser == true && this._libraryCodeList.Count != 1)
                {
                    this._libraryCodeList.Clear();
                    this._libraryCodeList.Add("");
                }
                int i = 0;
                foreach (string librarycode in this.LibraryCodeList)
                {
                    if (i > 0)
                        text.Append("<operator value='OR' />");

                    text.Append("<item><word>"
                        + StringUtil.GetXmlStringSimple(bGlobalUser ? "" : librarycode + "-")
                        + "</word><match>left</match><relation>=</relation><dataType>string</dataType><maxCount>-1</maxCount></item><lang>zh</lang>");
                    i++;
                }

                if (bGlobalUser == true)
                {
                    if (i > 0)
                        text.Append("<operator value='OR' />");

                    // 针对空批次号的检索。空只能被全局用户可见
                    text.Append("<item><word>"
            + StringUtil.GetXmlStringSimple("")
            + "</word><match>exact</match><relation>=</relation><dataType>string</dataType><maxCount>-1</maxCount></item><lang>zh</lang>");
                    i++;
                }

                text.Append("</target>");

#if NO
                // 构造检索式
                string strQueryXml = "<target list='"
                        + StringUtil.GetXmlStringSimple(strInventoryDbName + ":" + "批次号")
                        + "'><item><word>"
                        + StringUtil.GetXmlStringSimple("")
                        + "</word><match>left</match><relation>=</relation><dataType>string</dataType><maxCount>-1</maxCount></item><lang>zh</lang>";
                strQueryXml += "<operator value='OR' />";
                strQueryXml += "<item><word>"
        + StringUtil.GetXmlStringSimple("")
        + "</word><match>exact</match><relation>=</relation><dataType>string</dataType><maxCount>-1</maxCount></item><lang>zh</lang></target>";
#endif

                long lRet = channel.Search(
                    stop,
                    text.ToString(),
                    "batchno",
                    "keycount", // strOutputStyle
                    out strError);
                if (lRet == 0)
                {
                    strError = "not found";
                    return 0;   // not found
                }
                if (lRet == -1)
                    return -1;

                long lHitCount = lRet;

                long lStart = 0;
                long lCount = lHitCount;
                DigitalPlatform.CirculationClient.localhost.Record[] searchresults = null;

                // 装入浏览格式
                for (; ; )
                {
                    Application.DoEvents();	// 出让界面控制权

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

                    lRet = channel.GetSearchResult(
                        stop,
                        "batchno",   // strResultSetName
                        lStart,
                        lCount,
                        "keycount",
                        "zh",
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        strError = "GetSearchResult() error: " + strError;
                        return -1;
                    }

                    if (lRet == 0)
                    {
                        // MessageBox.Show(this, "未命中");
                        return 0;
                    }

                    // 处理浏览结果
                    foreach (Record record in searchresults)
                    {
                        if (record.Cols == null)
                        {
                            strError = "请更新应用服务器和数据库内核到最新版本,才能使用列出批次号的功能";
                            return -1;
                        }

                        // 跳过数字为 0 的事项
                        if (record.Cols.Length > 0 && record.Cols[0] == "0")
                            continue;

                        ListViewItem item = new ListViewItem();
                        item.Text = string.IsNullOrEmpty(record.Path) == false ? record.Path : "[空]";
                        ListViewUtil.ChangeItemText(item, 1, record.Cols[0]);

                        this.listView_records.Items.Add(item);
                    }

                    lStart += searchresults.Length;
                    lCount -= searchresults.Length;

                    stop.SetMessage("共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条");

                    if (lStart >= lHitCount || lCount <= 0)
                        break;
                }

            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(channel.DoStop);
                stop.Initial("");

                // EnableControls(true);
            }
            return 1;
        }
Example #35
0
        // 获得日志记录
        // return:
        //      -1  出错
        //      0   日志文件不存在
        //      1   日志文件存在
        int GetLogRecords(string strServerAddr,
                          string strLogFileName,
                          out string strError)
        {
            strError = "";
            int nStartIndex = 0;

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.SetMessage("正在从服务器获得日志记录 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            try
            {
                string strPath = strServerAddr + "/log/" + strLogFileName + "/" + nStartIndex.ToString();

                bool bFirst = true;

                string strDate   = "";
                int    nRecID    = -1;
                string strOffset = "";

                int nStyle = 0;

                for (int i = nStartIndex; ; i++)
                {
                    Application.DoEvents();     // 出让界面控制权

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

                    byte[] baPackage = null;

                    if (bFirst == true)
                    {
                    }
                    else
                    {
                        strPath = strServerAddr + "/log/" + strDate /*strLogFileName*/ + "/" + nRecID.ToString() + "@" + strOffset;
                    }

                    Encoding encoding = this.Channel.GetPathEncoding(strPath);

                    stop.SetMessage("正在获得日志记录 " + strPath);

                    int nRet = this.Channel.Search(strPath,
                                                   DtlpChannel.RIZHI_STYLE | nStyle,
                                                   out baPackage);
                    if (nRet == -1)
                    {
                        int errorcode = this.Channel.GetLastErrno();
                        if (errorcode == DtlpChannel.GL_NOTEXIST)
                        {
                            if (bFirst == true)
                            {
                                break;
                            }
                        }

                        // 更换新通道
                        if (errorcode == DtlpChannel.GL_INTR ||
                            errorcode == DtlpChannel.GL_SEND ||
                            errorcode == DtlpChannel.GL_RECV)
                        {
                            this.Channel = channelArray.CreateChannel(0);
                        }

                        strError = "获取日志记录:\r\n"
                                   + "路径: " + strPath + "\r\n"
                                   + "错误码: " + errorcode + "\r\n"
                                   + "错误信息: " + this.Channel.GetErrorString(errorcode) + "\r\n";
                        return(-1);
                    }


                    // 解析出记录
                    Package package = new Package();
                    package.LoadPackage(baPackage,
                                        encoding);
                    package.Parse(PackageFormat.Binary);

                    // 获得下一路径
                    string strNextPath = "";
                    strNextPath = package.GetFirstPath();
                    if (String.IsNullOrEmpty(strNextPath) == true)
                    {
                        if (this.checkBox_loop.Checked == true)
                        {
                            i--;
                            continue;
                        }

                        if (bFirst == true)
                        {
                            strError = "文件 " + strLogFileName + "不存在";
                            return(0);
                        }
                        // strError = "检索 '" + strPath + "' 响应包中路径部分不存在 ...";
                        // return -1;
                        break;
                    }

                    // 获得记录内容
                    byte[] baContent = null;
                    nRet = package.GetFirstBin(out baContent);
                    if (nRet != 1)
                    {
                        baContent = null;       // 但是为空包
                    }



                    // 处理记录


                    string strMARC = DtlpChannel.GetDt1000LogRecord(baContent, encoding);

                    string strOperCode    = "";
                    string strOperComment = "";
                    string strOperPath    = "";

                    nRet = DtlpChannel.ParseDt1000LogRecord(strMARC,
                                                            out strOperCode,
                                                            out strOperComment,
                                                            out strOperPath,
                                                            out strError);
                    if (nRet == -1)
                    {
                        strOperComment = strError;
                    }

                    LogItemInfo info = new LogItemInfo();
                    info.Index      = i;
                    info.Offset     = GetStartOffs(strOffset);
                    info.OriginData = baContent;
                    info.Encoding   = encoding;

                    ListViewItem item = new ListViewItem();
                    item.Text = i.ToString();
                    item.SubItems.Add(info.Offset);
                    item.SubItems.Add(strOperComment);
                    item.SubItems.Add(strOperPath);
                    item.Tag = info;

                    this.listView_records.Items.Add(item);

                    // 将日志记录路径解析为日期、序号、偏移
                    // 一个日志记录路径的例子为:
                    // /ip/log/19991231/0@1234~5678
                    // parameters:
                    //		strLogPath		待解析的日志记录路径
                    //		strDate			解析出的日期
                    //		nRecID			解析出的记录号
                    //		strOffset		解析出的记录偏移,例如1234~5678
                    // return:
                    //		-1		出错
                    //		0		正确
                    nRet = DtlpChannel.ParseLogPath(strNextPath,
                                                    out strDate,
                                                    out nRecID,
                                                    out strOffset,
                                                    out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }

                    // ModiOffset(ref strOffset);

                    bFirst = false;
                }


                return(1);   // 日志文件存在,已获得了记录
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }
        }