예제 #1
0
파일: DtlpIO.cs 프로젝트: renyh1013/dp2
		// 得到下一条记录
		// return:
		//		-1	出错
		//		0	继续
		//		1	到达末尾(超过m_strEndNumber)
		//		2	没有找到记录
		public int NextRecord(ref int nRecCount,
            out string strError)
		{
            strError = "";

			string strPath;
			string strNumber;
			string strNextNumber;
			byte[] baPackage = null;
		
			int nSearchStyle = DtlpChannel.XX_STYLE;
			int nRet;
			int nErrorNo;
			int nDirStyle = 0;	// 方向风格
			byte[] baMARC = null;

            if (this.channel == null)
                this.channel = this.Channels.CreateChannel(0);

			Debug.Assert(m_strStartNumber != "",
				"m_strStartNumber值不能为空");
			Debug.Assert(m_strEndNumber != "",
				"m_strEndNumber值不能为空");

			// 首次进入本函数
			if (nRecCount == -1) 
			{
				strNumber = m_strStartNumber;

				nDirStyle = 0;
				nRecCount = 0;
			}
			else 
			{
				strNumber = m_strNextNumber;

				if (Convert.ToInt64(m_strStartNumber) <= Convert.ToInt64(m_strEndNumber)) 
				{
					nDirStyle = DtlpChannel.NEXT_RECORD;
					if (Convert.ToInt64(strNumber) >= Convert.ToInt64(m_strEndNumber))
						return 1;	// 结束
				}
				else 
				{
					nDirStyle = DtlpChannel.PREV_RECORD;
					if (Convert.ToInt64(strNumber) <= Convert.ToInt64(m_strEndNumber))
						return 1;	// 结束
				}
			}


			strPath = m_strDBPath;
			strPath += "/ctlno/";
			strPath += strNumber;

	//		REDO:
				nRet = channel.Search(strPath,
					nSearchStyle | nDirStyle,
					out baPackage);
			if (nRet == -1) 
			{
				nErrorNo  = channel.GetLastErrno();
				if (nErrorNo == DtlpChannel.GL_NOTLOGIN) 
				{
					// 重新登录的事情,已经被Search()接管了
				}
				else 
				{
					if (nErrorNo == DtlpChannel.GL_NOTEXIST) 
					{
						// 增量号码
						Int64 n64Number = Convert.ToInt64(strNumber);
						string strVersion;

						// GetDTLPVersion(m_strDBPath, strVersion);	// 可以将库名再去除,效果更好
						strVersion = "0.9";
				
						if (n64Number+1<9999999
							&& strVersion == "0.9") 
						{
							//strNumber.Format(_T("%I0764d"), n64Number+1);
							// 确保7位数字
							strNumber = String.Format("{0:D7}", n64Number+1);   // "{0,7:D}" BUG!!! 左边实际上是空格 2009/2/26
						}
						else 
						{
							// strNumber.Format(_T("%I64d"), n64Number+1);
                            strNumber = String.Format("{0:D7}", n64Number + 1);  // "{0,7:D}" BUG!!! 左边实际上是空格 2009/2/26
						}


						m_strCurNumber = strNumber;
						goto NOTFOUND;
					}

					this.ErrorNo = nErrorNo;

					if (nErrorNo == DtlpChannel.GL_INVALIDCHANNEL)
						this.channel = null;

					// 得到字符串即可
                    /*
					channel.ErrorBox(owner, "DtlpIO",
						"检索发生错误\nSearch() error");
                     * */
                    strError = "检索发生错误\nSearch() error: \r\n" + channel.GetErrorDescription();
					goto ERROR1;
				}

				m_strPath = strPath;
	
				goto ERROR1;
			}


			/// 
			Package package = new Package();

			package.LoadPackage(baPackage, channel.GetPathEncoding(strPath));
			nRet = package.Parse(PackageFormat.Binary);
			if (nRet == -1) 
			{
				Debug.Assert(false, "Package::Parse() error");
                strError = "Package::Parse() error";
				goto ERROR1;
			}

			nRet = package.GetFirstBin(out baMARC);
			if (nRet == -1 || nRet == 0) 
			{
				Debug.Assert(false, "Package::GetFirstBin() error");
                strError = "Package::GetFirstBin() error";
				goto ERROR1;
			}

			if (baMARC.Length >= 9) 
			{
				Array.Copy(baMARC, 0, m_baTimeStamp, 0, 9);

				byte [] baBody = new byte[baMARC.Length - 9];
				Array.Copy(baMARC, 9, baBody, 0, baMARC.Length - 9);
				baMARC = baBody;

				//baMARC.RemoveAt(0, 9);	// 时间戳
			}
			else 
			{
				// 记录有问题,放入一个空记录?
			}

			// ---????????? 编写一个在byte[]末尾追加东西的函数?

			// baMARC = ByteArray.Add(baMARC, (byte)0);
			// baMARC.Add(0);
			// baMARC.Add(0);

			m_strRecord = channel.GetPathEncoding(strPath).GetString(baMARC);

			strPath = package.GetFirstPath();

			nRet = GetCtlNoFromPath(strPath,
				out strNextNumber);
			if (nRet == -1) 
			{
				Debug.Assert(false, "GetCtlNoFromPath() return error ...");
				strError = "GetCtlNoFromPath() error ...";
				goto ERROR1;
			}

			m_strNextNumber = strNextNumber;

			if (nRecCount == 0)	// 首次
				m_strCurNumber = strNumber;
			else
				m_strCurNumber = strNextNumber;

			m_strPath = strPath;	//

			nRecCount ++;
			return 0;
			ERROR1:
				return -1;
			NOTFOUND:
				return 2;
		}
