Esempio n. 1
0
        // 获得一条记录的 MARC 格式 OID
        static string GetMarcSyntaxOID(DigitalPlatform.LibraryClient.localhost.Record dp2library_record)
        {
            if (dp2library_record.RecordBody == null)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(dp2library_record.RecordBody.Xml))
            {
                return(null);
            }

            // return:
            //      -1  出错
            //      0   正常
            int nRet = MarcUtil.GetMarcSyntax(dp2library_record.RecordBody.Xml,
                                              out string strOutMarcSyntax,
                                              out string strError);

            if (nRet == -1)
            {
                throw new Exception("获得 MARCXML 记录的 MARC Syntax 时出错: " + strError);
            }

            if (strOutMarcSyntax == "unimarc")
            {
                return("1.2.840.10003.5.1");
            }
            if (strOutMarcSyntax == "usmarc")
            {
                return("1.2.840.10003.5.10");
            }

            return(null);
        }
Esempio n. 2
0
        public IEnumerator GetEnumerator()
        {
            List <string> batch = new List <string>();

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

                // 每100个一批,或者最后一次
                if (batch.Count >= 100 ||
                    (index == m_recpaths.Count - 1 && batch.Count > 0))
                {
REDO:
#if NO
                    string[] paths = new string[batch.Count];
                    batch.CopyTo(paths);
#endif
                    string [] paths = batch.ToArray();

                    DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null;
                    string strError = "";

                    long lRet = Channel.GetBrowseRecords(
                        this.Stop,
                        paths,
                        this.Format,    // "id,cols",
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        throw new Exception(strError);
                    }
#if NO
                    if (lRet == -1)
                    {
                        if (lRet == 0 && String.IsNullOrEmpty(strError) == true)
                        {
                            foreach (string path in batch)
                            {
                                DigitalPlatform.LibraryClient.localhost.Record record = new DigitalPlatform.LibraryClient.localhost.Record();
                                record.Path = path;
                                // TODO: 是否需要设置 ErrorCode ?
                                yield return(record);
                            }
                            goto CONTINUE;
                        }

                        // 如果results.Length表现正常,其实还可以继续处理?
                        if (searchresults != null && searchresults.Length > 0)
                        {
                        }
                        else
                        {
                            strError = "获得浏览记录 '" + StringUtil.MakePathList(batch) + "' 时发生错误: " + strError;
                            throw new Exception(strError);
                        }
                    }
#endif

                    if (searchresults == null)
                    {
                        strError = "searchresults == null";
                        throw new Exception(strError);
                    }

                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        DigitalPlatform.LibraryClient.localhost.Record record = searchresults[i];
                        if (batch[i] != record.Path)
                        {
                            throw new Exception("下标 " + i + " 的 batch 元素 '" + batch[i] + "' 和返回的该下标位置 GetBrowseRecords() 结果路径 '" + record.Path + "' 不匹配");
                        }
                        Debug.Assert(batch[i] == record.Path, "");
                        yield return(record);
                    }

                    // CONTINUE:
                    if (batch.Count > searchresults.Length)
                    {
                        // 有本次没有获取到的记录
                        batch.RemoveRange(0, searchresults.Length);
                        if (index == m_recpaths.Count - 1)
                        {
                            goto REDO;  // 当前已经是最后一轮了,需要继续做完
                        }
                        // 否则可以留给下一轮处理
                    }
                    else
                    {
                        batch.Clear();
                    }
                }
            }
        }
