internal ChunkedUploadWrapperStream(Stream stream, int wrappedStreamBufferSize, AWS4SigningResult headerSigningResult)
            : base(stream)
        {
            HeaderSigningResult    = headerSigningResult;
            PreviousChunkSignature = headerSigningResult.Signature;

            _wrappedStreamBufferSize = wrappedStreamBufferSize;
            _inputBuffer             = new byte[DefaultChunkSize];
            _outputBuffer            = new byte[CalculateChunkHeaderLength(DefaultChunkSize)]; // header+data

#if BCL
            // if the wrapped stream implements encryption, switch to a read-and-copy
            // strategy for filling the chunk buffer
            var encryptionStream = SearchWrappedStream(s =>
            {
                var encryptUploadPartStream = s as EncryptUploadPartStream;
                if (encryptUploadPartStream != null)
                {
                    return(true);
                }

                var encryptStream = s as EncryptStream;
                return(encryptStream != null);
            });

            if (encryptionStream != null)
            {
                _readStrategy = ReadStrategy.ReadAndCopy;
            }
#endif
        }
예제 #2
0
 /// <summary>
 ///     Creates new intanse of <see cref="KeyboardListener" />. New Text event will be fired on EndSymbol.
 /// </summary>
 /// <param name="startSymbol"></param>
 /// <param name="endSymbol"></param>
 public KeyboardListener(char startSymbol, char endSymbol)
 {
     StartSymbol            = startSymbol;
     EndSymbol              = endSymbol;
     Strategy               = ReadStrategy.DependsOnSymbols;
     _hook                  = new GlobalKeyboardHook();
     _hook.KeyboardPressed += KeyPressed;
 }
예제 #3
0
 /// <summary>
 ///     New Text event will be fired on EndSymbol.
 /// </summary>
 /// <param name="startSymbol"></param>
 /// <param name="endSymbol"></param>
 public KeyboardListener ChangeReadStrategy(char startSymbol, char endSymbol)
 {
     StartSymbol = startSymbol;
     EndSymbol   = endSymbol;
     Strategy    = ReadStrategy.DependsOnSymbols;
     _buffer.Clear();
     return(this);
 }
예제 #4
0
        /// <summary>
        /// Factory Method to create the correct type of reader acording to generic type specified.
        /// </summary>
        /// <typeparam name="T">Type of register that one wants to read</typeparam>
        /// <param name="strategy">Reading strategy to be assigned to the returning reader.</param>
        /// <returns>
        /// Class that implements the methods required to read the type of registers specified.
        /// </returns>
        public static IReader <T> CreateReader <T>(ReadStrategy strategy)
        {
            var reader = CreateReader <T>();

            reader.ReadStrategy = strategy;

            return(reader);
        }
예제 #5
0
 /// <summary>
 ///     Creates new intanse of <see cref="KeyboardListener" />. New Text event will be fired on string with passed length.
 /// </summary>
 /// <param name="stringLength"></param>
 public KeyboardListener(int stringLength)
 {
     if (stringLength < 1)
     {
         throw new ArgumentOutOfRangeException($"{nameof(stringLength)} must be greater than 0");
     }
     StringLength           = stringLength;
     Strategy               = ReadStrategy.DependsOnLength;
     _hook                  = new GlobalKeyboardHook();
     _hook.KeyboardPressed += KeyPressed;
 }
예제 #6
0
 /// <summary>
 ///     New Text event will be fired on string with passed length.
 /// </summary>
 /// <param name="stringLength"></param>
 public KeyboardListener ChangeReadStrategy(int stringLength)
 {
     if (stringLength < 1)
     {
         throw new ArgumentOutOfRangeException($"{nameof(stringLength)} must be greater than 0");
     }
     StringLength = stringLength;
     Strategy     = ReadStrategy.DependsOnLength;
     _buffer.Clear();
     return(this);
 }
예제 #7
0
 /// <summary>
 ///     Creates new intanse of <see cref="KeyboardListener" />. New Text event will be fired on Enter.
 /// </summary>
 public KeyboardListener(bool fireNewTextOnEnter = false)
 {
     if (fireNewTextOnEnter)
     {
         Strategy = ReadStrategy.DependsOnEnter;
     }
     else
     {
         Strategy = ReadStrategy.Disabled;
     }
     _hook = new GlobalKeyboardHook();
     _hook.KeyboardPressed += KeyPressed;
 }
