예제 #1
0
        public void Should_be_idempotent_when_calling_dispose()
        {
            var stream = new ResponseStream((arr, act) => false, () => { });

            stream.Dispose();
            stream.Dispose();
        }
예제 #2
0
 public void Dispose()
 {
     if (!IsDisposed)
     {
         if (WebResponse != null)
         {
             WebResponse.Close();
             WebResponse = null;
         }
         if (ResponseStream != null)
         {
             ResponseStream.Dispose();
             ResponseStream = null;
         }
         Buffer = null;
         if (InstallerFileStream != null)
         {
             InstallerFileStream.Dispose();
             InstallerFileStream = null;
         }
         if (InstallerProcess != null)
         {
             InstallerProcess.Dispose();
         }
         if (_waitHandle != null)
         {
             _waitHandle.Set();
             _waitHandle = null;
         }
         IsDisposed = true;
     }
 }
예제 #3
0
        private string GetTokenFromResponse()
        {
            try
            {
                ResponseStream = EndpointResponse.GetResponseStream();
                if (ResponseStream != null)
                {
                    using (var reader = new StreamReader(ResponseStream))
                    {
                        ResponseValue = reader.ReadToEnd();
                    }
                }

                dynamic apiResponse = JsonConvert.DeserializeObject(ResponseValue);
                AccessToken = apiResponse.access_token;
                Console.WriteLine($"Access token generated by authorization server is : {AccessToken}");
            }
            catch (Exception streamProcessing)
            {
                Console.WriteLine($"Unable to process response stream due to error {streamProcessing.Message}");
                throw;
            }
            finally
            {
                ResponseStream?.Dispose();
            }
            return(AccessToken);
        }
예제 #4
0
        /*private string GetResponseKey()
         * {
         *  int hash = OriginalResponse.ResponseUri.AbsoluteUri.GetHashCode();
         *  string name = Path.GetFileName(OriginalResponse.ResponseUri.AbsolutePath);
         *  string key = name + hash.ToString("X");
         *  return key;
         * }*/

        public void CleanReponseStream()
        {
            if (ResponseStream != null)
            {
                ResponseStream.Dispose();
            }

            CreateResponseStream();
        }
예제 #5
0
 /// <summary>
 /// Implements the Dispose pattern
 /// </summary>
 /// <param name="disposing">Whether this object is being disposed via a call to Dispose
 /// or garbage collected.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             if (this.ResponseStream != null)
             {
                 ResponseStream.Dispose();
                 ResponseStream = null;
             }
         }
         this.disposed = true;
     }
 }
예제 #6
0
        public void Dispose()
        {
            if (ProxyRequest != null)
            {
                ProxyRequest.Abort();
            }

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

            if (ServerResponse != null)
            {
                ServerResponse.Close();
            }
        }
예제 #7
0
        private bool disposedValue = false; // 중복 호출을 검색하려면

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: 관리되는 상태(관리되는 개체)를 삭제합니다.
                    ResponseStream?.Dispose();
                }

                // TODO: 관리되지 않는 리소스(관리되지 않는 개체)를 해제하고 아래의 종료자를 재정의합니다.
                // TODO: 큰 필드를 null로 설정합니다.

                this.Name     = null;
                this.FileName = null;

                disposedValue = true;
            }
        }
예제 #8
0
        public void Dispose()
        {
            if (OriginalResponse != null)
            {
                OriginalResponse.Dispose();
                OriginalResponse = null;
            }

            if (ResponseStream != null)
            {
                ResponseStream.Dispose();
                ResponseStream = null;

                /*if (streamKey != null)
                 * {
                 *  streamCache.ClearAsync(streamKey, StreamType.File).Wait();
                 * }*/
            }
        }
예제 #9
0
        //-------------------------------------------------------------------------------------------------------------------------
        private async Task ProcessResponse()
        {
            CurrentUri       = HttpWebResponse.ResponseUri;
            ResponseEncoding = (HttpWebResponse.CharacterSet == "") ? Encoding.UTF8 : Encoding.GetEncoding(HttpWebResponse.CharacterSet);

            if (ResponseStream != null)
            {
                ResponseStream.Dispose();
            }
            if (PageSourceCache != String.Empty)
            {
                PageSourceCache = String.Empty;
            }

            ResponseStream = new MemoryStream();
            await HttpWebResponse.GetResponseStream().CopyToAsync(ResponseStream);

            ResponseStream.Position = 0;
        }