예제 #2
0
파일: DtlpIO.cs 프로젝트: renyh1013/dp2
		// 校准转出范围的首尾号
		// return:
		//		-1	出错
		//		0	没有改变首尾号
		//		1	校准后改变了首尾号
		//		2	书目库中没有记录
		public int VerifyRange(out string strError)
		{
            strError = "";

			string strPath;
			byte[] baPackage;

			string strMinNumber;
			string strMaxNumber;
			int nRet;
			int style = DtlpChannel.JH_STYLE;
			int nErrorNo;

			bool bChanged = false;
			string strVersion;

            if (this.channel == null)
                this.channel = this.Channels.CreateChannel(0);

			Debug.Assert(m_strStartNumber != "",
				"m_strStartNumber值不能为空");
			Debug.Assert(m_strEndNumber != "",
				"m_strEndNumber值不能为空");

			// 校准最大号
			//REDO1:
				strPath = m_strDBPath;

			// GetDTLPVersion(m_strDBPath, strVersion);	// 可以将库名再去除,效果更好
			strVersion = "0.9";

			if (strVersion == "0.9")
				strPath += "/ctlno/9999999";	// 7位
			else
				strPath += "/ctlno/9999999999";	// 10位

			nRet = channel.Search(strPath,
				style | DtlpChannel.PREV_RECORD,
				out baPackage);
			if (nRet <= 0) 
			{
				nErrorNo  = channel.GetLastErrno();
				this.ErrorNo = nErrorNo;

				if (nErrorNo == DtlpChannel.GL_NOTEXIST)
					return 2;

				if (nErrorNo == DtlpChannel.GL_INVALIDCHANNEL)
					this.channel = null;

                /*
				channel.ErrorBox(owner,
                    "dp1Batch",
                    "校准最大号时发生错误\nSearch() style=PREV_RECORD error");
                 * */
                strError = "校准最大号时发生错误\nSearch() style=PREV_RECORD error: \r\n" + channel.GetErrorDescription();
				goto ERROR1;
			}

			/// 
			Package package = new Package();

			package.LoadPackage(baPackage, channel.GetPathEncoding(strPath));
			nRet = package.Parse(PackageFormat.Binary);
			if (nRet == -1) 
			{
                strError = "Package::Parse(PackageFormat.Binary) error";
				Debug.Assert(false, strError);
				goto ERROR1;
			}

			strPath = package.GetFirstPath();

			nRet = GetCtlNoFromPath(strPath,
				out strMaxNumber);
			if (nRet == -1) 
			{
                strError = "GetCtlNoFromPath() error ...";
				Debug.Assert(false, strError);
				goto ERROR1;
			}

            // 2007/8/18
            if (strVersion == "0.9")
                strMaxNumber = strMaxNumber.PadLeft(7, '0');	// 7位
            else
                strMaxNumber = strMaxNumber.PadLeft(10, '0');	// 10位


			if (Convert.ToInt64(m_strStartNumber) <= Convert.ToInt64(m_strEndNumber)) 
			{
				if (Convert.ToInt64(m_strEndNumber) > Convert.ToInt64(strMaxNumber)) 
				{
					m_strEndNumber = strMaxNumber;
					bChanged = true;
				}
			}
			else 
			{
				if (Convert.ToInt64(m_strStartNumber) > Convert.ToInt64(strMaxNumber)) 
				{
					m_strStartNumber = strMaxNumber;
					bChanged = true;
				}
			}


			// 校准最小号
			//REDO2:
				strPath = m_strDBPath;
			strPath += "/ctlno/0000000000";	// -

			nRet = channel.Search(strPath,
				style | DtlpChannel.NEXT_RECORD,
				out baPackage);
			if (nRet <= 0) 
			{
				nErrorNo = channel.GetLastErrno();

				this.ErrorNo = nErrorNo;

				if (nErrorNo == DtlpChannel.GL_NOTEXIST)
					return 2;
				if (nErrorNo == DtlpChannel.GL_INVALIDCHANNEL)
					this.channel = null;

                /*
				channel.ErrorBox(owner,
					"Batch",
					"校准最小号时发生错误\nSearch() style=NEXT_RECORD error");
                 * */
                strError = "校准最小号时发生错误\nSearch() style=NEXT_RECORD error: \r\n" + channel.GetErrorDescription();
				goto ERROR1;

			}

			/// 
			package.LoadPackage(baPackage, channel.GetPathEncoding(strPath));
			nRet = package.Parse(PackageFormat.Binary);
			if (nRet == -1) 
			{
                strError = "Package::Parse(PackageFormat.Binary) error";
				Debug.Assert(false, strError);
				goto ERROR1;
			}

			strPath = package.GetFirstPath();

			nRet = GetCtlNoFromPath(strPath,
				out strMinNumber);
			if (nRet == -1) 
			{
                strError = "GetCtlNoFromPath() error ...";
				Debug.Assert(false, strError);
				goto ERROR1;
			}

            // 2007/8/18
            if (strVersion == "0.9")
                strMinNumber = strMinNumber.PadLeft(7, '0');	// 7位
            else
                strMinNumber = strMinNumber.PadLeft(10, '0');	// 10位


			if (Convert.ToInt64(m_strStartNumber) <= Convert.ToInt64(m_strEndNumber)) 
			{
				if (Convert.ToInt64(m_strStartNumber) < Convert.ToInt64(strMinNumber)) 
				{
					m_strStartNumber = strMinNumber;
					bChanged = true;
				}
			}
			else 
			{
				if (Convert.ToInt64(m_strEndNumber) < Convert.ToInt64(strMinNumber)) 
				{
					m_strEndNumber = strMinNumber;
					bChanged = true;
				}
			}

			if (bChanged == true)
				return 1;
			else
				return 0;

			ERROR1:
				return -1;
		}