Esempio n. 3
0
        public IEnumerator GetEnumerator()
        {
            // 首先按照服务器名的不同,划分为若干个区段
            List <OneBatch> batchs = new List <OneBatch>();

            {
                OneBatch batch = new OneBatch();
                for (int index = 0; index < m_recpaths.Count; index++)
                {
                    string s = m_recpaths[index];

                    // 解析记录路径
                    string strServerName = "";
                    string strPurePath   = "";
                    dp2SearchForm.ParseRecPath(s,
                                               out strServerName,
                                               out strPurePath);

                    // 服务器名发生变化了
                    if (batch.Count > 0 && strServerName != batch.ServerName)
                    {
                        batchs.Add(batch);
                        batch            = new OneBatch();
                        batch.ServerName = strServerName;
                        batch.Add(strPurePath);
                        continue;
                    }

                    if (string.IsNullOrEmpty(batch.ServerName) == true)
                    {
                        batch.ServerName = strServerName;
                    }

                    batch.Add(strPurePath);
                }

                if (batch.Count > 0)
                {
                    batchs.Add(batch);
                }
            }

            // 进行循环获取
            foreach (OneBatch temp in batchs)
            {
                // 获得server url
                dp2Server server = this.Servers.GetServerByName(temp.ServerName);
                if (server == null)
                {
                    string strError = "名为 '" + temp.ServerName + "' 的服务器在检索窗中尚未定义...";
                    throw new Exception(strError);
                }
                string strServerUrl = server.Url;

                LibraryChannel channel = this.ChannelManager.GetChannel(strServerUrl);

                try
                {
                    List <string> batch = new List <string>();
                    for (; batch.Count > 0 || temp.Count > 0;)
                    {
                        if (batch.Count == 0)
                        {
                            for (int i = 0; i < Math.Min(temp.Count, 100); i++)
                            {
                                batch.Add(temp[i]);
                            }
                            temp.RemoveRange(0, batch.Count);
                        }

                        // 每100个一批
                        if (batch.Count > 0)
                        {
REDO:
                            string[] paths = new string[batch.Count];
                            batch.CopyTo(paths);

                            DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null;
                            string strError = "";

                            long lRet = channel.GetBrowseRecords(
                                this.Stop,
                                paths,
                                "id,cols",
                                out searchresults,
                                out strError);
                            if (lRet == -1)
                            {
                                throw new Exception(strError);
                            }


                            if (searchresults == null)
                            {
                                strError = "searchresults == null";
                                throw new Exception(strError);
                            }

                            for (int i = 0; i < searchresults.Length; i++)
                            {
                                DigitalPlatform.LibraryClient.localhost.Record record = searchresults[i];
                                Debug.Assert(batch[i] == record.Path, "");

                                // 包含服务器名
                                record.Path = record.Path + "@" + temp.ServerName;
                                yield return(record);
                            }

CONTINUE:
                            if (batch.Count > searchresults.Length)
                            {
                                // 有本次没有获取到的记录
                                batch.RemoveRange(0, searchresults.Length);

                                /*
                                 * if (index == m_recpaths.Count - 1)
                                 *  goto REDO;  // 当前已经是最后一轮了,需要继续做完
                                 * */

                                // 否则可以留给下一轮处理
                            }
                            else
                            {
                                batch.Clear();
                            }
                        }
                    }

                    //
                }
                finally
                {
                    Program.MainForm.ReturnChannel(channel);
                }
            }
        }
