Example #1
0
        private void MarcEditor_GetConfigDom(object sender, GetConfigDomEventArgs e)
        {
            // Debug.Assert(false, "");
            bool bRemote = string.IsNullOrEmpty(this.MarcSyntax) == false;

            if (String.IsNullOrEmpty(this.BiblioRecPath) == true
                && bRemote == false)
            {
                e.ErrorInfo = "MarcSyntax 为空,并且记录路径为空,无法获得配置文件 '" + e.Path + "'";
                this.ShowMessage(e.ErrorInfo, "red", true);
                return;
            }

            // 得到干净的文件名
            string strCfgFileName = e.Path;
            int nRet = strCfgFileName.IndexOf("#");
            if (nRet != -1)
            {
                strCfgFileName = strCfgFileName.Substring(0, nRet);
            }

            // 根据 MarcSyntax 取得配置文件
            if (bRemote && string.IsNullOrEmpty(this.BiblioRecPath) == true)
            {
                string strFileName = Path.Combine(this.MainForm.DataDir, this.MarcSyntax + "_cfgs/" + strCfgFileName);

                // 在cache中寻找
                e.XmlDocument = this.MainForm.DomCache.FindObject(strFileName);
                if (e.XmlDocument != null)
                    return;

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.Load(strFileName);
                }
                catch (Exception ex)
                {
                    e.ErrorInfo = "配置文件 '" + strFileName + "' 装入 XMLDOM 时出错: " + ex.Message;
                    this.ShowMessage(e.ErrorInfo, "red", true);
                    return;
                }
                e.XmlDocument = dom;
                this.MainForm.DomCache.SetObject(strFileName, dom);  // 保存到缓存
                return;
            }

            string strBiblioDbName = Global.GetDbName(this.BiblioRecPath);

            string strCfgFilePath = strBiblioDbName + "/cfgs/" + strCfgFileName;

            // 在cache中寻找
            e.XmlDocument = this.MainForm.DomCache.FindObject(strCfgFilePath);
            if (e.XmlDocument != null)
                return;

            // 下载配置文件
            string strContent = "";
            string strError = "";

            byte[] baCfgOutputTimestamp = null;
            // return:
            //      -1  error
            //      0   not found
            //      1   found
            nRet = GetCfgFileContent(strCfgFilePath,
                out strContent,
                out baCfgOutputTimestamp,
                out strError);
            if (nRet == -1 || nRet == 0)
            {
                e.ErrorInfo = "获得配置文件 '" + strCfgFilePath + "' 时出错:" + strError;
            }
            else
            {
                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strContent);
                }
                catch (Exception ex)
                {
                    e.ErrorInfo = "配置文件 '" + strCfgFilePath + "' 装入XMLDUM时出错: " + ex.Message;
                    this.ShowMessage(e.ErrorInfo, "red", true);
                    return;
                }
                e.XmlDocument = dom;
                this.MainForm.DomCache.SetObject(strCfgFilePath, dom);  // 保存到缓存
            }
        }
Example #2
0
        private void MarcEditor_GetConfigDom(object sender, GetConfigDomEventArgs e)
        {
            if (String.IsNullOrEmpty(textBox_recPath.Text) == true)
            {
                e.ErrorInfo = "记录路径为空,无法获得配置文件 '" + e.Path + "'";
                return;
            }
            ResPath respath = new ResPath(textBox_recPath.Text);

            // 得到干净的文件名
            string strCfgFileName = e.Path;
            int nRet = strCfgFileName.IndexOf("#");
            if (nRet != -1)
            {
                strCfgFileName = strCfgFileName.Substring(0, nRet);
            }

            string strPath = ResPath.GetDbName(respath.Path) + "/cfgs/" + strCfgFileName;

            // 在cache中寻找
            e.XmlDocument = this.MainForm.DomCache.FindObject(strPath);
            if (e.XmlDocument != null)
                return;

            // 使用Channel

            RmsChannel channelSave = channel;

            channel = Channels.GetChannel(respath.Url);
            Debug.Assert(channel != null, "Channels.GetChannel 异常");

            m_nInGetCfgFile++;

            try
            {
                string strContent;
                string strError;

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在下载文件" + strPath);
                stop.BeginLoop();

                byte[] baTimeStamp = null;
                string strMetaData;
                string strOutputPath;

                long lRet = channel.GetRes(
                    MainForm.cfgCache,
                    strPath,
                    out strContent,
                    out strMetaData,
                    out baTimeStamp,
                    out strOutputPath,
                    out strError);

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

                if (lRet == -1)
                {
                    if (channel.ErrorCode == ChannelErrorCode.NotFound)
                    {
                        e.ErrorInfo = "";
                        return;
                    }


                    e.ErrorInfo = "获得配置文件 '" + strPath + "' 时出错:" + strError;
                    return;
                }


                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strContent);
                }
                catch (Exception ex)
                {
                    e.ErrorInfo = "配置文件 '" + strPath + "' 装入XMLDUM时出错: " + ex.Message;
                    return;
                }
                e.XmlDocument = dom;
                this.MainForm.DomCache.SetObject(strPath, dom);  // 保存到缓存
            }
            finally
            {
                channel = channelSave;

                m_nInGetCfgFile--;
            }
        }