예제 #3
0
        // 获得一条MARC记录
        // 注:如果this.DtlpChannel被占用,启动启用新的通道
        // TODO: 尚未处理启用新通道时启用新Stop的课题
        // parameters:
        //      strPath 记录路径。格式为"localhost/中文图书/ctlno/1"
        //      strDirection    方向。为 prev/next/current之一。current可以缺省。
        //      strOutputPath   [out]返回的实际路径。格式和strPath相同。
        // return:
        //      -1  error 包括not found
        //      0   found
        //      1   为诊断记录
        int InternalGetOneRecord(
            string strStyle,
            string strPath,
            string strDirection,
            out string strMARC,
            out string strOutputPath,
            out string strOutStyle,
            out byte[] baTimestamp,
            out DigitalPlatform.Z3950.Record record,
            out Encoding currrentEncoding,
            out string strError)
        {
            strMARC = "";
            record = null;
            strError = "";
            currrentEncoding = this.CurrentEncoding;
            baTimestamp = null;
            strOutStyle = "marc";
            strOutputPath = ""; // TODO: 需要参考dp1batch看获得outputpath的方法

            if (strStyle != "marc")
            {
                strError = "DtlpSearchForm只支持获取MARC格式记录";
                return -1;
            }

            int nRet = 0;

            int nStyle = DtlpChannel.XX_STYLE; // 获得详细记录

            if (strDirection == "prev")
                nStyle |= DtlpChannel.PREV_RECORD;
            else if (strDirection == "next")
                nStyle |= DtlpChannel.NEXT_RECORD;

            /*
            // 将路径转换为内核可以接受的正规形态
            string strPath = DigitalPlatform.DTLP.Global.ModifyDtlpRecPath(strPath,
                "ctlno");
             * */
            Stop temp_stop = this.stop;
            DtlpChannel channel = null;

            bool bNewChannel = false;
            if (this.m_nInSearching == 0)
                channel = this.DtlpChannel;
            else
            {
                channel = this.DtlpChannels.CreateChannel(0);
                bNewChannel = true;

                temp_stop = new Stop();
                temp_stop.Tag = channel;
                temp_stop.Register(MainForm.stopManager, true);	// 和容器关联

                temp_stop.OnStop += new StopEventHandler(this.DoNewStop);
                temp_stop.Initial("正在初始化浏览器组件 ...");
                temp_stop.BeginLoop();

            }

                byte[] baPackage = null;
            Encoding encoding = null;
            try
            {

                nRet = channel.Search(strPath,
                    nStyle,
                    out baPackage);
                if (nRet == -1)
                {
                    int errorcode = channel.GetLastErrno();

                    if (errorcode == DtlpChannel.GL_NOTEXIST
                        && (strDirection == "prev" || strDirection == "next"))
                    {
                        if (strDirection == "prev")
                            strError = "到头";
                        else if (strDirection == "next")
                            strError = "到尾";
                        goto ERROR1;
                    }
                    strError = "检索出错:\r\n"
                        + "检索式: " + strPath + "\r\n"
                        + "错误码: " + errorcode + "\r\n"
                        + "错误信息: " + channel.GetErrorString(errorcode) + "\r\n";
                    goto ERROR1;
                }

                encoding = channel.GetPathEncoding(strPath);
            }
            finally
            {
                if (bNewChannel == true)
                {
                    temp_stop.EndLoop();
                    temp_stop.OnStop -= new StopEventHandler(this.DoNewStop);
                    temp_stop.Initial("");

                    this.DtlpChannels.DestroyChannel(channel);
                    channel = null;


                    temp_stop.Unregister();	// 和容器关联
                    temp_stop = null;
                }
            }
            Package package = new Package();
            package.LoadPackage(baPackage,
                encoding);
            nRet = package.Parse(PackageFormat.Binary);
            if (nRet == -1)
            {
                strError = "Package::Parse() error";
                goto ERROR1;
            }

            strOutputPath = package.GetFirstPath();

            byte[] content = null;
            nRet = package.GetFirstBin(out content);
            if (nRet == -1)
            {
                strError = "Package::GetFirstBin() error";
                goto ERROR1;
            }

            if (content == null
                || content.Length < 9)
            {
                strError = "content length < 9";
                goto ERROR1;
            }

            baTimestamp = new byte[9];
            Array.Copy(content, baTimestamp, 9);

            byte[] marc = new byte[content.Length - 9];
            Array.Copy(content,
                9,
                marc,
                0,
                content.Length - 9);

            // strMARC = this.CurrentEncoding.GetString(marc);
            strMARC = encoding.GetString(marc);

            // 去掉最后若干连续的29字符或者0字符
            // 2008/3/11
            int nDelta = 0;
            for (int i = strMARC.Length - 1; i > 24; i--)
            {
                char ch = strMARC[i];
                if (ch == 0 || ch == 29)
                    nDelta++;
                else
                    break;
            }

            if (nDelta > 0)
                strMARC = strMARC.Substring(0, strMARC.Length - nDelta);

            // 自动识别MARC格式
            string strOutMarcSyntax = "";
            // 探测记录的MARC格式 unimarc / usmarc / reader
            // return:
            //      0   没有探测出来。strMarcSyntax为空
            //      1   探测出来了
            nRet = MarcUtil.DetectMarcSyntax(strMARC,
                out strOutMarcSyntax);
            if (strOutMarcSyntax == "")
                strOutMarcSyntax = "unimarc";

            record = new DigitalPlatform.Z3950.Record();
            if (strOutMarcSyntax == "unimarc" || strOutMarcSyntax == "")
                record.m_strSyntaxOID = "1.2.840.10003.5.1";
            else if (strOutMarcSyntax == "usmarc")
                record.m_strSyntaxOID = "1.2.840.10003.5.10";
            else if (strOutMarcSyntax == "dt1000reader")
                record.m_strSyntaxOID = "1.2.840.10003.5.dt1000reader";
            else
            {
                /*
                strError = "未知的MARC syntax '" + strOutMarcSyntax + "'";
                goto ERROR1;
                 * */
                // TODO: 可以出现菜单选择
            }

            return 0;
        ERROR1:
            return -1;
        }