예제 #8
0
 private void AppendBuffer(char result, ReadStrategy strategy)
 {
     if (strategy == ReadStrategy.DependsOnSymbols)
     {
         if (_buffer.Length == 0 && result == StartSymbol)
         {
             _buffer.Append(result);
             return;
         }
         if (_buffer.Length > 0)
         {
             _buffer.Append(result);
         }
     }
     else
     {
         _buffer.Append(result);
     }
 }
예제 #9
0
        private void CheckBuffer(ReadStrategy strategy, Keys key)
        {
            switch (strategy)
            {
            case ReadStrategy.DependsOnLength:
            {
                if (_buffer.Length >= StringLength)
                {
                    var text = _buffer.ToString();
                    _buffer.Clear();
                    NewText?.Invoke(this, new NewStringEventArgs(text));
                }
                break;
            }

            case ReadStrategy.DependsOnSymbols:
            {
                char end;
                if (key.TryToChar(_shiftPressed, out end))
                {
                    if (end == EndSymbol)
                    {
                        var text = _buffer.ToString();
                        _buffer.Clear();
                        NewText?.Invoke(this, new NewStringEventArgs(text));
                    }
                }
                break;
            }

            case ReadStrategy.DependsOnEnter:
            {
                if (key == Keys.Return)
                {
                    var text = _buffer.ToString();
                    _buffer.Clear();
                    NewText?.Invoke(this, new NewStringEventArgs(text));
                }
                break;
            }
            }
        }
예제 #10
0
        /// <summary>
        /// Initializes a chunked upload stream
        /// </summary>
        /// <param name="stream">stream to wrap</param>
        /// <param name="wrappedStreamBufferSize">Size of buffer used for reading from stream</param>
        /// <param name="headerSigningResult">SigV4 or SigV4a signing result for the request's headers</param>
        internal ChunkedUploadWrapperStream(Stream stream, int wrappedStreamBufferSize, AWSSigningResultBase headerSigningResult) : base(stream)
        {
            if (!(headerSigningResult is AWS4aSigningResult || headerSigningResult is AWS4SigningResult))
            {
                throw new AmazonClientException($"{nameof(ChunkedUploadWrapperStream)} was initialized without a SigV4 or SigV4a signing result.");
            }
            else if (headerSigningResult is AWS4aSigningResult)
            {
                Sigv4aSigner = new AWS4aSignerCRTWrapper();
            }

            HeaderSigningResult    = headerSigningResult;
            PreviousChunkSignature = headerSigningResult?.Signature;

            _wrappedStreamBufferSize = wrappedStreamBufferSize;
            _inputBuffer             = new byte[DefaultChunkSize];
            _outputBuffer            = new byte[CalculateChunkHeaderLength(DefaultChunkSize, HeaderSigningResult is AWS4aSigningResult ? V4A_SIGNATURE_LENGTH : V4_SIGNATURE_LENGTH)]; // header+data

            // if the wrapped stream implements encryption, switch to a read-and-copy
            // strategy for filling the chunk buffer
            var encryptionStream = SearchWrappedStream(s =>
            {
                var encryptUploadPartStream = s as EncryptUploadPartStream;
                if (encryptUploadPartStream != null)
                {
                    return(true);
                }

                var encryptStream = s as EncryptStream;
                return(encryptStream != null);
            });

            if (encryptionStream != null)
            {
                _readStrategy = ReadStrategy.ReadAndCopy;
            }
        }
        internal ChunkedUploadWrapperStream(Stream stream, int wrappedStreamBufferSize, AWS4SigningResult headerSigningResult)
            : base(stream)
        {
            HeaderSigningResult = headerSigningResult;
            PreviousChunkSignature = headerSigningResult.Signature;

            _wrappedStreamBufferSize = wrappedStreamBufferSize;
            _inputBuffer = new byte[DefaultChunkSize];
            _outputBuffer = new byte[CalculateChunkHeaderLength(DefaultChunkSize)]; // header+data

#if BCL
            // if the wrapped stream implements encryption, switch to a read-and-copy
            // strategy for filling the chunk buffer
            var encryptionStream = SearchWrappedStream(s =>
                {
                    var encryptUploadPartStream = s as EncryptUploadPartStream;
                    if (encryptUploadPartStream != null)
                        return true;

                    var encryptStream = s as EncryptStream;
                    return encryptStream != null;
                });

            if (encryptionStream != null)
                _readStrategy = ReadStrategy.ReadAndCopy;
#endif
        }
예제 #12
0
 /// <summary>
 ///     New Text event will be fired on Enter.
 /// </summary>
 public KeyboardListener ChangeReadStrategy()
 {
     Strategy = ReadStrategy.DependsOnEnter;
     _buffer.Clear();
     return(this);
 }