Example #3
0
		// 显示值列表
		public void ShowValueList(
            int nCaretPosition,
            int nLineChars,
            string strCurLine)
		{
			this.Update();

			if (this.nCurLine == -1)
				return;

            if (this.m_nInShowValueList > 0)
            {
                // TODO: 是否Post一个消息出去,稍后再作?
                return;
            }


            this.m_nInShowValueList++;
            try
            {
                string strError = "";

                TemplateLine line = (TemplateLine)this.templateRoot.Lines[this.nCurLine];
                if (line == null)
                {
                    strError = "未找到序号为'" + Convert.ToString(this.nCurLine) + "'行";
                    return;
                }

                int nValueChars = 0;    // 值的字符数

                if (line.ValueListNodes == null
                    || line.ValueListNodes.Count == 0)
                {
                    this.listView_values.Items.Clear();
                    return;
                }

                Cursor oldCursor = this.Cursor;
                this.Cursor = Cursors.WaitCursor;

                if (this.CurValueListNodes != null
                    && this.CurValueListNodes == line.ValueListNodes)
                {
                    if (this.listView_values.Items.Count > 0)
                    {
                        nValueChars = this.listView_values.Items[0].Text.Length;
                        goto SELECT; // 优化
                    }
                }

                this.listView_values.Items.Clear();

                // 解决ref
                while (true)
                {
                    bool bFoundNew = false;
                    for (int i = 0; i < line.ValueListNodes.Count; i++)
                    {
                        XmlNode valuelist_node = line.ValueListNodes[i];
                        string strRef = DomUtil.GetAttr(valuelist_node, "ref");
                        if (string.IsNullOrEmpty(strRef) == true)
                            continue;

                        {
                            if (this.GetConfigDom == null)
                                return;

                            GetConfigDomEventArgs ar = new GetConfigDomEventArgs();
                            ar.Path = strRef;
                            ar.XmlDocument = null;
                            this.GetConfigDom(this, ar);
                            if (string.IsNullOrEmpty(ar.ErrorInfo) == false)
                            {
                                strError = "获取 '" + line.m_strName + "' 对应的ValueList出错,原因:" + ar.ErrorInfo;
                                goto END1;
                            }
                            if (ar.XmlDocument == null)
                                return; // ??

                            string strSource = "";
                            string strValueListName = "";
                            int nIndex = strRef.IndexOf('#');
                            if (nIndex != -1)
                            {
                                strSource = strRef.Substring(0, nIndex);
                                strValueListName = strRef.Substring(nIndex + 1);
                            }
                            else
                            {
                                strValueListName = strRef;
                            }
                            XmlNode valueListNode = ar.XmlDocument.SelectSingleNode("//ValueList[@name='" + strValueListName + "']");
                            if (valueListNode == null)
                            {
                                strError = "未找到路径为'" + strRef + "'的节点。";
                                goto END1;
                            }

                            // 替换
                            line.ValueListNodes[i] = valueListNode;
                            bFoundNew = true;
                        }
                    }

                    if (bFoundNew == false)
                        break;
                }

                this.listView_values.Items.Clear(); // 2006/5/30 add

                foreach (XmlNode valuelist_node in line.ValueListNodes)
                {
                    XmlNodeList itemList = valuelist_node.SelectNodes("Item");
                    foreach (XmlNode itemNode in itemList)
                    {
                        string strItemLable = "";

                        // 从一个元素的下级的多个<strElementName>元素中, 提取语言符合的XmlNode的InnerText
                        // parameters:
                        //      bReturnFirstNode    如果找不到相关语言的,是否返回第一个<strElementName>
                        strItemLable = DomUtil.GetXmlLangedNodeText(
                    this.Lang,
                    itemNode,
                    "Label",
                    true);
                        if (string.IsNullOrEmpty(strItemLable) == true)
                            strItemLable = "<尚未定义>";
                        else
                            strItemLable = StringUtil.Trim(strItemLable);

#if NO
                        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
                        nsmgr.AddNamespace("xml", Ns.xml);
                        XmlNode itemLabelNode = itemNode.SelectSingleNode("Label[@xml:lang='" + this.Lang + "']", nsmgr);
                        if (itemLabelNode == null
                            || string.IsNullOrEmpty(itemLabelNode.InnerText.Trim()) == true)
                        {
                            // 如果找不到,则找到第一个有值的
                            XmlNodeList nodes = itemNode.SelectNodes("Label", nsmgr);
                            foreach (XmlNode temp_node in nodes)
                            {
                                if (string.IsNullOrEmpty(temp_node.InnerText.Trim()) == false)
                                {
                                    itemLabelNode = temp_node;
                                    break;
                                }
                            }
                        }

                        if (itemLabelNode == null)
                            strItemLable = "<尚未定义>";
                        else
                            strItemLable = StringUtil.Trim(itemLabelNode.InnerText);
#endif


                        XmlNode itemValueNode = itemNode.SelectSingleNode("Value");
                        string strItemValue = StringUtil.Trim(itemValueNode.InnerText);

                        if (String.IsNullOrEmpty(strItemValue) == false)
                        {
                            nValueChars = strItemValue.Length;
                        }

                        // 加入listview
                        ListViewItem item = new ListViewItem(strItemValue);
                        item.SubItems.Add(strItemLable);
                        this.listView_values.Items.Add(item);
                    }
                }

                this.CurValueListNodes = line.ValueListNodes;

            SELECT:

                // 加亮当前事项
                if (nValueChars != 0)
                {
                    // 算出当前插入符在第几个单元的值上
                    int nIndex = nCaretPosition / nValueChars;
                    if ((nIndex * nValueChars) + nValueChars <= strCurLine.Length)
                    {

                        string strCurUnit = strCurLine.Substring(nIndex * nValueChars, nValueChars);

                        // 在listview中找到这个值, 并选择它。
                        for (int i = 0; i < this.listView_values.Items.Count; i++)
                        {
                            if (this.listView_values.Items[i].Text.Replace("_", " ") == strCurUnit)
                            {
                                this.CurActiveValueUnit = strCurUnit;

                                this.listView_values.Items[i].Selected = true;
                                // 滚入视线内
                                this.listView_values.EnsureVisible(i);
                            }
                            else
                            {
                                if (this.listView_values.Items[i].Selected != false)
                                    this.listView_values.Items[i].Selected = false;
                            }
                        }
                    }

                }

            END1:
                /////////////////////////////////////
                // 触发EndGetValueList事件
                ///////////////////////////////////////
                EndGetValueListEventArgs argsEnd = new EndGetValueListEventArgs();
                if (strError != "")
                    argsEnd.Ref = strError;
                else
                    argsEnd.Ref = "";
                this.fireEndGetValueList(this, argsEnd);
                this.Cursor = oldCursor;
            }
            finally
            {
                this.m_nInShowValueList--;
            }
		}