예제 #4
0
        // 得到下一条记录
        // return:
        //		-1	出错
        //		0	继续
        //		1	到达末尾(超过m_strEndNumber)
        //		2	没有找到记录
        public int NextRecord(ref int nRecCount,
                              out string strError)
        {
            strError = "";

            string strPath;
            string strNumber;
            string strNextNumber;

            byte[] baPackage = null;

            int nSearchStyle = DtlpChannel.XX_STYLE;
            int nRet;
            int nErrorNo;
            int nDirStyle = 0;                  // 方向风格

            byte[] baMARC = null;

            if (this.channel == null)
            {
                this.channel = this.Channels.CreateChannel(0);
            }

            Debug.Assert(m_strStartNumber != "",
                         "m_strStartNumber值不能为空");
            Debug.Assert(m_strEndNumber != "",
                         "m_strEndNumber值不能为空");

            // 首次进入本函数
            if (nRecCount == -1)
            {
                strNumber = m_strStartNumber;

                nDirStyle = 0;
                nRecCount = 0;
            }
            else
            {
                strNumber = m_strNextNumber;

                if (Convert.ToInt64(m_strStartNumber) <= Convert.ToInt64(m_strEndNumber))
                {
                    nDirStyle = DtlpChannel.NEXT_RECORD;
                    if (Convert.ToInt64(strNumber) >= Convert.ToInt64(m_strEndNumber))
                    {
                        return(1);                              // 结束
                    }
                }
                else
                {
                    nDirStyle = DtlpChannel.PREV_RECORD;
                    if (Convert.ToInt64(strNumber) <= Convert.ToInt64(m_strEndNumber))
                    {
                        return(1);                              // 结束
                    }
                }
            }


            strPath  = m_strDBPath;
            strPath += "/ctlno/";
            strPath += strNumber;

            //		REDO:
            nRet = channel.Search(strPath,
                                  nSearchStyle | nDirStyle,
                                  out baPackage);
            if (nRet == -1)
            {
                nErrorNo = channel.GetLastErrno();
                if (nErrorNo == DtlpChannel.GL_NOTLOGIN)
                {
                    // 重新登录的事情,已经被Search()接管了
                }
                else
                {
                    if (nErrorNo == DtlpChannel.GL_NOTEXIST)
                    {
                        // 增量号码
                        Int64  n64Number = Convert.ToInt64(strNumber);
                        string strVersion;

                        // GetDTLPVersion(m_strDBPath, strVersion);	// 可以将库名再去除,效果更好
                        strVersion = "0.9";

                        if (n64Number + 1 < 9999999 &&
                            strVersion == "0.9")
                        {
                            //strNumber.Format(_T("%I0764d"), n64Number+1);
                            // 确保7位数字
                            strNumber = String.Format("{0:D7}", n64Number + 1);                             // "{0,7:D}" BUG!!! 左边实际上是空格 2009/2/26
                        }
                        else
                        {
                            // strNumber.Format(_T("%I64d"), n64Number+1);
                            strNumber = String.Format("{0:D7}", n64Number + 1);  // "{0,7:D}" BUG!!! 左边实际上是空格 2009/2/26
                        }


                        m_strCurNumber = strNumber;
                        goto NOTFOUND;
                    }

                    this.ErrorNo = nErrorNo;

                    if (nErrorNo == DtlpChannel.GL_INVALIDCHANNEL)
                    {
                        this.channel = null;
                    }

                    // 得到字符串即可

                    /*
                     *                  channel.ErrorBox(owner, "DtlpIO",
                     *                          "检索发生错误\nSearch() error");
                     * */
                    strError = "检索发生错误\nSearch() error: \r\n" + channel.GetErrorDescription();
                    goto ERROR1;
                }

                m_strPath = strPath;

                goto ERROR1;
            }


            ///
            Package package = new Package();

            package.LoadPackage(baPackage, channel.GetPathEncoding(strPath));
            nRet = package.Parse(PackageFormat.Binary);
            if (nRet == -1)
            {
                Debug.Assert(false, "Package::Parse() error");
                strError = "Package::Parse() error";
                goto ERROR1;
            }

            nRet = package.GetFirstBin(out baMARC);
            if (nRet == -1 || nRet == 0)
            {
                Debug.Assert(false, "Package::GetFirstBin() error");
                strError = "Package::GetFirstBin() error";
                goto ERROR1;
            }

            if (baMARC.Length >= 9)
            {
                Array.Copy(baMARC, 0, m_baTimeStamp, 0, 9);

                byte [] baBody = new byte[baMARC.Length - 9];
                Array.Copy(baMARC, 9, baBody, 0, baMARC.Length - 9);
                baMARC = baBody;

                //baMARC.RemoveAt(0, 9);	// 时间戳
            }
            else
            {
                // 记录有问题,放入一个空记录?
            }

            // ---????????? 编写一个在byte[]末尾追加东西的函数?

            // baMARC = ByteArray.Add(baMARC, (byte)0);
            // baMARC.Add(0);
            // baMARC.Add(0);

            m_strRecord = channel.GetPathEncoding(strPath).GetString(baMARC);

            strPath = package.GetFirstPath();

            nRet = GetCtlNoFromPath(strPath,
                                    out strNextNumber);
            if (nRet == -1)
            {
                Debug.Assert(false, "GetCtlNoFromPath() return error ...");
                strError = "GetCtlNoFromPath() error ...";
                goto ERROR1;
            }

            m_strNextNumber = strNextNumber;

            if (nRecCount == 0)                 // 首次
            {
                m_strCurNumber = strNumber;
            }
            else
            {
                m_strCurNumber = strNextNumber;
            }

            m_strPath = strPath;                //

            nRecCount++;
            return(0);

ERROR1:
            return(-1);

NOTFOUND:
            return(2);
        }
