Пример #1
0
        private void resTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            if (resTree.SelectedNode == null)
            {
                return;
            }

            if (EnabledIndices != null &&
                StringUtil.IsInList(resTree.SelectedNode.ImageIndex, EnabledIndices) == false)
            {
                textBox_resPath.Text = "";
                return;
            }

            /*
             * if (resTree.SelectedNode.ImageIndex != ResTree.RESTYPE_DB)
             * {
             *      textBox_resPath.Text = "";
             *      return;
             * }
             */

            ResPath respath = new ResPath(resTree.SelectedNode);

            textBox_resPath.Text = respath.FullPath;
        }
Пример #2
0
        public int ExportOneRecord(
            RmsChannel channel,
            DigitalPlatform.Stop stop,
            string strServerUrl,
            string strRecPath,
            string strXmlBody,
            string strMetadata,
            byte[] baTimestamp,
            out string strError)
        {
            strError = "";

            if (this.FileType == ExportFileType.XmlFile)
            {
                XmlDocument dom = new XmlDocument();

                try
                {
                    dom.LoadXml(strXmlBody);

                    ResPath respathtemp = new ResPath();
                    respathtemp.Url  = strServerUrl;
                    respathtemp.Path = strRecPath;

                    // DomUtil.SetAttr(dom.DocumentElement, "xmlns:dprms", DpNs.dprms);
                    // 给根元素设置几个参数
                    DomUtil.SetAttr(dom.DocumentElement, "path", DpNs.dprms, respathtemp.FullPath);
                    DomUtil.SetAttr(dom.DocumentElement, "timestamp", DpNs.dprms, ByteArray.GetHexTimeStampString(baTimestamp));

                    // DomUtil.SetAttr(dom.DocumentElement, "xmlns:marc", null);
                    dom.DocumentElement.WriteTo(writer);
                }
                catch (Exception ex)
                {
                    strError = ExceptionUtil.GetAutoText(ex);
                    return(-1);
                }
            }

            if (this.FileType == ExportFileType.BackupFile)
            {
                Debug.Assert(channel != null, "");
                // 将主记录和相关资源写入备份文件
                int nRet = WriteRecordToBackupFile(
                    this.m_owner,
                    channel,
                    stop,
                    this.outputfile,
                    strRecPath, // 记录路径
                    strMetadata,
                    strXmlBody,
                    baTimestamp,
                    out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
            }
            return(0);
        }
Пример #3
0
 public ResPath Clone()
 {
     ResPath newobj = new ResPath();
     newobj.Url = this.Url;
     newobj.Path = this.Path;
     return newobj;
 }
Пример #4
0
        // 获得当前选择的若干记录路径
        public static string[] GetSelectedRecordPaths(
            ListView listview,
            bool bIncludeFocuedItem)
        {
            int nDelta = 0;

            if (bIncludeFocuedItem == true)
            {
                if (listview.FocusedItem != null)
                {
                    nDelta = 1;
                }
            }
            string [] paths = new string [listview.SelectedItems.Count + nDelta];


            for (int i = 0; i < listview.SelectedItems.Count; i++)
            {
                paths[i] = ResPath.GetRegularRecordPath(listview.SelectedItems[i].Text);
            }

            if (nDelta == 1)
            {
                paths[paths.Length - 1]       = ResPath.GetRegularRecordPath(listview.FocusedItem.Text);
                listview.FocusedItem.Selected = true;
            }

            return(paths);
        }
Пример #5
0
        public ResPath Clone()
        {
            ResPath newobj = new ResPath();

            newobj.Url  = this.Url;
            newobj.Path = this.Path;
            return(newobj);
        }
Пример #6
0
        // 2017/3/8
        // 判断路径最后一级是否为问号或者空,也就是追加的方式
        public static bool IsAppendRecPath(string strBiblioRecPath)
        {
            if (string.IsNullOrEmpty(strBiblioRecPath))
            {
                return(false);
            }
            string strTargetRecId = ResPath.GetRecordId(strBiblioRecPath);

            if (strTargetRecId == "?" || String.IsNullOrEmpty(strTargetRecId) == true)
            {
                return(true);
            }
            return(false);
        }
Пример #7
0
        // 当前服务器内直接对应
        private void button_directSingleServerMap_Click(object sender, EventArgs e)
        {
            if (this.textBox_origin.Text.IndexOf("?") == -1)
            {
                MessageBox.Show("无法设置对应");
                return;
            }

            ResPath respath = new ResPath(this.textBox_origin.Text);

            this.textBox_origin.Text       = respath.Url + "?*";
            this.textBox_origin.Enabled    = true;
            this.button_findOrigin.Enabled = true;

            this.textBox_target.Text       = respath.Url + "?*";
            this.textBox_target.Enabled    = true;
            this.button_findTarget.Enabled = true;
        }
Пример #8
0
        private void resTree_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            if (resTree.CheckBoxes != true)
            {
                return;
            }


            TreeNode[] nodes = TreeViewUtil.GetCheckedNodes(this.resTree);

            if (nodes.Length == 0)
            {
                textBox_resPath.Text = "";
                return;
            }

            textBox_resPath.Text = "";

            for (int i = 0; i < nodes.Length; i++)
            {
                if (EnabledIndices != null &&
                    StringUtil.IsInList(nodes[i].ImageIndex, EnabledIndices) == false)
                {
                    continue;
                }

                /*
                 * if (nodes[i].ImageIndex != ResTree.RESTYPE_DB)
                 *      continue;
                 */

                if (textBox_resPath.Text != "")
                {
                    textBox_resPath.Text += ";";
                }

                ResPath respath = new ResPath(nodes[i]);
                textBox_resPath.Text += respath.FullPath;
            }
        }
Пример #9
0
        // 2017/3/8
        // 规范追加形态的路径为 "中文图书/?"
        public static bool CannoicalizeAppendRecPath(ref string strBiblioRecPath)
        {
            if (string.IsNullOrEmpty(strBiblioRecPath))
            {
                return(false);
            }

            string strTargetRecId = ResPath.GetRecordId(strBiblioRecPath);

            if (strTargetRecId == "?")
            {
                return(false);
            }

            if (String.IsNullOrEmpty(strTargetRecId) == true)
            {
                strBiblioRecPath = ResPath.GetDbName(strBiblioRecPath) + "/?";
                return(true);
            }

            return(false);
        }
Пример #10
0
		private void menuItem_databaseManagement_Click(object sender, System.EventArgs e)
		{
			if (treeView_res.SelectedNode == null)
			{
				MessageBox.Show("请选择一个数据库节点");
				return;
			}

			ResPath respath = new ResPath(treeView_res.SelectedNode);
			if (respath.Path == "")
			{
				MessageBox.Show("请选择一个数据库类型的节点");
				return;
			}
			string strPath = respath.Path;
			string strDbName = StringUtil.GetFirstPartPath(ref strPath);
			if (strDbName == "")
			{
				MessageBox.Show("错误: 数据库名为空");
				return;
			}

			DatabaseDlg dlg = new DatabaseDlg();
            MainForm.SetControlFont(dlg, this.DefaultFont);
            dlg.StartPosition = FormStartPosition.CenterScreen;
			dlg.MainForm = this;
			dlg.Initial(respath.Url, 
                strDbName);

			this.AppInfo.LinkFormState(dlg, "databasedlg_state");
			dlg.ShowDialog(this);
			this.AppInfo.UnlinkFormState(dlg);
		}
Пример #11
0
		private void treeView_res_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			if (treeView_res.SelectedNode == null)
			{
                this.toolStripStatusLabel_main.Text = "尚未选择一个节点";
				return;
			}

			ResPath respath = new ResPath(treeView_res.SelectedNode);

            this.toolStripStatusLabel_main.Text = "当前节点: " + respath.FullPath;
		
		}
Пример #12
0
        private void OpenResDlg_Load(object sender, System.EventArgs e)
        {
            if (ap != null)
            {
                if (ApCfgTitle != "" && ApCfgTitle != null)
                {
                    ap.LoadFormStates(this,
                                      ApCfgTitle);
                }
                else
                {
                    Debug.Assert(true, "若要用ap保存和恢复窗口外观状态,必须先设置ApCfgTitle成员");
                }
            }

            if (this.resTree.Servers != null)
            {
                this.resTree.Servers.ServerChanged += new ServerChangedEventHandle(Servers_ServerChanged);
            }
            // resTree.EnabledIndices = new int[] { ResTree.RESTYPE_DB };

            // 填充内容
            resTree.Fill(null);

            if (MultiSelect == true)
            {
                resTree.CheckBoxes = true;                      // 允许复选
            }

            if (this.Path != "")
            {
                ResPath respath = new ResPath(this.Path);

                // 展开到指定的节点
                if (resTree.ExpandPath(respath) == true &&
                    resTree.SelectedNode != null &&
                    EnabledIndices != null)
                {
                    // 2013/2/15
                    // 如果下一级是全部灰色的节点,则不要展开它们
                    bool bFound = false;
                    foreach (TreeNode child in resTree.SelectedNode.Nodes)
                    {
                        if (StringUtil.IsInList(child.ImageIndex, EnabledIndices) == true)
                        {
                            bFound = true;
                        }
                    }

                    if (bFound == false)
                    {
                        resTree.SelectedNode.Collapse();
                    }
                }
            }



            if (this.Paths != "")
            {
                resTree.CheckBoxes = true;                      // 允许复选

                string[] aPath = this.Paths.Split(new char[] { ';' });

                for (int i = 0; i < aPath.Length; i++)
                {
                    if (aPath[i].Trim() == "")
                    {
                        continue;
                    }

                    ResPath respath = new ResPath(aPath[i].Trim());

                    // 展开到指定的节点
                    resTree.ExpandPath(respath);

                    bool bRet = this.resTree.CheckNode(respath,
                                                       true);
                }
            }
        }
Пример #13
0
		public int DownloadFilesToLocalDir(out string strError)
		{
			strError = "";

			// 列出所有文件
						
			Debug.Assert(this.Container != null, "");

			m_nDownloading ++;

			try 
			{

				ResPath respath = new ResPath(this.ServerPath);

                RmsChannel channel = this.Container.Channels.GetChannel(respath.Url);

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

				string [] items = null;
			
				long lRet = channel.DoDir(respath.Path,
					"zh",
                    null,   // 不需要返回所有语言的名字
					ResTree.RESTYPE_FILE,
					out items,
					out strError);
				if (lRet == -1)
					return -1;

				this.Names = items;
				Container.Changed = true;

				for(int i=0;i<items.Length;i++)
				{
					string strName = items[i];

					string strServerPath = respath.Path + "/" + strName;

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

					// string strStyle = "attachment,data,timestamp,outputpath";

					string strLocalFileName = this.LocalPath + "/" + strName;

					lRet = channel.GetRes(
						strServerPath,
						strLocalFileName,
						null,	// stop
						out strMetaData,
						out baTimeStamp,
						out strOutputPath,
						out strError);
					if (lRet == -1)
						return -1;


				}


				return 0;
			}
			finally 
			{
				m_nDownloading --;
			}
		}
