コード例 #1
0
        internal IDataService BeginExecuteCommand(PqlDataCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (m_activeCommand != null || m_connectionState == ConnectionState.Executing || m_connectionState == ConnectionState.Fetching)
            {
                throw new InvalidOperationException("Another command is being executed or fetching is in progress");
            }

            if (m_connectionState != ConnectionState.Open && m_connectionState != ConnectionState.Closed)
            {
                throw new InvalidOperationException("Cannot execute in this state: " + m_connectionState);
            }

            if (m_cancellationTokenSource != null && m_cancellationTokenSource.IsCancellationRequested)
            {
                m_connectionState = ConnectionState.Broken;
                throw new InvalidOperationException("Cancellation token source has not been reset to null");
            }

            Open();

            m_cancellationTokenSource = new CancellationTokenSource();
            m_connectionState         = ConnectionState.Executing;
            m_activeCommand           = command;
            return(m_channel);
        }
コード例 #2
0
        internal void ConfirmExecutionCompletion(bool successful)
        {
            if (m_activeCommand == null)
            {
                return;
            }

            m_connectionState = successful && (m_connectionState == ConnectionState.Executing || m_connectionState == ConnectionState.Fetching)
                ? ConnectionState.Open : ConnectionState.Broken;

            m_cancellationTokenSource = null;
            m_activeCommand           = null;
        }
コード例 #3
0
        private void Cleanup()
        {
            var source = Interlocked.CompareExchange(ref m_cancellationTokenSource, null, m_cancellationTokenSource);

            if (source != null)
            {
                // this will signal all commands and readers to abort any waiting
                source.Cancel();
            }

            m_connectionState = ConnectionState.Closed;
            m_activeCommand   = null;

            var factory = Interlocked.CompareExchange(ref m_channelFactory, null, m_channelFactory);
            var channel = Interlocked.CompareExchange(ref m_channel, null, m_channel);

            RobustClose(factory);
            RobustClose((ICommunicationObject)channel);

            if (source != null)
            {
                source.Dispose();
            }
        }