Ejemplo n.º 1
0
        private bool TryEnumerateSubqueues(out List <String> subqueues)
        {
            subqueues = new List <string>();
            int[] ids = new int[1];
            UnsafeNativeMethods.MQMSGPROPS    props = new UnsafeNativeMethods.MQMSGPROPS();
            UnsafeNativeMethods.MQPROPVARIANT prop  = new UnsafeNativeMethods.MQPROPVARIANT();
            UnsafeNativeMethods.MQPROPVARIANT retProp;

            GCHandle propsHandle             = GCHandle.Alloc(null, GCHandleType.Pinned);
            GCHandle nativePropertyIdsHandle = GCHandle.Alloc(null, GCHandleType.Pinned);
            GCHandle propHandle = GCHandle.Alloc(null, GCHandleType.Pinned);

            props.status = IntPtr.Zero;
            props.count  = 1;
            ids[0]       = UnsafeNativeMethods.PROPID_MGMT_QUEUE_SUBQUEUE_NAMES;
            prop.vt      = UnsafeNativeMethods.VT_NULL;

            try
            {
                // pin
                propsHandle.Target             = props;
                nativePropertyIdsHandle.Target = ids;
                propHandle.Target = prop;

                props.variants = propHandle.AddrOfPinnedObject();
                props.ids      = nativePropertyIdsHandle.AddrOfPinnedObject();

                if (UnsafeNativeMethods.MQMgmtGetInfo(this.hostname, "queue=" + this.formatName, propsHandle.AddrOfPinnedObject()) == 0)
                {
                    retProp = (UnsafeNativeMethods.MQPROPVARIANT)Marshal.PtrToStructure(props.variants, typeof(UnsafeNativeMethods.MQPROPVARIANT));

                    IntPtr[] stringArrays = new IntPtr[retProp.stringArraysValue.count];
                    Marshal.Copy(retProp.stringArraysValue.stringArrays, stringArrays, 0, retProp.stringArraysValue.count);

                    for (int i = 0; i < retProp.stringArraysValue.count; i++)
                    {
                        subqueues.Add(Marshal.PtrToStringUni(stringArrays[i]));
                        UnsafeNativeMethods.MQFreeMemory(stringArrays[i]);
                    }
                    UnsafeNativeMethods.MQFreeMemory(retProp.stringArraysValue.stringArrays);
                }
                else
                {
                    return(false);
                }
            }
            finally
            {
                // unpin
                nativePropertyIdsHandle.Target = null;
                propsHandle.Target             = null;
                propHandle.Target = null;
            }
            return(true);
        }
