Example #1
0
        // 从 XML 文件中装载服务器配置信息
        public NormalResult LoadServer(string xmlFileName,
                                       Marc8Encoding marc8Encoding)
        {
            this.Clear();

            this.XmlFileName = xmlFileName;

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.Load(xmlFileName);
            }
            catch (Exception ex)
            {
                return(new NormalResult {
                    Value = -1, ErrorInfo = ex.Message
                });
            }

            XmlNodeList servers = dom.DocumentElement.SelectNodes("server");

            foreach (XmlElement server in servers)
            {
                var result = ZServerUtil.GetTarget(server,
                                                   marc8Encoding,
                                                   out TargetInfo targetInfo);
                if (result.Value == -1)
                {
                    return(result);
                }
                ZClientChannel channel = new ZClientChannel
                {
                    ServerName = server.GetAttribute("name"),
                    ZClient    = new ZClient(),
                    TargetInfo = targetInfo,
                    Enabled    = ZServerListDialog.IsEnabled(server.GetAttribute("enabled"), true)
                };
                _channels.Add(channel);
            }

            return(new NormalResult());
        }
Example #2
0
        private void button_e2uStringConvert_Click(object sender, EventArgs e)
        {
            if (this.textBox_e2uFilename.Text == "")
            {
                MessageBox.Show(this, "尚未指定 e2u 码表文件");
                return;
            }

            this.textBox_unicodeCode.Text = "";

            CharsetTable charsettable_e2u = new CharsetTable();

            charsettable_e2u.Attach(this.textBox_e2uFilename.Text,
                this.textBox_e2uFilename.Text + ".index");

            Marc8Encoding encoding = new Marc8Encoding(charsettable_e2u,
                this.MainForm.DataDir + "\\asciicodetables.xml");

            try
            {
                string strText = "";

                if (this.textBox_field066value.Text != "")
                    encoding.SetDefaultCodePage(this.textBox_field066value.Text.Replace('|', (char)31));

                encoding.Marc8_to_Unicode(
                    Encoding.ASCII.GetBytes(
                    this.textBox_eaccString.Text),
                    out strText);

                this.textBox_unicodeString.Text = strText;
            }
            finally
            {
                string strTemp1;
                string strTemp2;

                charsettable_e2u.Detach(out strTemp1,
                    out strTemp2);
            }


        }
