Esempio n. 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="nativeSession"></param>
        internal ReliableMessagingSession(
            NativeReliableMessaging.IFabricReliableSession nativeSession)
        {
            // AppTrace.TraceSource.WriteNoise("ReliableMessaging.NativeReliableSession.FabricCreateReliableSession");

            // Initialize native reliable session interface pointer.
            // TODO: exception handling
            this.nativeReliableSession = nativeSession;
            Debug.Assert(null != this.nativeReliableSession);
            this.nativeMessageDataFactory = (NativeReliableMessaging.IFabricMessageDataFactory)nativeSession;
        }
Esempio n. 2
0
        internal NativeRuntime.IFabricOperationData Pin(NativeReliableMessaging.IFabricMessageDataFactory messageDataFactory)
        {
            if (null != Interlocked.CompareExchange(ref this.pinCollection, new PinCollection(), null))
            {
                //
                // We do not allow the same ReliableSessionMessage object to be pinned concurrently.
                //
                throw new InvalidOperationException();
            }

            var sizes = this.originalMessage.Select(element => (uint)element.Count).ToArray();

            var bufferCount = (uint)sizes.Length;

            if (bufferCount == 0)
            {
                return(null);
            }

            // pin the IOperationData buffers
            var pinnedBuffers = this.originalMessage.Select(element => this.pinCollection.AddBlittable(element.Array)).ToArray();

            NativeRuntime.IFabricOperationData messageData = null;

            using (PinBlittable pinSizes = new PinBlittable(sizes), pinBuffers = new PinBlittable(pinnedBuffers))
            {
                messageData = messageDataFactory.CreateMessageData(
                    bufferCount,
                    pinSizes.AddrOfPinnedObject(),
                    pinBuffers.AddrOfPinnedObject());
            }

            this.savedNativeMessageRef = messageData;

            return(messageData);
        }