Пример #14
0
		// 保存记录
		// parameters:
		//		strRecordPath	记录路径。如果==null,表示直接用textBox_recPath中当前的内容作为路径
		public void SaveRecord(string strRecordPath)
		{
			if (strRecordPath != null)
				textBox_recPath.Text = strRecordPath;

			if (textBox_recPath.Text == "")
			{
				MessageBox.Show(this, "路径不能为空");
				return;
			}

			ResPath respath = new ResPath(textBox_recPath.Text);

			Uri uri = null;
			try 
			{
				uri = new Uri(respath.Url);
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, "路径错误: " + ex.Message);
				return;
			}
			// 保存到文件
			if (uri.IsFile)
			{
				MessageBox.Show(this, "暂时不支持保存到文件");
				return;
			}


			string strError;

			string strXml = "";
            bool bHasUploadedFile = false;

			int nRet = GetXmlRecord(out strXml,
                out bHasUploadedFile,
                out strError);
			if (nRet == -1)
			{
				MessageBox.Show(this, strError);
				return;
			}


			byte [] baOutputTimeStamp = null;
			string strOutputPath = "";
			long lRet = 0;

            int nUploadCount = 0;

			// 使用Channel
			RmsChannel channelSave = channel;

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

			try 
			{

                stop.OnStop += new StopEventHandler(this.DoStop);
				stop.Initial("正在保存记录 " + respath.FullPath);
				stop.BeginLoop();


				EnableControlsInLoading(true);

				//string strTemp = ByteArray.GetHexTimeStampString(this.TimeStamp);

                if (String.IsNullOrEmpty(this.strDatabaseOriginPath) == false
                    && bHasUploadedFile == true
                    && respath.FullPath != this.strDatabaseOriginPath)
                {
                    ResPath respath_old = new ResPath(this.strDatabaseOriginPath);

                    if (respath_old.Url != respath.Url)
                    {
                        MessageBox.Show(this, "目前暂不支持跨服务器情况下的资源复制。本记录中原有的已上载资源,在另存到目标库的时丢失(为空),请注意保存完后手动上载。");
                        goto SKIPCOPYRECORD;
                    }
                    // 复制记录
                    // return:
                    //		-1	出错。错误信息在strError中
                    //		0或者其他		成功
                    nRet = channel.DoCopyRecord(respath_old.Path,
                        respath.Path,
                        false,  // bool bDeleteOriginRecord,
                        out baOutputTimeStamp,
                        out strOutputPath,
                        out strError);
                    if (nRet == -1)
                    {
                        MessageBox.Show(this, "复制资源时发生错误: " + strError);
                    }
                    else
                    {
                        // 为继续保存最新XML记录作准备
                        respath.Path = strOutputPath;   // ?形式路径其实已经确定
                        this.TimeStamp = baOutputTimeStamp;
                    }
                }
                SKIPCOPYRECORD:

				lRet = channel.DoSaveTextRes(respath.Path,
					strXml,
					false,	// bInlucdePreamble
					"",	// style
					this.TimeStamp,
					out baOutputTimeStamp,
					out strOutputPath,
					out strError);


				EnableControlsInLoading(false);

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


				if (lRet == -1) 
				{
					MessageBox.Show(this, "保存记录失败,原因: "+strError);
					return;
                }

                //


                this.TimeStamp = baOutputTimeStamp;
                respath.Path = strOutputPath;
                textBox_recPath.Text = respath.FullPath;

                ////
                this.strDatabaseOriginPath = respath.Url + "?" + strOutputPath; // 保存从数据库中来的原始path

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在保存资源 " + respath.FullPath);
                stop.BeginLoop();

                EnableControlsInLoading(true);
                Debug.Assert(channel != null, "");
                // 保存对象资源,循环对象列表就可以了
                nUploadCount = this.listView_resFiles.DoUpload(
                    respath.Path,
                    channel,
                    stop,
                    out strError);
                EnableControlsInLoading(false);

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

            }
            finally
            {
                channel = channelSave;
            }

			if (nUploadCount == -1) 
			{
				MessageBox.Show(this, "XML记录保存成功, 但保存资源失败,原因: "+strError);
				return;
			}

			if (nUploadCount > 0)
			{
				// 使用Channel
				channelSave = channel;

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


				// 需要重新获得时间戳
				string strStyle = "timestamp,metadata";	// withresmetadata
				string strMetaData = "";
				string strContent = "";

				try 
				{
					lRet = channel.GetRes(respath.Path,
						strStyle,
						out strContent,
						out strMetaData,
						out baOutputTimeStamp,
						out strOutputPath,
						out strError);
					if (lRet == -1)
					{
						MessageBox.Show(this, "重新获得时间戳 '" + respath.FullPath + "' 失败。原因 : " + strError);
						return;
					}
				}
				finally 
				{
					channel = channelSave;
				}
				this.TimeStamp = baOutputTimeStamp;	// 设置时间戳很重要。即便xml不合法,也应设置好时间戳,否则窗口无法进行正常删除。
				this.m_strMetaData = strMetaData;	// 记忆XML记录的元数据



			}

			this.Changed = false;

			MessageBox.Show(this, "保存记录 '" + respath.FullPath + "' 成功。");
		}
