Esempio n. 1
0
File: MyForm.cs Progetto: gvhung/dp2
        int m_nInGetCfgFile = 0;    // 防止GetCfgFile()函数重入 2008/3/6

        // 获得配置文件
        // parameters:
        //
        // return:
        //      -1  error
        //      0   not found
        //      1   found
        public int GetCfgFileContent(string strCfgFilePath,
                                     out string strContent,
                                     out byte[] baOutputTimestamp,
                                     out string strError)
        {
            baOutputTimestamp = null;
            strError          = "";
            strContent        = "";

            if (m_nInGetCfgFile > 0)
            {
                strError = "GetCfgFile() 重入了";
                return(-1);
            }

            LibraryChannel channel       = this.GetChannel();
            string         strOldMessage = Progress.Initial("正在下载配置文件 ...");
            TimeSpan       old_timeout   = channel.Timeout;

            channel.Timeout = new TimeSpan(0, 1, 0);

#if NO
            Progress.OnStop += new StopEventHandler(this.DoStop);
            Progress.Initial("正在下载配置文件 ...");
            Progress.BeginLoop();
#endif

            m_nInGetCfgFile++;

            try
            {
                Progress.SetMessage("正在下载配置文件 " + strCfgFilePath + " ...");
                string strMetaData   = "";
                string strOutputPath = "";

                string strStyle = "content,data,metadata,timestamp,outputpath";

                long lRet = channel.GetRes(Progress,
                                           MainForm.cfgCache,
                                           strCfgFilePath,
                                           strStyle,
                                           null,
                                           out strContent,
                                           out strMetaData,
                                           out baOutputTimestamp,
                                           out strOutputPath,
                                           out strError);
                if (lRet == -1)
                {
                    if (channel.ErrorCode == ErrorCode.NotFound)
                    {
                        return(0);
                    }

                    goto ERROR1;
                }
            }
            finally
            {
#if NO
                Progress.EndLoop();
                Progress.OnStop -= new StopEventHandler(this.DoStop);
                Progress.Initial("");
#endif
                Progress.Initial(strOldMessage);

                channel.Timeout = old_timeout;
                this.ReturnChannel(channel);

                m_nInGetCfgFile--;
            }

            return(1);

ERROR1:
            return(-1);
        }