Example #4
0
        public void MarcEditor_GetConfigDom(object sender, GetConfigDomEventArgs e)
        {
            // Debug.Assert(false, "");

            // 路径中应该包含 @服务器名

            if (String.IsNullOrEmpty(e.Path) == true)
            {
                e.ErrorInfo = "e.Path 为空,无法获得配置文件";
                goto ERROR1;
            }

            // e.Path 是这样的形态 marcdef:中文图书/1@当前服务器 。冒号后面部分可以缺省,表示未知服务器的记录(没有路径和服务器名)

            string strPath = "";
            string strServerName = "";
            StringUtil.ParseTwoPart(e.Path, "@", out strPath, out strServerName);

            //
            string strPureFileName = "";
            string strBiblioRecPath = "";
            StringUtil.ParseTwoPart(strPath, ":", out strPureFileName, out strBiblioRecPath);

            string strServerType = _base.GetServerType(strServerName);
            if (strServerType == "amazon" || strServerName == "!unknown")
            {
                // TODO: 如何知道 MARC 记录是什么具体的 MARC 格式?
                // 可能需要在服务器信息中增加一个首选的 MARC 格式属性
                string strFileName = Path.Combine(this.MainForm.DataDir, "unimarc_cfgs/" + strPath);

                // 在cache中寻找
                e.XmlDocument = this.MainForm.DomCache.FindObject(strFileName);
                if (e.XmlDocument != null)
                    return;

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.Load(strFileName);
                }
                catch (Exception ex)
                {
                    e.ErrorInfo = "配置文件 '" + strFileName + "' 装入 XMLDOM 时出错: " + ex.Message;
                    goto ERROR1;
                }
                e.XmlDocument = dom;
                this.MainForm.DomCache.SetObject(strFileName, dom);  // 保存到缓存
                return;
            }

            AccountInfo account = _base.GetAccountInfo(strServerName, false);   // false 可以不影响可能正在进行的检索长操作,因为长操作可能要用到 this._base._currentAccount
            if (account == null)
            {
                e.ErrorInfo = "e.Path 中 '" + e.Path + "' 服务器名 '" + strServerName + "' 没有配置";
                goto ERROR1;
            }

            Debug.Assert(strServerType == "dp2library", "");


            // string strBiblioDbName = Global.GetDbName(this._biblio.BiblioRecPath);
            string strBiblioDbName = Global.GetDbName(strBiblioRecPath);

            // 得到干净的文件名
            string strCfgFilePath = strBiblioDbName + "/cfgs/" + strPureFileName;    // e.Path;
            int nRet = strCfgFilePath.IndexOf("#");
            if (nRet != -1)
            {
                strCfgFilePath = strCfgFilePath.Substring(0, nRet);
            }

            // 在cache中寻找
            e.XmlDocument = this.MainForm.DomCache.FindObject(strCfgFilePath);
            if (e.XmlDocument == null)
            {

                // TODO: 可以通过服务器名,得到 url username 等配置参数

                // 下载配置文件
                string strContent = "";
                string strError = "";

                byte[] baCfgOutputTimestamp = null;
                // return:
                //      -1  error
                //      0   not found
                //      1   found
                nRet = GetCfgFileContent(
                    account.ServerUrl,
                    account.UserName,
                    strCfgFilePath,
                    out strContent,
                    out baCfgOutputTimestamp,
                    out strError);
                if (nRet == -1 || nRet == 0)
                {
                    e.ErrorInfo = "获得配置文件 '" + strCfgFilePath + "' 时出错:" + strError;
                    goto ERROR1;
                }
                else
                {
                    XmlDocument dom = new XmlDocument();
                    try
                    {
                        dom.LoadXml(strContent);
                    }
                    catch (Exception ex)
                    {
                        e.ErrorInfo = "配置文件 '" + strCfgFilePath + "' 装入XMLDUM时出错: " + ex.Message;
                        goto ERROR1;
                    }
                    e.XmlDocument = dom;
                    this.MainForm.DomCache.SetObject(strCfgFilePath, dom);  // 保存到缓存
                }
            }

            // 只使用属于数据库的 marcdef 文件中的 MarcSyntax 信息,然后使用安装目录中的 marcdef 配置文件
            {
                string strFileName = "";

                string strMarcSyntax = GetMarcSyntax(e.XmlDocument);
                if (strMarcSyntax == "usmarc")
                    strFileName = Path.Combine(this.MainForm.DataDir, "usmarc_cfgs/" + strPureFileName);
                else
                    strFileName = Path.Combine(this.MainForm.DataDir, "unimarc_cfgs/" + strPureFileName);

                // 在cache中寻找
                e.XmlDocument = this.MainForm.DomCache.FindObject(strFileName);
                if (e.XmlDocument != null)
                    return;

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.Load(strFileName);
                }
                catch (Exception ex)
                {
                    e.ErrorInfo = "配置文件 '" + strFileName + "' 装入 XMLDOM 时出错: " + ex.Message;
                    goto ERROR1;
                }
                e.XmlDocument = dom;
                this.MainForm.DomCache.SetObject(strFileName, dom);  // 保存到缓存
            }
            return;
        ERROR1:
            this.ShowMessage(e.ErrorInfo, "red", true);
        }