Ejemplo n.º 2
0
        private bool TryEnumerateSubqueues(out List <string> subqueues)
        {
            subqueues = new List <string>();
            int[] numArray = new int[1];
            UnsafeNativeMethods.MQMSGPROPS    mqmsgprops    = new UnsafeNativeMethods.MQMSGPROPS();
            UnsafeNativeMethods.MQPROPVARIANT mqpropvariant = new UnsafeNativeMethods.MQPROPVARIANT();
            GCHandle handle  = GCHandle.Alloc(null, GCHandleType.Pinned);
            GCHandle handle2 = GCHandle.Alloc(null, GCHandleType.Pinned);
            GCHandle handle3 = GCHandle.Alloc(null, GCHandleType.Pinned);

            mqmsgprops.status = IntPtr.Zero;
            mqmsgprops.count  = 1;
            numArray[0]       = 0x1b;
            mqpropvariant.vt  = 1;
            try
            {
                handle.Target       = mqmsgprops;
                handle2.Target      = numArray;
                handle3.Target      = mqpropvariant;
                mqmsgprops.variants = handle3.AddrOfPinnedObject();
                mqmsgprops.ids      = handle2.AddrOfPinnedObject();
                if (UnsafeNativeMethods.MQMgmtGetInfo(this.hostname, "queue=" + base.formatName, handle.AddrOfPinnedObject()) == 0)
                {
                    UnsafeNativeMethods.MQPROPVARIANT mqpropvariant2 = (UnsafeNativeMethods.MQPROPVARIANT)Marshal.PtrToStructure(mqmsgprops.variants, typeof(UnsafeNativeMethods.MQPROPVARIANT));
                    IntPtr[] destination = new IntPtr[mqpropvariant2.stringArraysValue.count];
                    Marshal.Copy(mqpropvariant2.stringArraysValue.stringArrays, destination, 0, mqpropvariant2.stringArraysValue.count);
                    for (int i = 0; i < mqpropvariant2.stringArraysValue.count; i++)
                    {
                        subqueues.Add(Marshal.PtrToStringUni(destination[i]));
                        UnsafeNativeMethods.MQFreeMemory(destination[i]);
                    }
                    UnsafeNativeMethods.MQFreeMemory(mqpropvariant2.stringArraysValue.stringArrays);
                }
                else
                {
                    return(false);
                }
            }
            finally
            {
                handle2.Target = null;
                handle.Target  = null;
                handle3.Target = null;
            }
            return(true);
        }
 private bool TryEnumerateSubqueues(out List<string> subqueues)
 {
     subqueues = new List<string>();
     int[] numArray = new int[1];
     UnsafeNativeMethods.MQMSGPROPS mqmsgprops = new UnsafeNativeMethods.MQMSGPROPS();
     UnsafeNativeMethods.MQPROPVARIANT mqpropvariant = new UnsafeNativeMethods.MQPROPVARIANT();
     GCHandle handle = GCHandle.Alloc(null, GCHandleType.Pinned);
     GCHandle handle2 = GCHandle.Alloc(null, GCHandleType.Pinned);
     GCHandle handle3 = GCHandle.Alloc(null, GCHandleType.Pinned);
     mqmsgprops.status = IntPtr.Zero;
     mqmsgprops.count = 1;
     numArray[0] = 0x1b;
     mqpropvariant.vt = 1;
     try
     {
         handle.Target = mqmsgprops;
         handle2.Target = numArray;
         handle3.Target = mqpropvariant;
         mqmsgprops.variants = handle3.AddrOfPinnedObject();
         mqmsgprops.ids = handle2.AddrOfPinnedObject();
         if (UnsafeNativeMethods.MQMgmtGetInfo(this.hostname, "queue=" + base.formatName, handle.AddrOfPinnedObject()) == 0)
         {
             UnsafeNativeMethods.MQPROPVARIANT mqpropvariant2 = (UnsafeNativeMethods.MQPROPVARIANT) Marshal.PtrToStructure(mqmsgprops.variants, typeof(UnsafeNativeMethods.MQPROPVARIANT));
             IntPtr[] destination = new IntPtr[mqpropvariant2.stringArraysValue.count];
             Marshal.Copy(mqpropvariant2.stringArraysValue.stringArrays, destination, 0, mqpropvariant2.stringArraysValue.count);
             for (int i = 0; i < mqpropvariant2.stringArraysValue.count; i++)
             {
                 subqueues.Add(Marshal.PtrToStringUni(destination[i]));
                 UnsafeNativeMethods.MQFreeMemory(destination[i]);
             }
             UnsafeNativeMethods.MQFreeMemory(mqpropvariant2.stringArraysValue.stringArrays);
         }
         else
         {
             return false;
         }
     }
     finally
     {
         handle2.Target = null;
         handle.Target = null;
         handle3.Target = null;
     }
     return true;
 }
        private bool TryEnumerateSubqueues(out List<String> subqueues)
        {
            subqueues = new List<string>();
            int[] ids = new int[1];
            UnsafeNativeMethods.MQMSGPROPS props = new UnsafeNativeMethods.MQMSGPROPS();
            UnsafeNativeMethods.MQPROPVARIANT prop = new UnsafeNativeMethods.MQPROPVARIANT();
            UnsafeNativeMethods.MQPROPVARIANT retProp;

            GCHandle propsHandle = GCHandle.Alloc(null, GCHandleType.Pinned);
            GCHandle nativePropertyIdsHandle = GCHandle.Alloc(null, GCHandleType.Pinned);
            GCHandle propHandle = GCHandle.Alloc(null, GCHandleType.Pinned);

            props.status = IntPtr.Zero;
            props.count = 1;
            ids[0] = UnsafeNativeMethods.PROPID_MGMT_QUEUE_SUBQUEUE_NAMES;
            prop.vt = UnsafeNativeMethods.VT_NULL;

            try
            {
                // pin
                propsHandle.Target = props;
                nativePropertyIdsHandle.Target = ids;
                propHandle.Target = prop;

                props.variants = propHandle.AddrOfPinnedObject();
                props.ids = nativePropertyIdsHandle.AddrOfPinnedObject();

                if (UnsafeNativeMethods.MQMgmtGetInfo(this.hostname, "queue=" + this.formatName, propsHandle.AddrOfPinnedObject()) == 0)
                {
                    retProp = (UnsafeNativeMethods.MQPROPVARIANT)Marshal.PtrToStructure(props.variants, typeof(UnsafeNativeMethods.MQPROPVARIANT));

                    IntPtr[] stringArrays = new IntPtr[retProp.stringArraysValue.count];
                    Marshal.Copy(retProp.stringArraysValue.stringArrays, stringArrays, 0, retProp.stringArraysValue.count);

                    for (int i = 0; i < retProp.stringArraysValue.count; i++)
                    {
                        subqueues.Add(Marshal.PtrToStringUni(stringArrays[i]));
                        UnsafeNativeMethods.MQFreeMemory(stringArrays[i]);
                    }
                    UnsafeNativeMethods.MQFreeMemory(retProp.stringArraysValue.stringArrays);
                }
                else
                {
                    return false;
                }

            }
            finally
            {
                // unpin
                nativePropertyIdsHandle.Target = null;
                propsHandle.Target = null;
                propHandle.Target = null;
            }
            return true;
        }