Пример #15
0
        // 下载资源,保存到备份文件
        static int WriteResToBackupFile(
            IWin32Window owner,
            RmsChannel channel,
            DigitalPlatform.Stop stop,
            Stream outputfile,
            string strXmlRecPath,
            string[] res_ids,
            out string strError)
        {
            strError = "";

            long lRet;

            for (int i = 0; i < res_ids.Length; i++)
            {
                if (owner != null)
                {
                    Application.DoEvents();     // 出让界面控制权
                }
                if (stop != null && stop.State != 0)
                {
                    if (owner != null)
                    {
                        DialogResult result = MessageBox.Show(owner,
                                                              "确实要中断当前批处理操作?",
                                                              "导出数据",
                                                              MessageBoxButtons.YesNo,
                                                              MessageBoxIcon.Question,
                                                              MessageBoxDefaultButton.Button2);
                        if (result == DialogResult.Yes)
                        {
                            strError = "用户中断";
                            return(-1);
                        }
                        else
                        {
                            stop.Continue();
                        }
                    }
                    else
                    {
                        strError = "用户中断";
                        return(-1);
                    }
                }

                string strID = res_ids[i].Trim();

                if (string.IsNullOrEmpty(strID))
                {
                    continue;
                }

                string strResPath = strXmlRecPath + "/object/" + strID;

                string strMetaData;

                if (stop != null)
                {
                    stop.SetMessage("正在下载 " + strResPath);
                }

                byte[] baOutputTimeStamp = null;
                string strOutputPath;

REDO_GETRES:
                lRet = channel.GetRes(strResPath,
                                      (Stream)null, // 故意不获取资源体
                                      stop,
                                      "metadata,timestamp,outputpath",
                                      null,
                                      out strMetaData, // 但是要获得metadata
                                      out baOutputTimeStamp,
                                      out strOutputPath,
                                      out strError);
                if (lRet == -1)
                {
                    if (channel.OriginErrorCode == rmsws_localhost.ErrorCodeValue.NotFoundObjectFile)
                    {
                        continue;   // TODO: 返回警告信息
                    }
                    if (owner != null)
                    {
                        // TODO: 允许重试
                        DialogResult redo_result = MessageBox.Show(owner,
                                                                   "获取记录 '" + strResPath + "' 时出现错误: " + strError + "\r\n\r\n重试,还是中断当前批处理操作?\r\n(Retry 重试;Cancel 中断批处理)",
                                                                   "导出数据",
                                                                   MessageBoxButtons.RetryCancel,
                                                                   MessageBoxIcon.Question,
                                                                   MessageBoxDefaultButton.Button1);
                        if (redo_result == DialogResult.Cancel)
                        {
                            return(-1);
                        }
                        goto
                        REDO_GETRES;
                    }
                    else
                    {
                        return(-1);
                    }
                }

                long lResStart = 0;
                // 写res的头。
                // 如果不能预先确知整个res的长度,可以用随便一个lTotalLength值调用本函数,
                // 但是需要记忆下函数所返回的lStart,最后调用EndWriteResToBackupFile()。
                // 如果能预先确知整个res的长度,则最后不必调用EndWriteResToBackupFile()
                long lRet0 = Backup.BeginWriteResToBackupFile(
                    outputfile,
                    0,  // 未知
                    out lResStart);

                byte[] timestamp = baOutputTimeStamp;

                ResPath respath = new ResPath();
                respath.Url  = channel.Url;
                respath.Path = strOutputPath;   // strResPath;

                // strMetaData还要加入资源id?
                StringUtil.ChangeMetaData(ref strMetaData,
                                          strID,
                                          null,
                                          null,
                                          null,
                                          respath.FullPath,
                                          ByteArray.GetHexTimeStampString(baOutputTimeStamp));

                lRet = Backup.WriteResMetadataToBackupFile(outputfile,
                                                           strMetaData);
                if (lRet == -1)
                {
                    return(-1);
                }

                long lBodyStart = 0;
                // 写res body的头。
                // 如果不能预先确知body的长度,可以用随便一个lBodyLength值调用本函数,
                // 但是需要记忆下函数所返回的lBodyStart,最后调用EndWriteResBodyToBackupFile()。
                // 如果能预先确知body的长度,则最后不必调用EndWriteResBodyToBackupFile()
                lRet = Backup.BeginWriteResBodyToBackupFile(
                    outputfile,
                    0, // 未知
                    out lBodyStart);
                if (lRet == -1)
                {
                    return(-1);
                }

                if (stop != null)
                {
                    stop.SetMessage("正在下载 " + strResPath + " 的数据体");
                }

REDO_GETRES_1:
                lRet = channel.GetRes(strResPath,
                                      outputfile,
                                      stop,
                                      "content,data,timestamp", //"content,data,timestamp"
                                      timestamp,
                                      out strMetaData,
                                      out baOutputTimeStamp,
                                      out strOutputPath,
                                      out strError);
                if (lRet == -1)
                {
                    if (channel.ErrorCode == ChannelErrorCode.EmptyRecord ||
                        channel.ErrorCode == ChannelErrorCode.NotFoundObjectFile)       // 2017/7/13
                    {
                        // 空记录
                    }
                    else
                    {
                        if (owner != null)
                        {
                            // TODO: 允许重试
                            DialogResult redo_result = MessageBox.Show(owner,
                                                                       "获取记录 '" + strResPath + "' 时出现错误: " + strError + "\r\n\r\n重试,还是中断当前批处理操作?\r\n(Retry 重试;Cancel 中断批处理)",
                                                                       "导出数据",
                                                                       MessageBoxButtons.RetryCancel,
                                                                       MessageBoxIcon.Question,
                                                                       MessageBoxDefaultButton.Button1);
                            if (redo_result == DialogResult.Cancel)
                            {
                                return(-1);
                            }
                            goto
                            REDO_GETRES_1;
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                }

                long lBodyLength = outputfile.Position - lBodyStart - 8;
                // res body收尾
                lRet = Backup.EndWriteResBodyToBackupFile(
                    outputfile,
                    lBodyLength,
                    lBodyStart);
                if (lRet == -1)
                {
                    return(-1);
                }

                long lTotalLength = outputfile.Position - lResStart - 8;
                lRet = Backup.EndWriteResToBackupFile(
                    outputfile,
                    lTotalLength,
                    lResStart);
                if (lRet == -1)
                {
                    return(-1);
                }
            }

            return(0);
        }
Пример #16
0
        // 将主记录和相关资源写入备份文件
        // 本函数如果失败,会自动把本次写入的局部内容从文件末尾抹去
        // TODO: 测试磁盘空间耗尽的情况
        // return:
        //      -1  出错
        //      0   因 strXmlBody 为空,忽略此记录,并没有导出任何内容
        //      1   导出了内容
        static int WriteRecordToBackupFile(
            IWin32Window owner,
            RmsChannel channel,
            DigitalPlatform.Stop stop,
            Stream outputfile,
            string strPath, // 记录路径
            string strMetaData,
            string strXmlBody,
            byte[] body_timestamp,
            out string strError)
        {
            strError = "";

            if (string.IsNullOrEmpty(strXmlBody))
            {
                strError = "strXmlBody 为空,忽略此记录";
                return(0);
            }

            Debug.Assert(String.IsNullOrEmpty(strXmlBody) == false, "strXmlBody不能为空");

            Debug.Assert(channel != null, "");
            // string strPath = strDbName + "/" + strID;

            long lStart = outputfile.Position;  // 记忆起始位置
            bool bDone  = false;

            try
            {
                byte[] length = new byte[8];

                outputfile.LockingWrite(length, 0, 8);  // 临时写点数据,占据记录总长度位置

                ResPath respath = new ResPath();
                respath.Url  = channel.Url;
                respath.Path = strPath;

                // 加工元数据
                StringUtil.ChangeMetaData(ref strMetaData,
                                          null,
                                          null,
                                          null,
                                          null,
                                          respath.FullPath,
                                          ByteArray.GetHexTimeStampString(body_timestamp)); // 2005/6/11

                // 向backup文件中保存第一个 res
                long lRet = Backup.WriteFirstResToBackupFile(
                    outputfile,
                    strMetaData,
                    strXmlBody);

                // 其余
                string[] ids = null;

                // 得到Xml记录中所有<file>元素的id属性值
                int nRet = GetFileIds(strXmlBody,
                                      out ids,
                                      out strError);
                if (nRet == -1)
                {
                    // outputfile.SetLength(lStart);	// 把本次追加写入的全部去掉
                    strError = "GetFileIds()出错,无法获得 XML 记录 (" + strPath + ") 中的 <dprms:file>元素的 id 属性, 因此保存记录失败,原因: " + strError;
                    goto ERROR1;
                }

                nRet = WriteResToBackupFile(
                    owner,
                    channel,
                    stop,
                    outputfile,
                    respath.Path,
                    ids,
                    out strError);
                if (nRet == -1)
                {
                    // outputfile.SetLength(lStart);	// 把本次追加写入的全部去掉
                    strError = "WriteResToBackupFile()出错,因此保存记录 (" + strPath + ") 失败,原因: " + strError;
                    goto ERROR1;
                }

                ///


                // 写入总长度
                long   lTotalLength = outputfile.Position - lStart - 8;
                byte[] data         = BitConverter.GetBytes(lTotalLength);

                // 返回记录最开头位置
                outputfile.Seek(lStart - outputfile.Position, SeekOrigin.Current);
                Debug.Assert(outputfile.Position == lStart, "");

                // outputfile.Seek(lStart, SeekOrigin.Begin);   // 文件大了以后这句话的性能会很差
                outputfile.LockingWrite(data, 0, 8);

                // 跳到记录末尾位置
                outputfile.Seek(lTotalLength, SeekOrigin.Current);
                bDone = true;
            }
            finally
            {
                if (bDone == false)
                {
                    outputfile.SetLength(lStart);       // 把本次追加写入的全部去掉
                    outputfile.Seek(0, SeekOrigin.End); // 把文件指针恢复到文件末尾位置,便于下次调用继续写入
                }
            }

            return(1);

ERROR1:
            return(-1);
        }
Пример #17
0
        private void menuItem_deleteObject_Click(object sender, System.EventArgs e)
		{
            try
            {
                string strError = "";

                if (treeView_res.SelectedNode == null)
                {
                    MessageBox.Show("请选择一个数据库、目录或文件节点");
                    return;
                }

                ResPath respath = new ResPath(treeView_res.SelectedNode);

                string strPath = "";
                if (respath.Path != "")
                {
                    strPath = respath.Path;
                    // strPath = StringUtil.GetFirstPartPath(ref strPath);
                }
                else
                {
                    // Debug.Assert(false, "");
                    MessageBox.Show("请选择一个数据库、目录或文件节点");
                    return;
                }

                string strText = "";

                if (treeView_res.SelectedNode.ImageIndex == ResTree.RESTYPE_DB)
                    strText = "确实要删除位于 " + respath.Url + "\r\n的数据库 '" + strPath + "' ?\r\n\r\n***警告:数据库一旦删除,就无法恢复。";
                else
                    strText = "确实要删除位于 " + respath.Url + "\r\n的对象 '" + strPath + "' ?\r\n\r\n***警告:对象一旦删除,就无法恢复。";

                //
                DialogResult result = MessageBox.Show(this,
                    strText,
                    "dp2manager",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button2);
                if (result != DialogResult.Yes)
                    return;

                RmsChannel channel = Channels.GetChannel(respath.Url);
                if (channel == null)
                {
                    strError = "Channels.GetChannel 异常";
                    goto ERROR1;
                }

                long lRet = 0;

                if (treeView_res.SelectedNode.ImageIndex == ResTree.RESTYPE_DB)
                {
                    // 删除数据库
                    lRet = channel.DoDeleteDB(strPath, out strError);
                }
                else
                {
                    byte[] timestamp = null;
                    byte[] output_timestamp = null;

                REDODELETE:
                    // 删除其他资源
                    lRet = channel.DoDeleteRes(strPath,
                        timestamp,
                        out output_timestamp,
                        out strError);
                    if (lRet == -1 && channel.ErrorCode == ChannelErrorCode.TimestampMismatch)
                    {
                        timestamp = output_timestamp;
                        goto REDODELETE;
                    }
                }

                if (lRet == -1)
                    goto ERROR1;

                if (treeView_res.SelectedNode.ImageIndex == ResTree.RESTYPE_DB)
                    MessageBox.Show(this, "数据库 '" + strPath + "' 已被成功删除");
                else
                    MessageBox.Show(this, "对象 '" + strPath + "' 已被成功删除");



                this.treeView_res.Refresh(ResTree.RefreshStyle.All);

                return;
            ERROR1:
                MessageBox.Show(this, strError);
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "menuItem_deleteObject_Click() 抛出异常: " + ExceptionUtil.GetDebugText(ex));
            }
		}
Пример #18
0
        // 导入模板
        void menuItem_importTemplate_Click(object sender, System.EventArgs e)
        {
            if (treeView_res.SelectedNode == null)
            {
                MessageBox.Show("请选择一个节点");
                return;
            }

            if (treeView_res.SelectedNode.ImageIndex != ResTree.RESTYPE_SERVER)
            {
                MessageBox.Show("请选择一个服务器类型节点");
                return;
            }

            ResPath respath = new ResPath(treeView_res.SelectedNode);

            /*
            string strRefDbName = "";
            if (treeView_res.SelectedNode != null)
            {
                if (respath.Path != "")
                {
                    string strPath = respath.Path;
                    strRefDbName = StringUtil.GetFirstPartPath(ref strPath);
                }
            }
             */


            OpenFileDialog filedlg = new OpenFileDialog();

            filedlg.FileName = "*.template";
			// filedlg.InitialDirectory = Environment.CurrentDirectory;
			filedlg.Filter = "模板文件 (*.template)|*.template|All files (*.*)|*.*" ;
			filedlg.RestoreDirectory = true ;

			if (filedlg.ShowDialog() != DialogResult.OK)
			{
				return;
			}


            ImportTemplateDlg dlg = new ImportTemplateDlg();
            MainForm.SetControlFont(dlg, this.DefaultFont);

            dlg.Url = respath.Url;
            dlg.FileName = filedlg.FileName;
            dlg.MainForm = this;
            dlg.ShowDialog(this);
        }
Пример #19
0
		// 删除记录
		// parameters:
		//		strRecordPath	记录路径。如果==null,表示直接用textBox_recPath中当前的内容作为路径
		public void DeleteRecord(string strRecordPath)
		{
			if (strRecordPath != null)
				textBox_recPath.Text = strRecordPath;

			if (textBox_recPath.Text == "")
			{
				MessageBox.Show(this, "路径不能为空");
				return;
			}

			ResPath respath = new ResPath(textBox_recPath.Text);

			Uri uri = null;
			try 
			{
				uri = new Uri(respath.Url);
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, "路径错误: " + ex.Message);
				return;
			}			// 保存到文件
			if (uri.IsFile)
			{
				MessageBox.Show(this, "暂时不支持删除文件");
				return;
			}


			string strText = "你确实要删除位于服务器 '"+respath.Url+"' 上的记录 '"+respath.Path + "' 吗?";

			DialogResult msgResult = MessageBox.Show(this,
				strText,
				"dp2rms",
				MessageBoxButtons.OKCancel,
				MessageBoxIcon.Question,
				MessageBoxDefaultButton.Button2);
				
			if (msgResult != DialogResult.OK) 
			{
				MessageBox.Show(this, "删除操作被放弃...");
				return;
			}

			string strError;
			byte [] baOutputTimeStamp = null;

			// 使用Channel
			RmsChannel channelSave = channel;

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

			try 
			{

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在删除记录 " + respath.FullPath);
				stop.BeginLoop();


				EnableControlsInLoading(true);

				long lRet = channel.DoDeleteRes(respath.Path,
					this.TimeStamp,
					out baOutputTimeStamp,
					out strError);

				EnableControlsInLoading(false);

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

				if (lRet == -1) 
				{
					MessageBox.Show(this, "删除记录 '"+respath.Path+"' 失败,原因: "+strError);
					return;
				}

			}
			finally
			{
				channel = channelSave;
			}



			// 如果删除成功,原来时间戳遗留在this.TimeStamp中,也无害

			MessageBox.Show(this, "删除记录 '" + respath.FullPath + "' 成功。");

		}
