Example #1
0
		public ClientResultset NewResultset(string strName)
		{
			// 加写锁
			this.m_lock.AcquireWriterLock(m_nLockTimeout);
			try 
			{
				ClientResultset resultset = (ClientResultset)hashtable[strName];

				if (resultset == null)
				{
					resultset = new ClientResultset();
					resultset.Name = strName;

					hashtable.Add(strName, resultset);

					resultset.File.Open(true);
				}

				return resultset;

			}
			finally
			{
				this.m_lock.ReleaseWriterLock();
			}
		}
Example #2
0
        public ClientResultset NewResultset(string strName)
        {
            // 加写锁
            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                ClientResultset resultset = (ClientResultset)hashtable[strName];

                if (resultset == null)
                {
                    resultset      = new ClientResultset();
                    resultset.Name = strName;

                    hashtable.Add(strName, resultset);

                    resultset.File.Open(true);
                }

                return(resultset);
            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }
        }
Example #3
0
        public ClientResultset GetResultset(string strName)
        {
            // 加读锁
            this.m_lock.AcquireReaderLock(m_nLockTimeout);
            try
            {
                ClientResultset resultset = (ClientResultset)hashtable[strName];

                return(resultset);
            }
            finally
            {
                this.m_lock.ReleaseReaderLock();
            }
        }
Example #4
0
		// 功能: 合并结果集
		// parameters:
		//		strStyle	运算风格 OR , AND , SUB
		//		sourceLeft	源,左边结果集
		//		sourceRight	源,右边结果集
		//		targetLeft	目标,左边结果集
		//		targetMiddle	目标,中间结果集
		//		targetRight	目标,右边结果集
		//		strDebugInfo	处理信息
		// return:
		//		-1	失败
		//		0	成功
		public static int Merge(string strStyle,
			ClientResultset sourceLeft,
			ClientResultset sourceRight,
			ClientResultset targetLeft,
			ClientResultset targetMiddle,
			ClientResultset targetRight,
			bool bOutputDebugInfo,
			out string strDebugInfo,
			out string strError)
		{
			strDebugInfo = "";
			strError = "";
			if (bOutputDebugInfo == true)
			{
				strDebugInfo += "strStyle值:"+strStyle+"\r\n";
				strDebugInfo += "sourceLeft结果集:\r\n"+sourceLeft.Dump()+"\r\n";
				strDebugInfo += "sourceRight结果集:\r\n"+sourceRight.Dump()+"\r\n";
			}

			if (String.Compare(strStyle,"OR",true) == 0)
			{
				if (targetLeft!=null || targetRight!=null)
				{
					Exception ex = new Exception("当strStyle参数值为\"OR\"时,targetLeft参数和targetRight无效,值应为null");
					throw(ex);
				}
			}

			if (sourceLeft != null)
			{
				if (sourceLeft.File.HasIndexed == false)
				{
					strError = "为了提高运行速度, sourceLeft应在调用Merge()前确保indexed";
					return -1;
				}
			}

			if (sourceRight != null)
			{
				if (sourceRight.File.HasIndexed == false)
				{
					strError = "为了提高运行速度, sourceRight应在调用Merge()前确保indexed";
					return -1;
				}
			}

			ClientRecordItem dpRecordLeft;
			ClientRecordItem dpRecordRight;
			int i = 0;   
			int j = 0;
			int ret;
			while (true)
			{
				dpRecordLeft = null;
				dpRecordRight = null;
				if (i >= sourceLeft.Count)
				{
					if (bOutputDebugInfo == true)
						strDebugInfo += "i大于等于sourceLeft的个数,将i改为-1\r\n";
					i = -1;
				}
				else if (i != -1)
				{
					try
					{
						dpRecordLeft = (ClientRecordItem)sourceLeft.File[i];
						if (bOutputDebugInfo == true)
							strDebugInfo += "取出sourceLeft集合中第 "+Convert.ToString(i)+" 个元素,Path为 '"+dpRecordLeft.Path+"' \r\n";
					}
					catch
					{
						Exception ex = new Exception("sourceLeft取元素异常: i="+Convert.ToString(i)+"----Count="+Convert.ToString(sourceLeft.Count)+"");
						throw(ex);
					}
				}
				if (j >= sourceRight.Count)
				{
					if (bOutputDebugInfo == true)
						strDebugInfo += "j大于等于sourceRight的个数,将j改为-1\r\n";
					j = -1;
				}
				else if (j != -1)
				{
					try
					{
						dpRecordRight = (ClientRecordItem)sourceRight.File[j];
						if (bOutputDebugInfo == true)
							strDebugInfo += "取出sourceRight集合中第 "+Convert.ToString(j)+" 个元素,Path为 '"+dpRecordRight.Path+"'\r\n";
					}
					catch
					{
						Exception ex = new Exception("sourceRight取元素异常: j="+Convert.ToString(j)+"----Count="+Convert.ToString(sourceLeft.Count)+sourceRight.GetHashCode()+"<br/>");
						throw(ex);
					}
				}
				if (i == -1 && j == -1)
				{
					if (bOutputDebugInfo == true)
						strDebugInfo += "i,j都等于-1跳出\r\n";
					break;
				}

				if (dpRecordLeft == null)
				{
					if (bOutputDebugInfo == true)
						strDebugInfo += "dpRecordLeft为null,设ret等于1\r\n";
					ret = 1;
				}
				else if (dpRecordRight == null)
				{
					if (bOutputDebugInfo == true)
						strDebugInfo += "dpRecordRight为null,设ret等于-1\r\n";
					ret = -1;
				}
				else
				{
					ret = dpRecordLeft.CompareTo(dpRecordRight);  //MyCompareTo(oldOneKey); //改CompareTO
					if (bOutputDebugInfo == true)
						strDebugInfo += "dpRecordLeft与dpRecordRight均不为null,比较两条记录得到ret等于"+Convert.ToString(ret)+"\r\n";
				}


				if (String.Compare(strStyle,"OR",true) == 0 
					&& targetMiddle != null)
				{
					if (ret == 0) 
					{
						targetMiddle.File.Add(dpRecordLeft);
						i++;
						j++;
					}
					else if (ret<0) 
					{
						targetMiddle.File.Add(dpRecordLeft);
						i++;
					}
					else if (ret>0)
					{
						targetMiddle.File.Add(dpRecordRight);
						j++;
					}
					continue;
				}

				if (ret == 0 && targetMiddle != null) 
				{
					if (bOutputDebugInfo == true)
						strDebugInfo += "ret等于0,加到targetMiddle里面\r\n";
					targetMiddle.File.Add(dpRecordLeft);
					i++;
					j++;
				}

				if (ret<0) 
				{
					if (bOutputDebugInfo == true)
						strDebugInfo += "ret小于0,加到targetLeft里面\r\n";

					if (targetLeft != null && dpRecordLeft != null)
						targetLeft.File.Add(dpRecordLeft);
					i++;
				}

				if (ret>0 )
				{
					if (bOutputDebugInfo == true)
						strDebugInfo += "ret大于0,加到targetRight里面\r\n";

					if (targetRight != null && dpRecordRight != null)
						targetRight.File.Add(dpRecordRight);

					j++;
				}
			}
			return 0;
		}
