123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433 |
- //------------------------------------------------------------------------------
- // <copyright file="Message.cs" company="Microsoft">
- // Copyright (c) Microsoft Corporation. All rights reserved.
- // </copyright>
- //------------------------------------------------------------------------------
- using Experimental.System.Messaging.Interop;
- using System;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Diagnostics.CodeAnalysis;
- using System.Globalization;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Text;
- namespace Experimental.System.Messaging
- {
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message"]/*' />
- /// <devdoc>
- /// <para>
- /// Provides access to the properties needed to define a
- /// Message Queuing message.
- /// </para>
- /// </devdoc>
- [Designer("System.Messaging.Design.MessageDesigner, " + AssemblyRef.SystemDesign)]
- public class Message : Component
- {
- private const int GenericIdSize = 16;
- private const int MessageIdSize = 20;
- private const int DefaultQueueNameSize = 255;
- private const int DefaultCryptographicProviderNameSize = 255;
- private const int DefaultDigitalSignatureSize = 255;
- private const int DefaultSenderCertificateSize = 255;
- private const int DefaultSenderIdSize = 255;
- private const int DefaultSymmetricKeySize = 255;
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.InfiniteTimeout"]/*' />
- /// <devdoc>
- /// <para>
- /// Specifies that there is no timeout.
- /// </para>
- /// </devdoc>
- public static readonly TimeSpan InfiniteTimeout = TimeSpan.FromSeconds(UInt32.MaxValue);
- private MessagePropertyFilter filter;
- private string machineName;
- private bool receiveCreated;
- private object cachedBodyObject;
- private Stream cachedBodyStream;
- private IMessageFormatter cachedFormatter;
- private MessageQueue cachedResponseQueue;
- private MessageQueue cachedTransactionStatusQueue;
- private MessageQueue cachedAdminQueue;
- private MessageQueue cachedDestinationQueue;
- internal MessagePropertyVariants properties;
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Message"]/*' />
- /// <devdoc>
- /// <para>
- /// Initializes a new instance of the <see cref='System.Messaging.Message'/> class with an empty body.
- /// </para>
- /// </devdoc>
- public Message()
- {
- properties = new MessagePropertyVariants();
- receiveCreated = false;
- this.filter = new MessagePropertyFilter();
- //Always add Id
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_MSGID, new byte[MessageIdSize]);
- this.filter.Id = true;
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Message1"]/*' />
- /// <devdoc>
- /// <para>
- /// Initializes a new instance of the <see cref='System.Messaging.Message'/>
- /// class, serializing the object passed as
- /// an argument.
- /// </para>
- /// </devdoc>
- public Message(object body)
- : this()
- {
- this.Body = body;
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Message2"]/*' />
- /// <devdoc>
- /// <para>[To be supplied.]</para>
- /// </devdoc>
- public Message(object body, IMessageFormatter formatter)
- : this()
- {
- this.Formatter = formatter;
- this.Body = body;
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Message3"]/*' />
- /// <internalonly/>
- internal Message(MessagePropertyFilter filter)
- {
- properties = new MessagePropertyVariants();
- receiveCreated = true;
- this.filter = filter;
- if (filter.data1 != 0)
- {
- int data = filter.data1;
- if (0 != (data & MessagePropertyFilter.ACKNOWLEDGEMENT))
- properties.SetUI2(NativeMethods.MESSAGE_PROPID_CLASS, (short)0);
- if (0 != (data & MessagePropertyFilter.ACKNOWLEDGE_TYPE))
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_ACKNOWLEDGE, (byte)0);
- if (0 != (data & MessagePropertyFilter.ADMIN_QUEUE))
- {
- properties.SetString(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE, new byte[DefaultQueueNameSize * 2]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE_LEN, DefaultQueueNameSize);
- }
- if (0 != (data & MessagePropertyFilter.BODY))
- {
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_BODY, new byte[filter.bodySize]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_BODY_SIZE, filter.bodySize);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_BODY_TYPE, 0);
- }
- if (0 != (data & MessagePropertyFilter.LABEL))
- {
- properties.SetString(NativeMethods.MESSAGE_PROPID_LABEL, new byte[filter.labelSize * 2]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_LABEL_LEN, filter.labelSize);
- }
- if (0 != (data & MessagePropertyFilter.ID))
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_MSGID, new byte[MessageIdSize]);
- if (0 != (data & MessagePropertyFilter.LOOKUP_ID))
- properties.SetUI8(NativeMethods.MESSAGE_PROPID_LOOKUPID, (long)0);
- if (0 != (data & MessagePropertyFilter.USE_DEADLETTER_QUEUE))
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL, (byte)0);
- if (0 != (data & MessagePropertyFilter.RESPONSE_QUEUE))
- {
- properties.SetString(NativeMethods.MESSAGE_PROPID_RESP_QUEUE, new byte[DefaultQueueNameSize * 2]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_RESP_QUEUE_LEN, DefaultQueueNameSize);
- }
- //Acknowledgment and MessageType are overloaded in MQ.
- if ((0 == (data & MessagePropertyFilter.ACKNOWLEDGEMENT)) && (0 != (data & MessagePropertyFilter.MESSAGE_TYPE)))
- properties.SetUI2(NativeMethods.MESSAGE_PROPID_CLASS, (short)0);
- //Journaling and Deadletter are overloaded in MSMQ
- if ((0 == (data & MessagePropertyFilter.USE_DEADLETTER_QUEUE)) && (0 != (data & MessagePropertyFilter.USE_JOURNALING)))
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL, (byte)0);
- }
- if (filter.data2 != 0)
- {
- int data = filter.data2;
- if (0 != (data & MessagePropertyFilter.APP_SPECIFIC))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_APPSPECIFIC, 0);
- if (0 != (data & MessagePropertyFilter.ARRIVED_TIME))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_ARRIVEDTIME, 0);
- if (0 != (data & MessagePropertyFilter.ATTACH_SENDER_ID))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENDERID_TYPE, 0);
- if (0 != (data & MessagePropertyFilter.AUTHENTICATED))
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_AUTHENTICATED, (byte)0);
- if (0 != (data & MessagePropertyFilter.CONNECTOR_TYPE))
- properties.SetGuid(NativeMethods.MESSAGE_PROPID_CONNECTOR_TYPE, new byte[GenericIdSize]);
- if (0 != (data & MessagePropertyFilter.CORRELATION_ID))
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_CORRELATIONID, new byte[MessageIdSize]);
- if (0 != (data & MessagePropertyFilter.CRYPTOGRAPHIC_PROVIDER_NAME))
- {
- properties.SetString(NativeMethods.MESSAGE_PROPID_PROV_NAME, new byte[DefaultCryptographicProviderNameSize * 2]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_PROV_NAME_LEN, DefaultCryptographicProviderNameSize);
- }
- if (0 != (data & MessagePropertyFilter.CRYPTOGRAPHIC_PROVIDER_TYPE))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_PROV_TYPE, 0);
- if (0 != (data & MessagePropertyFilter.IS_RECOVERABLE))
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_DELIVERY, (byte)0);
- if (0 != (data & MessagePropertyFilter.DESTINATION_QUEUE))
- {
- properties.SetString(NativeMethods.MESSAGE_PROPID_DEST_QUEUE, new byte[DefaultQueueNameSize * 2]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_DEST_QUEUE_LEN, DefaultQueueNameSize);
- }
- if (0 != (data & MessagePropertyFilter.DIGITAL_SIGNATURE))
- {
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SIGNATURE, new byte[DefaultDigitalSignatureSize]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_SIGNATURE_LEN, DefaultDigitalSignatureSize);
- }
- if (0 != (data & MessagePropertyFilter.ENCRYPTION_ALGORITHM))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_ENCRYPTION_ALG, 0);
- if (0 != (data & MessagePropertyFilter.EXTENSION))
- {
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_EXTENSION, new byte[filter.extensionSize]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_EXTENSION_LEN, filter.extensionSize);
- }
- if (0 != (data & MessagePropertyFilter.FOREIGN_ADMIN_QUEUE))
- {
- properties.SetString(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE, new byte[DefaultQueueNameSize * 2]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE_LEN, DefaultQueueNameSize);
- }
- if (0 != (data & MessagePropertyFilter.HASH_ALGORITHM))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_HASH_ALG, 0);
- if (0 != (data & MessagePropertyFilter.IS_FIRST_IN_TRANSACTION))
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_FIRST_IN_XACT, (byte)0);
- if (0 != (data & MessagePropertyFilter.IS_LAST_IN_TRANSACTION))
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_LAST_IN_XACT, (byte)0);
- if (0 != (data & MessagePropertyFilter.PRIORITY))
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_PRIORITY, (byte)0);
- if (0 != (data & MessagePropertyFilter.SENDER_CERTIFICATE))
- {
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SENDER_CERT, new byte[DefaultSenderCertificateSize]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENDER_CERT_LEN, DefaultSenderCertificateSize);
- }
- if (0 != (data & MessagePropertyFilter.SENDER_ID))
- {
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SENDERID, new byte[DefaultSenderIdSize]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENDERID_LEN, DefaultSenderIdSize);
- }
- if (0 != (data & MessagePropertyFilter.SENT_TIME))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENTTIME, 0);
- if (0 != (data & MessagePropertyFilter.SOURCE_MACHINE))
- properties.SetGuid(NativeMethods.MESSAGE_PROPID_SRC_MACHINE_ID, new byte[GenericIdSize]);
- if (0 != (data & MessagePropertyFilter.SYMMETRIC_KEY))
- {
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY, new byte[DefaultSymmetricKeySize]);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY_LEN, DefaultSymmetricKeySize);
- }
- if (0 != (data & MessagePropertyFilter.TIME_TO_BE_RECEIVED))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_TIME_TO_BE_RECEIVED, 0);
- if (0 != (data & MessagePropertyFilter.TIME_TO_REACH_QUEUE))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_TIME_TO_REACH_QUEUE, 0);
- if (0 != (data & MessagePropertyFilter.TRANSACTION_ID))
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_XACTID, new byte[MessageIdSize]);
- if (0 != (data & MessagePropertyFilter.USE_AUTHENTICATION))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_AUTH_LEVEL, 0);
- if (0 != (data & MessagePropertyFilter.USE_ENCRYPTION))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_PRIV_LEVEL, 0);
- if (0 != (data & MessagePropertyFilter.USE_TRACING))
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_TRACE, (byte)0);
- if (0 != (data & MessagePropertyFilter.VERSION))
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_VERSION, 0);
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Acknowledgment"]/*' />
- /// <devdoc>
- /// <para>Gets the classification
- /// of acknowledgment messages that Message Queuing posts.</para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgAcknowledgement)]
- public Acknowledgment Acknowledgment
- {
- get
- {
- if (!this.filter.Acknowledgment)
- {
- //This message cannot be an acknowledgment, because it has not been sent.
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.NotAcknowledgement));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "Acknowledgment"));
- }
- //Casting unsigned short to int, mask off sign extension.
- int res = ((int)properties.GetUI2(NativeMethods.MESSAGE_PROPID_CLASS)) & 0x0000FFFF;
- return (Acknowledgment)res;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.AcknowledgeType"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the type of acknowledgment
- /// message requested
- /// from
- /// Message Queuing when a message arrives in the queue.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgAcknowledgeType)]
- public AcknowledgeTypes AcknowledgeType
- {
- get
- {
- if (!this.filter.AcknowledgeType)
- {
- //Return the default.
- if (!receiveCreated)
- return AcknowledgeTypes.None;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "AcknowledgeType"));
- }
- return (AcknowledgeTypes)this.properties.GetUI1(NativeMethods.MESSAGE_PROPID_ACKNOWLEDGE);
- }
- set
- {
- //If default
- if (value == AcknowledgeTypes.None)
- {
- this.filter.AcknowledgeType = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_ACKNOWLEDGE);
- }
- else
- {
- this.filter.AcknowledgeType = true;
- this.properties.SetUI1(NativeMethods.MESSAGE_PROPID_ACKNOWLEDGE, (byte)value);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.AdministrationQueue"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the queue used for acknowledgment
- /// messages.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgAdministrationQueue)]
- public MessageQueue AdministrationQueue
- {
- get
- {
- if (!this.filter.AdministrationQueue)
- {
- //This property has not been set, lets return an undefined value.
- if (!receiveCreated)
- return null;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "AdministrationQueue"));
- }
- if (this.cachedAdminQueue == null)
- {
- if (properties.GetUI4(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE_LEN) != 0)
- {
- string queueFormatName = StringFromBytes(properties.GetString(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE),
- properties.GetUI4(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE_LEN));
- this.cachedAdminQueue = new MessageQueue("FORMATNAME:" + queueFormatName);
- }
- }
- return this.cachedAdminQueue;
- }
- set
- {
- if (value != null)
- this.filter.AdministrationQueue = true;
- else
- {
- //If default
- if (this.filter.AdministrationQueue)
- {
- this.filter.AdministrationQueue = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE);
- properties.Remove(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE_LEN);
- }
- }
- this.cachedAdminQueue = value;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.AppSpecific"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets
- /// application-generated information regarding the message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgAppSpecific)]
- public int AppSpecific
- {
- get
- {
- if (!this.filter.AppSpecific)
- {
- //Return the default.
- if (!receiveCreated)
- return 0;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "AppSpecific"));
- }
- return properties.GetUI4(NativeMethods.MESSAGE_PROPID_APPSPECIFIC);
- }
- set
- {
- //If default
- if (value == 0)
- {
- this.filter.AppSpecific = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_APPSPECIFIC);
- }
- else
- {
- this.filter.AppSpecific = true;
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_APPSPECIFIC, value);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.ArrivedTime"]/*' />
- /// <devdoc>
- /// Indicates when the message arrived at the queue.
- /// </devdoc>
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgArrivedTime)]
- public DateTime ArrivedTime
- {
- get
- {
- if (!this.filter.ArrivedTime)
- {
- //Undefined at this point, throw an exception.
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.ArrivedTimeNotSet));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "ArrivedTime"));
- }
- //Number of seconds ellapsed since 1/1/1970
- DateTime time = new DateTime(1970, 1, 1);
- time = time.AddSeconds(properties.GetUI4(NativeMethods.MESSAGE_PROPID_ARRIVEDTIME)).ToLocalTime();
- return time;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.AttachSenderId"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets a value indicating whether the sender ID is to be attached
- /// to the message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgAttachSenderId)]
- public bool AttachSenderId
- {
- get
- {
- if (!this.filter.AttachSenderId)
- {
- //SenderId is attached by default.
- if (!receiveCreated)
- return true;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "AttachSenderId"));
- }
- int type = properties.GetUI4(NativeMethods.MESSAGE_PROPID_SENDERID_TYPE);
- if (type == NativeMethods.MESSAGE_SENDERID_TYPE_NONE)
- return false;
- return true;
- }
- set
- {
- //If default.
- if (value)
- {
- this.filter.AttachSenderId = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_SENDERID_TYPE);
- }
- else
- {
- this.filter.AttachSenderId = true;
- if (value)
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENDERID_TYPE, NativeMethods.MESSAGE_SENDERID_TYPE_SID);
- else
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENDERID_TYPE, NativeMethods.MESSAGE_SENDERID_TYPE_NONE);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Authenticated"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets a value indicating whether the message was
- /// authenticated.
- /// </para>
- /// </devdoc>
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgAuthenticated)]
- public bool Authenticated
- {
- get
- {
- if (!this.filter.Authenticated)
- {
- //Authentication is undefined, there is nothing to return here.
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.AuthenticationNotSet));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "Authenticated"));
- }
- return (properties.GetUI1(NativeMethods.MESSAGE_PROPID_AUTHENTICATED) != 0);
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.AuthenticationProviderName"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the name of the cryptographic
- /// provider used to generate the digital signature of the message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgAuthenticationProviderName)]
- public string AuthenticationProviderName
- {
- get
- {
- if (!this.filter.AuthenticationProviderName)
- {
- //Return default
- if (!receiveCreated)
- return "Microsoft Base Cryptographic Provider, Ver. 1.0";
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "AuthenticationProviderName"));
- }
- if (this.properties.GetUI4(NativeMethods.MESSAGE_PROPID_PROV_NAME_LEN) != 0)
- return StringFromBytes(this.properties.GetString(NativeMethods.MESSAGE_PROPID_PROV_NAME),
- properties.GetUI4(NativeMethods.MESSAGE_PROPID_PROV_NAME_LEN));
- else
- return "";
- }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
- //Should not remove if default, the default value might change in future MQ clients
- //if (value.CompareTo("Microsoft Base Cryptographic Provider, Ver. 1.0") == 0) {
- // this.filter.AuthenticationProviderName = false;
- // properties.Remove(NativeMethods.MESSAGE_PROPID_PROV_NAME);
- // properties.Remove(NativeMethods.MESSAGE_PROPID_PROV_NAME_LEN);
- //}
- //else {
- this.filter.AuthenticationProviderName = true;
- properties.SetString(NativeMethods.MESSAGE_PROPID_PROV_NAME, StringToBytes(value));
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_PROV_NAME_LEN, value.Length);
- //}
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.AuthenticationProviderType"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the type of cryptographic provider used to
- /// generate the digital signature of the
- /// message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgAuthenticationProviderType)]
- public CryptographicProviderType AuthenticationProviderType
- {
- get
- {
- //Return default
- if (!this.filter.AuthenticationProviderType)
- {
- if (!receiveCreated)
- return CryptographicProviderType.RsaFull;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "AuthenticationProviderType"));
- }
- return (CryptographicProviderType)properties.GetUI4(NativeMethods.MESSAGE_PROPID_PROV_TYPE);
- }
- set
- {
- if (!ValidationUtility.ValidateCryptographicProviderType(value))
- throw new InvalidEnumArgumentException("value", (int)value, typeof(CryptographicProviderType));
- //Should not remove if default, the default value might change in future MQ clients
- //if (value == CryptographicProviderType.RsaFull) {
- // this.filter.AuthenticationProviderType = false;
- // properties.Remove(NativeMethods.MESSAGE_PROPID_PROV_TYPE);
- //}
- //else {
- this.filter.AuthenticationProviderType = true;
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_PROV_TYPE, (int)value);
- //}
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Body"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets
- /// or sets the serialized
- /// contents of the message.
- /// </para>
- /// </devdoc>
- [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public object Body
- {
- get
- {
- if (!this.filter.Body)
- {
- if (!receiveCreated)
- return null;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "Body"));
- }
- if (this.cachedBodyObject == null)
- {
- if (this.Formatter == null)
- throw new InvalidOperationException(Res.GetString(Res.FormatterMissing));
- this.cachedBodyObject = this.Formatter.Read(this);
- }
- return this.cachedBodyObject;
- }
- set
- {
- this.filter.Body = true;
- this.cachedBodyObject = value;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.BodyStream"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the information in the body of
- /// the message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true),
- DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
- Editor("System.ComponentModel.Design.BinaryEditor, " + AssemblyRef.SystemDesign, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
- MessagingDescription(Res.MsgBodyStream)]
- public Stream BodyStream
- {
- get
- {
- if (!this.filter.Body)
- {
- if (!receiveCreated)
- {
- this.filter.Body = true;
- if (this.cachedBodyStream == null)
- this.cachedBodyStream = new MemoryStream();
- return this.cachedBodyStream;
- }
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "Body"));
- }
- if (this.cachedBodyStream == null)
- this.cachedBodyStream = new MemoryStream(properties.GetUI1Vector(NativeMethods.MESSAGE_PROPID_BODY),
- 0, properties.GetUI4(NativeMethods.MESSAGE_PROPID_BODY_SIZE));
- return this.cachedBodyStream;
- }
- set
- {
- if (value != null)
- this.filter.Body = true;
- else
- {
- this.filter.Body = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_BODY);
- properties.Remove(NativeMethods.MESSAGE_PROPID_BODY_TYPE);
- properties.Remove(NativeMethods.MESSAGE_PROPID_BODY_SIZE);
- }
- this.cachedBodyStream = value;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.BodyType"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets
- /// or sets the type of data the message body contains.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgBodyType)]
- public int BodyType
- {
- get
- {
- if (!this.filter.Body)
- {
- //Return default.
- if (!receiveCreated)
- return 0;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "Body"));
- }
- return this.properties.GetUI4(NativeMethods.MESSAGE_PROPID_BODY_TYPE);
- }
- set
- {
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_BODY_TYPE, value);
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.ConnectorType"]/*' />
- /// <devdoc>
- /// <para>
- /// Is required whenever an application sets a message property that is
- /// typically set by MSMQ. It is typically used in the following two cases.
- /// Whenever a message is passed by a connector application, the connector
- /// type is required so that the sending and receiving applications know how
- /// to interpret the security and acknowledgment properties of the messages.
- /// When sending application-encrypted messages, this property tells the
- /// MSMQ run time to use the symmetric key.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgConnectorType)]
- public Guid ConnectorType
- {
- get
- {
- if (!this.filter.ConnectorType)
- {
- //Return default.
- if (!receiveCreated)
- return Guid.Empty;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "ConnectorType"));
- }
- return new Guid(this.properties.GetGuid(NativeMethods.MESSAGE_PROPID_CONNECTOR_TYPE));
- }
- set
- {
- //If default
- if (value.Equals(Guid.Empty))
- {
- this.filter.ConnectorType = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_CONNECTOR_TYPE);
- }
- else
- {
- this.filter.ConnectorType = true;
- properties.SetGuid(NativeMethods.MESSAGE_PROPID_CONNECTOR_TYPE, ((Guid)value).ToByteArray());
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.CorrelationId"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the message identifier used by
- /// acknowledgment and report messages to reference the original
- /// message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgCorrelationId)]
- public string CorrelationId
- {
- get
- {
- if (!this.filter.CorrelationId)
- {
- //Return default
- if (!receiveCreated)
- return String.Empty;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "CorrelationId"));
- }
- return IdFromByteArray(this.properties.GetUI1Vector(NativeMethods.MESSAGE_PROPID_CORRELATIONID));
- }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
- //If default
- if (value.Length == 0)
- {
- this.filter.CorrelationId = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_CORRELATIONID);
- }
- else
- {
- this.filter.CorrelationId = true;
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_CORRELATIONID, IdToByteArray(value));
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.DefaultBodySize"]/*' />
- /// <devdoc>
- /// The default body buffer size to create,
- /// when the message is received.
- /// </devdoc>
- [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- private int DefaultBodySize
- {
- get
- {
- return this.filter.DefaultBodySize;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.DefaultExtensionSize"]/*' />
- /// <devdoc>
- /// The default extension buffer size to create,
- /// when the message is received.
- /// </devdoc>
- [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- private int DefaultExtensionSize
- {
- get
- {
- return this.filter.DefaultExtensionSize;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.DefaultLabelSize"]/*' />
- /// <devdoc>
- /// The default label buffer size to create,
- /// when the message is received.
- /// </devdoc>
- [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- private int DefaultLabelSize
- {
- get
- {
- return this.filter.DefaultLabelSize;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.DestinationQueue"]/*' />
- /// <devdoc>
- /// <para>
- /// Identifies the original destination queue for a message. It is typically
- /// used to determine the original destination of a message that is in a journal
- /// or dead-letter queue, however it can also be used when sending a
- /// response message back to a response queue.
- /// </para>
- /// </devdoc>
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgDestinationQueue)]
- public MessageQueue DestinationQueue
- {
- get
- {
- if (!this.filter.DestinationQueue)
- {
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.DestinationQueueNotSet));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "DestinationQueue"));
- }
- if (this.cachedDestinationQueue == null)
- {
- if (this.properties.GetUI4(NativeMethods.MESSAGE_PROPID_DEST_QUEUE_LEN) != 0)
- {
- string queueFormatName = StringFromBytes(properties.GetString(NativeMethods.MESSAGE_PROPID_DEST_QUEUE),
- properties.GetUI4(NativeMethods.MESSAGE_PROPID_DEST_QUEUE_LEN));
- this.cachedDestinationQueue = new MessageQueue("FORMATNAME:" + queueFormatName);
- }
- }
- return this.cachedDestinationQueue;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.DestinationSymmetricKey"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets
- /// or sets the symmetric key used to encrypt messages.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
- MessagingDescription(Res.MsgDestinationSymmetricKey)]
- [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
- [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
- public byte[] DestinationSymmetricKey
- {
- get
- {
- if (!this.filter.DestinationSymmetricKey)
- {
- if (!receiveCreated)
- return new byte[0];
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "DestinationSymmetricKey"));
- }
- byte[] bytes = new byte[properties.GetUI4(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY_LEN)];
- Array.Copy(properties.GetUI1Vector(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY), bytes, bytes.Length);
- return bytes;
- }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
- //If default
- if (value.Length == 0)
- {
- this.filter.DestinationSymmetricKey = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY);
- properties.Remove(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY_LEN);
- }
- else
- {
- this.filter.DestinationSymmetricKey = true;
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY, value);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY_LEN, value.Length);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.DigitalSignature"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or
- /// sets the digital signature used to authenticate
- /// the message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgDigitalSignature)]
- [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
- [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
- public byte[] DigitalSignature
- {
- get
- {
- if (!this.filter.DigitalSignature)
- {
- if (!receiveCreated)
- return new byte[0];
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "DigitalSignature"));
- }
- byte[] bytes = new byte[properties.GetUI4(NativeMethods.MESSAGE_PROPID_SIGNATURE_LEN)];
- Array.Copy(properties.GetUI1Vector(NativeMethods.MESSAGE_PROPID_SIGNATURE), bytes, bytes.Length);
- return bytes;
- }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
- if (value.Length == 0)
- {
- this.filter.DigitalSignature = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_SIGNATURE);
- properties.Remove(NativeMethods.MESSAGE_PROPID_SIGNATURE_LEN);
- }
- else
- {
- this.filter.DigitalSignature = true;
- this.filter.UseAuthentication = true;
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SIGNATURE, value);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_SIGNATURE_LEN, value.Length);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.EncryptionAlgorithm"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the encryption algorithm used to encrypt the
- /// body of a private message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgEncryptionAlgorithm)]
- public EncryptionAlgorithm EncryptionAlgorithm
- {
- get
- {
- if (!this.filter.EncryptionAlgorithm)
- {
- //Return default.
- if (!receiveCreated)
- return EncryptionAlgorithm.Rc2;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "EncryptionAlgorithm"));
- }
- return (EncryptionAlgorithm)properties.GetUI4(NativeMethods.MESSAGE_PROPID_ENCRYPTION_ALG);
- }
- set
- {
- if (!ValidationUtility.ValidateEncryptionAlgorithm(value))
- throw new InvalidEnumArgumentException("value", (int)value, typeof(EncryptionAlgorithm));
- //Should not remove if default, the default value might change in future MQ clients
- //if (value == EncryptionAlgorithm.Rc2) {
- // this.filter.EncryptionAlgorithm = false;
- // properties.Remove(NativeMethods.MESSAGE_PROPID_ENCRYPTION_ALG);
- //}
- //else {
- this.filter.EncryptionAlgorithm = true;
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_ENCRYPTION_ALG, (int)value);
- //}
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Extension"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets
- /// additional information associated with the message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
- MessagingDescription(Res.MsgExtension)]
- [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
- [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
- public byte[] Extension
- {
- get
- {
- if (!this.filter.Extension)
- {
- //Return default.
- if (!receiveCreated)
- return new byte[0];
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "Extension"));
- }
- byte[] bytes = new byte[properties.GetUI4(NativeMethods.MESSAGE_PROPID_EXTENSION_LEN)];
- Array.Copy(properties.GetUI1Vector(NativeMethods.MESSAGE_PROPID_EXTENSION), bytes, bytes.Length);
- return bytes;
- }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
- //If default
- if (value.Length == 0)
- {
- this.filter.Extension = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_EXTENSION);
- properties.Remove(NativeMethods.MESSAGE_PROPID_EXTENSION_LEN);
- }
- else
- {
- this.filter.Extension = true;
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_EXTENSION, value);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_EXTENSION_LEN, value.Length);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Formatter"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets
- /// the formatter used to read or write an object into the message
- /// body.
- /// </para>
- /// </devdoc>
- [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public IMessageFormatter Formatter
- {
- get
- {
- return this.cachedFormatter;
- }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
- this.cachedFormatter = value;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.HashAlgorithm"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the hashing
- /// algorithm used when authenticating messages.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgHashAlgorithm)]
- public HashAlgorithm HashAlgorithm
- {
- get
- {
- if (!this.filter.HashAlgorithm)
- {
- //This property has not been set, lets return an empty queue.
- if (!receiveCreated)
- {
- /*
- if (LocalAppContextSwitches.UseMD5ForDefaultHashAlgorithm)
- {
-
- }
- return HashAlgorithm.Sha512;
- */
- return HashAlgorithm.Md5;
- }
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "HashAlgorithm"));
- }
- return (HashAlgorithm)properties.GetUI4(NativeMethods.MESSAGE_PROPID_HASH_ALG);
- }
- set
- {
- if (!ValidationUtility.ValidateHashAlgorithm(value))
- throw new InvalidEnumArgumentException("value", (int)value, typeof(HashAlgorithm));
- //Should not remove if default since MQ3.0 changed the default algorithm
- //if (value == HashAlgorithm.Md5) {
- // this.filter.HashAlgorithm = false;
- // properties.Remove(NativeMethods.MESSAGE_PROPID_HASH_ALG);
- //}
- //else {
- this.filter.HashAlgorithm = true;
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_HASH_ALG, (int)value);
- //}
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Id"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets
- /// the Message Queuing-generated identifier of the message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgId)]
- public string Id
- {
- get
- {
- if (!this.filter.Id)
- {
- //The Id is undefined at this point
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.IdNotSet));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "Id"));
- }
- return IdFromByteArray(this.properties.GetUI1Vector(NativeMethods.MESSAGE_PROPID_MSGID));
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.IsFirstInTransaction"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets a value indicating
- /// whether the message was the first message sent in a transaction.
- /// </para>
- /// </devdoc>
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgIsFirstInTransaction)]
- public bool IsFirstInTransaction
- {
- get
- {
- if (!this.filter.IsFirstInTransaction)
- {
- if (!receiveCreated)
- return false;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "IsFirstInTransaction"));
- }
- return (properties.GetUI1(NativeMethods.MESSAGE_PROPID_FIRST_IN_XACT) != 0);
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.IsLastInTransaction"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets a value indicating whether the message was
- /// the last message sent in a transaction.
- /// </para>
- /// </devdoc>
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgIsLastInTransaction)]
- public bool IsLastInTransaction
- {
- get
- {
- if (!this.filter.IsLastInTransaction)
- {
- if (!receiveCreated)
- return false;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "IsLastInTransaction"));
- }
- return (properties.GetUI1(NativeMethods.MESSAGE_PROPID_LAST_IN_XACT) != 0);
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Label"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the message label.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgLabel)]
- public string Label
- {
- get
- {
- if (!this.filter.Label)
- {
- //Return default
- if (!receiveCreated)
- return String.Empty;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "Label"));
- }
- if (properties.GetUI4(NativeMethods.MESSAGE_PROPID_LABEL_LEN) != 0)
- return StringFromBytes(this.properties.GetString(NativeMethods.MESSAGE_PROPID_LABEL),
- properties.GetUI4(NativeMethods.MESSAGE_PROPID_LABEL_LEN));
- else
- return "";
- }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
- //If default
- if (value.Length == 0)
- {
- this.filter.Label = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_LABEL);
- properties.Remove(NativeMethods.MESSAGE_PROPID_LABEL_LEN);
- }
- else
- {
- this.filter.Label = true;
- properties.SetString(NativeMethods.MESSAGE_PROPID_LABEL, StringToBytes(value));
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_LABEL_LEN, value.Length);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.LookupId"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets the Message Queue-generated lookup identifier of the message.
- /// </para>
- /// </devdoc>
- public long LookupId
- {
- get
- {
- if (!MessageQueue.Msmq3OrNewer)
- throw new PlatformNotSupportedException(Res.GetString(Res.PlatformNotSupported));
- if (!this.filter.LookupId)
- {
- //Return default
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.LookupIdNotSet));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "LookupId"));
- }
- return this.properties.GetUI8(NativeMethods.MESSAGE_PROPID_LOOKUPID);
- }
- }
- internal void SetLookupId(long value)
- {
- this.filter.LookupId = true;
- this.properties.SetUI8(NativeMethods.MESSAGE_PROPID_LOOKUPID, value);
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.MessageType"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets the type of the message (normal, acknowledgment, or report).
- /// </para>
- /// </devdoc>
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgMessageType)]
- public MessageType MessageType
- {
- get
- {
- if (!this.filter.MessageType)
- {
- //Return default
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.MessageTypeNotSet));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "MessageType"));
- }
- int cls = properties.GetUI2(NativeMethods.MESSAGE_PROPID_CLASS);
- if (cls == NativeMethods.MESSAGE_CLASS_NORMAL)
- return MessageType.Normal;
- if (cls == NativeMethods.MESSAGE_CLASS_REPORT)
- return MessageType.Report;
- return MessageType.Acknowledgment;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Priority"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the message priority, used to determine
- /// where the
- /// message is placed in the
- /// queue.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgPriority)]
- public MessagePriority Priority
- {
- get
- {
- if (!this.filter.Priority)
- {
- //Return default
- if (!receiveCreated)
- return MessagePriority.Normal;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "Priority"));
- }
- return (MessagePriority)properties.GetUI1(NativeMethods.MESSAGE_PROPID_PRIORITY);
- }
- set
- {
- if (!ValidationUtility.ValidateMessagePriority(value))
- throw new InvalidEnumArgumentException("value", (int)value, typeof(MessagePriority));
- //If default
- if (value == MessagePriority.Normal)
- {
- this.filter.Priority = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_PRIORITY);
- }
- else
- {
- this.filter.Priority = true;
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_PRIORITY, (byte)value);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Recoverable"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets a value
- /// indicating whether the message is guaranteed to be delivered in the event of
- /// a computer failure or network problem.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgRecoverable)]
- public bool Recoverable
- {
- get
- {
- if (!this.filter.Recoverable)
- {
- //Return default
- if (!receiveCreated)
- return false;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "Recoverable"));
- }
- return properties.GetUI1(NativeMethods.MESSAGE_PROPID_DELIVERY) == NativeMethods.MESSAGE_DELIVERY_RECOVERABLE;
- }
- set
- {
- //If default
- if (!value)
- {
- this.filter.Recoverable = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_DELIVERY);
- }
- else
- {
- this.filter.Recoverable = true;
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_DELIVERY, (byte)NativeMethods.MESSAGE_DELIVERY_RECOVERABLE);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.ResponseQueue"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the queue which receives application-generated
- /// response messages.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgResponseQueue)]
- public MessageQueue ResponseQueue
- {
- get
- {
- if (!this.filter.ResponseQueue)
- {
- //This property has not been set, lets return an undefined value.
- if (!receiveCreated)
- return null;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "ResponseQueue"));
- }
- if (this.cachedResponseQueue == null)
- {
- if (properties.GetUI4(NativeMethods.MESSAGE_PROPID_RESP_QUEUE_LEN) != 0)
- {
- string queueFormatName = StringFromBytes(properties.GetString(NativeMethods.MESSAGE_PROPID_RESP_QUEUE),
- properties.GetUI4(NativeMethods.MESSAGE_PROPID_RESP_QUEUE_LEN));
- this.cachedResponseQueue = new MessageQueue("FORMATNAME:" + queueFormatName);
- }
- }
- return this.cachedResponseQueue;
- }
- set
- {
- //If default
- if (value != null)
- this.filter.ResponseQueue = true;
- else
- {
- if (this.filter.ResponseQueue)
- {
- this.filter.ResponseQueue = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_RESP_QUEUE);
- properties.Remove(NativeMethods.MESSAGE_PROPID_RESP_QUEUE_LEN);
- }
- }
- this.cachedResponseQueue = value;
- }
- }
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public SecurityContext SecurityContext
- {
- get
- {
- if (!this.filter.SecurityContext)
- return null;
- IntPtr handle = (IntPtr)(int)properties.GetUI4(NativeMethods.MESSAGE_PROPID_SECURITY_CONTEXT);
- return new SecurityContext(new SecurityContextHandle(handle));
- }
- set
- {
- if (value == null)
- {
- this.filter.SecurityContext = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_SECURITY_CONTEXT);
- }
- else
- {
- this.filter.SecurityContext = true;
- // Can't store IntPtr because property type is UI4, but IntPtr can be 64 bits
- int handle = value.Handle.DangerousGetHandle().ToInt32(); // this is safe because MSMQ always returns 32-bit handle
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_SECURITY_CONTEXT, handle);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.SenderCertificate"]/*' />
- /// <devdoc>
- /// <para>
- /// Specifies the security certificate used to authenticate messages.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgSenderCertificate)]
- [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
- [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
- public byte[] SenderCertificate
- {
- get
- {
- if (!this.filter.SenderCertificate)
- {
- //Return default
- if (!receiveCreated)
- return new byte[0];
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "SenderCertificate"));
- }
- byte[] bytes = new byte[properties.GetUI4(NativeMethods.MESSAGE_PROPID_SENDER_CERT_LEN)];
- Array.Copy(properties.GetUI1Vector(NativeMethods.MESSAGE_PROPID_SENDER_CERT), bytes, bytes.Length);
- return bytes;
- }
- set
- {
- if (value == null)
- throw new ArgumentNullException("value");
- //If default
- if (value.Length == 0)
- {
- this.filter.SenderCertificate = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_SENDER_CERT);
- properties.Remove(NativeMethods.MESSAGE_PROPID_SENDER_CERT_LEN);
- }
- else
- {
- this.filter.SenderCertificate = true;
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SENDER_CERT, value);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENDER_CERT_LEN, value.Length);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.SenderId"]/*' />
- /// <devdoc>
- /// <para>
- /// This property is set by MSMQ, and is used primarily by the
- /// receiving Queue Manager when authenticating a message. The receiving
- /// Queue Manager uses the sender identifier in this property to verify where
- /// the message originated and to verify the sender has access rights to a queue.
- /// </para>
- /// </devdoc>
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgSenderId)]
- [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
- public byte[] SenderId
- {
- get
- {
- if (!this.filter.SenderId)
- {
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.SenderIdNotSet));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "SenderId"));
- }
- byte[] bytes = new byte[properties.GetUI4(NativeMethods.MESSAGE_PROPID_SENDERID_LEN)];
- Array.Copy(properties.GetUI1Vector(NativeMethods.MESSAGE_PROPID_SENDERID), bytes, bytes.Length);
- return bytes;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.SenderVersion"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets the version of Message Queuing used to send the message.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgSenderVersion)]
- public long SenderVersion
- {
- get
- {
- if (!this.filter.SenderVersion)
- {
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.VersionNotSet));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "SenderVersion"));
- }
- return (long)((uint)properties.GetUI4(NativeMethods.MESSAGE_PROPID_VERSION));
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.SentTime"]/*' />
- /// <devdoc>
- /// Indicates the date and time that the message was sent by
- /// the source Queue Manager.
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgSentTime)]
- public DateTime SentTime
- {
- get
- {
- if (!this.filter.SentTime)
- {
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.SentTimeNotSet));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "SentTime"));
- }
- //Number of seconds ellapsed since 1/1/1970
- DateTime time = new DateTime(1970, 1, 1);
- time = time.AddSeconds(properties.GetUI4(NativeMethods.MESSAGE_PROPID_SENTTIME)).ToLocalTime();
- return time;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.SourceMachine"]/*' />
- /// <devdoc>
- /// Specifies the computer where the message originated.
- /// </devdoc>
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgSourceMachine)]
- public string SourceMachine
- {
- get
- {
- if (!this.filter.SourceMachine)
- {
- if (!receiveCreated)
- throw new InvalidOperationException(Res.GetString(Res.SourceMachineNotSet));
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "SourceMachine"));
- }
- if (this.machineName == null)
- {
- byte[] bytes = this.properties.GetGuid(NativeMethods.MESSAGE_PROPID_SRC_MACHINE_ID);
- GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
- MachinePropertyVariants machineProperties = new MachinePropertyVariants();
- machineProperties.SetNull(NativeMethods.MACHINE_PATHNAME);
- int status = UnsafeNativeMethods.MQGetMachineProperties(null, handle.AddrOfPinnedObject(), machineProperties.Lock());
- machineProperties.Unlock();
- handle.Free();
- IntPtr memoryHandle = machineProperties.GetIntPtr(NativeMethods.MACHINE_PATHNAME);
- if (memoryHandle != (IntPtr)0)
- {
- //Using Unicode API even on Win9x
- this.machineName = Marshal.PtrToStringUni(memoryHandle);
- SafeNativeMethods.MQFreeMemory(memoryHandle);
- }
- if (MessageQueue.IsFatalError(status))
- throw new MessageQueueException(status);
- }
- return this.machineName;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.TimeToBeReceived"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or
- /// sets the time limit for the message to be retrieved from the target
- /// queue.
- /// </para>
- /// </devdoc>
- [ReadOnly(true),
- DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
- TypeConverter(typeof(System.Messaging.Design.TimeoutConverter)),
- MessagingDescription(Res.MsgTimeToBeReceived)]
- public TimeSpan TimeToBeReceived
- {
- get
- {
- if (!this.filter.TimeToBeReceived)
- {
- //Return default
- if (!receiveCreated)
- return InfiniteTimeout;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "TimeToBeReceived"));
- }
- return TimeSpan.FromSeconds((uint)properties.GetUI4(NativeMethods.MESSAGE_PROPID_TIME_TO_BE_RECEIVED));
- }
- set
- {
- long timeoutInSeconds = (long)value.TotalSeconds;
- if (timeoutInSeconds < 0)
- throw new ArgumentException(Res.GetString(Res.InvalidProperty, "TimeToBeReceived", value.ToString()));
- if (timeoutInSeconds > UInt32.MaxValue)
- timeoutInSeconds = UInt32.MaxValue;
- //If default
- if (timeoutInSeconds == UInt32.MaxValue)
- {
- this.filter.TimeToBeReceived = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_TIME_TO_BE_RECEIVED);
- }
- else
- {
- this.filter.TimeToBeReceived = true;
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_TIME_TO_BE_RECEIVED, (int)((uint)timeoutInSeconds));
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.TimeToReachQueue"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets the time limit for the message to reach
- /// the queue.
- /// </para>
- /// </devdoc>
- [ReadOnly(true),
- DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
- TypeConverter(typeof(System.Messaging.Design.TimeoutConverter)),
- MessagingDescription(Res.MsgTimeToReachQueue)]
- public TimeSpan TimeToReachQueue
- {
- get
- {
- if (!this.filter.TimeToReachQueue)
- {
- //Return default
- if (!receiveCreated)
- return InfiniteTimeout;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "TimeToReachQueue"));
- }
- return TimeSpan.FromSeconds((uint)properties.GetUI4(NativeMethods.MESSAGE_PROPID_TIME_TO_REACH_QUEUE));
- }
- set
- {
- long timeoutInSeconds = (long)value.TotalSeconds;
- if (timeoutInSeconds < 0)
- throw new ArgumentException(Res.GetString(Res.InvalidProperty, "TimeToReachQueue", value.ToString()));
- if (timeoutInSeconds > UInt32.MaxValue)
- timeoutInSeconds = UInt32.MaxValue;
- if (timeoutInSeconds == UInt32.MaxValue)
- {
- this.filter.TimeToReachQueue = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_TIME_TO_REACH_QUEUE);
- }
- else
- {
- this.filter.TimeToReachQueue = true;
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_TIME_TO_REACH_QUEUE, (int)((uint)timeoutInSeconds));
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.TransactionId"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets the
- /// identifier for the transaction of which the message was a part.
- /// </para>
- /// </devdoc>
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgTransactionId)]
- public string TransactionId
- {
- get
- {
- if (!this.filter.TransactionId)
- {
- //Return default
- if (!receiveCreated)
- return String.Empty;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "TransactionId"));
- }
- return IdFromByteArray(this.properties.GetUI1Vector(NativeMethods.MESSAGE_PROPID_XACTID));
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.TransactionStatusQueue"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets the
- /// transaction status queue on the source computer.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgTransactionStatusQueue)]
- public MessageQueue TransactionStatusQueue
- {
- get
- {
- if (!this.filter.TransactionStatusQueue)
- {
- //This property has not been set, lets return an undefined value.
- if (!receiveCreated)
- return null;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "TransactionStatusQueue"));
- }
- if (this.cachedTransactionStatusQueue == null)
- {
- if (this.properties.GetUI4(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE_LEN) != 0)
- {
- string queueFormatName = StringFromBytes(properties.GetString(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE),
- properties.GetUI4(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE_LEN));
- this.cachedTransactionStatusQueue = new MessageQueue("FORMATNAME:" + queueFormatName);
- }
- }
- return this.cachedTransactionStatusQueue;
- }
- set
- {
- //If default
- if (value != null)
- this.filter.TransactionStatusQueue = true;
- else
- {
- if (this.filter.TransactionStatusQueue)
- {
- this.filter.TransactionStatusQueue = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE);
- properties.Remove(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE_LEN);
- }
- }
- this.cachedTransactionStatusQueue = value;
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.UseAuthentication"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets
- /// or sets a value indicating whether a message must be authenticated.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgUseAuthentication)]
- public bool UseAuthentication
- {
- get
- {
- if (!this.filter.UseAuthentication)
- {
- //Return default
- if (!receiveCreated)
- {
- // Actually, we dont know what default is:
- // Algorithm to determine whether or not messages
- // should be authenticated by default is non-trivial
- // and should not be reproduced in System.Messaging.
- //
- // One idea is to add a new native API,
- // MQGetDefaultPropertyValue, to retrieve default values.
- // (Microsoft, Nov 3 2004)
- return false;
- }
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "UseAuthentication"));
- }
- return (properties.GetUI4(NativeMethods.MESSAGE_PROPID_AUTH_LEVEL) != NativeMethods.MESSAGE_AUTHENTICATION_LEVEL_NONE);
- }
- set
- {
- //default is different on different versions of MSMQ,
- //so dont make any assumptions and explicitly pass what user requested
- this.filter.UseAuthentication = true;
- if (!value)
- {
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_AUTH_LEVEL, NativeMethods.MESSAGE_AUTHENTICATION_LEVEL_NONE);
- }
- else
- {
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_AUTH_LEVEL, NativeMethods.MESSAGE_AUTHENTICATION_LEVEL_ALWAYS);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.UseDeadLetterQueue"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets a value indicating whether
- /// a copy of an undeliverable message should be sent to a dead-letter queue.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgUseDeadLetterQueue)]
- public bool UseDeadLetterQueue
- {
- get
- {
- if (!this.filter.UseDeadLetterQueue)
- {
- //Return default
- if (!receiveCreated)
- return false;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "UseDeadLetterQueue"));
- }
- return ((properties.GetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL) & NativeMethods.MESSAGE_JOURNAL_DEADLETTER) != 0);
- }
- set
- {
- //If Default
- if (!value)
- {
- if (this.filter.UseDeadLetterQueue)
- {
- this.filter.UseDeadLetterQueue = false;
- if (!this.filter.UseJournalQueue)
- properties.Remove(NativeMethods.MESSAGE_PROPID_JOURNAL);
- else
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL, (byte)(properties.GetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL) & ~NativeMethods.MESSAGE_JOURNAL_DEADLETTER));
- }
- }
- else
- {
- if (!this.filter.UseDeadLetterQueue && !this.filter.UseJournalQueue)
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL, (byte)NativeMethods.MESSAGE_JOURNAL_DEADLETTER);
- else
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL, (byte)(properties.GetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL) | NativeMethods.MESSAGE_JOURNAL_DEADLETTER));
- this.filter.UseDeadLetterQueue = true;
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.UseEncryption"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets a value indicating whether to encrypt messages.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgUseEncryption)]
- public bool UseEncryption
- {
- get
- {
- if (!this.filter.UseEncryption)
- {
- //Return default
- if (!receiveCreated)
- return false;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "UseEncryption"));
- }
- return (properties.GetUI4(NativeMethods.MESSAGE_PROPID_PRIV_LEVEL) != NativeMethods.MESSAGE_PRIVACY_LEVEL_NONE);
- }
- set
- {
- //If default
- if (!value)
- {
- this.filter.UseEncryption = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_PRIV_LEVEL);
- }
- else
- {
- this.filter.UseEncryption = true;
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_PRIV_LEVEL, NativeMethods.MESSAGE_PRIVACY_LEVEL_BODY);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.UseJournalQueue"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or sets a value indicating whether a copy of the message should be kept in a machine
- /// journal on the originating computer.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgUseJournalQueue)]
- public bool UseJournalQueue
- {
- get
- {
- if (!this.filter.UseJournalQueue)
- {
- //Return default
- if (!receiveCreated)
- return false;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "UseJournalQueue"));
- }
- return ((properties.GetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL) & NativeMethods.MESSAGE_JOURNAL_JOURNAL) != 0);
- }
- set
- {
- //If Default
- if (!value)
- {
- if (this.filter.UseJournalQueue)
- {
- this.filter.UseJournalQueue = false;
- if (!this.filter.UseDeadLetterQueue)
- properties.Remove(NativeMethods.MESSAGE_PROPID_JOURNAL);
- else
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL, (byte)(properties.GetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL) & ~NativeMethods.MESSAGE_JOURNAL_JOURNAL));
- }
- }
- else
- {
- if (!this.filter.UseDeadLetterQueue && !this.filter.UseJournalQueue)
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL, (byte)NativeMethods.MESSAGE_JOURNAL_JOURNAL);
- else
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL, (byte)(properties.GetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL) | NativeMethods.MESSAGE_JOURNAL_JOURNAL));
- this.filter.UseJournalQueue = true;
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.UseTracing"]/*' />
- /// <devdoc>
- /// <para>
- /// Gets or
- /// sets a value indicating whether to trace a message as
- /// it moves toward its destination queue.
- /// </para>
- /// </devdoc>
- [ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MessagingDescription(Res.MsgUseTracing)]
- public bool UseTracing
- {
- get
- {
- if (!this.filter.UseTracing)
- {
- //Return default
- if (!receiveCreated)
- return false;
- throw new InvalidOperationException(Res.GetString(Res.MissingProperty, "UseTracing"));
- }
- return (properties.GetUI1(NativeMethods.MESSAGE_PROPID_TRACE) != NativeMethods.MESSAGE_TRACE_NONE);
- }
- set
- {
- //If Default
- if (!value)
- {
- this.filter.UseTracing = false;
- properties.Remove(NativeMethods.MESSAGE_PROPID_TRACE);
- }
- else
- {
- this.filter.UseTracing = true;
- if (!value)
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_TRACE, (byte)NativeMethods.MESSAGE_TRACE_NONE);
- else
- properties.SetUI1(NativeMethods.MESSAGE_PROPID_TRACE, (byte)NativeMethods.MESSAGE_TRACE_SEND_ROUTE_TO_REPORT_QUEUE);
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.AdjustMemory"]/*' />
- /// <internalonly/>
- internal void AdjustMemory()
- {
- if (filter.AdministrationQueue)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE_LEN);
- if (size > Message.DefaultQueueNameSize)
- properties.SetString(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE, new byte[size * 2]);
- }
- if (filter.Body)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_BODY_SIZE);
- if (size > DefaultBodySize)
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_BODY, new byte[size]);
- }
- if (filter.AuthenticationProviderName)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_PROV_NAME_LEN);
- if (size > Message.DefaultCryptographicProviderNameSize)
- properties.SetString(NativeMethods.MESSAGE_PROPID_PROV_NAME, new byte[size * 2]);
- }
- if (filter.DestinationQueue)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_DEST_QUEUE_LEN);
- if (size > Message.DefaultQueueNameSize)
- properties.SetString(NativeMethods.MESSAGE_PROPID_DEST_QUEUE, new byte[size * 2]);
- }
- if (filter.Extension)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_EXTENSION_LEN);
- if (size > DefaultExtensionSize)
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_EXTENSION, new byte[size]);
- }
- if (filter.TransactionStatusQueue)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE_LEN);
- if (size > Message.DefaultQueueNameSize)
- properties.SetString(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE, new byte[size * 2]);
- }
- if (filter.Label)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_LABEL_LEN);
- if (size > DefaultLabelSize)
- properties.SetString(NativeMethods.MESSAGE_PROPID_LABEL, new byte[size * 2]);
- }
- if (filter.ResponseQueue)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_RESP_QUEUE_LEN);
- if (size > Message.DefaultQueueNameSize)
- properties.SetString(NativeMethods.MESSAGE_PROPID_RESP_QUEUE, new byte[size * 2]);
- }
- if (filter.SenderCertificate)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_SENDER_CERT_LEN);
- if (size > Message.DefaultSenderCertificateSize)
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SENDER_CERT, new byte[size]);
- }
- if (filter.SenderId)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_SENDERID_LEN);
- if (size > Message.DefaultSenderIdSize)
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SENDERID, new byte[size]);
- }
- if (filter.DestinationSymmetricKey)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY_LEN);
- if (size > Message.DefaultSymmetricKeySize)
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY, new byte[size]);
- }
- if (filter.DigitalSignature)
- {
- int size = properties.GetUI4(NativeMethods.MESSAGE_PROPID_SIGNATURE_LEN);
- if (size > Message.DefaultDigitalSignatureSize)
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SIGNATURE, new byte[size]);
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.AdjustToSend"]/*' />
- /// <internalonly/>
- internal void AdjustToSend()
- {
- //Write cached properties
- string queueFormatName;
- if (this.filter.AdministrationQueue && this.cachedAdminQueue != null)
- {
- queueFormatName = this.cachedAdminQueue.FormatName;
- properties.SetString(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE, StringToBytes(queueFormatName));
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE_LEN, queueFormatName.Length);
- }
- if (this.filter.ResponseQueue && this.cachedResponseQueue != null)
- {
- queueFormatName = this.cachedResponseQueue.FormatName;
- properties.SetString(NativeMethods.MESSAGE_PROPID_RESP_QUEUE, StringToBytes(queueFormatName));
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_RESP_QUEUE_LEN, queueFormatName.Length);
- }
- if (this.filter.TransactionStatusQueue && this.cachedTransactionStatusQueue != null)
- {
- queueFormatName = this.cachedTransactionStatusQueue.FormatName;
- properties.SetString(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE, StringToBytes(queueFormatName));
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE_LEN, queueFormatName.Length);
- }
- if (this.filter.Body && this.cachedBodyObject != null)
- {
- if (this.Formatter == null)
- this.Formatter = new XmlMessageFormatter();
- this.Formatter.Write(this, this.cachedBodyObject);
- }
- if (this.filter.Body && this.cachedBodyStream != null)
- {
- this.cachedBodyStream.Position = 0;
- byte[] bytes = new byte[(int)this.cachedBodyStream.Length];
- this.cachedBodyStream.Read(bytes, 0, bytes.Length);
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_BODY, bytes);
- properties.SetUI4(NativeMethods.MESSAGE_PROPID_BODY_SIZE, bytes.Length);
- }
- if (this.receiveCreated)
- {
- lock (this)
- {
- if (this.receiveCreated)
- {
- //We don't want to send the buffers as they were allocated
- //when receiving, they might be to big.
- //Adjust sizes
- if (this.filter.Body)
- {
- int bodySize = properties.GetUI4(NativeMethods.MESSAGE_PROPID_BODY_SIZE);
- byte[] bodyArray = properties.GetUI1Vector(NativeMethods.MESSAGE_PROPID_BODY);
- Debug.Assert(bodySize <= bodyArray.Length, "Allocated body array size is bigger than BODY_SIZE property");
- if (bodySize < bodyArray.Length)
- { // need to reallocate body array
- byte[] bytes = new byte[bodySize];
- Array.Copy(bodyArray, bytes, bodySize);
- properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_BODY, bytes);
- }
- }
- if (this.filter.Extension)
- {
- this.properties.AdjustSize(NativeMethods.MESSAGE_PROPID_EXTENSION,
- this.properties.GetUI4(NativeMethods.MESSAGE_PROPID_EXTENSION_LEN));
- }
- if (this.filter.SenderCertificate)
- {
- this.properties.AdjustSize(NativeMethods.MESSAGE_PROPID_SENDER_CERT,
- this.properties.GetUI4(NativeMethods.MESSAGE_PROPID_SENDER_CERT_LEN));
- }
- if (this.filter.DestinationSymmetricKey)
- {
- this.properties.AdjustSize(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY,
- this.properties.GetUI4(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY_LEN));
- }
- //Ghost properties.
- if (this.filter.Acknowledgment || this.filter.MessageType)
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_CLASS);
- if (this.filter.ArrivedTime)
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_ARRIVEDTIME);
- if (this.filter.Authenticated)
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_AUTHENTICATED);
- if (this.filter.DestinationQueue)
- {
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_DEST_QUEUE);
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_DEST_QUEUE_LEN);
- this.cachedDestinationQueue = null;
- }
- if (this.filter.IsFirstInTransaction)
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_FIRST_IN_XACT);
- if (this.filter.IsLastInTransaction)
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_LAST_IN_XACT);
- if (this.filter.SenderId)
- {
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_SENDERID);
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_SENDERID_LEN);
- }
- if (this.filter.SentTime)
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_SENTTIME);
- if (this.filter.SourceMachine)
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_SRC_MACHINE_ID);
- if (this.filter.TransactionId)
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_XACTID);
- if (this.filter.SenderVersion)
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_VERSION);
- //Ghost invalid returned properties
- if (this.filter.AdministrationQueue)
- {
- if (properties.GetUI4(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE_LEN) == 0)
- {
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE);
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE_LEN);
- }
- }
- //Encryption algorithm cannot be set if not using Encryption
- if (this.filter.EncryptionAlgorithm)
- {
- if ((this.filter.UseEncryption && !this.UseEncryption) || !this.filter.UseEncryption)
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_ENCRYPTION_ALG);
- }
- if (this.filter.DigitalSignature)
- {
- if (properties.GetUI4(NativeMethods.MESSAGE_PROPID_SIGNATURE_LEN) == 0)
- {
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_SIGNATURE);
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_SIGNATURE_LEN);
- }
- }
- if (this.filter.DestinationSymmetricKey)
- {
- if (properties.GetUI4(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY_LEN) == 0)
- {
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY);
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY_LEN);
- }
- }
- if (this.filter.ResponseQueue)
- {
- if (properties.GetUI4(NativeMethods.MESSAGE_PROPID_RESP_QUEUE_LEN) == 0)
- {
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_RESP_QUEUE);
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_RESP_QUEUE_LEN);
- }
- }
- if (this.filter.TransactionStatusQueue)
- {
- if (properties.GetUI4(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE_LEN) == 0)
- {
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE);
- this.properties.Ghost(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE_LEN);
- }
- }
- this.receiveCreated = false;
- }
- }
- }
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.IdFromByteArray"]/*' />
- /// <internalonly/>
- private string IdFromByteArray(byte[] bytes)
- {
- StringBuilder result = new StringBuilder();
- byte[] guidBytes = new byte[GenericIdSize];
- Array.Copy(bytes, guidBytes, GenericIdSize);
- int id = BitConverter.ToInt32(bytes, GenericIdSize);
- result.Append((new Guid(guidBytes)).ToString());
- result.Append("\\");
- result.Append(id);
- return result.ToString();
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.IdToByteArray"]/*' />
- /// <internalonly/>
- private byte[] IdToByteArray(string id)
- {
- string[] pieces = id.Split(new char[] { '\\' });
- if (pieces.Length != 2)
- throw new InvalidOperationException(Res.GetString(Res.InvalidId));
- Guid guid;
- try
- {
- guid = new Guid(pieces[0]);
- }
- catch (FormatException)
- {
- throw new InvalidOperationException(Res.GetString(Res.InvalidId));
- }
- int integerId;
- try
- {
- integerId = Convert.ToInt32(pieces[1], CultureInfo.InvariantCulture);
- }
- catch (FormatException)
- {
- throw new InvalidOperationException(Res.GetString(Res.InvalidId));
- }
- catch (OverflowException)
- {
- throw new InvalidOperationException(Res.GetString(Res.InvalidId));
- }
- byte[] bytes = new byte[MessageIdSize];
- Array.Copy(guid.ToByteArray(), bytes, GenericIdSize);
- Array.Copy(BitConverter.GetBytes(integerId), 0, bytes, GenericIdSize, 4);
- return bytes;
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Lock"]/*' />
- /// <internalonly/>
- internal MessagePropertyVariants.MQPROPS Lock()
- {
- return this.properties.Lock();
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.StringFromBytes"]/*' />
- /// <internalonly/>
- internal static string StringFromBytes(byte[] bytes, int len)
- {
- //If the string ends with 0, lets trim it.
- if (len != 0 && bytes[len * 2 - 1] == 0 && bytes[len * 2 - 2] == 0)
- --len;
- char[] charBuffer = new char[len];
- Encoding.Unicode.GetChars(bytes, 0, len * 2, charBuffer, 0);
- return new String(charBuffer, 0, len);
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.StringToBytes"]/*' />
- /// <internalonly/>
- internal static byte[] StringToBytes(string value)
- {
- int size = value.Length * 2 + 1;
- byte[] byteBuffer = new byte[size];
- byteBuffer[size - 1] = 0;
- Encoding.Unicode.GetBytes(value.ToCharArray(), 0, value.Length, byteBuffer, 0);
- return byteBuffer;
- }
- /// <include file='doc\Message.uex' path='docs/doc[@for="Message.Unlock"]/*' />
- /// <internalonly/>
- internal void Unlock()
- {
- this.properties.Unlock();
- }
- }
- }
|