Пример #20
0
        // 获得一个发起库对应的缺省查重方案名
        int GetDefaultProjectName(string strFromDbFullPath,
            out string strDefaultProjectName,
            out string strError)
        {
            strDefaultProjectName = "";
            strError = "";

            if (this.domDupCfg == null)
            {
                strError = "配置文件dom尚未初始化";
                return -1;
            }

            ResPath respath = new ResPath(strFromDbFullPath);


            XmlNode node = this.domDupCfg.SelectSingleNode("//default[@origin='" + strFromDbFullPath + "']");
            if (node == null)
            {
                node = this.domDupCfg.SelectSingleNode("//default[@origin='" + respath.Path + "']");
            }

            if (node == null)
                return 0;	// not found

            strDefaultProjectName = DomUtil.GetAttr(node, "project");

            return 1;
        }
Пример #21
0
		// 观察检索点
		// parameters:
		//		strRecordPath	记录路径。如果==null,表示直接用textBox_recPath中当前的内容作为路径
		public void ViewAccessPoint(string strRecordPath)
		{
			if (strRecordPath == null || strRecordPath == "")
				strRecordPath = textBox_recPath.Text;

			if (strRecordPath == "")
			{
				MessageBox.Show(this, "必须指定好路径后, 才能模拟创建检索点");
				return;
			}

			ResPath respath = new ResPath(strRecordPath);

			string strError;

			string strXml = "";

			// 使用Channel
			RmsChannel channelSave = channel;

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

			try 
			{
                bool bHasUploadedFile = false;

				int nRet = GetXmlRecord(out strXml, 
                    out bHasUploadedFile,
                    out strError);
				if (nRet == -1)
				{
					MessageBox.Show(this, strError);
					return;
				}
			}
			finally 
			{
				channel = channelSave;
			}

            ViewAccessPointForm accessPointWindow = MainForm.TopViewAccessPointForm;

            if (accessPointWindow == null)
            {
                accessPointWindow = new ViewAccessPointForm();
                // accessPointWindow.StartPosition = FormStartPosition.CenterScreen;
                accessPointWindow.Show();
                accessPointWindow.MdiParent = MainForm; // MDI子窗口
            }
            else
                accessPointWindow.Activate();

                /*
			else 
			{
				accessPointWindow.Focus();
				if (accessPointWindow.WindowState == FormWindowState.Minimized) 
				{
					accessPointWindow.WindowState = FormWindowState.Normal;
				}
			}
                 */

            /*
			if (accessPointWindow.Visible == false) 
			{
				try // Close()过的窗口
				{
					accessPointWindow.Show();
				}
				catch (System.ObjectDisposedException)
				{
					accessPointWindow = new ViewAccessPointForm();
					accessPointWindow.StartPosition = FormStartPosition.CenterScreen;
					accessPointWindow.Show();
				}
			}
             */


			// 使用Channel
			channelSave = channel;

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

			try 
			{
                stop.OnStop += new StopEventHandler(this.DoStop);
				stop.Initial("正在获取检索点 " + respath.FullPath);
				stop.BeginLoop();


				EnableControlsInLoading(true);

				long lRet = channel.DoGetKeys(
					respath.Path,
					strXml,
					"zh",
					// "",
					accessPointWindow,
					stop,
					out strError);

				EnableControlsInLoading(false);

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

				if (lRet == -1) 
				{
					MessageBox.Show(this, "获取检索点失败,原因: "+strError);
					return;
				}

                // 设置标题
                // ResPath respath = new ResPath(this.textBox_recPath.Text);
                accessPointWindow.Text = "观察检索点: " + respath.ReverseFullPath;


			}
			finally 
			{
				channel = channelSave;
			}




		}
Пример #22
0
		// 装载记录
		// 把strRecordPath表示的记录装载到窗口中,并且在窗口第一行
		// 路径内容设置好
		// parameters:
		//		strRecordPath	记录路径。如果==null,表示直接用textBox_recPath中当前的内容作为路径
		//		strExtStyle	如果为null,表示获取strRecordPath或textbox表示的记录。如果为"next"或"prev",
		//					则表示取其后或前一条记录
		// return:
		//		-2	放弃
		//		-1	出错
		//		0	正常
		//		1	到头或者到尾
		public int LoadRecord(string strRecordPath,
			string strExtStyle,
			out string strError)
		{
			strError = "";

			EnableControlsInLoading(true);

			try 
			{

				if (this.Changed == true)
				{

					DialogResult result = MessageBox.Show(this, 
						"装载新内容前, 发现当前窗口中已有内容修改后未来得及保存。是否要继续装载新内容到窗口中(这样将丢失先前修改过的内容)?\r\n\r\n(是)继续装载新内容 (否)不装载新内容",
						"dp2rms",
						MessageBoxButtons.YesNo,
						MessageBoxIcon.Question,
						MessageBoxDefaultButton.Button2);
					if (result != DialogResult.Yes) 
					{
						strError = "装载新内容操作被放弃...";
						return -2;
					}
				}

				if (strRecordPath != null)
					textBox_recPath.Text = strRecordPath;

				ResPath respath = new ResPath(textBox_recPath.Text);

				this.Text = respath.ReverseFullPath;


				string strContent;
				string strMetaData;
				// string strError;
				byte [] baTimeStamp = null;
				string strOutputPath;


				// 使用Channel
				RmsChannel channelSave = channel;

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

				try 
				{

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

					if (strExtStyle != null && strExtStyle != "")
					{
						strStyle += "," + strExtStyle;
					}

                    stop.OnStop += new StopEventHandler(this.DoStop);
					stop.Initial("正在装载记录" + respath.FullPath);
					stop.BeginLoop();


            
					long lRet = channel.GetRes(respath.Path,
						strStyle,
						// this.eventClose,
						out strContent,
						out strMetaData,
						out baTimeStamp,
						out strOutputPath,
						out strError);


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

					this.TimeStamp = baTimeStamp;	// 设置时间戳很重要。即便xml不合法,也应设置好时间戳,否则窗口无法进行正常删除。

                    this.strDatabaseOriginPath = respath.Url+"?"+strOutputPath; // 保存从数据库中来的原始path

					if (lRet == -1) 
					{
                        if (channel.ErrorCode == ChannelErrorCode.NotFoundSubRes)
                        {
                            // 下级资源不存在, 警告一下就行了
                            MessageBox.Show(this, strError);
                            goto CONTINUELOAD;
                        }
						else if (channel.ErrorCode == ChannelErrorCode.NotFound) 
						{
							if (strExtStyle == "prev")
								strError = "到头";
							else if (strExtStyle == "next")
								strError = "到尾";
							return 1;
						}
						else 
						{
							// this.TimeStamp = null;
							strError = "从路径 '"+respath.Path+"' 获取记录时出错: " + strError;
							return -1;
						}
					}

				}
				finally 
				{
					channel = channelSave;
				}

                CONTINUELOAD:

				respath.Path = strOutputPath;
				textBox_recPath.Text = respath.FullPath;

				//string strTemp = ByteArray.GetHexTimeStampString(baTimeStamp);

				this.m_strMetaData = strMetaData;	// 记忆XML记录的元数据

				int nRet = SetRecordToControls(strContent,
					out strError);
				if (nRet == -1)
					return -1;


				return 0;
			}
			finally
			{
				EnableControlsInLoading(false);
			}
		}
Пример #23
0
		// 启动查重
		// parameters:
		//		strRecordPath	记录路径。如果==null,表示直接用textBox_recPath中当前的内容作为路径
		public void SearchDup(string strRecordPath)
		{
			if (strRecordPath == null || strRecordPath == "")
				strRecordPath = textBox_recPath.Text;

			if (strRecordPath == "")
			{
				MessageBox.Show(this, "必须指定好路径后, 才能进行查重");
				return;
			}

			ResPath respath = new ResPath(strRecordPath);

			string strError;

			string strXml = "";
            bool bHasUploadedFile = false;

			int nRet = GetXmlRecord(out strXml, 
                out bHasUploadedFile,
                out strError);
			if (nRet == -1)
			{
				MessageBox.Show(this, strError);
				return;
			}


			// 最好激活当前已经存在的查重mdi窗口

			DupDlg dlg = new DupDlg();
            dlg.Font = GuiUtil.GetDefaultFont();

			// dlg.TopMost = true;
			dlg.OpenDetail -= new OpenDetailEventHandler(this.MainForm.OpenDetailCallBack);
			dlg.OpenDetail += new OpenDetailEventHandler(this.MainForm.OpenDetailCallBack);
			dlg.Closed -= new EventHandler(dupdlg_Closed);
			dlg.Closed += new EventHandler(dupdlg_Closed);

			SearchPanel searchpanel = new SearchPanel();
			searchpanel.Initial(this.MainForm.Servers,
				this.MainForm.cfgCache);

			searchpanel.ap = this.MainForm.AppInfo;
			searchpanel.ApCfgTitle = "detailform_dupdlg";

			string strDbFullName = respath.Url + "?" + ResPath.GetDbName(respath.Path);
			// 获得上次遗留的缺省查重方案名
			string strDupProjectName = GetUsedDefaultDupProject(strDbFullName);

			dlg.Initial(searchpanel,
				respath.Url,
				true);
			dlg.ProjectName = strDupProjectName;
			dlg.RecordFullPath = strRecordPath;
			dlg.Record = strXml;
			dlg.MdiParent = this.MainForm;	// MDI化
			dlg.Show();



			// this.MainForm.SetFirstMdiWindowState();
		}