Example #5
0
        // 功能: 合并结果集
        // parameters:
        //		strStyle	运算风格 OR , AND , SUB
        //		sourceLeft	源,左边结果集
        //		sourceRight	源,右边结果集
        //		targetLeft	目标,左边结果集
        //		targetMiddle	目标,中间结果集
        //		targetRight	目标,右边结果集
        //		strDebugInfo	处理信息
        // return:
        //		-1	失败
        //		0	成功
        public static int Merge(string strStyle,
                                ClientResultset sourceLeft,
                                ClientResultset sourceRight,
                                ClientResultset targetLeft,
                                ClientResultset targetMiddle,
                                ClientResultset targetRight,
                                bool bOutputDebugInfo,
                                out string strDebugInfo,
                                out string strError)
        {
            strDebugInfo = "";
            strError     = "";
            if (bOutputDebugInfo == true)
            {
                strDebugInfo += "strStyle值:" + strStyle + "\r\n";
                strDebugInfo += "sourceLeft结果集:\r\n" + sourceLeft.Dump() + "\r\n";
                strDebugInfo += "sourceRight结果集:\r\n" + sourceRight.Dump() + "\r\n";
            }

            if (String.Compare(strStyle, "OR", true) == 0)
            {
                if (targetLeft != null || targetRight != null)
                {
                    Exception ex = new Exception("当strStyle参数值为\"OR\"时,targetLeft参数和targetRight无效,值应为null");
                    throw (ex);
                }
            }

            if (sourceLeft != null)
            {
                if (sourceLeft.File.HasIndexed == false)
                {
                    strError = "为了提高运行速度, sourceLeft应在调用Merge()前确保indexed";
                    return(-1);
                }
            }

            if (sourceRight != null)
            {
                if (sourceRight.File.HasIndexed == false)
                {
                    strError = "为了提高运行速度, sourceRight应在调用Merge()前确保indexed";
                    return(-1);
                }
            }

            ClientRecordItem dpRecordLeft;
            ClientRecordItem dpRecordRight;
            int i = 0;
            int j = 0;
            int ret;

            while (true)
            {
                dpRecordLeft  = null;
                dpRecordRight = null;
                if (i >= sourceLeft.Count)
                {
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "i大于等于sourceLeft的个数,将i改为-1\r\n";
                    }
                    i = -1;
                }
                else if (i != -1)
                {
                    try
                    {
                        dpRecordLeft = (ClientRecordItem)sourceLeft.File[i];
                        if (bOutputDebugInfo == true)
                        {
                            strDebugInfo += "取出sourceLeft集合中第 " + Convert.ToString(i) + " 个元素,Path为 '" + dpRecordLeft.Path + "' \r\n";
                        }
                    }
                    catch
                    {
                        Exception ex = new Exception("sourceLeft取元素异常: i=" + Convert.ToString(i) + "----Count=" + Convert.ToString(sourceLeft.Count) + "");
                        throw (ex);
                    }
                }
                if (j >= sourceRight.Count)
                {
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "j大于等于sourceRight的个数,将j改为-1\r\n";
                    }
                    j = -1;
                }
                else if (j != -1)
                {
                    try
                    {
                        dpRecordRight = (ClientRecordItem)sourceRight.File[j];
                        if (bOutputDebugInfo == true)
                        {
                            strDebugInfo += "取出sourceRight集合中第 " + Convert.ToString(j) + " 个元素,Path为 '" + dpRecordRight.Path + "'\r\n";
                        }
                    }
                    catch
                    {
                        Exception ex = new Exception("sourceRight取元素异常: j=" + Convert.ToString(j) + "----Count=" + Convert.ToString(sourceLeft.Count) + sourceRight.GetHashCode() + "<br/>");
                        throw (ex);
                    }
                }
                if (i == -1 && j == -1)
                {
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "i,j都等于-1跳出\r\n";
                    }
                    break;
                }

                if (dpRecordLeft == null)
                {
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "dpRecordLeft为null,设ret等于1\r\n";
                    }
                    ret = 1;
                }
                else if (dpRecordRight == null)
                {
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "dpRecordRight为null,设ret等于-1\r\n";
                    }
                    ret = -1;
                }
                else
                {
                    ret = dpRecordLeft.CompareTo(dpRecordRight);  //MyCompareTo(oldOneKey); //改CompareTO
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "dpRecordLeft与dpRecordRight均不为null,比较两条记录得到ret等于" + Convert.ToString(ret) + "\r\n";
                    }
                }


                if (String.Compare(strStyle, "OR", true) == 0 &&
                    targetMiddle != null)
                {
                    if (ret == 0)
                    {
                        targetMiddle.File.Add(dpRecordLeft);
                        i++;
                        j++;
                    }
                    else if (ret < 0)
                    {
                        targetMiddle.File.Add(dpRecordLeft);
                        i++;
                    }
                    else if (ret > 0)
                    {
                        targetMiddle.File.Add(dpRecordRight);
                        j++;
                    }
                    continue;
                }

                if (ret == 0 && targetMiddle != null)
                {
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "ret等于0,加到targetMiddle里面\r\n";
                    }
                    targetMiddle.File.Add(dpRecordLeft);
                    i++;
                    j++;
                }

                if (ret < 0)
                {
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "ret小于0,加到targetLeft里面\r\n";
                    }

                    if (targetLeft != null && dpRecordLeft != null)
                    {
                        targetLeft.File.Add(dpRecordLeft);
                    }
                    i++;
                }

                if (ret > 0)
                {
                    if (bOutputDebugInfo == true)
                    {
                        strDebugInfo += "ret大于0,加到targetRight里面\r\n";
                    }

                    if (targetRight != null && dpRecordRight != null)
                    {
                        targetRight.File.Add(dpRecordRight);
                    }

                    j++;
                }
            }
            return(0);
        }