public bool MoveNext()
 {
     string str;
     MQPROPVARIANTS[] variantArray = new MQPROPVARIANTS[2];
     byte[] destination = new byte[0x10];
     string strA = null;
     if ((this.criteria != null) && this.criteria.FilterMachine)
     {
         if (this.criteria.MachineName.CompareTo(".") == 0)
         {
             strA = MessageQueue.ComputerName + @"\";
         }
         else
         {
             strA = this.criteria.MachineName + @"\";
         }
     }
     do
     {
         int propertyCount = 2;
         int num2 = SafeNativeMethods.MQLocateNext(this.Handle, ref propertyCount, variantArray);
         if (MessageQueue.IsFatalError(num2))
         {
             throw new MessageQueueException(num2);
         }
         if (propertyCount != 2)
         {
             this.currentMessageQueue = null;
             return false;
         }
         str = Marshal.PtrToStringUni(variantArray[0].ptr);
         Marshal.Copy(variantArray[1].ptr, destination, 0, 0x10);
         SafeNativeMethods.MQFreeMemory(variantArray[0].ptr);
         SafeNativeMethods.MQFreeMemory(variantArray[1].ptr);
     }
     while ((strA != null) && ((strA.Length >= str.Length) || (string.Compare(strA, 0, str, 0, strA.Length, true, CultureInfo.InvariantCulture) != 0)));
     this.currentMessageQueue = new MessageQueue(str, new Guid(destination));
     return true;
 }
        public virtual MQPROPS Lock()
        {
            int[] newVectorIdentifiers = new int[propertyCount];
            int[] newVectorStatus = new int[propertyCount];
            MQPROPVARIANTS[] newVectorProperties = new MQPROPVARIANTS[propertyCount];
            int usedProperties = 0;

            for (int i = 0; i < MAX_PROPERTIES; ++i)
            {
                short vt = variantTypes[i];
                if (vt != VT_UNDEFINED)
                {
                    //Set PropertyId
                    newVectorIdentifiers[usedProperties] = i + basePropertyId;
                    //Set VariantType
                    newVectorProperties[usedProperties].vt = vt;
                    if (vt == (short)(VT_VECTOR | VT_UI1))
                    {
                        if (handles[i] == null)
                            newVectorProperties[usedProperties].caub.cElems = (uint)((byte[])objects[i]).Length;
                        else
                            newVectorProperties[usedProperties].caub.cElems = (uint)handles[i];

                        GCHandle handle = GCHandle.Alloc(objects[i], GCHandleType.Pinned);
                        handles[i] = handle;
                        newVectorProperties[usedProperties].caub.pElems = handle.AddrOfPinnedObject();
                    }
                    else if (vt == VT_UI1 || vt == VT_I1)
                        newVectorProperties[usedProperties].bVal = (byte)objects[i];
                    else if (vt == VT_UI2 || vt == VT_I2)
                        newVectorProperties[usedProperties].iVal = (short)objects[i];
                    else if (vt == VT_UI4 || vt == VT_I4)
                        newVectorProperties[usedProperties].lVal = (int)objects[i];
                    else if (vt == VT_UI8 || vt == VT_I8)
                        newVectorProperties[usedProperties].hVal = (long)objects[i];
                    else if (vt == VT_LPWSTR || vt == VT_CLSID)
                    {
                        GCHandle handle = GCHandle.Alloc(objects[i], GCHandleType.Pinned);
                        handles[i] = handle;
                        newVectorProperties[usedProperties].ptr = handle.AddrOfPinnedObject();
                    }
                    else if (vt == VT_EMPTY)
                        newVectorProperties[usedProperties].vt = 0; //real value for VT_EMPTY

                    ++usedProperties;
                    if (propertyCount == usedProperties)
                        break;
                }
            }

            handleVectorIdentifiers = GCHandle.Alloc(newVectorIdentifiers, GCHandleType.Pinned);
            handleVectorProperties = GCHandle.Alloc(newVectorProperties, GCHandleType.Pinned);
            handleVectorStatus = GCHandle.Alloc(newVectorStatus, GCHandleType.Pinned);
            vectorIdentifiers = newVectorIdentifiers;
            vectorStatus = newVectorStatus;
            vectorProperties = newVectorProperties;
            reference.propertyCount = propertyCount;
            reference.propertyIdentifiers = handleVectorIdentifiers.AddrOfPinnedObject();
            reference.propertyValues = handleVectorProperties.AddrOfPinnedObject();
            reference.status = handleVectorStatus.AddrOfPinnedObject();
            return reference;
        }
