Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Messaging / System / Messaging / Interop / Restrictions.cs / 1305376 / Restrictions.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Messaging.Interop { using System.Runtime.InteropServices; using System.Diagnostics; using System; using System.ComponentModel; using Microsoft.Win32; internal class Restrictions { private MQRESTRICTION restrictionStructure; public const int PRLT = 0; public const int PRLE = 1; public const int PRGT = 2; public const int PRGE = 3; public const int PREQ = 4; public const int PRNE = 5; public Restrictions(int maxRestrictions) { this.restrictionStructure = new MQRESTRICTION(maxRestrictions); } public virtual void AddGuid(int propertyId, int op, Guid value) { IntPtr data = Marshal.AllocHGlobal(16); Marshal.Copy(value.ToByteArray(), 0 , data, 16); this.AddItem(propertyId, op, MessagePropertyVariants.VT_CLSID, data); } public virtual void AddGuid(int propertyId, int op) { IntPtr data = Marshal.AllocHGlobal(16); this.AddItem(propertyId, op, MessagePropertyVariants.VT_CLSID, data); } private void AddItem(int id,int op, short vt, IntPtr data) { Marshal.WriteInt32(restrictionStructure.GetNextValidPtr(0) , op); Marshal.WriteInt32(restrictionStructure.GetNextValidPtr(4), id); Marshal.WriteInt16(restrictionStructure.GetNextValidPtr(8), vt); Marshal.WriteInt16(restrictionStructure.GetNextValidPtr(10), (short)0); Marshal.WriteInt16(restrictionStructure.GetNextValidPtr(12), (short)0); Marshal.WriteInt16(restrictionStructure.GetNextValidPtr(14), (short)0); Marshal.WriteIntPtr(restrictionStructure.GetNextValidPtr(16), data); Marshal.WriteIntPtr(restrictionStructure.GetNextValidPtr(16 + IntPtr.Size), (IntPtr)0); ++restrictionStructure.restrictionCount; } public virtual void AddI4(int propertyId, int op, int value) { this.AddItem(propertyId, op, MessagePropertyVariants.VT_I4, (IntPtr)value); } public virtual void AddString(int propertyId, int op, string value) { if (value == null) this.AddItem(propertyId, op, MessagePropertyVariants.VT_NULL, (IntPtr)0); else { IntPtr data = Marshal.StringToHGlobalUni(value); this.AddItem(propertyId, op, MessagePropertyVariants.VT_LPWSTR, data); } } public virtual MQRESTRICTION GetRestrictionsRef() { return this.restrictionStructure; } [StructLayout(LayoutKind.Sequential)] public class MQRESTRICTION { public int restrictionCount; [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] public IntPtr restrinctions; public MQRESTRICTION(int maxCount) { this.restrinctions = Marshal.AllocHGlobal(maxCount * GetRestrictionSize()); } ~MQRESTRICTION() { if (this.restrinctions != (IntPtr)0) { for (int index= 0; index < this.restrictionCount; ++ index) { short vt = Marshal.ReadInt16((IntPtr)((long)this.restrinctions + (index * GetRestrictionSize()) + 8)); if (vt != MessagePropertyVariants.VT_I4) { IntPtr dataPtr = (IntPtr)((long)this.restrinctions + (index * GetRestrictionSize()) + 16); IntPtr data = Marshal.ReadIntPtr(dataPtr); Marshal.FreeHGlobal(data); } } Marshal.FreeHGlobal(this.restrinctions); this.restrinctions = (IntPtr)0; } } public IntPtr GetNextValidPtr(int offset) { return (IntPtr)((long)restrinctions + restrictionCount * GetRestrictionSize() + offset); } public static int GetRestrictionSize() { return 16 + (IntPtr.Size * 2); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Messaging.Interop { using System.Runtime.InteropServices; using System.Diagnostics; using System; using System.ComponentModel; using Microsoft.Win32; internal class Restrictions { private MQRESTRICTION restrictionStructure; public const int PRLT = 0; public const int PRLE = 1; public const int PRGT = 2; public const int PRGE = 3; public const int PREQ = 4; public const int PRNE = 5; public Restrictions(int maxRestrictions) { this.restrictionStructure = new MQRESTRICTION(maxRestrictions); } public virtual void AddGuid(int propertyId, int op, Guid value) { IntPtr data = Marshal.AllocHGlobal(16); Marshal.Copy(value.ToByteArray(), 0 , data, 16); this.AddItem(propertyId, op, MessagePropertyVariants.VT_CLSID, data); } public virtual void AddGuid(int propertyId, int op) { IntPtr data = Marshal.AllocHGlobal(16); this.AddItem(propertyId, op, MessagePropertyVariants.VT_CLSID, data); } private void AddItem(int id,int op, short vt, IntPtr data) { Marshal.WriteInt32(restrictionStructure.GetNextValidPtr(0) , op); Marshal.WriteInt32(restrictionStructure.GetNextValidPtr(4), id); Marshal.WriteInt16(restrictionStructure.GetNextValidPtr(8), vt); Marshal.WriteInt16(restrictionStructure.GetNextValidPtr(10), (short)0); Marshal.WriteInt16(restrictionStructure.GetNextValidPtr(12), (short)0); Marshal.WriteInt16(restrictionStructure.GetNextValidPtr(14), (short)0); Marshal.WriteIntPtr(restrictionStructure.GetNextValidPtr(16), data); Marshal.WriteIntPtr(restrictionStructure.GetNextValidPtr(16 + IntPtr.Size), (IntPtr)0); ++restrictionStructure.restrictionCount; } public virtual void AddI4(int propertyId, int op, int value) { this.AddItem(propertyId, op, MessagePropertyVariants.VT_I4, (IntPtr)value); } public virtual void AddString(int propertyId, int op, string value) { if (value == null) this.AddItem(propertyId, op, MessagePropertyVariants.VT_NULL, (IntPtr)0); else { IntPtr data = Marshal.StringToHGlobalUni(value); this.AddItem(propertyId, op, MessagePropertyVariants.VT_LPWSTR, data); } } public virtual MQRESTRICTION GetRestrictionsRef() { return this.restrictionStructure; } [StructLayout(LayoutKind.Sequential)] public class MQRESTRICTION { public int restrictionCount; [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")] public IntPtr restrinctions; public MQRESTRICTION(int maxCount) { this.restrinctions = Marshal.AllocHGlobal(maxCount * GetRestrictionSize()); } ~MQRESTRICTION() { if (this.restrinctions != (IntPtr)0) { for (int index= 0; index < this.restrictionCount; ++ index) { short vt = Marshal.ReadInt16((IntPtr)((long)this.restrinctions + (index * GetRestrictionSize()) + 8)); if (vt != MessagePropertyVariants.VT_I4) { IntPtr dataPtr = (IntPtr)((long)this.restrinctions + (index * GetRestrictionSize()) + 16); IntPtr data = Marshal.ReadIntPtr(dataPtr); Marshal.FreeHGlobal(data); } } Marshal.FreeHGlobal(this.restrinctions); this.restrinctions = (IntPtr)0; } } public IntPtr GetNextValidPtr(int offset) { return (IntPtr)((long)restrinctions + restrictionCount * GetRestrictionSize() + offset); } public static int GetRestrictionSize() { return 16 + (IntPtr.Size * 2); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WebFaultException.cs
- EdmComplexPropertyAttribute.cs
- DbParameterCollectionHelper.cs
- DataGridRow.cs
- ArrayExtension.cs
- HttpCapabilitiesBase.cs
- TcpChannelFactory.cs
- TraceUtility.cs
- VariableQuery.cs
- BookmarkScopeHandle.cs
- EventSinkActivity.cs
- StringBuilder.cs
- DataMemberListEditor.cs
- Point3DKeyFrameCollection.cs
- XmlDocumentSerializer.cs
- PlanCompilerUtil.cs
- HatchBrush.cs
- AllMembershipCondition.cs
- EntityRecordInfo.cs
- TraceXPathNavigator.cs
- InfoCardRSAOAEPKeyExchangeDeformatter.cs
- _SafeNetHandles.cs
- DbConnectionOptions.cs
- UnhandledExceptionEventArgs.cs
- DataKeyArray.cs
- ArglessEventHandlerProxy.cs
- MouseActionValueSerializer.cs
- MediaPlayer.cs
- SqlClientMetaDataCollectionNames.cs
- DocumentXPathNavigator.cs
- DPCustomTypeDescriptor.cs
- EncoderBestFitFallback.cs
- ServiceConfigurationTraceRecord.cs
- WindowsAuthenticationEventArgs.cs
- HtmlInputSubmit.cs
- mongolianshape.cs
- ProcessHost.cs
- BinaryOperationBinder.cs
- TransformerConfigurationWizardBase.cs
- RectangleGeometry.cs
- Compiler.cs
- DataSourceProvider.cs
- UpdatePanelTrigger.cs
- TableRowCollection.cs
- StringResourceManager.cs
- SpoolingTask.cs
- WorkflowLayouts.cs
- NotCondition.cs
- MergablePropertyAttribute.cs
- MarkupCompilePass2.cs
- DynamicUpdateCommand.cs
- XPathException.cs
- RequestCache.cs
- LookupNode.cs
- XsdSchemaFileEditor.cs
- SqlConnection.cs
- TextElementCollectionHelper.cs
- MD5.cs
- TreeViewEvent.cs
- SafeFindHandle.cs
- HtmlTableCell.cs
- Point3DAnimationBase.cs
- ReceiveMessageContent.cs
- Metadata.cs
- Comparer.cs
- ContainerVisual.cs
- BaseParser.cs
- SqlEnums.cs
- Rotation3DAnimationUsingKeyFrames.cs
- WebPartsPersonalizationAuthorization.cs
- Transform.cs
- TableProvider.cs
- EventDescriptor.cs
- COM2IPerPropertyBrowsingHandler.cs
- ToolStripDropDownItem.cs
- ListenerElementsCollection.cs
- RequestQueryParser.cs
- ReadOnlyPermissionSet.cs
- EnumMember.cs
- XmlSchemaSimpleTypeRestriction.cs
- SerializationAttributes.cs
- ButtonBase.cs
- EntityDataSourceDataSelectionPanel.cs
- EventToken.cs
- SecurityUtils.cs
- QuaternionRotation3D.cs
- DrawingImage.cs
- CompiledIdentityConstraint.cs
- SelectorItemAutomationPeer.cs
- AccessText.cs
- ProxyManager.cs
- WindowProviderWrapper.cs
- Int64Animation.cs
- EnvelopedPkcs7.cs
- CharEnumerator.cs
- CollectionEditVerbManager.cs
- CodeAttributeDeclaration.cs
- RewritingSimplifier.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- PlainXmlSerializer.cs