예제 #5
0
        // 校准转出范围的首尾号
        // return:
        //		-1	出错
        //		0	没有改变首尾号
        //		1	校准后改变了首尾号
        //		2	书目库中没有记录
        public int VerifyRange(out string strError)
        {
            strError = "";

            string strPath;

            byte[] baPackage;

            string strMinNumber;
            string strMaxNumber;
            int    nRet;
            int    style = DtlpChannel.JH_STYLE;
            int    nErrorNo;

            bool   bChanged = false;
            string strVersion;

            if (this.channel == null)
            {
                this.channel = this.Channels.CreateChannel(0);
            }

            Debug.Assert(m_strStartNumber != "",
                         "m_strStartNumber值不能为空");
            Debug.Assert(m_strEndNumber != "",
                         "m_strEndNumber值不能为空");

            // 校准最大号
            //REDO1:
            strPath = m_strDBPath;

            // GetDTLPVersion(m_strDBPath, strVersion);	// 可以将库名再去除,效果更好
            strVersion = "0.9";

            if (strVersion == "0.9")
            {
                strPath += "/ctlno/9999999";                    // 7位
            }
            else
            {
                strPath += "/ctlno/9999999999";                 // 10位
            }
            nRet = channel.Search(strPath,
                                  style | DtlpChannel.PREV_RECORD,
                                  out baPackage);
            if (nRet <= 0)
            {
                nErrorNo     = channel.GetLastErrno();
                this.ErrorNo = nErrorNo;

                if (nErrorNo == DtlpChannel.GL_NOTEXIST)
                {
                    return(2);
                }

                if (nErrorNo == DtlpChannel.GL_INVALIDCHANNEL)
                {
                    this.channel = null;
                }

                /*
                 *              channel.ErrorBox(owner,
                 *  "dp1Batch",
                 *  "校准最大号时发生错误\nSearch() style=PREV_RECORD error");
                 * */
                strError = "校准最大号时发生错误\nSearch() style=PREV_RECORD error: \r\n" + channel.GetErrorDescription();
                goto ERROR1;
            }

            ///
            Package package = new Package();

            package.LoadPackage(baPackage, channel.GetPathEncoding(strPath));
            nRet = package.Parse(PackageFormat.Binary);
            if (nRet == -1)
            {
                strError = "Package::Parse(PackageFormat.Binary) error";
                Debug.Assert(false, strError);
                goto ERROR1;
            }

            strPath = package.GetFirstPath();

            nRet = GetCtlNoFromPath(strPath,
                                    out strMaxNumber);
            if (nRet == -1)
            {
                strError = "GetCtlNoFromPath() error ...";
                Debug.Assert(false, strError);
                goto ERROR1;
            }

            // 2007/8/18
            if (strVersion == "0.9")
            {
                strMaxNumber = strMaxNumber.PadLeft(7, '0');    // 7位
            }
            else
            {
                strMaxNumber = strMaxNumber.PadLeft(10, '0');   // 10位
            }
            if (Convert.ToInt64(m_strStartNumber) <= Convert.ToInt64(m_strEndNumber))
            {
                if (Convert.ToInt64(m_strEndNumber) > Convert.ToInt64(strMaxNumber))
                {
                    m_strEndNumber = strMaxNumber;
                    bChanged       = true;
                }
            }
            else
            {
                if (Convert.ToInt64(m_strStartNumber) > Convert.ToInt64(strMaxNumber))
                {
                    m_strStartNumber = strMaxNumber;
                    bChanged         = true;
                }
            }


            // 校准最小号
            //REDO2:
            strPath  = m_strDBPath;
            strPath += "/ctlno/0000000000";             // -

            nRet = channel.Search(strPath,
                                  style | DtlpChannel.NEXT_RECORD,
                                  out baPackage);
            if (nRet <= 0)
            {
                nErrorNo = channel.GetLastErrno();

                this.ErrorNo = nErrorNo;

                if (nErrorNo == DtlpChannel.GL_NOTEXIST)
                {
                    return(2);
                }
                if (nErrorNo == DtlpChannel.GL_INVALIDCHANNEL)
                {
                    this.channel = null;
                }

                /*
                 *              channel.ErrorBox(owner,
                 *                      "Batch",
                 *                      "校准最小号时发生错误\nSearch() style=NEXT_RECORD error");
                 * */
                strError = "校准最小号时发生错误\nSearch() style=NEXT_RECORD error: \r\n" + channel.GetErrorDescription();
                goto ERROR1;
            }

            ///
            package.LoadPackage(baPackage, channel.GetPathEncoding(strPath));
            nRet = package.Parse(PackageFormat.Binary);
            if (nRet == -1)
            {
                strError = "Package::Parse(PackageFormat.Binary) error";
                Debug.Assert(false, strError);
                goto ERROR1;
            }

            strPath = package.GetFirstPath();

            nRet = GetCtlNoFromPath(strPath,
                                    out strMinNumber);
            if (nRet == -1)
            {
                strError = "GetCtlNoFromPath() error ...";
                Debug.Assert(false, strError);
                goto ERROR1;
            }

            // 2007/8/18
            if (strVersion == "0.9")
            {
                strMinNumber = strMinNumber.PadLeft(7, '0');    // 7位
            }
            else
            {
                strMinNumber = strMinNumber.PadLeft(10, '0');   // 10位
            }
            if (Convert.ToInt64(m_strStartNumber) <= Convert.ToInt64(m_strEndNumber))
            {
                if (Convert.ToInt64(m_strStartNumber) < Convert.ToInt64(strMinNumber))
                {
                    m_strStartNumber = strMinNumber;
                    bChanged         = true;
                }
            }
            else
            {
                if (Convert.ToInt64(m_strEndNumber) < Convert.ToInt64(strMinNumber))
                {
                    m_strEndNumber = strMinNumber;
                    bChanged       = true;
                }
            }

            if (bChanged == true)
            {
                return(1);
            }
            else
            {
                return(0);
            }

ERROR1:
            return(-1);
        }