Пример #24
0
		// 递归
		public int Fill(TreeNode node)
		{
			TreeNodeCollection children = null;

			if (node == null) 
			{
				children = this.Nodes;
			}
			else 
			{
				children = node.Nodes;
			}

			int i;


			// 填充根
			if (node == null) 
			{
				children.Clear();

				TreeNode nodeNew = new TreeNode(this.ServerUrl, ResTree.RESTYPE_SERVER, ResTree.RESTYPE_SERVER);
				ResTree.SetLoading(nodeNew);

				NodeInfo nodeinfo = new NodeInfo();
				nodeinfo.TreeNode = nodeNew;
				nodeinfo.Expandable = true;
				nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex);
				nodeinfo.NodeState |= NodeState.Object;

				nodeNew.Tag = nodeinfo;


				if (EnabledIndices != null
					&& StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false)
					nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor);

				children.Add(nodeNew);
				return 0;
			}


			// 根以下的节点类型
			ResPath respath = new ResPath(node);

			string strPath = respath.Path;

			//if (node != null)
			//	strPath = TreeViewUtil.GetPath(node);

			this.channel = Channels.GetChannel(this.ServerUrl);

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

			ResInfoItem [] items = null;

			string strError = "";

			DigitalPlatform.Stop stop = null;

			if (stopManager != null) 
			{
				stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);	// 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
				stop.Initial("正在列目录: " + this.ServerUrl + "?" + strPath);
				stop.BeginLoop();

			}

			long lRet = channel.DoDir(strPath,
				this.Lang,
                null,   // 不需要列出全部语言的名字
				out items,
				out strError);

			if (stopManager != null) 
			{
				stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
				stop.Initial("");

				stop.Unregister();	// 和容器关联
			}

			this.channel = null;

			if (lRet == -1) 
			{
				try 
				{
					MessageBox.Show(this, "Channel::DoDir() Error: " + strError);
				}
				catch
				{
					// this可能已经不存在
					return -1;
				}

				if (node != null) 
				{
					ResTree.SetLoading(node);	// 出错的善后处理,重新出现+号
					node.Collapse();
				}
				return -1;
			}


			if (items != null) 
			{
				children.Clear();

				for(i=0;i<items.Length;i++) 
				{
					// 忽略from类型节点
					if (items[i].Type == ResTree.RESTYPE_FROM)
						continue;

					TreeNode nodeNew = new TreeNode(items[i].Name, items[i].Type, items[i].Type);


					NodeInfo nodeinfo = new NodeInfo();
					nodeinfo.TreeNode = nodeNew;
					nodeinfo.Expandable = items[i].HasChildren;
					nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex);
					nodeinfo.NodeState |= NodeState.Object;
                    nodeinfo.Style = items[i].Style;
					nodeNew.Tag = nodeinfo;

					if (items[i].HasChildren)
						ResTree.SetLoading(nodeNew);

					if (EnabledIndices != null
						&& StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false)
						nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor);

					children.Add(nodeNew);
				}
			}

			return 0;
		}
Пример #25
0
        // 新建帐户
        void menuItem_newAccount_Click(object sender, System.EventArgs e)
        {

            if (treeView_res.SelectedNode == null)
            {
                MessageBox.Show("请选择一个节点");
                return;
            }

            ResPath respath = new ResPath(treeView_res.SelectedNode);

            UserRightsDlg dlg = new UserRightsDlg();
            MainForm.SetControlFont(dlg, this.DefaultFont);

            dlg.MainForm = this;
            dlg.ServerUrl = respath.Url;
            dlg.ShowDialog(this);
        }
Пример #26
0
		int DownloadOneFile(string strID,
			out string strError)
		{

			strError = "";
			ResPath respath = new ResPath(textBox_recPath.Text);
			string strResPath = respath.Path + "/object/" + strID;

			strResPath = strResPath.Replace(":", "/");


			string strLocalPath = this.listView_resFiles.GetLocalFileName(strID);

			SaveFileDialog dlg = new SaveFileDialog();

			dlg.Title = "请指定要保存的本地文件名";
			dlg.CreatePrompt = false;
			dlg.FileName = strLocalPath == "" ? strID + ".res" : strLocalPath;
			dlg.InitialDirectory = Environment.CurrentDirectory;
			// dlg.Filter = "projects files (outer*.xml)|outer*.xml|All files (*.*)|*.*" ;

			dlg.RestoreDirectory = true ;

			if(dlg.ShowDialog() != DialogResult.OK)
			{
				strError = "放弃";
				return -1;
			}


			// 使用Channel
			RmsChannel channelSave = channel;

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

			try 
			{

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

				byte [] baOutputTimeStamp = null;

				EnableControlsInLoading(true);

				string strMetaData;
				string strOutputPath = "";

				long lRet = channel.GetRes(strResPath,
					dlg.FileName,
					stop,
					out strMetaData,
					out baOutputTimeStamp,
					out strOutputPath,
					out strError);

				EnableControlsInLoading(false);

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


				if (lRet == -1) 
				{
					MessageBox.Show(this, "下载资源文件失败,原因: "+strError);
					goto ERROR1;
				}

			}
			finally 
			{
				channel = channelSave;
			}
			return 0;

			ERROR1:
			return -1;

		}
Пример #27
0
        // 递归
        public int Fill(TreeNode node)
        {
            TreeNodeCollection children = null;

            if (node == null)
            {
                children = this.Nodes;
            }
            else
            {
                children = node.Nodes;
            }

            int i;


            // 填充根
            if (node == null)
            {
                children.Clear();

                TreeNode nodeNew = new TreeNode(this.ServerUrl, ResTree.RESTYPE_SERVER, ResTree.RESTYPE_SERVER);
                ResTree.SetLoading(nodeNew);

                NodeInfo nodeinfo = new NodeInfo();
                nodeinfo.TreeNode   = nodeNew;
                nodeinfo.Expandable = true;
                nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex);
                nodeinfo.NodeState |= NodeState.Object;

                nodeNew.Tag = nodeinfo;


                if (EnabledIndices != null &&
                    StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false)
                {
                    nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor);
                }

                children.Add(nodeNew);
                return(0);
            }


            // 根以下的节点类型
            ResPath respath = new ResPath(node);

            string strPath = respath.Path;

            //if (node != null)
            //	strPath = TreeViewUtil.GetPath(node);

            this.channel = Channels.GetChannel(this.ServerUrl);

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

            ResInfoItem[] items = null;

            string strError = "";

            DigitalPlatform.Stop stop = null;

            if (stopManager != null)
            {
                stop = new DigitalPlatform.Stop();

                stop.Register(this.stopManager, true);  // 和容器关联

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在列目录: " + this.ServerUrl + "?" + strPath);
                stop.BeginLoop();
            }

            long lRet = channel.DoDir(strPath,
                                      this.Lang,
                                      null, // 不需要列出全部语言的名字
                                      out items,
                                      out strError);

            if (stopManager != null)
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");

                stop.Unregister();      // 和容器关联
            }

            this.channel = null;

            if (lRet == -1)
            {
                try
                {
                    MessageBox.Show(this, "Channel::DoDir() Error: " + strError);
                }
                catch
                {
                    // this可能已经不存在
                    return(-1);
                }

                if (node != null)
                {
                    ResTree.SetLoading(node);   // 出错的善后处理,重新出现+号
                    node.Collapse();
                }
                return(-1);
            }


            if (items != null)
            {
                children.Clear();

                for (i = 0; i < items.Length; i++)
                {
                    // 忽略from类型节点
                    if (items[i].Type == ResTree.RESTYPE_FROM)
                    {
                        continue;
                    }

                    TreeNode nodeNew = new TreeNode(items[i].Name, items[i].Type, items[i].Type);


                    NodeInfo nodeinfo = new NodeInfo();
                    nodeinfo.TreeNode   = nodeNew;
                    nodeinfo.Expandable = items[i].HasChildren;
                    nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex);
                    nodeinfo.NodeState |= NodeState.Object;
                    nodeinfo.Style      = items[i].Style;
                    nodeNew.Tag         = nodeinfo;

                    if (items[i].HasChildren)
                    {
                        ResTree.SetLoading(nodeNew);
                    }

                    if (EnabledIndices != null &&
                        StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false)
                    {
                        nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor);
                    }

                    children.Add(nodeNew);
                }
            }

            return(0);
        }
Пример #28
0
        public IEnumerator GetEnumerator()
        {
            string strError       = "";
            string strRange       = "0-9999999999";
            long   lTotalCount    = 0;  // 总命中数
            long   lExportCount   = 0;
            string strTimeMessage = "";

            DigitalPlatform.Stop stop = this.Stop;

            StopStyle old_style = StopStyle.None;

            if (stop != null)
            {
                old_style    = stop.Style;
                stop.Style   = StopStyle.EnableHalfStop; // API的间隙才让中断。避免获取结果集的中途,因为中断而导致 Session 失效,结果集丢失,进而无法 Retry 获取
                stop.OnStop += stop_OnStop;
            }
            ProgressEstimate estimate = new ProgressEstimate();

            try
            {
                int i_path = 0;
                foreach (string path in this.Paths)
                {
                    ResPath respath = new ResPath(path);

                    string strQueryXml = "<target list='" + respath.Path
                                         + ":" + "__id'><item><word>" + strRange + "</word><match>exact</match><relation>range</relation><dataType>number</dataType><maxCount>-1</maxCount></item><lang>chi</lang></target>";

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

                    try
                    {
                        long lRet = cur_channel.DoSearch(strQueryXml,
                                                         "default",
                                                         out strError);
                        if (lRet == -1)
                        {
                            strError = "检索数据库 '" + respath.Path + "' 时出错: " + strError;
                            throw new Exception(strError);
                        }

                        if (lRet == 0)
                        {
                            strError = "数据库 '" + respath.Path + "' 中没有任何数据记录";
                            continue;
                        }

                        lTotalCount += lRet;    // 总命中数

                        estimate.SetRange(0, lTotalCount);
                        if (i_path == 0)
                        {
                            estimate.StartEstimate();
                        }

                        if (stop != null)
                        {
                            stop.SetProgressRange(0, lTotalCount);
                        }

                        SearchResultLoader loader = new SearchResultLoader(cur_channel,
                                                                           stop,
                                                                           this.ResultSetName,
                                                                           this.FormatList,
                                                                           this.Lang);
                        loader.BatchSize = this.BatchSize;

                        foreach (KernelRecord record in loader)
                        {
                            if (stop != null)
                            {
                                stop.SetProgressValue(lExportCount + 1);
                            }
                            lExportCount++;

                            yield return(record);
                        }

                        strTimeMessage = "总共耗费时间: " + estimate.GetTotalTime().ToString();
                    }
                    finally
                    {
                        cur_channel.Close();
                        cur_channel = null;
                    }
                    // MessageBox.Show(this, "位于服务器 '" + respath.Url + "' 上的数据库 '" + respath.Path + "' 内共有记录 " + lTotalCount.ToString() + " 条,本次导出 " + lExportCount.ToString() + " 条。" + strTimeMessage);

                    i_path++;
                }
            }
            finally
            {
                if (stop != null)
                {
                    stop.Style   = old_style;
                    stop.OnStop -= stop_OnStop;
                }
            }
        }