Esempio n. 4
0
        public IEnumerator GetEnumerator()
        {
            List <string> batch = new List <string>();

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

                // 每100个一批,或者最后一次
                if (batch.Count >= 100 ||
                    (index == m_recpaths.Count - 1 && batch.Count > 0))
                {
REDO:
#if NO
                    string[] paths = new string[batch.Count];
                    batch.CopyTo(paths);
#endif
                    string[] paths = batch.ToArray();

                    DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null;
                    string strError = "";

                    long lRet = Channel.GetBrowseRecords(
                        this.Stop,
                        paths,
                        this.Format,    // "id,cols",
                        out searchresults,
                        out strError);
                    if (lRet == -1)
                    {
                        // throw new Exception(strError);

                        if (this.Prompt != null)
                        {
                            MessagePromptEventArgs e = new MessagePromptEventArgs();
                            e.MessageText = "获得浏览记录时发生错误: " + strError + "\r\npaths='" + StringUtil.MakePathList(paths) + "' (" + this.Format + ")";
                            e.Actions     = "yes,no,cancel";
                            this.Prompt(this, e);
                            if (e.ResultAction == "cancel")
                            {
                                throw new ChannelException(Channel.ErrorCode, strError);
                            }
                            else if (e.ResultAction == "yes")
                            {
                                goto REDO;
                            }
                            else
                            {
                                // no 也是抛出异常。因为继续下一批代价太大
                                throw new ChannelException(Channel.ErrorCode, strError);
                            }
                        }
                        else
                        {
                            throw new ChannelException(Channel.ErrorCode, strError);
                        }
                    }

                    if (searchresults == null)
                    {
                        strError = "searchresults == null";
                        throw new Exception(strError);
                    }

                    for (int i = 0; i < searchresults.Length; i++)
                    {
                        DigitalPlatform.LibraryClient.localhost.Record record = searchresults[i];
                        if (batch[i] != record.Path)
                        {
                            throw new Exception("下标 " + i + " 的 batch 元素 '" + batch[i] + "' 和返回的该下标位置 GetBrowseRecords() 结果路径 '" + record.Path + "' 不匹配");
                        }
                        Debug.Assert(batch[i] == record.Path, "");
                        yield return(record);
                    }

                    // CONTINUE:
                    if (batch.Count > searchresults.Length)
                    {
                        // 有本次没有获取到的记录
                        batch.RemoveRange(0, searchresults.Length);
                        if (index == m_recpaths.Count - 1)
                        {
                            goto REDO;  // 当前已经是最后一轮了,需要继续做完
                        }
                        // 否则可以留给下一轮处理
                    }
                    else
                    {
                        batch.Clear();
                    }
                }
            }
        }
Esempio n. 5
0
        // TODO: 实现简略格式和详细格式提供。简略格式可以理解为略去一些分类号主题词字段,最好用一段用户定制的脚本来进行过滤
        // 获得MARC记录
        // parameters:
        //      elementSetNames 元素集列表。每个元素集为 'B' 或 'F',表示简略和详细格式
        //      bAddField901    是否加入901字段?
        // return:
        //      -1  error
        //      0   not found
        //      1   found
        static int GetIso2709Record(
            DigitalPlatform.LibraryClient.localhost.Record dp2library_record,
            List <string> elementSetNames,
            bool bAddField901,
            string strRemoveFields,
            Encoding marcRecordEncoding,
            out string strMarcSyntaxOID,
            out byte[] baIso2709,
            out string strError)
        {
            baIso2709        = null;
            strError         = "";
            strMarcSyntaxOID = "";

            // 转换为机内格式
            int nRet = MarcUtil.Xml2Marc(dp2library_record.RecordBody.Xml,
                                         true,
                                         "",
                                         out string strMarcSyntax,
                                         out string strMarc,
                                         out strError);

            if (nRet == -1)
            {
                strError = "XML转换到MARC记录时出错: " + strError;
                return(-1);
            }

            // 去掉记录中的 997/998
            MarcRecord record = new MarcRecord(strMarc);

            if (string.IsNullOrEmpty(strRemoveFields) == false)
            {
                List <string> field_names = StringUtil.SplitList(strRemoveFields);
                foreach (string field_name in field_names)
                {
                    if (field_name.Length != 3)
                    {
                        strError = "removeFields 定义里面出现了不是 3 字符的字段名('" + strRemoveFields + "')";
                        return(-1);
                    }
                    record.select("field[@name='" + field_name + "']").detach();
                }
            }

            if (bAddField901 == true)
            {
                // 901  $p记录路径$t时间戳
                string strContent = "$p" + dp2library_record.Path
                                    + "$t" + ByteArray.GetHexTimeStampString(dp2library_record.RecordBody.Timestamp);
                record.setFirstField("901", "  ", strContent.Replace("$", MarcQuery.SUBFLD), "  ");
            }
            strMarc = record.Text;

            // 转换为ISO2709
            nRet = MarcUtil.CvtJineiToISO2709(
                strMarc,
                strMarcSyntax,
                marcRecordEncoding,
                out baIso2709,
                out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            if (strMarcSyntax == "unimarc")
            {
                strMarcSyntaxOID = "1.2.840.10003.5.1";
            }
            if (strMarcSyntax == "usmarc")
            {
                strMarcSyntaxOID = "1.2.840.10003.5.10";
            }

            return(1);
        }