Example #3
0
        public static NormalResult GetTarget(
            XmlElement xmlServerNode,
            Marc8Encoding marc8Encoding,
            out TargetInfo targetinfo)
        {
            targetinfo = null;

            targetinfo = new TargetInfo();

            List <string> dbnames = GetDatabaseNames(xmlServerNode);

            targetinfo.HostName = xmlServerNode.GetAttribute("addr");
            string strPort = xmlServerNode.GetAttribute("port");

            if (String.IsNullOrEmpty(strPort) == false)
            {
                targetinfo.Port = Convert.ToInt32(strPort);
            }

            targetinfo.DbNames  = dbnames.ToArray();
            targetinfo.UserName = xmlServerNode.GetAttribute("username");

            // password
            string strPassword = xmlServerNode.GetAttribute("password");

            targetinfo.Password = ZServerPropertyForm.GetPassword(strPassword);

            targetinfo.GroupID = xmlServerNode.GetAttribute("groupid");
            string strAuthenticationMethod = xmlServerNode.GetAttribute("authmethod");

            if (String.IsNullOrEmpty(strAuthenticationMethod) == false)
            {
                targetinfo.AuthenticationMethod = Convert.ToInt32(strAuthenticationMethod);
            }

            // converteacc 缺省值为 "0"
            targetinfo.ConvertEACC = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("converteacc"), false);
            // firstfull 缺省值为 "0"
            targetinfo.FirstFull = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("firstfull"), false);
            // detectmarcsyntax 缺省值为 "0"
            targetinfo.DetectMarcSyntax = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("detectmarcsyntax"), false);

            // ignorereferenceid 缺省值为 "0"
            targetinfo.IgnoreReferenceID = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("ignorereferenceid"), false);

            // 对ISBN的预处理
            // isbn_force13 缺省值为 "0"
            targetinfo.IsbnForce13 = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("isbn_force13"), false);
            // isbn_force10 缺省值为 "0"
            targetinfo.IsbnForce10 = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("isbn_force10"), false);
            // isbn_addhyphen 缺省值为 "0"
            targetinfo.IsbnAddHyphen = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("isbn_addhyphen"), false);
            // isbn_removehyphen 缺省值为 "0"
            targetinfo.IsbnRemoveHyphen = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("isbn_removehyphen"), false);
            // isbn_wild 缺省值为 "0"
            targetinfo.IsbnWild = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("isbn_wild"), false);

            // issn_force8 缺省值为 "1"
            targetinfo.IssnForce8 = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("issn_force8"), true);

            string strPresentPerBatchCount = xmlServerNode.GetAttribute("recsperbatch");

            if (String.IsNullOrEmpty(strPresentPerBatchCount) == false)
            {
                targetinfo.PresentPerBatchCount = Convert.ToInt32(strPresentPerBatchCount);
            }
            else
            {
                targetinfo.PresentPerBatchCount = 10;
            }

            // 缺省编码方式
            string strDefaultEncodingName = xmlServerNode.GetAttribute("defaultEncoding");

            if (String.IsNullOrEmpty(strDefaultEncodingName) == false)
            {
                try
                {
                    // 单独处理MARC-8 Encoding
                    if (strDefaultEncodingName.ToLower() == "eacc" ||
                        strDefaultEncodingName.ToLower() == "marc-8")
                    {
                        if (marc8Encoding == null)
                        {
                            return new NormalResult
                                   {
                                       Value     = -1,
                                       ErrorInfo = "marc8Encoding 不应为 null"
                                   }
                        }
                        ;
                        targetinfo.DefaultRecordsEncoding = marc8Encoding;
                    }
                    else
                    {
                        targetinfo.DefaultRecordsEncoding = Encoding.GetEncoding(strDefaultEncodingName);
                    }
                }
                catch
                {
                    targetinfo.DefaultRecordsEncoding = Encoding.GetEncoding(936);
                }
            }

            // 检索词编码方式
            string strQueryTermEncodingName = xmlServerNode.GetAttribute("queryTermEncoding");

            if (String.IsNullOrEmpty(strQueryTermEncodingName) == false)
            {
                try
                {
                    targetinfo.DefaultQueryTermEncoding = Encoding.GetEncoding(strQueryTermEncodingName);
                }
                catch
                {
                    targetinfo.DefaultQueryTermEncoding = Encoding.GetEncoding(936);
                }
            }

            string strDefaultMarcSyntax = xmlServerNode.GetAttribute("defaultMarcSyntaxOID");

            // strDefaultMarcSyntax = strDefaultMarcSyntax;    // 可以有--部分

            if (String.IsNullOrEmpty(strDefaultMarcSyntax) == false)
            {
                targetinfo.PreferredRecordSyntax = strDefaultMarcSyntax;
            }

            //
            string strDefaultElementSetName = xmlServerNode.GetAttribute("defaultElementSetName");

            // strDefaultElementSetName = strDefaultElementSetName;    // 可以有--部分

            if (String.IsNullOrEmpty(strDefaultElementSetName) == false)
            {
                targetinfo.DefaultElementSetName = strDefaultElementSetName;
            }

            // 格式和编码之间的绑定信息
            string strBindingDef = xmlServerNode.GetAttribute("recordSyntaxAndEncodingBinding");

            targetinfo.Bindings = new RecordSyntaxAndEncodingBindingCollection();
            if (String.IsNullOrEmpty(strBindingDef) == false)
            {
                targetinfo.Bindings.Load(strBindingDef);
            }

            // charset nego
            // charNegoUtf8 缺省值为 "0"
            targetinfo.CharNegoUTF8 = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("charNegoUtf8"), false);
            // charNego_recordsInSeletedCharsets 缺省值为 "0"
            targetinfo.CharNegoRecordsUTF8 = ZServerPropertyForm.GetBool(
                xmlServerNode.GetAttribute("charNego_recordsInSeletedCharsets"), false);

            targetinfo.UnionCatalogBindingDp2ServerName =
                xmlServerNode.GetAttribute("unionCatalog_bindingDp2ServerName");

            targetinfo.UnionCatalogBindingUcServerUrl =
                xmlServerNode.GetAttribute("unionCatalog_bindingUcServerUrl");

            return(new NormalResult());
        }