Пример #29
0
		// 回调函数
		int DownloadOneFileMetaData(string strID,
			out string strResultXml,
			out byte[] timestamp,
			out string strError)
		{
			timestamp = null;
			strError = "";
			ResPath respath = new ResPath(textBox_recPath.Text);
			string strResPath = respath.Path + "/object/" + strID;

			strResPath = strResPath.Replace(":", "/");

			// 使用Channel

			RmsChannel channelSave = channel;

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

			try 
			{

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在下载资源文件的元数据 " + strResPath);
				stop.BeginLoop();

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

				EnableControlsInLoading(true);

				// 只得到metadata
				long lRet = channel.GetRes(strResPath,
					(Stream)null,
					stop,
					"metadata,timestamp,outputpath",
					null,
					out strResultXml,
					out baOutputTimeStamp,
					out strOutputPath,
					out strError);

				EnableControlsInLoading(false);

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


				if (lRet == -1) 
				{
					MessageBox.Show(this, "下载资源文件元数据失败,原因: "+strError);
					goto ERROR1;
				}

				timestamp = baOutputTimeStamp;

			}
			finally 
			{
				channel = channelSave;
			}
			return 0;

			ERROR1:
			return -1;
		}
Пример #30
0
		// 关联本地目录
		private void menuItem_linkLocalDir_Click(object sender, System.EventArgs e)
		{
			string strDefault = "";
			if (treeView_res.SelectedNode != null)
			{
				ResPath respath = new ResPath(treeView_res.SelectedNode);


				if (treeView_res.SelectedNode.ImageIndex == ResTree.RESTYPE_FOLDER)
					strDefault = respath.FullPath;
				else
					strDefault = respath.Url;
			}


			LinkInfoDlg dlg = new LinkInfoDlg();
            MainForm.SetControlFont(dlg, this.DefaultFont);

			dlg.LinkInfos = this.LinkInfos;
			dlg.CreateNewServerPath = strDefault;
			dlg.ShowDialog(this);
		}
Пример #31
0
		// 保存到备份格式
		public void SaveToBackup(string strOutputFileName)
		{
			string strError;

			// 询问文件名
			if (strOutputFileName == null)
			{
				SaveFileDialog dlg = new SaveFileDialog();

				dlg.Title = "请指定要保存的备份文件名";
				dlg.CreatePrompt = false;
				dlg.OverwritePrompt = false;
                dlg.FileName = MainForm.UsedBackupFileName;  // "*.dp2bak";
				dlg.InitialDirectory = Environment.CurrentDirectory;
				dlg.Filter = "backup files (*.dp2bak)|*.dp2bak|All files (*.*)|*.*" ;

				dlg.RestoreDirectory = true;

				if(dlg.ShowDialog() != DialogResult.OK)
					return;

				strOutputFileName = dlg.FileName;
                MainForm.UsedBackupFileName = strOutputFileName;    // 记忆下来
			}

            bool bOverwrite = false;

            if (File.Exists(strOutputFileName) == true)
            {
                OverwriteOrAppendBackupFileDlg dlg = new OverwriteOrAppendBackupFileDlg();
                dlg.Font = GuiUtil.GetDefaultFont();

                dlg.Text = "文件已经存在,是否覆盖?";
                dlg.Message = "文件 " + strOutputFileName + " 已经存在,是追加还是覆盖?";
                dlg.ShowDialog(this);

                if (dlg.DialogResult == DialogResult.Yes)
                {
                    // 追加
                    bOverwrite = false;
                }
                else if (dlg.DialogResult == DialogResult.No)
                {
                    // 覆盖
                    bOverwrite = true;
                }
                return; // 放弃
            }

			// 打开文件

			FileStream fileTarget = File.Open(
				strOutputFileName,
				FileMode.OpenOrCreate,	// 原来是Open,后来修改为OpenOrCreate。这样对临时文件被系统管理员手动意外删除(但是xml文件中仍然记载了任务)的情况能够适应。否则会抛出FileNotFoundException异常
				FileAccess.Write,
				FileShare.ReadWrite);

            if (bOverwrite == true)
                fileTarget.SetLength(0);

			try 
			{

				fileTarget.Seek(0, SeekOrigin.End);	// 具有追加的能力

				long lStart = fileTarget.Position;	// 记忆起始位置

				byte [] length = new byte[8];

				fileTarget.Write(length, 0, 8);	// 临时写点数据,占据记录总长度位置

                bool bHasUploadedFile = false;


				// 获得Xml记录
				string strXmlBody;	
				int nRet = GetXmlRecord(out strXmlBody,
                    out bHasUploadedFile,
                    out strError);
				if (nRet == -1)
				{
					fileTarget.SetLength(lStart);	// 把本次追加写入的全部去掉
					goto ERROR1;
				}

				ResPath respath = new ResPath(textBox_recPath.Text);

				// 向backup文件中保存第一个 res
				ExportUtil.ChangeMetaData(ref this.m_strMetaData, // ResFileList
					null,
					null,
					null,
					null,
					respath.FullPath,
					ByteArray.GetHexTimeStampString(this.TimeStamp));   // 任延华加 2005/6/11

				long lRet = Backup.WriteFirstResToBackupFile(
					fileTarget,
					this.m_strMetaData,
					strXmlBody);

				// 使用Channel
				RmsChannel channelSave = channel;

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

				try 
				{

                    stop.OnStop += new StopEventHandler(this.DoStop);
                    stop.Initial("正在保存记录 " + respath.FullPath + "到备份文件 " + strOutputFileName);
					stop.BeginLoop();

					EnableControlsInLoading(true);


					nRet = this.listView_resFiles.DoSaveResToBackupFile(
						fileTarget,
						respath.Path,
						channel,
						stop,
						out strError);

					EnableControlsInLoading(false);

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

					if (nRet == -1) 
					{
						fileTarget.SetLength(lStart);	// 把本次追加写入的全部去掉
						strError = "保存记录失败,原因: "+ strError;
						goto ERROR1;
					}
				}
				finally 
				{
					channel = channelSave;
				}

				// 写入总长度
				long lTotalLength = fileTarget.Position - lStart - 8;
				byte[] data = BitConverter.GetBytes(lTotalLength);

				fileTarget.Seek(lStart, SeekOrigin.Begin);
				fileTarget.Write(data, 0, 8);
			}
			finally 
			{
				fileTarget.Close();
				fileTarget = null;
			}

            string strText = "";

            if (bOverwrite == false)
                strText = "追加保存备份文件完成...";
            else
                strText = "覆盖保存备份文件完成 ...";

			MessageBox.Show(this, strText);
			return;

		
			ERROR1:
				MessageBox.Show(this, strError);
		}
Пример #32
0
		private void menuItem_accountManagement_Click(object sender, System.EventArgs e)
		{

			if (treeView_res.SelectedNode == null)
			{
				MessageBox.Show("请选择一个节点");
				return;
			}

			ResPath respath = new ResPath(treeView_res.SelectedNode);

			GetUserNameDlg namedlg = new GetUserNameDlg();
            MainForm.SetControlFont(namedlg, this.DefaultFont);

			string strError = "";
            this.Cursor = Cursors.WaitCursor;
            int nRet = namedlg.Initial(this.Servers,
				this.Channels,
				this.stopManager,
				respath.Url,
				out strError);
            this.Cursor = Cursors.Arrow;
            if (nRet == -1)
			{
				MessageBox.Show(strError);
				return;
			}

			namedlg.StartPosition = FormStartPosition.CenterScreen;
			namedlg.ShowDialog(this);
			if (namedlg.DialogResult != DialogResult.OK)
				return;

			UserRightsDlg dlg = new UserRightsDlg();
            MainForm.SetControlFont(dlg, this.DefaultFont);
            dlg.StartPosition = FormStartPosition.CenterScreen;
			dlg.UserName = namedlg.SelectedUserName;
            dlg.UserRecPath = namedlg.SelectedUserRecPath;
			dlg.ServerUrl = respath.Url;
			dlg.MainForm = this;

			this.AppInfo.LinkFormState(dlg, "userrightsdlg_state");
			dlg.ShowDialog(this);
			this.AppInfo.UnlinkFormState(dlg);
		}
Пример #33
0
		// 自动加工数据
		public void AutoGenerate()
		{
			// 库名部分路径
			ResPath respath = new ResPath(textBox_recPath.Text);
			respath.MakeDbName();

			string strError;
			string strCode;
			string strRef;

			// 使用Channel
			RmsChannel channelSave = channel;

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

			try 
			{
				string strCfgPath = respath.Path + "/cfgs/autoGenerate.cs";

				string strCfgRefPath = respath.Path + "/cfgs/autoGenerate.cs.ref";

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

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

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

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

				if (lRet == -1) 
				{
					MessageBox.Show(this, strError);
					return;
				}


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

				lRet = channel.GetRes(
					MainForm.cfgCache,
					strCfgRefPath,
					out strRef,
					out strMetaData,
					out baTimeStamp,
					out strOutputPath,
					out strError);

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


				if (lRet == -1) 
				{
					MessageBox.Show(this, strError);
					return;
				}

			}
			finally 
			{
				channel = channelSave;
			}



			// 执行代码
			int nRet = RunScript(strCode,
                strRef,
                out strError);
			if (nRet == -1) 
			{
				MessageBox.Show(this, strError);
				return;
			}

		}
Пример #34
0
		// 创建新数据库
		private void menuItem_newDatabase_Click(object sender, System.EventArgs e)
		{
			if (treeView_res.SelectedNode == null)
			{
				MessageBox.Show("请选择一个服务器或数据库节点");
				return;
			}

			ResPath respath = new ResPath(treeView_res.SelectedNode);

			string strRefDbName = "";
			if (treeView_res.SelectedNode != null
                && treeView_res.SelectedNode.ImageIndex == ResTree.RESTYPE_DB)
			{
				if (respath.Path != "")
				{
					string strPath = respath.Path;
					strRefDbName = StringUtil.GetFirstPartPath(ref strPath);
				}
			}


			DatabaseDlg dlg = new DatabaseDlg();
            MainForm.SetControlFont(dlg, this.DefaultFont);
            dlg.Text = "创建新数据库";
			dlg.IsCreate = true;
			dlg.RefDbName = strRefDbName;
			dlg.StartPosition = FormStartPosition.CenterScreen;
			dlg.MainForm = this;
			dlg.Initial(respath.Url, 
				"");

			this.AppInfo.LinkFormState(dlg, "databasedlg_state");
			dlg.ShowDialog(this);
			this.AppInfo.UnlinkFormState(dlg);
		}
