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 Message Process(Message message) { if (message == null) { throw new ArgumentNullException("message"); } var pqlMessage = message as PqlMessage; if (pqlMessage == null) { throw new Exception(string.Format("Invalid message type, expected {0}, got {1}", typeof(PqlMessage).AssemblyQualifiedName, message.GetType().AssemblyQualifiedName)); } try { // re-establish authentication context as it is on the client side var authContext = AuthContextSerializer.GetObject(pqlMessage.AuthTicket); PqlEngineSecurityContext.Set(authContext); // get a processing manager from pool, start production var holder = m_requestManagersPool.Take(m_cancellationTokenSource.Token); try { var engine = m_enginesCache.GetEngine(authContext.TenantId, pqlMessage.ScopeId); holder.Item.Attach((PqlMessage)message, engine, authContext); engine.BeginExecution(holder.Item.ExecutionContext); } catch { holder.Item.ExecutionContext.Cancel(null); holder.Dispose(); throw; } // return the message to WCF infrastructure try { holder.Item.ExecutionContext.AttachRequestCompletion(); return(new PqlMessage( holder.Item, new IDisposable[] { holder.Item.ExecutionContext.Completion, holder }, pqlMessage.AuthTicket, pqlMessage.ScopeId, m_protocolVersion)); } catch (Exception e) { holder.Item.ExecutionContext.Cancel(e); holder.Dispose(); throw; } } catch (Exception e) { m_tracer.Exception(e); return(new PqlMessage(new PqlErrorDataWriter(1, e, true), null, pqlMessage.AuthTicket, pqlMessage.ScopeId, m_protocolVersion)); } }