Esempio n. 2
0
        Hashtable _biblioXmlTable = new Hashtable(); // biblioRecPath --> xml

        private void button_search_Click(object sender, EventArgs e)
        {
            string strError = "";
            int    nRet     = 0;

            // 按下 Control 的时候空字符串也可以检索
            if (!(Control.ModifierKeys == Keys.Control) &&
                string.IsNullOrEmpty(this.textBox_queryWord.Text) == true)
            {
                strError = "请输入检索词";
                goto ERROR1;
            }

            this._biblioXmlTable.Clear();
            this._biblioRecPaths.Clear();
            this.dpTable_items.Rows.Clear();

            LibraryChannel channel = this.GetChannel();

            Progress.Style   = StopStyle.EnableHalfStop;
            Progress.OnStop += new StopEventHandler(this.DoStop);
            Progress.Initial("正在检索 ...");
            Progress.BeginLoop();

            this.EnableControls(false);

            m_nInSearching++;

            this.SetFloatMessage("waiting", "正在检索 ...");

            try
            {
                if (this.comboBox_from.Text == "")
                {
                    strError = "尚未选定检索途径";
                    goto ERROR1;
                }
                string strFromStyle = "";

                try
                {
                    strFromStyle = BiblioSearchForm.GetBiblioFromStyle(this.comboBox_from.Text);
                }
                catch (Exception ex)
                {
                    strError = "GetBiblioFromStyle() exception: " + ExceptionUtil.GetAutoText(ex);
                    goto ERROR1;
                }

                if (String.IsNullOrEmpty(strFromStyle) == true)
                {
                    strError = "GetFromStyle()没有找到 '" + this.comboBox_from.Text + "' 对应的style字符串";
                    goto ERROR1;
                }

                string strMatchStyle = "left";  // BiblioSearchForm.GetCurrentMatchStyle(this.comboBox_matchStyle.Text);
                if (this.textBox_queryWord.Text == "")
                {
                    if (strMatchStyle == "null")
                    {
                        this.textBox_queryWord.Text = "";

                        // 专门检索空值
                        strMatchStyle = "exact";
                    }
                    else
                    {
                        // 为了在检索词为空的时候,检索出全部的记录
                        strMatchStyle = "left";
                    }
                }
                else
                {
                    if (strMatchStyle == "null")
                    {
                        strError = "检索空值的时候,请保持检索词为空";
                        goto ERROR1;
                    }
                }

                string strQueryWord = GetBiblioQueryString();

                string strQueryXml = "";
                long   lRet        = channel.SearchBiblio(Progress,
                                                          this.GetBiblioDbNames(), // "<全部>",
                                                          strQueryWord,            // this.textBox_queryWord.Text,
                                                          1000,
                                                          strFromStyle,
                                                          strMatchStyle,
                                                          this.Lang,
                                                          null, // strResultSetName
                                                          "",   // strSearchStyle
                                                          "",   // strOutputStyle
                                                          "",
                                                          out strQueryXml,
                                                          out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }

                // TODO: 最多检索1000条的限制,可以作为参数配置?

                long lHitCount = lRet;

                if (lHitCount == 0)
                {
                    strError = "从途径 '" + strFromStyle + "' 检索 '" + strQueryWord + "' 没有命中";
                    this.SetFloatMessage("", strError);
                    this.textBox_queryWord.SelectAll();
                    this.textBox_queryWord.Focus();
                    return;
                }

                long lStart    = 0;
                long lPerCount = Math.Min(50, lHitCount);
                DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null;

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

                    if (Progress != null)
                    {
                        if (Progress.State != 0)
                        {
                            // MessageBox.Show(this, "用户中断");
                            break;  // 已经装入的还在
                        }
                    }

                    Progress.SetMessage("正在装入书目记录ID " + (lStart + 1).ToString() + " - " + (lStart + lPerCount).ToString() + " (命中 " + lHitCount.ToString() + " 条记录) ...");

                    lRet = channel.GetSearchResult(
                        Progress,
                        null,   // strResultSetName
                        lStart,
                        lPerCount,
                        this.FunctionType == "read" ? "id,xml" : "id", // "id,cols",
                        this.Lang,
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        if (Progress.State != 0)
                        {
                            // MessageBox.Show(this, "用户中断");
                            break;
                        }

                        goto ERROR1;
                    }

                    if (lRet == 0)
                    {
                        strError = "未命中";
                        goto ERROR1;
                    }

                    // 处理浏览结果
                    foreach (DigitalPlatform.LibraryClient.localhost.Record record in searchresults)
                    {
                        this._biblioRecPaths.Add(record.Path);
                        // 存储书目记录 XML
                        if (this.FunctionType == "read" && record.RecordBody != null)
                        {
                            this._biblioXmlTable[record.Path] = record.RecordBody.Xml;
                        }
                    }

                    lStart += searchresults.Length;
                    // lCount -= searchresults.Length;
                    if (lStart >= lHitCount || lPerCount <= 0)
                    {
                        break;
                    }
                }

                this.SetFloatMessage("waiting", "正在装入册记录 ...");
                Progress.SetProgressRange(0, this._biblioRecPaths.Count);
                // 将每条书目记录下属的册记录装入
                int i = 0;
                foreach (string strBiblioRecPath in this._biblioRecPaths)
                {
                    Application.DoEvents();

                    if (Progress.State != 0)
                    {
                        break;
                    }

                    nRet = LoadBiblioSubItems(
                        channel,
                        strBiblioRecPath,
                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                    Progress.SetProgressValue(++i);
                }
                // MessageBox.Show(this, Convert.ToString(lRet) + " : " + strError);
            }
            finally
            {
                Progress.EndLoop();
                Progress.OnStop -= new StopEventHandler(this.DoStop);
                Progress.Initial("");
                Progress.HideProgress();

                // this.button_search.Enabled = true;
                this.EnableControls(true);

                this.ReturnChannel(channel);

                m_nInSearching--;
            }

            int nClickableCount = GetClickableCount();

            if (nClickableCount == 0)
            {
                this.SetFloatMessage("", "没有可用的册记录");
            }
            else
            {
                this.SetFloatMessage("", "");
                SelectFirstUseableItem();
                if (nClickableCount == 1 &&
                    this.AutoOperSingleItem == true)
                {
                    this.dpTable_items_DoubleClick(this, new EventArgs());
                }
            }
            this.textBox_queryWord.SelectAll();
            return;

ERROR1:
            this.SetFloatMessage("", strError);
            if (this.Visible == true)
            {
                MessageBox.Show(this, strError);
            }
            this.textBox_queryWord.SelectAll();
            this.textBox_queryWord.Focus();
        }
Esempio n. 3
0
File: MyForm.cs Progetto: gvhung/dp2
        // 保存配置文件
        public int SaveCfgFile(string strBiblioDbName,
                               string strCfgFileName,
                               string strContent,
                               byte[] baTimestamp,
                               out string strError)
        {
            strError = "";

            LibraryChannel channel       = this.GetChannel();
            string         strOldMessage = Progress.Initial("正在保存配置文件 ...");
            TimeSpan       old_timeout   = channel.Timeout;

            channel.Timeout = new TimeSpan(0, 1, 0);

#if NO
            Progress.OnStop += new StopEventHandler(this.DoStop);
            Progress.Initial("正在保存配置文件 ...");
            Progress.BeginLoop();
#endif

            try
            {
                string strPath = strBiblioDbName + "/cfgs/" + strCfgFileName;

                Progress.SetMessage("正在保存配置文件 " + strPath + " ...");

                byte[] output_timestamp = null;
                string strOutputPath    = "";

                long lRet = channel.WriteRes(
                    Progress,
                    strPath,
                    strContent,
                    true,
                    "", // style
                    baTimestamp,
                    out output_timestamp,
                    out strOutputPath,
                    out strError);
                if (lRet == -1)
                {
                    goto ERROR1;
                }
            }
            finally
            {
#if NO
                Progress.EndLoop();
                Progress.OnStop -= new StopEventHandler(this.DoStop);
                Progress.Initial("");
#endif
                Progress.Initial(strOldMessage);

                channel.Timeout = old_timeout;
                this.ReturnChannel(channel);
            }

            return(1);

ERROR1:
            return(-1);
        }