Пример #35
0
		// 获得一个汉字的拼音
		// 所获得的拼音, 是一个分号间隔的字符串, 表示对应于这个汉字的多音
		// return:
		//		-1	error
		//		1	found
		//		0	not found
		int GetOnePinyin(string strOneHanzi,
			out string strPinyin,
			out string strError)
		{
			strPinyin = "";
			strError = "";

			// 拼音库路径
			string strPinyinDbPath = MainForm.AppInfo.GetString("pinyin",
				"pinyin_db_path",
				"");

            if (String.IsNullOrEmpty(strPinyinDbPath) == true)
            {
                strError = "拼音库路径尚未配置。请先用菜单“帮助/系统参数设置”功能配置适当的拼音库路径。";
                return -1;
            }

			ResPath respath = new ResPath(strPinyinDbPath);

			string strDbName = respath.Path;

            // 2007/4/5 改造 加上了 GetXmlStringSimple()
			string strQueryXml = "<target list='" + strDbName + ":" + "汉字'><item><word>"
				+ StringUtil.GetXmlStringSimple(strOneHanzi)
                + "</word><match>exact</match><relation>=</relation><dataType>string</dataType><maxCount>10</maxCount></item><lang>chi</lang></target>";

			// 使用Channel
			RmsChannel channelSave = channel;

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

			try 
			{

                stop.OnStop += new StopEventHandler(this.DoStop);
                stop.Initial("正在检索拼音 '" + strOneHanzi + "'");
				stop.BeginLoop();

				try 
				{

					long nRet = channel.DoSearch(strQueryXml,
                        "default",
                        out strError);
					if (nRet == -1) 
					{
						strError = "检索拼音库时出错: " + strError;
						return -1;
					}
					if (nRet == 0)
						return 0;	// not found

					List<string> aPath = null;
					nRet = channel.DoGetSearchResult(
                        "default",
						1,
						this.Lang,
						stop,
						out aPath,
						out strError);
					if (nRet == -1) 
					{
						strError = "检索拼音库获取检索结果时出错: " + strError;
						return -1;
					}

					if (aPath.Count == 0)
					{
						strError = "检索拼音库获取的检索结果为空";
						return -1;
					}

					string strStyle = "content,data";

					string strContent;
					string strMetaData;
					byte[] baTimeStamp;
					string strOutputPath;

					nRet = channel.GetRes((string)aPath[0],
						strStyle,
						// this.eventClose,
						out strContent,
						out strMetaData,
						out baTimeStamp,
						out strOutputPath,
						out strError);
					if (nRet == -1) 
					{
						strError = "获取拼音记录体时出错: " + strError;
						return -1;
					}

					// 取出拼音字符串
					XmlDocument dom = new XmlDocument();


					try
					{
						dom.LoadXml(strContent);
					}
					catch (Exception ex)
					{
						strError  = "汉字 '" + strOneHanzi + "' 所获取的拼音记录 " + strContent + " XML数据装载出错: " + ex.Message;
						return -1;
					}

					strPinyin = DomUtil.GetAttr(dom.DocumentElement, "p");

					return 1;

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

			}
			finally 
			{
				channel = channelSave;
			}

		}
Пример #36
0
        // 导出模板
        void menuItem_exportTemplate_Click(object sender, System.EventArgs e)
        {
            if (treeView_res.SelectedNode == null)
            {
                MessageBox.Show("请选择一个节点");
                return;
            }

            if (treeView_res.SelectedNode.ImageIndex != ResTree.RESTYPE_DB
                && treeView_res.SelectedNode.ImageIndex != ResTree.RESTYPE_SERVER)
            {
                MessageBox.Show("请选择一个服务器或数据库类型节点");
                return;
            }

            treeView_res.Refresh(ResTree.RefreshStyle.Selected);

            ExportTemplateDlg dlg = new ExportTemplateDlg();
            MainForm.SetControlFont(dlg, this.DefaultFont);

            dlg.Objects = new List<ObjectInfo>();

            if (treeView_res.SelectedNode.ImageIndex == ResTree.RESTYPE_SERVER)
            {
                for (int i = 0; i < treeView_res.SelectedNode.Nodes.Count; i++)
                {
                    ObjectInfo objectinfo = new ObjectInfo();

                    ResPath respath = new ResPath(treeView_res.SelectedNode.Nodes[i]);

                    objectinfo.Path = respath.Path;
                    objectinfo.Url = respath.Url;
                    objectinfo.ImageIndex = treeView_res.SelectedNode.Nodes[i].ImageIndex;
                    dlg.Objects.Add(objectinfo);
                }
            }
            else
            {
                ObjectInfo objectinfo = new ObjectInfo();

                ResPath respath = new ResPath(treeView_res.SelectedNode);

                objectinfo.Path = respath.Path;
                objectinfo.Url = respath.Url;
                objectinfo.ImageIndex = treeView_res.SelectedNode.ImageIndex;
                dlg.Objects.Add(objectinfo);
            }

            dlg.MainForm = this;
            dlg.ShowDialog(this);
        }
Пример #37
0
        int m_nInGetCfgFile = 0;    // 防止GetCfgFile()函数重入 2008/3/6

        // marc编辑窗要从外部获得配置文件内容
        private void MarcEditor_GetConfigFile(object sender,
            DigitalPlatform.Marc.GetConfigFileEventArgs e)
        {

            if (m_nInGetCfgFile > 0)
            {
                e.ErrorInfo = "MarcEditor_GetConfigFile() 重入了";
                return;
            }

            if (String.IsNullOrEmpty(textBox_recPath.Text))
            {
                e.ErrorInfo = "URL为空";
                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;

            // 使用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;
                }
                else
                {
                    byte[] baContent = StringUtil.GetUtf8Bytes(strContent, true);
                    MemoryStream stream = new MemoryStream(baContent);
                    e.Stream = stream;
                }


            }
            finally
            {
                channel = channelSave;

                m_nInGetCfgFile--;
            }
        }
Пример #38
0
		private void OnChanged(object source, FileSystemEventArgs e)
		{

			// 防止因主动下载而引起无谓的上载
			if (m_nDownloading > 0)
				return;

			if ((e.ChangeType & WatcherChangeTypes.Changed) != WatcherChangeTypes.Changed)
				return;

			string strPureName = PathUtil.PureName(e.FullPath);

			if (this.Names != null)
			{
				bool bFound = false;
				for(int i=0;i<this.Names.Length;i++)
				{
					if (String.Compare(strPureName, this.Names[i], true) == 0)
					{
						bFound = true;
						break;
					}
				}
				if (bFound == false)
					return;	// 不属于范围内的文件
			}
			else 
			{
				return;
			}

			// Specify what is done when a file is changed, created, or deleted.
			// MessageBox.Show("File: " +  e.FullPath + " " + e.ChangeType);

			Debug.Assert(this.Container != null, "");

			ResPath respath = new ResPath(this.ServerPath);

            RmsChannel channel = this.Container.Channels.GetChannel(respath.Url);

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


			Stream stream = null;
			
			try 
			{
				stream = File.Open(e.FullPath, 
					FileMode.Open,
					FileAccess.Read, FileShare.ReadWrite);
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				return;
			}

			string strError = "";

			try 
			{

				// 保存配置文件
				byte [] baOutputTimestamp = null;
				string strOutputPath = "";
				string strStyle = "ignorechecktimestamp";


				string strRange = "";
				if (stream != null && stream.Length != 0) 
				{
					Debug.Assert(stream.Length != 0, "test");
					strRange = "0-" + Convert.ToString(stream.Length-1);
				}

				string strServerPath = respath.Path + "/" + PathUtil.PureName(e.FullPath);

				long lRet = channel.DoSaveResObject(strServerPath,
					stream,
					(stream != null && stream.Length != 0) ? stream.Length : 0,
					strStyle,
					null,	// strMetadata,
					strRange,
					true,
					null,	// this.TimeStamp,	// timestamp,
					out baOutputTimestamp,
					out strOutputPath,
					out strError);


				if (lRet == -1) 
				{
					goto ERROR1;
				}

				// this.TimeStamp = baOutputTimestamp;

			}
			finally 
			{
				stream.Close();
			}

			return;

			ERROR1:
					MessageBox.Show( strError);
					return;
		}
Пример #39
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--;
            }
        }
