Esempio n. 1
0
        public BaseCommand GetCommand(string cmdName)
        {
            if (CmdDict.ContainsKey(cmdName))
            {
                return CmdDict[cmdName];
            }

            // todo这里改为具体的类型
            BaseCommand command = null;
            if (cmdName == dp2CommandUtility.C_Command_Search)
            {
                command = new SearchCommand();
            }
            else if (cmdName == dp2CommandUtility.C_Command_Binding)
            {
                command = new BindingCommand();
            }
            else
            {
                command = new BaseCommand();
            }
            command.CommandName = cmdName;
            CmdDict[cmdName] = command;
            return command;
        }
Esempio n. 2
0
        /// <summary>
        /// 根据操作时间检索
        /// </summary>
        /// <param name="strWord"></param>
        /// <param name="searchCmd"></param>
        /// <param name="strFirstPage"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public long SearchBiblioByPublishtime(string strWord,
            SearchCommand searchCmd,
            out string strFirstPage,
            out string strError)
        {
            strFirstPage = "";
            strError = "";

            // 判断检索词
            strWord = strWord.Trim();
            if (String.IsNullOrEmpty(strWord))
            {
                strError = "检索词不能为空。";
                return -1;
            }

            long lTotoalCount = 0;
            // 从池中征用通道
            LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
            channel.Password = this.dp2Password;
            try
            {
                // -1失败
                // 0 未命令
                long lRet = channel.SearchBiblio(strWord,
                    "publishtime,_time,_freetime",
                    out strError);
                if (lRet == -1 || lRet == 0)
                {
                    return lRet;
                }

                // 取出命中记录列表
                lTotoalCount = lRet;

                List<string> totalResultList = new List<string>();
                long lStart = 0;
                // 当前总共取的多少记录
                long lCurTotalCount = 0;

            REDO:
                List<string> resultPathList = null;
                long lCount = -1;
                lRet = channel.GetBiblioSearchResult(lStart,
                    lCount,
                     out resultPathList,
                     out strError);
                if (lRet == -1)
                    return -1;

                // 加到结果集中
                totalResultList.AddRange(resultPathList);

                // 检查记录是否获取完成,没取完继续取
                lCurTotalCount += lRet;
                if (lCurTotalCount < lTotoalCount)
                {
                    lStart = lCurTotalCount;
                    goto REDO;
                }

                // 检查一下,取出来的记录数,是否与返回的命中数量一致
                if (lTotoalCount != totalResultList.Count)
                {
                    strError = "内部错误,不可能结果集数量不一致";
                    return -1;
                }

                // 将检索结果信息保存到检索命令中
                searchCmd.BiblioResultPathList = totalResultList;
                searchCmd.ResultNextStart = 0;
                searchCmd.IsCanNextPage = true;

                // 获得第一页检索结果
                bool bRet = searchCmd.GetNextPage(out strFirstPage, out strError);
                if (bRet == false)
                {
                    return -1;
                }
            }
            finally
            {
                // 归还通道到池
                this.ChannelPool.ReturnChannel(channel);
            }

            return lTotoalCount;
        }
Esempio n. 3
0
        /// <summary>
        /// 根据书目序号得到详细的参考信息
        /// </summary>
        /// <param name="nIndex">书目序号,从1排序</param>
        /// <param name="strInfo"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public int GetDetailBiblioInfo(SearchCommand searchCmd,
            int  nIndex,
            out string strBiblioInfo,
            out string strError)
        {
            strBiblioInfo = "";
            strError = "";
            Debug.Assert(searchCmd != null);

            //检查有无超过数组界面
            if (nIndex <= 0 || searchCmd.BiblioResultPathList.Count < nIndex)
            {
                strError = "您输入的书目序号[" + nIndex.ToString() + "]越出范围。";
                return -1;
            }

            // 获取路径,注意要截取
            string strPath = searchCmd.BiblioResultPathList[nIndex - 1];
            int index = strPath.IndexOf("*");
            if (index > 0)
                strPath = strPath.Substring(0, index);
            LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);
            channel.Password = this.dp2Password;
            try
            {
                long lRet1 = channel.GetBiblioDetail(strPath,
                    out strBiblioInfo,
                    out strError);
                if (lRet1 == -1)
                {
                    strError = "获取详细信息失败:" + strError;
                    return -1;
                }
            }
            finally
            {
                this.ChannelPool.ReturnChannel(channel);
            }
            return 0;
        }