Example #5
0
        private void MarcEditor_GetConfigDom(object sender, GetConfigDomEventArgs e)
        {
            int nRet = 0;
            string strError = "";

            if (String.IsNullOrEmpty(this.SavePath) == false)
            {
                string strProtocol = "";
                string strPath = "";

                // 分离出各个部分
                nRet = Global.ParsePath(this.SavePath,
                    out strProtocol,
                    out strPath,
                    out strError);
                if (nRet == -1)
                {
                    strError = "解析路径 '" + this.SavePath + "' 字符串过程中发生错误: " + strError;
                    goto ERROR1;
                }

                if (strProtocol != "dp2library")
                    goto OTHER;

                dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

                if (dp2_searchform == null)
                {
                    strError = "没有连接的或者打开的dp2检索窗,无法获取配置文件";
                    goto ERROR1;
                }

                string strServerName = "";
                string strLocalPath = "";

                // 解析记录路径。
                // 记录路径为如下形态 "中文图书/1 @服务器"
                dp2SearchForm.ParseRecPath(strPath,
                    out strServerName,
                    out strLocalPath);

                if (string.Compare(strServerName, "mem", true) == 0
                || string.Compare(strServerName, "file", true) == 0)
                    goto OTHER;

                string strBiblioDbName = dp2SearchForm.GetDbName(strLocalPath);

                string strSyntax = "";
                // 获得一个数据库的数据syntax
                // parameters:
                //      stop    如果!=null,表示使用这个stop,它已经OnStop +=
                //              如果==null,表示会自动使用this.stop,并自动OnStop+=
                // return:
                //      -1  error
                //      0   not found
                //      1   found
                nRet = dp2_searchform.GetDbSyntax(
                    null,
                    strServerName,
                    strBiblioDbName,
                    out strSyntax,
                    out strError);
                if (nRet == -1)
                {
                    strError = "获取书目库 '" + strBiblioDbName + "的数据格式时发生错误: " + strError;
                    goto ERROR1;
                }

                /*
                string strDefFilename = "";

                if (strSyntax == "unimarc"
                    || strSyntax == "usmarc")
                    strDefFilename = "marcdef";
                else
                {
                    strError = "所选书目库 '" + strBiblioDbName + "' 不是MARC格式的数据库";
                    goto ERROR1;
                }*/

                // 得到干净的文件名
                string strCfgFileName = e.Path;
                nRet = strCfgFileName.IndexOf("#");
                if (nRet != -1)
                {
                    strCfgFileName = strCfgFileName.Substring(0, nRet);
                }

                // 然后获得cfgs/template配置文件
                string strCfgFilePath = strBiblioDbName + "/cfgs/" + strCfgFileName + "@" + strServerName;

                e.XmlDocument = this.MainForm.DomCache.FindObject(strCfgFilePath);
                if (e.XmlDocument != null)
                    return;

                string strCode = "";
                byte[] baCfgOutputTimestamp = null;
                nRet = dp2_searchform.GetCfgFile(
                    true,
                    strCfgFilePath,
                    out strCode,
                    out baCfgOutputTimestamp,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strCode);
                }
                catch (Exception ex)
                {
                    e.ErrorInfo = "装载配置文件 '"+strCfgFilePath+"' 到 XMLDOM 的过程中出现错误: " + ex.Message;
                    return;
                }
                e.XmlDocument = dom;
                this.MainForm.DomCache.SetObject(strCfgFilePath, dom);
                return;
            }

        OTHER:
            {
                string strCfgFileName = e.Path;
                nRet = strCfgFileName.IndexOf("#");
                if (nRet != -1)
                {
                    strCfgFileName = strCfgFileName.Substring(0, nRet);
                }


                string strMarcSyntaxOID = "";

                strMarcSyntaxOID = this.GetCurrentMarcSyntaxOID(out strError);
                if (String.IsNullOrEmpty(strMarcSyntaxOID) == true)
                {
                    e.ErrorInfo = "因为: " + strError + ",无法获得配置文件 '" + strCfgFileName + "'";
                    return;
                }


                string strPath = this.MainForm.DataDir + "\\" + strMarcSyntaxOID.Replace(".", "_") + "\\" + strCfgFileName;

                e.XmlDocument = this.MainForm.DomCache.FindObject(strPath);
                if (e.XmlDocument != null)
                    return;

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.Load(strPath);
                }
                catch (Exception ex)
                {
                    e.ErrorInfo = "装载配置文件 '" + strPath + "' 到 XMLDOM 的过程中出现错误: " + ex.Message;
                    return;
                }
                e.XmlDocument = dom;
                this.MainForm.DomCache.SetObject(strPath, dom);
            }

            return;
        ERROR1:
            e.ErrorInfo = strError;
        }