Пример #3
0
        /// <include file='doc\MessageQueueEnumerator.uex' path='docs/doc[@for="MessageQueueEnumerator.MoveNext"]/*' />
        /// <devdoc>
        ///    <para> 
        ///       Advances the enumerator to the next queue of the enumeration, if one
        ///       is currently available.</para>
        /// </devdoc>
        public bool MoveNext()
        {
            MQPROPVARIANTS[] array = new MQPROPVARIANTS[2];
            int propertyCount;
            string currentItem;
            byte[] currentGuid = new byte[16];
            string machineName = null;

            if (this.criteria != null && this.criteria.FilterMachine)
            {
                if (this.criteria.MachineName.CompareTo(".") == 0)
                    machineName = MessageQueue.ComputerName + "\\";
                else
                    machineName = this.criteria.MachineName + "\\";
            }

            do
            {
                propertyCount = 2;
                int status;
                status = SafeNativeMethods.MQLocateNext(this.Handle, ref propertyCount, array);
                if (MessageQueue.IsFatalError(status))
                    throw new MessageQueueException(status);

                if (propertyCount != 2)
                {
                    this.currentMessageQueue = null;
                    return false;
                }

                //Using Unicode API even on Win9x
                currentItem = Marshal.PtrToStringUni(array[0].ptr);
                Marshal.Copy(array[1].ptr, currentGuid, 0, 16);
                //MSMQ allocated this memory, lets free it.
                SafeNativeMethods.MQFreeMemory(array[0].ptr);
                SafeNativeMethods.MQFreeMemory(array[1].ptr);
            }
            while (machineName != null && (machineName.Length >= currentItem.Length ||
                                           String.Compare(machineName, 0, currentItem, 0, machineName.Length, true, CultureInfo.InvariantCulture) != 0));

            this.currentMessageQueue = new MessageQueue(currentItem, new Guid(currentGuid));
            return true;
        }
        public virtual MQPROPS Lock()
        {
            int[]            newVectorIdentifiers = new int[propertyCount];
            int[]            newVectorStatus      = new int[propertyCount];
            MQPROPVARIANTS[] newVectorProperties  = new MQPROPVARIANTS[propertyCount];
            int usedProperties = 0;

            for (int i = 0; i < MAX_PROPERTIES; ++i)
            {
                short vt = variantTypes[i];
                if (vt != VT_UNDEFINED)
                {
                    //Set PropertyId
                    newVectorIdentifiers[usedProperties] = i + basePropertyId;
                    //Set VariantType
                    newVectorProperties[usedProperties].vt = vt;
                    if (vt == (short)(VT_VECTOR | VT_UI1))
                    {
                        if (handles[i] == null)
                        {
                            newVectorProperties[usedProperties].caub.cElems = (uint)((byte[])objects[i]).Length;
                        }
                        else
                        {
                            newVectorProperties[usedProperties].caub.cElems = (uint)handles[i];
                        }

                        GCHandle handle = GCHandle.Alloc(objects[i], GCHandleType.Pinned);
                        handles[i] = handle;
                        newVectorProperties[usedProperties].caub.pElems = handle.AddrOfPinnedObject();
                    }
                    else if (vt == VT_UI1 || vt == VT_I1)
                    {
                        newVectorProperties[usedProperties].bVal = (byte)objects[i];
                    }
                    else if (vt == VT_UI2 || vt == VT_I2)
                    {
                        newVectorProperties[usedProperties].iVal = (short)objects[i];
                    }
                    else if (vt == VT_UI4 || vt == VT_I4)
                    {
                        newVectorProperties[usedProperties].lVal = (int)objects[i];
                    }
                    else if (vt == VT_UI8 || vt == VT_I8)
                    {
                        newVectorProperties[usedProperties].hVal = (long)objects[i];
                    }
                    else if (vt == VT_LPWSTR || vt == VT_CLSID)
                    {
                        GCHandle handle = GCHandle.Alloc(objects[i], GCHandleType.Pinned);
                        handles[i] = handle;
                        newVectorProperties[usedProperties].ptr = handle.AddrOfPinnedObject();
                    }
                    else if (vt == VT_EMPTY)
                    {
                        newVectorProperties[usedProperties].vt = 0; //real value for VT_EMPTY
                    }
                    ++usedProperties;
                    if (propertyCount == usedProperties)
                    {
                        break;
                    }
                }
            }

            handleVectorIdentifiers       = GCHandle.Alloc(newVectorIdentifiers, GCHandleType.Pinned);
            handleVectorProperties        = GCHandle.Alloc(newVectorProperties, GCHandleType.Pinned);
            handleVectorStatus            = GCHandle.Alloc(newVectorStatus, GCHandleType.Pinned);
            vectorIdentifiers             = newVectorIdentifiers;
            vectorStatus                  = newVectorStatus;
            vectorProperties              = newVectorProperties;
            reference.propertyCount       = propertyCount;
            reference.propertyIdentifiers = handleVectorIdentifiers.AddrOfPinnedObject();
            reference.propertyValues      = handleVectorProperties.AddrOfPinnedObject();
            reference.status              = handleVectorStatus.AddrOfPinnedObject();
            return(reference);
        }
        public virtual MQPROPS Lock()
        {
            int[]            numArray            = new int[this.propertyCount];
            int[]            numArray2           = new int[this.propertyCount];
            MQPROPVARIANTS[] mqpropvariantsArray = new MQPROPVARIANTS[this.propertyCount];
            int index = 0;

            for (int i = 0; i < this.MAX_PROPERTIES; i++)
            {
                short num3 = this.variantTypes[i];
                if (num3 != 0)
                {
                    numArray[index] = i + this.basePropertyId;
                    mqpropvariantsArray[index].vt = num3;
                    switch (num3)
                    {
                    case 0x11:
                    case 0x10:
                        mqpropvariantsArray[index].bVal = (byte)this.objects[i];
                        break;

                    case 0x1011:
                    {
                        if (this.handles[i] == null)
                        {
                            mqpropvariantsArray[index].caub.cElems = (uint)((byte[])this.objects[i]).Length;
                        }
                        else
                        {
                            mqpropvariantsArray[index].caub.cElems = (uint)this.handles[i];
                        }
                        GCHandle handle = GCHandle.Alloc(this.objects[i], GCHandleType.Pinned);
                        this.handles[i] = handle;
                        mqpropvariantsArray[index].caub.pElems = handle.AddrOfPinnedObject();
                        break;
                    }

                    case 0x12:
                    case 2:
                        mqpropvariantsArray[index].iVal = (short)this.objects[i];
                        break;

                    case 0x13:
                    case 3:
                        mqpropvariantsArray[index].lVal = (int)this.objects[i];
                        break;

                    case 0x15:
                    case 20:
                        mqpropvariantsArray[index].hVal = (long)this.objects[i];
                        break;

                    case 0x1f:
                    case 0x48:
                    {
                        GCHandle handle2 = GCHandle.Alloc(this.objects[i], GCHandleType.Pinned);
                        this.handles[i] = handle2;
                        mqpropvariantsArray[index].ptr = handle2.AddrOfPinnedObject();
                        break;
                    }

                    default:
                        if (num3 == 0x7fff)
                        {
                            mqpropvariantsArray[index].vt = 0;
                        }
                        break;
                    }
                    index++;
                    if (this.propertyCount == index)
                    {
                        break;
                    }
                }
            }
            this.handleVectorIdentifiers       = GCHandle.Alloc(numArray, GCHandleType.Pinned);
            this.handleVectorProperties        = GCHandle.Alloc(mqpropvariantsArray, GCHandleType.Pinned);
            this.handleVectorStatus            = GCHandle.Alloc(numArray2, GCHandleType.Pinned);
            this.vectorIdentifiers             = numArray;
            this.vectorStatus                  = numArray2;
            this.vectorProperties              = mqpropvariantsArray;
            this.reference.propertyCount       = this.propertyCount;
            this.reference.propertyIdentifiers = this.handleVectorIdentifiers.AddrOfPinnedObject();
            this.reference.propertyValues      = this.handleVectorProperties.AddrOfPinnedObject();
            this.reference.status              = this.handleVectorStatus.AddrOfPinnedObject();
            return(this.reference);
        }
        public virtual MQPROPS Lock()
        {
            int[] numArray = new int[this.propertyCount];
            int[] numArray2 = new int[this.propertyCount];
            MQPROPVARIANTS[] mqpropvariantsArray = new MQPROPVARIANTS[this.propertyCount];
            int index = 0;
            for (int i = 0; i < this.MAX_PROPERTIES; i++)
            {
                short num3 = this.variantTypes[i];
                if (num3 != 0)
                {
                    numArray[index] = i + this.basePropertyId;
                    mqpropvariantsArray[index].vt = num3;
                    switch (num3)
                    {
                        case 0x11:
                        case 0x10:
                            mqpropvariantsArray[index].bVal = (byte) this.objects[i];
                            break;

                        case 0x1011:
                        {
                            if (this.handles[i] == null)
                            {
                                mqpropvariantsArray[index].caub.cElems = (uint) ((byte[]) this.objects[i]).Length;
                            }
                            else
                            {
                                mqpropvariantsArray[index].caub.cElems = (uint) this.handles[i];
                            }
                            GCHandle handle = GCHandle.Alloc(this.objects[i], GCHandleType.Pinned);
                            this.handles[i] = handle;
                            mqpropvariantsArray[index].caub.pElems = handle.AddrOfPinnedObject();
                            break;
                        }
                        case 0x12:
                        case 2:
                            mqpropvariantsArray[index].iVal = (short) this.objects[i];
                            break;

                        case 0x13:
                        case 3:
                            mqpropvariantsArray[index].lVal = (int) this.objects[i];
                            break;

                        case 0x15:
                        case 20:
                            mqpropvariantsArray[index].hVal = (long) this.objects[i];
                            break;

                        case 0x1f:
                        case 0x48:
                        {
                            GCHandle handle2 = GCHandle.Alloc(this.objects[i], GCHandleType.Pinned);
                            this.handles[i] = handle2;
                            mqpropvariantsArray[index].ptr = handle2.AddrOfPinnedObject();
                            break;
                        }
                        default:
                            if (num3 == 0x7fff)
                            {
                                mqpropvariantsArray[index].vt = 0;
                            }
                            break;
                    }
                    index++;
                    if (this.propertyCount == index)
                    {
                        break;
                    }
                }
            }
            this.handleVectorIdentifiers = GCHandle.Alloc(numArray, GCHandleType.Pinned);
            this.handleVectorProperties = GCHandle.Alloc(mqpropvariantsArray, GCHandleType.Pinned);
            this.handleVectorStatus = GCHandle.Alloc(numArray2, GCHandleType.Pinned);
            this.vectorIdentifiers = numArray;
            this.vectorStatus = numArray2;
            this.vectorProperties = mqpropvariantsArray;
            this.reference.propertyCount = this.propertyCount;
            this.reference.propertyIdentifiers = this.handleVectorIdentifiers.AddrOfPinnedObject();
            this.reference.propertyValues = this.handleVectorProperties.AddrOfPinnedObject();
            this.reference.status = this.handleVectorStatus.AddrOfPinnedObject();
            return this.reference;
        }