Exemple #1
0
            /// <summary>
            /// When overridden in a derived class, reads a message from a specified stream.
            /// </summary>
            /// <returns>
            /// The <see cref="T:System.ServiceModel.Channels.Message"/> that is read from the stream specified.
            /// </returns>
            /// <param name="stream">The <see cref="T:System.IO.Stream"/> object from which the message is read.</param><param name="maxSizeOfHeaders">The maximum size of the headers that can be read from the message.</param><param name="contentType">The Multipurpose Internet Mail Extensions (MIME) message-level content-type.</param>
            public override Message ReadMessage(System.IO.Stream stream, int maxSizeOfHeaders, string contentType)
            {
                var message = new PqlMessage(stream, null);

                message.ReadHeaders();
                return(message);
            }
 /// <summary>
 /// When overridden in a derived class, reads a message from a specified stream.
 /// </summary>
 /// <returns>
 /// The <see cref="T:System.ServiceModel.Channels.Message"/> that is read from the stream specified.
 /// </returns>
 /// <param name="stream">The <see cref="T:System.IO.Stream"/> object from which the message is read.</param><param name="maxSizeOfHeaders">The maximum size of the headers that can be read from the message.</param><param name="contentType">The Multipurpose Internet Mail Extensions (MIME) message-level content-type.</param>
 public override Message ReadMessage(System.IO.Stream stream, int maxSizeOfHeaders, string contentType)
 {
     var message = new PqlMessage(stream, null);
     message.ReadHeaders();
     return message;
 }
        public void Attach(PqlMessage requestMessage, IDataEngine dataEngine, IPqlClientSecurityContext authContext)
        {
            if (dataEngine == null)
            {
                throw new ArgumentNullException("dataEngine");
            }

            if (authContext == null)
            {
                throw new ArgumentNullException("authContext");
            }

            m_executionContext.AssertIsClean();
            m_executionContext.AttachInputMessage(requestMessage, dataEngine, authContext);
        }
        private PqlMessage SendCommand(IDataService channel, DataRequest dataRequest, DataRequestParams dataRequestParams, DataRequestBulk dataRequestBulk)
        {
            var authContext = m_connection.ClientSecurityContext;

            if (authContext == null)
            {
                throw new InvalidOperationException("Authentication context is not set on the thread");
            }

            if (string.IsNullOrWhiteSpace(authContext.TenantId))
            {
                throw new InvalidOperationException("Current authentication context does not have value for TenantId");
            }

            Message responseMessage;
            using (var holder = PqlDataConnection.CommandStreams.Take(m_connection.CancellationTokenSource.Token))
            {
                holder.Item.Attach(dataRequest, dataRequestParams, dataRequestBulk);

                var requestMessage = new PqlMessage(
                    holder.Item, new IDisposable[] {holder},
                    AuthContextSerializer.GetString(authContext),
                    m_connection.ConnectionProps.ScopeId,
                    m_connection.ConnectionProps.ProtocolVersion);

                responseMessage = channel.Process(requestMessage);
            }

            var pqlMessage = responseMessage as PqlMessage;

            if (pqlMessage != null)
            {
                return pqlMessage;
            }

            throw new DataException(string.Format(
                "Message must be of type {0}. Actual type that came from WCF transport was {1}",
                typeof(PqlMessage).AssemblyQualifiedName,
                responseMessage.GetType().AssemblyQualifiedName));
        }
        public void Cleanup()
        {
            m_authContext = null;
            m_lastError = null;
            m_requestMessage = null;
            m_engine = null;
            ResponseHeaders = null;
            RecordsAffected = 0;
            TotalRowsProduced = 0;
            DriverOutputBuffer = null;
            InputDataEnumerator = null;
            ClauseEvaluationContext = null;
            OutputDataBuffer = null;
            Completion = null;
            ContainerDescriptor = null;

            CacheInfo = null;
            Request.Clear();
            RequestBulk.Clear();
            RequestParameters.Clear();
            ParsedRequest.Clear();

            var cancellation = Interlocked.CompareExchange(ref m_cancellationTokenSource, null, m_cancellationTokenSource);
            if (cancellation != null)
            {
                cancellation.Cancel();
            }

            var ring = Interlocked.CompareExchange(ref m_buffersRing, null, m_buffersRing);
            if (ring != null)
            {
                ring.Dispose();
            }

            var items = m_buffersRingItems; // do not replace with null
            if (items != null)
            {
                foreach (var item in items)
                {
                    item.Cleanup();
                }
            }
        }
        public void AttachInputMessage(PqlMessage requestMessage, IDataEngine engine, IPqlClientSecurityContext authContext)
        {
            if (requestMessage == null)
            {
                throw new ArgumentNullException("requestMessage");
            }

            if (engine == null)
            {
                throw new ArgumentNullException("engine");
            }

            if (authContext == null)
            {
                throw new ArgumentNullException("authContext");
            }

            AssertIsClean();

            ClauseEvaluationContext = new ClauseEvaluationContext();

            m_authContext = authContext;
            m_requestMessage = requestMessage;
            m_engine = engine;
            m_cancellationTokenSource = new CancellationTokenSource();

            // re-initialize the ring, for fault tolerance in case if previous processor fails to release items
            m_buffersRing = new DataRing<RequestExecutionBuffer>(m_buffersRingItems.Length, m_buffersRingItems.Length);
            foreach (var item in m_buffersRingItems)
            {
                // make all buffers available to producer
                m_buffersRing.AddTaskForProcessing(item, m_cancellationTokenSource.Token);
            }
        }