Example #6
0
        private void easyMarcControl1_GetConfigDom(object sender, GetConfigDomEventArgs e)
        {
            // if (GetConfigDom != null)
            {
                if (string.IsNullOrEmpty(this._biblio.BiblioRecPath) == true
                    && string.IsNullOrEmpty(this._biblio.ServerName) == true)
                {
                    // e.Path = e.Path + "@!unknown";
                    e.Path = e.Path;
                }
                else
                {
                    // e.Path = Global.GetDbName(this.BiblioRecPath) + "/cfgs/" + e.Path + "@" + this.ServerName;
                    e.Path = e.Path + ":" + this._biblio.BiblioRecPath + "@" + this._biblio.ServerName;
                }

                // GetConfigDom(this, e);
                MarcEditor_GetConfigDom(sender, e);
            }
        }
Example #7
0
        public void MarcEditor_GetConfigDom(object sender, GetConfigDomEventArgs e)
        {
            // Debug.Assert(false, "");

            // 路径中应该包含 @服务器名

            if (String.IsNullOrEmpty(e.Path) == true)
            {
                e.ErrorInfo = "e.Path 为空,无法获得配置文件";
                goto ERROR1;
            }

            string strPath = "";
            string strServerName = "";
            StringUtil.ParseTwoPart(e.Path, "@", out strPath, out strServerName);

            string strServerType = _base.GetServerType(strServerName);
            if (strServerType == "amazon" || strServerName == "!unknown")
            {
                // TODO: 如何知道 MARC 记录是什么具体的 MARC 格式?
                // 可能需要在服务器信息中增加一个首选的 MARC 格式属性
                string strFileName = Path.Combine(this.MainForm.DataDir, "unimarc_cfgs/" + strPath);

                // 在cache中寻找
                e.XmlDocument = this.MainForm.DomCache.FindObject(strFileName);
                if (e.XmlDocument != null)
                    return;

                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.Load(strFileName);
                }
                catch (Exception ex)
                {
                    e.ErrorInfo = "配置文件 '" + strFileName + "' 装入 XMLDOM 时出错: " + ex.Message;
                    goto ERROR1;
                }
                e.XmlDocument = dom;
                this.MainForm.DomCache.SetObject(strFileName, dom);  // 保存到缓存
                return;
            }

            AccountInfo account = _base.GetAccountInfo(strServerName);
            if (account == null)
            {
                e.ErrorInfo = "e.Path 中 '"+e.Path+"' 服务器名 '"+strServerName+"' 没有配置";
                goto ERROR1;
            }

            Debug.Assert(strServerType == "dp2library", "");

            BiblioRegisterControl control = sender as BiblioRegisterControl;
            string strBiblioDbName = Global.GetDbName(control.BiblioRecPath);

            // 得到干净的文件名
            string strCfgFilePath = strBiblioDbName + "/cfgs/" + strPath;    // e.Path;
            int nRet = strCfgFilePath.IndexOf("#");
            if (nRet != -1)
            {
                strCfgFilePath = strCfgFilePath.Substring(0, nRet);
            }

            // 在cache中寻找
            e.XmlDocument = this.MainForm.DomCache.FindObject(strCfgFilePath);
            if (e.XmlDocument != null)
                return;

            // TODO: 可以通过服务器名,得到 url username 等配置参数

            // 下载配置文件
            string strContent = "";
            string strError = "";

            byte[] baCfgOutputTimestamp = null;
            // return:
            //      -1  error
            //      0   not found
            //      1   found
            nRet = GetCfgFileContent(
                account.ServerUrl,
                account.UserName,
                strCfgFilePath,
                out strContent,
                out baCfgOutputTimestamp,
                out strError);
            if (nRet == -1 || nRet == 0)
            {
                e.ErrorInfo = "获得配置文件 '" + strCfgFilePath + "' 时出错:" + strError;
                goto ERROR1;
            }
            else
            {
                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(strContent);
                }
                catch (Exception ex)
                {
                    e.ErrorInfo = "配置文件 '" + strCfgFilePath + "' 装入XMLDUM时出错: " + ex.Message;
                    goto ERROR1;
                }
                e.XmlDocument = dom;
                this.MainForm.DomCache.SetObject(strCfgFilePath, dom);  // 保存到缓存
            }

            return;
        ERROR1:
            this.DisplayFloatErrorText(e.ErrorInfo, "");
        }