예제 #6
0
        // 获得日志记录
        // return:
        //      -1  出错
        //      0   日志文件不存在
        //      1   日志文件存在
        int GetLogRecords(string strServerAddr,
            string strLogFileName,
            out string strError)
        {
            strError = "";
            int nStartIndex = 0;

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.SetMessage("正在从服务器获得日志记录 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            try
            {

                string strPath = strServerAddr + "/log/" + strLogFileName + "/" + nStartIndex.ToString();

                bool bFirst = true;

                string strDate = "";
                int nRecID = -1;
                string strOffset = "";

                int nStyle = 0;

                for (int i = nStartIndex; ; i++)
                {
                    Application.DoEvents();	// 出让界面控制权

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

                    byte[] baPackage = null;

                    if (bFirst == true)
                    {
                    }
                    else
                    {
                        strPath = strServerAddr + "/log/" + strDate/*strLogFileName*/ + "/" + nRecID.ToString() + "@" + strOffset;
                    }

                    Encoding encoding = this.Channel.GetPathEncoding(strPath);

                    stop.SetMessage("正在获得日志记录 " + strPath);

                    int nRet = this.Channel.Search(strPath,
                        DtlpChannel.RIZHI_STYLE | nStyle,
                        out baPackage);
                    if (nRet == -1)
                    {
                        int errorcode = this.Channel.GetLastErrno();
                        if (errorcode == DtlpChannel.GL_NOTEXIST)
                        {
                            if (bFirst == true)
                                break;
                        }

                        // 更换新通道
                        if (errorcode == DtlpChannel.GL_INTR
                            || errorcode == DtlpChannel.GL_SEND
                            || errorcode == DtlpChannel.GL_RECV)
                        {
                            this.Channel = channelArray.CreateChannel(0);
                        }

                        strError = "获取日志记录:\r\n"
                            + "路径: " + strPath + "\r\n"
                            + "错误码: " + errorcode + "\r\n"
                            + "错误信息: " + this.Channel.GetErrorString(errorcode) + "\r\n";
                        return -1;
                    }


                    // 解析出记录
                    Package package = new Package();
                    package.LoadPackage(baPackage,
                        encoding);
                    package.Parse(PackageFormat.Binary);

                    // 获得下一路径
                    string strNextPath = "";
                    strNextPath = package.GetFirstPath();
                    if (String.IsNullOrEmpty(strNextPath) == true)
                    {
                        if (this.checkBox_loop.Checked == true)
                        {
                            i--;
                            continue;
                        }

                        if (bFirst == true)
                        {
                            strError = "文件 " + strLogFileName + "不存在";
                            return 0;
                        }
                        // strError = "检索 '" + strPath + "' 响应包中路径部分不存在 ...";
                        // return -1;
                        break;
                    }

                    // 获得记录内容
                    byte[] baContent = null;
                    nRet = package.GetFirstBin(out baContent);
                    if (nRet != 1)
                    {
                        baContent = null;	// 但是为空包
                    }



                    // 处理记录


                    string strMARC = DtlpChannel.GetDt1000LogRecord(baContent, encoding);

                    string strOperCode = "";
                    string strOperComment = "";
                    string strOperPath = "";

                    nRet = DtlpChannel.ParseDt1000LogRecord(strMARC,
                        out strOperCode,
                        out strOperComment,
                        out strOperPath,
                        out strError);
                    if (nRet == -1)
                    {
                        strOperComment = strError;
                    }

                    LogItemInfo info = new LogItemInfo();
                    info.Index = i;
                    info.Offset = GetStartOffs(strOffset);
                    info.OriginData = baContent;
                    info.Encoding = encoding;

                    ListViewItem item = new ListViewItem();
                    item.Text = i.ToString();
                    item.SubItems.Add(info.Offset);
                    item.SubItems.Add(strOperComment);
                    item.SubItems.Add(strOperPath);
                    item.Tag = info;

                    this.listView_records.Items.Add(item);

                    // 将日志记录路径解析为日期、序号、偏移
                    // 一个日志记录路径的例子为:
                    // /ip/log/19991231/0@1234~5678
                    // parameters:
                    //		strLogPath		待解析的日志记录路径
                    //		strDate			解析出的日期
                    //		nRecID			解析出的记录号
                    //		strOffset		解析出的记录偏移,例如1234~5678
                    // return:
                    //		-1		出错
                    //		0		正确
                    nRet = DtlpChannel.ParseLogPath(strNextPath,
                        out strDate,
                        out nRecID,
                        out strOffset,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    // ModiOffset(ref strOffset);

                    bFirst = false;
                }


                return 1;   // 日志文件存在,已获得了记录

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