Ejemplo n.º 1
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;
			}




		}
Ejemplo n.º 2
0
        // 模拟创建检索点
        public long DoGetKeys(
            string strRecPath,
            string strXmlBody,
            string strLang,
            // string strStyle,
            ViewAccessPointForm dlg,
            DigitalPlatform.Stop stop,
            out string strError)
        {
            strError = "";

            if (strRecPath == "")
            {
                strError = "记录路径为空时无法模拟创建检索点";
                return -1;
            }

            KeyInfo[] keys = null;

            int nStart = 0;
            int nPerCount = -1;

            int nCount = 0;

            dlg.Clear();

            long lTotalCount = -1;
            for (; ; )
            {
                DoIdle(); // 出让控制权,避免CPU资源耗费过度

                if (stop != null)
                {
                    if (stop.State != 0)
                    {
                        strError = "用户中断";
                        return -1;
                    }
                }


                    REDO:
                try
                {
                    IAsyncResult soapresult = this.ws.BeginCreateKeys(
                        strXmlBody,
                        strRecPath,
                        nStart,
                        nPerCount,
                        strLang,
                        // strStyle,
                        null,
                        null);

                    for (; ; )
                    {
                        DoIdle(); // 出让控制权,避免CPU资源耗费过度
                        bool bRet = soapresult.AsyncWaitHandle.WaitOne(100, false);
                        if (bRet == true)
                            break;
                    }
                    if (this.m_ws == null)
                    {
                        strError = "用户中断";
                        this.ErrorCode = ChannelErrorCode.RequestCanceled;
                        return -1;
                    }
                    Result result = this.ws.EndCreateKeys(
                        out keys,soapresult);

                    if (result.Value == -1)
                    {
                        // 2011/4/21
                        if (result.ErrorCode == ErrorCodeValue.NotLogin
                            && this.Container != null)
                        {
                            // return:
                            //		-1	error
                            //		0	login failed
                            //		1	login succeed
                            int nRet = this.UiLogin("",
                                out strError);
                            if (nRet == -1 || nRet == 0)
                            {
                                return -1;
                            }

                            goto REDO;
                        }
                        ConvertErrorCode(result);
                        strError = result.ErrorString;
                        return -1;
                    }
                    else
                    {
                        Debug.Assert(keys != null, "WebService GetRecords() API record参数返回值不应为null");

                        lTotalCount = result.Value;
                    }

                    if (keys != null)
                    {
                        nStart += keys.Length;
                        nCount += keys.Length;
                    }

                    // 做事
                    for (int i = 0; i < keys.Length; i++)
                    {
                        DoIdle(); // 出让控制权,避免CPU资源耗费过度

                        if (stop != null)
                        {
                            if (stop.State != 0)
                            {
                                strError = "用户中断";
                                return -1;
                            }

                            stop.SetMessage("正在装入 " + Convert.ToString(nStart + i) + " / "
                                + ((lTotalCount == -1) ? "?" : Convert.ToString(lTotalCount)));
                        }



                        KeyInfo keyInfo = keys[i];

                        dlg.NewLine(keyInfo);
                    }

                    if (nCount >= result.Value)
                        break;
                }

                catch (Exception ex)
                {
                    /*
                    strError = ConvertWebError(ex);
                    return -1;
                     * */
                    int nRet = ConvertWebError(ex, out strError);
                    if (nRet == 0)
                        return -1;
                    goto REDO;
                }

            }

            this.ClearRedoCount();
            return 0;
        }