Example #8
0
 void _biblioRegister_GetConfigDom(object sender, GetConfigDomEventArgs e)
 {
     (this.Container as EntityRegisterControl).MarcEditor_GetConfigDom(sender, e);
 }
Example #9
0
        /*
            <Field name='801'>
                <Property>
                    <Label xml:lang='en'>Originating Source</Label>
                    <Label xml:lang='cn'>记录来源</Label>
                </Property>
                <Subfield name='a'>
                    <Property>
                        <Label xml:lang='en'></Label>
                        <Label xml:lang='cn'>国家代码</Label>
                        <ValueList ref='countrycode' />
                    </Property>
                </Subfield>
        */
        // return:
        //		-1	出错
        //		0	未找到对应的ValueList
        //		1	找到
        /*public*/ int GetValueListNodes(string strFieldName,
            string strSubfieldName,
            out List<XmlNode> valueListNodes,
            out string strError)
        {
            valueListNodes = new List<XmlNode>();
            strError = "";

            if (this.MarcDefDom == null)
                return 0;


            string strXPath = "Field[@name='" + strFieldName + "']/Subfield[@name='" + strSubfieldName + "']/Property/ValueList";
            XmlNodeList nodes = this.MarcDefDom.DocumentElement.SelectNodes(strXPath);
            if (nodes.Count == 0)
                return 0;

            foreach (XmlNode node in nodes)
            {
                valueListNodes.Add(node);
            }

            while (true)
            {
                bool bFoundRef = false;

                for(int i=0;i<valueListNodes.Count ; i++)
                {
                    XmlNode node = valueListNodes[i];
                    //找ref
                    string strRef = DomUtil.GetAttr(node, "ref");
                    if (string.IsNullOrEmpty(strRef) == true)
                        continue;

                    bFoundRef = true;

                    // 未挂接事件
                    if (this.GetConfigDom == null)
                        return 0;

                    GetConfigDomEventArgs e = new GetConfigDomEventArgs();
                    e.Path = strRef;
                    e.XmlDocument = null;

                    this.GetConfigDom(this, e);
                    if (e.ErrorInfo != "")
                    {
                        strError = "获取'" + strFieldName + "$" + strSubfieldName + "'对应的ValueList出错,原因:" + e.ErrorInfo;
                        return -1;
                    }
                    if (e.XmlDocument == null)
                        return 0;

                    int nIndex = strRef.IndexOf('#');
                    string strSource = "";
                    string strValueListName = "";
                    if (nIndex != -1)
                    {
                        strSource = strRef.Substring(0, nIndex);
                        strValueListName = strRef.Substring(nIndex + 1);
                    }
                    else
                    {
                        strValueListName = strRef;
                    }

                    // 把原有的node从数组中删除
                    valueListNodes.Remove(node);
                    i--;

                    XmlNode node_valuelist = e.XmlDocument.SelectSingleNode("//ValueList[@name='" + strValueListName + "']");
                    if (node_valuelist == null)
                    {
                        strError = "未找到路径为'" + strRef + "'的节点。";
                        return -1;
                    }
                    valueListNodes.Add(node_valuelist);
                }

                if (bFoundRef == false)
                    break;
            }
            return 1;
        }
Example #10
0
        private void easyMarcControl1_GetConfigDom(object sender, GetConfigDomEventArgs e)
        {

            string strFileName = Path.Combine(this.MainForm.DataDir, "marcdef");
                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.Load(strFileName);
                }
                catch (Exception ex)
                {
                    e.ErrorInfo = "配置文件 '" + strFileName + "' 装入XMLDUM时出错: " + ex.Message;
                    return;
                }
                e.XmlDocument = dom;
        }