public MessageProperties() { _nativeProps = new MQPROPS(); _types = new short[_maxProperties]; _values = new object[_maxProperties]; _handles = new object[_maxProperties]; }
public unsafe static extern int ReceiveMessageByLookupId( QueueHandle handle, long lookupId, LookupAction action, MQPROPS properties, NativeOverlapped *overlapped, ReceiveCallback receiveCallback, ITransaction transaction); //MSMQ internal transaction
internal MessageProperties(int maxProperties, int baseId) { _nativeProps = new MQPROPS(); _maxProperties = maxProperties; _basePropertyId = baseId; _types = new short[_maxProperties]; _values = new object[_maxProperties]; _handles = new object[_maxProperties]; }
public unsafe static extern int ReceiveMessage( QueueHandle handle, uint timeout, ReadAction action, MQPROPS properties, NativeOverlapped *overlapped, ReceiveCallback receiveCallback, CursorHandle cursorHandle, ITransaction transaction); //MSMQ internal transaction
public QueueAsyncRequest(Message message, HashSet <QueueAsyncRequest> outstanding, uint timeoutMS, QueueHandle handle, ReadAction action, CursorHandle cursor) { Contract.Requires(cursor != null); this.action = action; this.handle = handle; this.timeoutMS = timeoutMS; Message = message; Props = message.Props.Allocate(); Tcs = new TaskCompletionSource <Message>(); Outstanding = outstanding; this.cursor = cursor; }
public unsafe Task <Message> ReceiveAsync() { // create overlapped with callback that sets the task complete source var overlapped = new Overlapped(); var nativeOverlapped = overlapped.Pack(EndReceive, null); try { for (;;) { // receive, may complete synchronously or call the async callback on the overlapped defined above int res = Native.ReceiveMessage(handle, timeoutMS, action, Props, nativeOverlapped, null, cursor, IntPtr.Zero); // successfully completed synchronously but no enough memory if (Native.NotEnoughMemory(res)) { Message.Props.Free(); Message.Props.IncreaseBufferSize(); Props = Message.Props.Allocate(); continue; // try again } if (Native.IsError(res)) { Message.Props.Free(); Overlapped.Free(nativeOverlapped); Tcs.TrySetException(new QueueException(unchecked (res))); // we really want Task.FromException... return(Tcs.Task); } return(Tcs.Task); } } catch (ObjectDisposedException ex) { Tcs.TrySetException(new QueueException(ErrorCode.OperationCanceled)); return(Tcs.Task); } }
public static extern int GetQueueProperties(string formatName, MQPROPS queueProperties);
public static extern int CreateQueue(IntPtr securityDescriptor, MQPROPS queueProperties, StringBuilder formatName, ref int formatNameLength);
public static extern int MgmtGetInfo(string machineName, string objectName, MQPROPS queueProperties);
public static extern int SendMessage(QueueHandle handle, MQPROPS properties, ITransaction transaction); //MSMQ internal transaction
public static extern int SendMessage(QueueHandle handle, MQPROPS properties, IntPtr transaction);
public unsafe void EndReceive(uint code, uint bytes, NativeOverlapped *native) { Overlapped.Free(native); Message.Props.Free(); lock (Outstanding) Outstanding.Remove(this); if (code == 995) // operation aborted { Tcs.TrySetException(new QueueException(ErrorCode.OperationCanceled)); return; } var result = Native.GetOverlappedResult(native); try { switch (result) { case 0: Message.Props.ResizeBody(); Tcs.TrySetResult(Message); break; case (int)ErrorCode.InsufficientResources: Tcs.SetException(new OutOfMemoryException("async receive operation reported InsufficientResources")); break; case (int)ErrorCode.IOTimeout: Tcs.TrySetResult(null); break; default: // successfully completed but no enough memory if (Native.NotEnoughMemory(result)) { Message.Props.Free(); Message.Props.IncreaseBufferSize(); Props = Message.Props.Allocate(); var overlapped = new Overlapped(); var nativeOverlapped = overlapped.Pack(EndReceive, null); int res = Native.ReceiveMessage(handle, timeoutMS, action, Props, nativeOverlapped, null, cursor, IntPtr.Zero); if (res == MQ_INFORMATION_OPERATION_PENDING) // running asynchronously { return; } // call completed synchronously Message.Props.Free(); Overlapped.Free(nativeOverlapped); if (!Native.IsError(res)) { Message.Props.ResizeBody(); Tcs.TrySetResult(Message); return; } } // some other error Tcs.TrySetException(new QueueException(unchecked ((int)code))); // or do we use the result? break; } } catch (ObjectDisposedException ex) { Tcs.TrySetException(new QueueException(ErrorCode.OperationCanceled)); } }