Пример #40
0
        /// <summary>
        /// 检索
        /// </summary>
        /// <param name="strError">返回的错误信息</param>
        /// <returns>-1出错;0正常</returns>
        public int DoSearch(out string strError)
        {
            strError = "";

            EventFinish.Reset();
            try
            {

                this.listView_browse.Items.Clear();
                this.m_tableItem.Clear();

                if (this.ServerUrl == "")
                {
                    strError = "主服务器URL尚未指定";
                    goto ERROR1;
                }
                if (this.ProjectName == "")
                {
                    strError = "查重方案名尚未指定";
                    goto ERROR1;
                }
                if (this.RecordFullPath == "")
                {
                    strError = "源记录路径尚未指定";
                    goto ERROR1;
                }
                if (this.Record == "")
                {
                    strError = "源记录内容尚未指定";
                    goto ERROR1;
                }

                // 从服务器上获取dup配置文件
                int nRet = GetDupCfgFile(out strError);
                if (nRet == -1)
                    goto ERROR1;

                if (this.ProjectName == "{default}")
                {
                    ResPath respathtemp = new ResPath(this.RecordFullPath);

                    string strOriginDbFullPath = respathtemp.Url + "?" + ResPath.GetDbName(respathtemp.Path);
                    string strDefaultProjectName = "";
                    nRet = GetDefaultProjectName(strOriginDbFullPath,
                        out strDefaultProjectName,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                    if (nRet == 0)
                    {
                        strError = "查重发起库 '" + strOriginDbFullPath + "' 尚未定义缺省查重方案参数(需在dup配置文件中用<default>元素定义)。\r\n或可用'查重方案'textbox右边的'...'按钮指定好一个实在的查重方案名后,再行查重。";
                        goto ERROR1;
                    }
                    Debug.Assert(nRet == 1, "");
                    this.ProjectName = strDefaultProjectName;
                }

                // 检查project name是否存在
                XmlNode nodeProject = GetProjectNode(this.ProjectName,
                    out strError);
                if (nodeProject == null)
                    goto ERROR1;

                // 分析源记录路径
                ResPath respath = new ResPath(this.RecordFullPath);

                List<AccessKeyInfo> aLine = null;	// AccessKeyInfo对象数组
                // 获得keys
                // 模拟创建检索点
                // return:
                //		-1	一般出错
                //		0	正常
                nRet = this.SearchPanel.GetKeys(
                    respath.Url,
                    respath.Path,
                    this.Record,
                    out aLine,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                nRet = LoopSearch(
                    nodeProject,
                    aLine,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                // 排序
                this.SearchPanel.BeginLoop("正在排序");
                try
                {
                    this.listView_browse.ListViewItemSorter = new ListViewItemComparer();
                }
                finally
                {
                    this.SearchPanel.EndLoop();
                }

                SetDupState();

                // 获得浏览信息
                this.SearchPanel.BeginLoop("正在获取浏览列信息 ...");
                try
                {
                    nRet = GetBrowseColumns(out strError);
                    if (nRet == -1)
                        goto ERROR1;
                }
                finally
                {
                    this.SearchPanel.EndLoop();
                }
                return 0;
            }
            finally
            {
                EventFinish.Set();
            }

        ERROR1:
            return -1;
        }
Пример #41
0
        // 解析每一个宏
        void m_macroutil_ParseOneMacro(object sender, ParseOneMacroEventArgs e)
        {
            string strError = "";
            string strName = Unquote(e.Macro);  // 去掉百分号

            // 函数名:
            string strFuncName = "";
            string strParams = "";

            int nRet = strName.IndexOf(":");
            if (nRet == -1)
            {
                strFuncName = strName.Trim();
            }
            else
            {
                strFuncName = strName.Substring(0, nRet).Trim();
                strParams = strName.Substring(nRet + 1).Trim();
            }

            if (String.Compare(strFuncName, "IncSeed", true) == 0)
            {
                string[] aParam = strParams.Split(new char[] {','});
                if (aParam.Length != 3 && aParam.Length != 2)
                {
                    strError = "IncSeed需要2或3个参数。";
                    goto ERROR1;
                }

                ResPath respath = new ResPath(textBox_recPath.Text);


                m_seedmanager.Initial(this.MainForm.SearchPanel,
                    respath.Url,
                    aParam[0].Trim());

                string strValue = "";

                if (e.Simulate == true)
                {
                    nRet = m_seedmanager.GetSeed(
                        aParam[1].Trim(),
                        out strValue,
                        out strError);
                    if (nRet == 0)
                    {
                        nRet = 1;
                        strValue = "1";
                    }
                }
                else
                {
                    nRet = m_seedmanager.IncSeed(
                        aParam[1].Trim(),
                        "1",
                        out strValue,
                        out strError);
                }
                if (nRet == -1)
                    goto ERROR1;

                // 补足左方'0'
                if (aParam.Length == 3)
                {
                    int nWidth = 0;
                    try {
                        nWidth = Convert.ToInt32(aParam[2]);
                    }
                    catch 
                    {
                        strError = "第三参数应当为纯数字(表示补足的宽度)";
                        goto ERROR1;
                    }
                    e.Value = strValue.PadLeft(nWidth, '0');
                }
                else
                    e.Value = strValue;
                return;
            }

            e.Canceled = true;  // 不能解释处理
            return;

        ERROR1:
            e.ErrorInfo = strError;
        }
Пример #42
0
        // 循环检索
        int LoopSearch(
            XmlNode nodeProject,
            List<AccessKeyInfo> aLine,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            if (nodeProject == null)
            {
                strError = "nodeProject参数不能为null";
                return -1;
            }

            Hashtable threshold_table = new Hashtable();    // 数据库名和阈值的对照表
            Hashtable keyscount_table = new Hashtable();    // 发起记录的每个from所包含的key的数目 对照表。hashtable key的形态为strDbName + "|" + strFrom

            XmlNodeList databases = nodeProject.SelectNodes("database");

            // <database>循环
            for (int i = 0; i < databases.Count; i++)
            {
                XmlNode database = databases[i];

                string strName = DomUtil.GetAttr(database, "name");
                if (strName == "")
                    continue;

                string strThreshold = DomUtil.GetAttr(database, "threshold");

                int nThreshold = 0;
                try
                {
                    nThreshold = Convert.ToInt32(strThreshold);
                }
                catch
                {
                    strError = "name为 '" + strName + "' 的<database>元素内threshold属性值 '" + strThreshold + "' 格式不正确,应为纯数字";
                    return -1;
                }

                threshold_table[strName] = nThreshold;

                string strUrl = "";
                string strDbName = "";
                // 分离出URL和库名
                nRet = strName.IndexOf("?");
                if (nRet == -1)
                {
                    strUrl = this.ServerUrl;	// 当前主服务器
                    strDbName = strName;
                }
                else
                {
                    strUrl = strName.Substring(0, nRet);
                    strDbName = strName.Substring(nRet + 1);
                }

                XmlNodeList accesspoints = database.SelectNodes("accessPoint");
                // <accessPoint>循环
                for (int j = 0; j < accesspoints.Count; j++)
                {
                    XmlNode accesspoint = accesspoints[j];

                    string strFrom = DomUtil.GetAttr(accesspoint, "name");

                    // 获得from所对应的key
                    List<string> keys = GetKeysByFrom(aLine,
                        strFrom);
                    if (keys.Count == 0)
                        continue;

                    keyscount_table[strDbName + "|" + strFrom] = keys.Count;

                    string strWeight = DomUtil.GetAttr(accesspoint, "weight");
                    string strSearchStyle = DomUtil.GetAttr(accesspoint, "searchStyle");

                    /*
					int nWeight = 0;
					try 
					{
						nWeight = Convert.ToInt32(strWeight);
					}
					catch
					{
						// 警告定义问题?
					}*/

                    for (int k = 0; k < keys.Count; k++)
                    {
                        string strKey = (string)keys[k];
                        if (strKey == "")
                            continue;

                        // 检索一个from
                        nRet = SearchOneFrom(
                            strUrl,
                            strDbName,
                            strFrom,
                            strKey,
                            strSearchStyle,
                            strWeight,
                            // nThreshold,
                            5000,
                            out strError);
                        if (nRet == -1)
                        {
                            // ??? 警告检索错误?
                        }
                    }

                }

                // 处理完一个数据库了
            }

            // 将listview中每行显示出来
            Color color = Color.FromArgb(255, 255, 200);

            for (int i = 0; i < this.listView_browse.Items.Count; i++)
            {
                ListViewItem item = this.listView_browse.Items[i];
                ItemInfo info = (ItemInfo)item.Tag;
                Debug.Assert(info != null, "");

                // 获得库名
                ResPath respath = new ResPath(ResPath.GetRegularRecordPath(item.Text));
                string strDbName = respath.GetDbName();


                int nWeight = AddWeight(
                    keyscount_table,
                    strDbName,
                    info.Hits);

                // 获得当前库的threshold
                int nThreshold = (int)threshold_table[strDbName];

                string strNumber = nWeight.ToString();
                if (nWeight >= nThreshold)
                {
                    strNumber = "*" + strNumber;
                    item.BackColor = color;
                }

                ListViewUtil.ChangeItemText(item, 1, strNumber);
                ListViewUtil.ChangeItemText(item, 2, BuildComment(info.Hits));
            }

            return 0;
        }
Пример #43
0
		public void LoadTemplate()
		{
			if (this.Changed == true)
			{

				DialogResult result = MessageBox.Show(this, 
					"装载模板前,发现当前窗口中已有内容修改后未来得及保存。是否要继续装载模板到窗口中(这样将丢失先前修改的内容)?\r\n\r\n(是)继续装载模板 (否)不装载模板",
					"dp2rms",
					MessageBoxButtons.YesNo,
					MessageBoxIcon.Question,
					MessageBoxDefaultButton.Button2);
				if (result != DialogResult.Yes) 
				{
					MessageBox.Show(this, "装载模板操作被放弃...");
					return;
				}
			}

			OpenResDlg dlg = new OpenResDlg();
            dlg.Font = GuiUtil.GetDefaultFont();

			dlg.Text = "请选择目标数据库";
			dlg.EnabledIndices = new int[] { ResTree.RESTYPE_DB };
			dlg.ap = this.MainForm.AppInfo;
			dlg.ApCfgTitle = "detailform_openresdlg";
			dlg.Path = textBox_recPath.Text;
			dlg.Initial( MainForm.Servers,
				this.Channels);	
			// dlg.StartPosition = FormStartPosition.CenterScreen;
			dlg.ShowDialog(this);

			if (dlg.DialogResult != DialogResult.OK)
				return;

			textBox_recPath.Text = dlg.Path + "/?";	// 为了追加保存

			// 下载配置文件
			ResPath respath = new ResPath(dlg.Path);


			// 使用Channel

			RmsChannel channelSave = channel;

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

			try 
			{

				string strContent;
				string strError;

				string strCfgFilePath = respath.Path + "/cfgs/template";

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

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

				long lRet = channel.GetRes(
					MainForm.cfgCache,
					strCfgFilePath,
					// this.eventClose,
					out strContent,
					out strMetaData,
					out baTimeStamp,
					out strOutputPath,
					out strError);

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


				if (lRet == -1) 
				{
					this.TimeStamp = null;
					MessageBox.Show(this, strError);
					return;
				}
				else 
				{
					// MessageBox.Show(this, strContent);
					SelectRecordTemplateDlg tempdlg = new SelectRecordTemplateDlg();
                    tempdlg.Font = GuiUtil.GetDefaultFont();

                    int nRet = tempdlg.Initial(strContent, out strError);
					if (nRet == -1) 
					{
						MessageBox.Show(this, "装载配置文件 '" + strCfgFilePath + "' 发生错误: " + strError);
						return;
					}

					tempdlg.ap = this.MainForm.AppInfo;
					tempdlg.ApCfgTitle = "detailform_selecttemplatedlg";
					tempdlg.ShowDialog(this);

					if (tempdlg.DialogResult != DialogResult.OK)
						return;


					this.TimeStamp = null;
					this.m_strMetaData = "";	// 记忆XML记录的元数据

                    this.strDatabaseOriginPath = ""; // 保存从数据库中来的原始path

					nRet = this.SetRecordToControls(tempdlg.SelectedRecordXml,
						out strError);
					if (nRet == -1)
					{
						MessageBox.Show(this, strError);
						return;
					}


					this.TimeStamp = baTimeStamp;

					this.Text = respath.ReverseFullPath;

				}

			}
			finally 
			{
				channel = channelSave;
			}

		}