예제 #10
0
        /// Close a stream. In fact it just does a Dispose().
        /// If either ResponseStream or WebResponse are open, then close these also.
        public void Dispose()
        {
            if (Reader != null)
            {
                Reader.Dispose();
                Reader = null;
            }

            if (ResponseStream != null)
            {
                ResponseStream.Close();
                ResponseStream.Dispose();
                ResponseStream = null;
            }

            if (WebResponse != null)
            {
                WebResponse.Close();
                WebResponse.Dispose();
                WebResponse = null;
            }
        }
 public virtual void Dispose()
 {
     ResponseStream?.Dispose();
 }
 public virtual void Dispose()
 {
     ResponseStream?.Dispose();
     DecodeSpan?.Dispose();
 }
예제 #13
0
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference
        /// other objects. Only unmanaged resources can be disposed.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                // Set the web socket state to closed.
                if (_context != null)
                {
                    _context.SocketState = SocketState.Closed;
                }

                // Release the receive and send spin wait handler.
                Interlocked.Exchange(ref _exitWaitReceiveIndicator, 0);
                Interlocked.Exchange(ref _exitWaitSendIndicator, 0);
                Interlocked.Exchange(ref _isContextActive, 0);

                // Note disposing has been done.
                _disposed = true;

                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Close the connection.
                    CloseEx();

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

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

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

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

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

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

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

                    if (_context != null)
                    {
                        if (_context.ContextState != null)
                        {
                            // If the current state context
                            // implements IDisposable then
                            // dispose of the resources.
                            if (_context.ContextState is IDisposable)
                            {
                                IDisposable disposable = (IDisposable)_context.ContextState;
                                disposable.Dispose();
                            }
                        }
                        _context.Dispose();
                    }
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                _socket                = null;
                _sslStream             = null;
                _networkStream         = null;
                _x509Certificate       = null;
                _endConnectionCallback = null;

                _requestBuffer  = null;
                _responseBuffer = null;

                _requestStream  = null;
                _responseStream = null;

                _request  = null;
                _response = null;

                _context.ContextState = null;
                _context = null;
            }
        }
예제 #14
0
        /// <summary>
        /// Triggered when all resources are released and parent resources need to be released.
        /// </summary>
        protected override void DisposeOfResources()
        {
            // Set the web socket state to closed.
            if (_context != null)
            {
                _context.SocketState = SocketState.Closed;
            }

            // Release the receive and send spin wait handler.
            Interlocked.Exchange(ref _exitWaitReceiveIndicator, 0);
            Interlocked.Exchange(ref _exitWaitSendIndicator, 0);
            Interlocked.Exchange(ref _isContextActive, 0);
            Interlocked.Exchange(ref _isAsyncModeActive, 0);

            base.State = null;

            _lockReceiver   = null;
            _lockSender     = null;
            _lockFromServer = null;

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

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

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

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

            if (_context != null)
            {
                if (_context.ContextState != null)
                {
                    // If the current state context
                    // implements IDisposable then
                    // dispose of the resources.
                    if (_context.ContextState is IDisposable)
                    {
                        IDisposable disposable = (IDisposable)_context.ContextState;
                        disposable.Dispose();
                    }
                }

                if (_context.State != null)
                {
                    // If the current state context
                    // implements IDisposable then
                    // dispose of the resources.
                    if (_context.State is IDisposable)
                    {
                        IDisposable disposable = (IDisposable)_context.State;
                        disposable.Dispose();
                    }
                }
                _context.Dispose();
            }

            _requestBuffer  = null;
            _responseBuffer = null;

            _requestStream  = null;
            _responseStream = null;

            _request  = null;
            _response = null;

            _context.State        = null;
            _context.ContextState = null;
            _context = null;
        }
예제 #15
0
 public void Dispose() => ResponseStream?.Dispose();