public RequestData(HttpMethod method, string path, PostData<object> data, IConnectionConfigurationValues global, IRequestConfiguration local, IMemoryStreamFactory memoryStreamFactory)
		{
			this.ConnectionSettings = global;
			this.MemoryStreamFactory = memoryStreamFactory;
			this.Method = method;
			this.PostData = data;
			this.Path = this.CreatePathWithQueryStrings(path, this.ConnectionSettings, null);

			this.Pipelined = global.HttpPipeliningEnabled || (local?.EnableHttpPipelining).GetValueOrDefault(false);
			this.HttpCompression = global.EnableHttpCompression;
			this.ContentType = local?.ContentType ?? MimeType;
			this.Headers = global.Headers;

			this.RequestTimeout = local?.RequestTimeout ?? global.RequestTimeout;
			this.PingTimeout = 
				local?.PingTimeout
				?? global?.PingTimeout
				?? (global.ConnectionPool.UsingSsl ? ConnectionConfiguration.DefaultPingTimeoutOnSSL : ConnectionConfiguration.DefaultPingTimeout);

			this.KeepAliveInterval = (int)(global.KeepAliveInterval?.TotalMilliseconds ?? 2000);
			this.KeepAliveTime = (int)(global.KeepAliveTime?.TotalMilliseconds ?? 2000);

			this.ProxyAddress = global.ProxyAddress;
			this.ProxyUsername = global.ProxyUsername;
			this.ProxyPassword = global.ProxyPassword;
			this.DisableAutomaticProxyDetection = global.DisableAutomaticProxyDetection;
			this.BasicAuthorizationCredentials = local?.BasicAuthenticationCredentials ?? global.BasicAuthenticationCredentials;
			this.CancellationToken = local?.CancellationToken ?? CancellationToken.None;
			this.AllowedStatusCodes = local?.AllowedStatusCodes ?? Enumerable.Empty<int>();
		}
Esempio n. 2
0
		public RequestData(HttpMethod method, string path, PostData<object> data, IConnectionConfigurationValues global, IRequestParameters local, IMemoryStreamFactory memoryStreamFactory)
#pragma warning disable CS0618 // Type or member is obsolete
			: this(method, path, data, global, (IRequestConfiguration)local?.RequestConfiguration, memoryStreamFactory)
#pragma warning restore CS0618 // Type or member is obsolete
		{
			this.CustomConverter = local?.DeserializationOverride;
			this.Path = this.CreatePathWithQueryStrings(path, this.ConnectionSettings, local);
		}
        public RequestPipeline(
            IConnectionConfigurationValues configurationValues,
            IDateTimeProvider dateTimeProvider,
            IMemoryStreamFactory memoryStreamFactory,
            IRequestParameters requestParameters
            )
        {
            _settings            = configurationValues;
            _connectionPool      = _settings.ConnectionPool;
            _connection          = _settings.Connection;
            _dateTimeProvider    = dateTimeProvider;
            _memoryStreamFactory = memoryStreamFactory;

            RequestParameters    = requestParameters;
            RequestConfiguration = requestParameters?.RequestConfiguration;
            StartedOn            = dateTimeProvider.Now();
        }
Esempio n. 4
0
 public DoPutAction(Stream currentStream, IActivityIOPath destination, IDev2CRUDOperationTO crudArgument,
                    string whereToPut, IDev2LogonProvider logOnProvider, IFile fileWrapper,
                    IFileStreamFactory fileStreamFactory, IFilePath pathWrapper, IMemoryStreamFactory memoryStreamFactory,
                    ImpersonationDelegate impersonationDelegate)
     : base(impersonationDelegate)
 {
     _logOnProvider       = logOnProvider;
     _pathWrapper         = pathWrapper;
     _fileWrapper         = fileWrapper;
     _fileStreamFactory   = fileStreamFactory;
     _memoryStreamFactory = memoryStreamFactory;
     _currentStream       = currentStream;
     _destination         = destination;
     _arguments           = crudArgument;
     _impersonatedUser    = _impersonationDelegate(_destination, _logOnProvider);
     _whereToPut          = whereToPut;
 }
Esempio n. 5
0
 public XmlValidator(
     IMemoryStreamFactory memoryStreamFactory = null,
     IFileSystem fileSystem = null,
     IXmlReaderSettingsFactory xmlReaderSettingsFactory = null,
     IEventRiserClass <ValidationErrorEventArgs> validationErrorEventRiser       = null,
     IEventRiserClass <ValidationFinishedEventArgs> validationFinishedEventRiser = null,
     IStreamValidator streamValidator       = null,
     IXmlValidationUtils xmlValidationUtils = null)
 {
     this.memoryStreamFactory          = memoryStreamFactory ?? new MemoryStreamFactory();
     this.fileSystem                   = fileSystem ?? new FileSystem();
     this.xmlReaderSettingsFactory     = xmlReaderSettingsFactory ?? new XmlReaderSettingsFactory();
     this.validationErrorEventRiser    = validationErrorEventRiser ?? new EventRiser <ValidationErrorEventArgs>();
     this.validationFinishedEventRiser = validationFinishedEventRiser ?? new EventRiser <ValidationFinishedEventArgs>();
     this.streamValidator              = streamValidator ?? new StreamUtils();
     this.xmlValidationUtils           = xmlValidationUtils ?? new XmlValidationUtils();
 }
Esempio n. 6
0
        public WebSocketSharpListener(ILogger logger, ICertificate certificate, IMemoryStreamFactory memoryStreamProvider, ITextEncoding textEncoding, INetworkManager networkManager, ISocketFactory socketFactory, ICryptoProvider cryptoProvider, IStreamFactory streamFactory, bool enableDualMode, Func <HttpListenerContext, IHttpRequest> httpRequestFactory, IFileSystem fileSystem, IEnvironmentInfo environment)
        {
            _logger               = logger;
            _certificate          = certificate;
            _memoryStreamProvider = memoryStreamProvider;
            _textEncoding         = textEncoding;
            _networkManager       = networkManager;
            _socketFactory        = socketFactory;
            _cryptoProvider       = cryptoProvider;
            _streamFactory        = streamFactory;
            _enableDualMode       = enableDualMode;
            _httpRequestFactory   = httpRequestFactory;
            _fileSystem           = fileSystem;
            _environment          = environment;

            _disposeCancellationToken = _disposeCancellationTokenSource.Token;
        }
Esempio n. 7
0
        /// <summary>
        /// Transport coordinates the client requests over the connection pool nodes and is in charge of falling over on different nodes
        /// </summary>
        /// <param name="configurationValues">The connectionsettings to use for this transport</param>
        /// <param name="pipelineProvider">In charge of create a new pipeline, safe to pass null to use the default</param>
        /// <param name="dateTimeProvider">The date time proved to use, safe to pass null to use the default</param>
        /// <param name="memoryStreamFactory">The memory stream provider to use, safe to pass null to use the default</param>
        public Transport(
            TConnectionSettings configurationValues,
            IRequestPipelineFactory pipelineProvider,
            IDateTimeProvider dateTimeProvider,
            IMemoryStreamFactory memoryStreamFactory
            )
        {
            configurationValues.ThrowIfNull(nameof(configurationValues));
            configurationValues.ConnectionPool.ThrowIfNull(nameof(configurationValues.ConnectionPool));
            configurationValues.Connection.ThrowIfNull(nameof(configurationValues.Connection));
            configurationValues.RequestResponseSerializer.ThrowIfNull(nameof(configurationValues.RequestResponseSerializer));

            this.Settings            = configurationValues;
            this.PipelineProvider    = pipelineProvider ?? new RequestPipelineFactory();
            this.DateTimeProvider    = dateTimeProvider ?? Elasticsearch.Net.DateTimeProvider.Default;
            this.MemoryStreamFactory = memoryStreamFactory ?? configurationValues.MemoryStreamFactory;
        }
Esempio n. 8
0
        private RequestData(
            HttpMethod method,
            string path,
            PostData data,
            IConnectionConfigurationValues global,
            IRequestConfiguration local,
            IMemoryStreamFactory memoryStreamFactory)
        {
            this.ConnectionSettings  = global;
            this.MemoryStreamFactory = memoryStreamFactory;
            this.Method   = method;
            this.PostData = data;

            if (data != null)
            {
                data.DisableDirectStreaming = local?.DisableDirectStreaming ?? global.DisableDirectStreaming;
            }

            this.Path = this.CreatePathWithQueryStrings(path, this.ConnectionSettings, null);

            this.Pipelined       = local?.EnableHttpPipelining ?? global.HttpPipeliningEnabled;
            this.HttpCompression = global.EnableHttpCompression;
            this.RequestMimeType = local?.ContentType ?? MimeType;
            this.Accept          = local?.Accept ?? MimeType;
            this.Headers         = global.Headers != null ? new NameValueCollection(global.Headers) : new NameValueCollection();
            this.RunAs           = local?.RunAs;
            this.SkipDeserializationForStatusCodes = global?.SkipDeserializationForStatusCodes;
            this.ThrowExceptions = local?.ThrowExceptions ?? global.ThrowExceptions;

            this.RequestTimeout = local?.RequestTimeout ?? global.RequestTimeout;
            this.PingTimeout    =
                local?.PingTimeout
                ?? global?.PingTimeout
                ?? (global.ConnectionPool.UsingSsl ? ConnectionConfiguration.DefaultPingTimeoutOnSSL : ConnectionConfiguration.DefaultPingTimeout);

            this.KeepAliveInterval = (int)(global.KeepAliveInterval?.TotalMilliseconds ?? 2000);
            this.KeepAliveTime     = (int)(global.KeepAliveTime?.TotalMilliseconds ?? 2000);

            this.ProxyAddress  = global.ProxyAddress;
            this.ProxyUsername = global.ProxyUsername;
            this.ProxyPassword = global.ProxyPassword;
            this.DisableAutomaticProxyDetection = global.DisableAutomaticProxyDetection;
            this.BasicAuthorizationCredentials  = local?.BasicAuthenticationCredentials ?? global.BasicAuthenticationCredentials;
            this.AllowedStatusCodes             = local?.AllowedStatusCodes ?? Enumerable.Empty <int>();
            this.ClientCertificates             = local?.ClientCertificates ?? global.ClientCertificates;
        }
        public RequestPipeline(
            IConnectionConfigurationValues configurationValues,
            IDateTimeProvider dateTimeProvider,
            IMemoryStreamFactory memoryStreamFactory,
            IRequestParameters requestParameters)
        {
            this._settings            = configurationValues;
            this._connectionPool      = this._settings.ConnectionPool;
            this._connection          = this._settings.Connection;
            this._dateTimeProvider    = dateTimeProvider;
            this._memoryStreamFactory = memoryStreamFactory;

            this.RequestParameters    = requestParameters;
            this.RequestConfiguration = requestParameters?.RequestConfiguration;
            this._cancellationToken   = this.RequestConfiguration?.CancellationToken ?? CancellationToken.None;
            this.StartedOn            = dateTimeProvider.Now();
        }
Esempio n. 10
0
        /// <summary>
        /// Transport coordinates the client requests over the connection pool nodes and is in charge of falling over on different nodes
        /// </summary>
        /// <param name="configurationValues">The connectionsettings to use for this transport</param>
        /// <param name="requestPipelineProvider">In charge of create a new pipeline, safe to pass null to use the default</param>
        /// <param name="dateTimeProvider">The date time proved to use, safe to pass null to use the default</param>
        /// <param name="memoryStreamFactory">The memory stream provider to use, safe to pass null to use the default</param>
        public Transport(
            TConnectionSettings configurationValues,
            IRequestPipelineFactory pipelineProvider,
            IDateTimeProvider dateTimeProvider,
            IMemoryStreamFactory memoryStreamFactory
            )
        {
            configurationValues.ThrowIfNull(nameof(configurationValues));
            configurationValues.ConnectionPool.ThrowIfNull(nameof(configurationValues.ConnectionPool));
            configurationValues.Connection.ThrowIfNull(nameof(configurationValues.Connection));
            configurationValues.Serializer.ThrowIfNull(nameof(configurationValues.Serializer));

            this.Settings            = configurationValues;
            this.PipelineProvider    = pipelineProvider ?? new RequestPipelineFactory();
            this.DateTimeProvider    = dateTimeProvider ?? Providers.DateTimeProvider.Default;
            this.MemoryStreamFactory = memoryStreamFactory ?? new MemoryStreamFactory();
            this._semaphore          = new SemaphoreSlim(1, 1);
        }
        public static async Task <MemoryStream> ToStreamAsync(
            this JToken token,
            IMemoryStreamFactory memoryStreamFactory = null,
            CancellationToken cancellationToken      = default(CancellationToken))
        {
            var ms = memoryStreamFactory?.Create() ?? new MemoryStream();

            using (var streamWriter = new StreamWriter(ms, InternalSerializer.ExpectedEncoding, InternalSerializer.DefaultBufferSize, leaveOpen: true))
                using (var writer = new JsonTextWriter(streamWriter))
                {
                    await token.WriteToAsync(writer, cancellationToken).ConfigureAwait(false);

                    await writer.FlushAsync(cancellationToken).ConfigureAwait(false);

                    ms.Position = 0;
                    return(ms);
                }
        }
Esempio n. 12
0
        public HttpConnection(ILogger logger, Socket socket, EndPointListener epl, bool secure, X509Certificate cert, ICryptoProvider cryptoProvider, IMemoryStreamFactory memoryStreamFactory, ITextEncoding textEncoding, IFileSystem fileSystem, IEnvironmentInfo environment)
        {
            _logger              = logger;
            this._socket         = socket;
            this._epl            = epl;
            this.secure          = secure;
            this.cert            = cert;
            _cryptoProvider      = cryptoProvider;
            _memoryStreamFactory = memoryStreamFactory;
            _textEncoding        = textEncoding;
            _fileSystem          = fileSystem;
            _environment         = environment;

            if (secure == false)
            {
                _stream = new SocketStream(_socket, false);
            }
            else
            {
                ssl_stream = new SslStream(new NetworkStream(_socket, false), false, (t, c, ch, e) =>
                {
                    if (c == null)
                    {
                        return(true);
                    }

                    //var c2 = c as X509Certificate2;
                    //if (c2 == null)
                    //{
                    //    c2 = new X509Certificate2(c.GetRawCertData());
                    //}

                    //_clientCert = c2;
                    //_clientCertErrors = new int[] { (int)e };
                    return(true);
                });

                _stream = ssl_stream;

                ssl_stream.AuthenticateAsServer(cert, false, (SslProtocols)ServicePointManager.SecurityProtocol, false);
            }
            Init();
        }
        public void Initialize()
        {
            _aesCryptoServiceProviderFactory = new AesCryptoServiceProviderFactory();
            _memoryStreamFactory = new MemoryStreamFactory();
            _cryptoStreamFactory = new CryptoStreamFactory();
            _testAesEncryptionStrategy = new AesEncryptionStrategy(_aesCryptoServiceProviderFactory, _memoryStreamFactory, _cryptoStreamFactory);

            _encoding = new UTF8Encoding();
            byte[] bSalt;
            Rfc2898DeriveBytes oRFC2898_Key;
            Rfc2898DeriveBytes oRFC2898_IV;

            bSalt = Encoding.UTF8.GetBytes("SALTSALT");
            oRFC2898_Key = new Rfc2898DeriveBytes("PASSWORD", bSalt);
            oRFC2898_IV = new Rfc2898DeriveBytes("PASSWORDSALTSALT", bSalt);

            _key = oRFC2898_Key.GetBytes(32);
            _iv = oRFC2898_IV.GetBytes(16);
        }
Esempio n. 14
0
        public void Setup()
        {
            fileSystem          = new FileSystem();
            memoryStreamFactory = new MemoryStreamFactory();

            assemblyLocation = fileSystem.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            xmlLocation = fileSystem.Path.Combine(assemblyLocation, "Files", "Xml");
            xsdLocation = fileSystem.Path.Combine(assemblyLocation, "Files", "Xsd");

            if (!fileSystem.Directory.Exists(xmlLocation))
            {
                throw new Exception("Could not find the Test Xml Files Folder.");
            }

            if (!fileSystem.Directory.Exists(xsdLocation))
            {
                throw new Exception("Could not find the Test Xsd Files Folder.");
            }

            xmlFilePaths = fileSystem.Directory.GetFiles(xmlLocation);
            xsdFilePaths = fileSystem.Directory.GetFiles(xsdLocation);

            if (xmlFilePaths == null)
            {
                throw new Exception("Could not find the Test Xml Files.");
            }

            if (xmlFilePaths.Length == 0)
            {
                throw new Exception("Could not find the Test Xml Files.");
            }

            if (xsdFilePaths == null)
            {
                throw new Exception("Could not find the Test Xsd Files.");
            }

            if (xsdFilePaths.Length == 0)
            {
                throw new Exception("Could not find the Test Xsd Files.");
            }
        }
Esempio n. 15
0
 public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func <IDtoService> dtoService, IServerApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func <IMediaEncoder> mediaEncoder, IFileSystem fileSystem, Func <ISubtitleEncoder> subtitleEncoder, IConfigurationManager config, IUserDataManager userDataManager, Func <IMediaSourceManager> mediaSourceManager, IJsonSerializer json, ITaskManager taskManager, IMemoryStreamFactory memoryStreamProvider)
 {
     _libraryManager       = libraryManager;
     _repo                 = repo;
     _imageProcessor       = imageProcessor;
     _logger               = logger;
     _userManager          = userManager;
     _dtoService           = dtoService;
     _appHost              = appHost;
     _tvSeriesManager      = tvSeriesManager;
     _mediaEncoder         = mediaEncoder;
     _fileSystem           = fileSystem;
     _subtitleEncoder      = subtitleEncoder;
     _config               = config;
     _userDataManager      = userDataManager;
     _mediaSourceManager   = mediaSourceManager;
     _json                 = json;
     _taskManager          = taskManager;
     _memoryStreamProvider = memoryStreamProvider;
 }
Esempio n. 16
0
		private RequestData(
			HttpMethod method,
			string path,
			PostData<object> data,
			IConnectionConfigurationValues global,
			IRequestConfiguration local,
			IMemoryStreamFactory memoryStreamFactory)
		{
			this.ConnectionSettings = global;
			this.MemoryStreamFactory = memoryStreamFactory;
			this.Method = method;
			this.PostData = data;

			if (data != null)
				data.DisableDirectStreaming = local?.DisableDirectStreaming ?? global.DisableDirectStreaming;

			this.Path = this.CreatePathWithQueryStrings(path, this.ConnectionSettings, null);

			this.Pipelined = local?.EnableHttpPipelining ?? global.HttpPipeliningEnabled;
			this.HttpCompression = global.EnableHttpCompression;
			this.ContentType = local?.ContentType ?? MimeType;
			this.Accept = local?.Accept ?? MimeType;
			this.Headers = global.Headers != null ? new NameValueCollection(global.Headers) : new NameValueCollection();
			this.RunAs = local?.RunAs;

			this.RequestTimeout = local?.RequestTimeout ?? global.RequestTimeout;
			this.PingTimeout =
				local?.PingTimeout
				?? global?.PingTimeout
				?? (global.ConnectionPool.UsingSsl ? ConnectionConfiguration.DefaultPingTimeoutOnSSL : ConnectionConfiguration.DefaultPingTimeout);

			this.KeepAliveInterval = (int)(global.KeepAliveInterval?.TotalMilliseconds ?? 2000);
			this.KeepAliveTime = (int)(global.KeepAliveTime?.TotalMilliseconds ?? 2000);

			this.ProxyAddress = global.ProxyAddress;
			this.ProxyUsername = global.ProxyUsername;
			this.ProxyPassword = global.ProxyPassword;
			this.DisableAutomaticProxyDetection = global.DisableAutomaticProxyDetection;
			this.BasicAuthorizationCredentials = local?.BasicAuthenticationCredentials ?? global.BasicAuthenticationCredentials;
			this.AllowedStatusCodes = local?.AllowedStatusCodes ?? Enumerable.Empty<int>();
		}
Esempio n. 17
0
        public EndPointListener(HttpListener listener, IpAddressInfo addr, int port, bool secure, ICertificate cert, ILogger logger, ICryptoProvider cryptoProvider, IStreamFactory streamFactory, ISocketFactory socketFactory, IMemoryStreamFactory memoryStreamFactory, ITextEncoding textEncoding)
        {
            this.listener        = listener;
            _logger              = logger;
            _cryptoProvider      = cryptoProvider;
            _streamFactory       = streamFactory;
            _socketFactory       = socketFactory;
            _memoryStreamFactory = memoryStreamFactory;
            _textEncoding        = textEncoding;

            this.secure = secure;
            this.cert   = cert;

            _enableDualMode = addr.Equals(IpAddressInfo.IPv6Any);
            endpoint        = new IpEndPointInfo(addr, port);

            prefixes     = new Dictionary <ListenerPrefix, HttpListener>();
            unregistered = new Dictionary <HttpConnection, HttpConnection>();

            CreateSocket();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerManager" /> class.
        /// </summary>
        /// <param name="applicationHost">The application host.</param>
        /// <param name="jsonSerializer">The json serializer.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="configurationManager">The configuration manager.</param>
        /// <exception cref="System.ArgumentNullException">applicationHost</exception>
        public ServerManager(IServerApplicationHost applicationHost, IJsonSerializer jsonSerializer, ILogger logger, IServerConfigurationManager configurationManager, IMemoryStreamFactory memoryStreamProvider, ITextEncoding textEncoding)
        {
            if (applicationHost == null)
            {
                throw new ArgumentNullException("applicationHost");
            }
            if (jsonSerializer == null)
            {
                throw new ArgumentNullException("jsonSerializer");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            _logger               = logger;
            _jsonSerializer       = jsonSerializer;
            _applicationHost      = applicationHost;
            ConfigurationManager  = configurationManager;
            _memoryStreamProvider = memoryStreamProvider;
            _textEncoding         = textEncoding;
        }
Esempio n. 19
0
        public EndPointListener(HttpListener listener, IPAddress addr, int port, bool secure, X509Certificate cert, ILogger logger, ICryptoProvider cryptoProvider, ISocketFactory socketFactory, IMemoryStreamFactory memoryStreamFactory, ITextEncoding textEncoding, IFileSystem fileSystem, IEnvironmentInfo environment)
        {
            this.listener        = listener;
            _logger              = logger;
            _cryptoProvider      = cryptoProvider;
            _socketFactory       = socketFactory;
            _memoryStreamFactory = memoryStreamFactory;
            _textEncoding        = textEncoding;
            _fileSystem          = fileSystem;
            _environment         = environment;

            this.secure = secure;
            this.cert   = cert;

            _enableDualMode = addr.Equals(IPAddress.IPv6Any);
            endpoint        = new IPEndPoint(addr, port);

            prefixes     = new Dictionary <ListenerPrefix, HttpListener>();
            unregistered = new Dictionary <HttpConnection, HttpConnection>();

            CreateSocket();
        }
Esempio n. 20
0
        /// <summary>
        /// Creates the server.
        /// </summary>
        /// <returns>IHttpServer.</returns>
        public static IHttpServer CreateServer(IServerApplicationHost applicationHost,
                                               ILogManager logManager,
                                               IServerConfigurationManager config,
                                               INetworkManager networkmanager,
                                               IMemoryStreamFactory streamProvider,
                                               string serverName,
                                               string defaultRedirectpath,
                                               ITextEncoding textEncoding,
                                               ISocketFactory socketFactory,
                                               ICryptoProvider cryptoProvider,
                                               IJsonSerializer json,
                                               IXmlSerializer xml,
                                               IEnvironmentInfo environment,
                                               ICertificate certificate,
                                               IFileSystem fileSystem,
                                               bool enableDualModeSockets)
        {
            var logger = logManager.GetLogger("HttpServer");

            return(new HttpListenerHost(applicationHost,
                                        logger,
                                        config,
                                        serverName,
                                        defaultRedirectpath,
                                        networkmanager,
                                        streamProvider,
                                        textEncoding,
                                        socketFactory,
                                        cryptoProvider,
                                        json,
                                        xml,
                                        environment,
                                        certificate,
                                        new StreamFactory(),
                                        GetParseFn,
                                        enableDualModeSockets,
                                        fileSystem));
        }
Esempio n. 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpClientManager" /> class.
        /// </summary>
        public HttpClientManager(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem, IMemoryStreamFactory memoryStreamProvider, Func <string> defaultUserAgentFn)
        {
            if (appPaths == null)
            {
                throw new ArgumentNullException("appPaths");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            _logger               = logger;
            _fileSystem           = fileSystem;
            _memoryStreamProvider = memoryStreamProvider;
            _appPaths             = appPaths;
            _defaultUserAgentFn   = defaultUserAgentFn;

            // http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c
            ServicePointManager.Expect100Continue = false;

            // Trakt requests sometimes fail without this
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
        }
Esempio n. 22
0
        private RequestData(
            HttpMethod method,
            string path,
            PostData <object> data,
            IConnectionConfigurationValues global,
            IRequestConfiguration local,
            IMemoryStreamFactory memoryStreamFactory)
        {
            this.ConnectionSettings  = global;
            this.MemoryStreamFactory = memoryStreamFactory;
            this.Method   = method;
            this.PostData = data;
            this.Path     = this.CreatePathWithQueryStrings(path, this.ConnectionSettings, null);

            this.Pipelined       = global.HttpPipeliningEnabled || (local?.EnableHttpPipelining).GetValueOrDefault(false);
            this.HttpCompression = global.EnableHttpCompression;
            this.ContentType     = local?.ContentType ?? MimeType;
            this.Accept          = local?.Accept ?? MimeType;
            this.Headers         = global.Headers;
            this.RunAs           = local?.RunAs;

            this.RequestTimeout = local?.RequestTimeout ?? global.RequestTimeout;
            this.PingTimeout    =
                local?.PingTimeout
                ?? global?.PingTimeout
                ?? (global.ConnectionPool.UsingSsl ? ConnectionConfiguration.DefaultPingTimeoutOnSSL : ConnectionConfiguration.DefaultPingTimeout);

            this.KeepAliveInterval = (int)(global.KeepAliveInterval?.TotalMilliseconds ?? 2000);
            this.KeepAliveTime     = (int)(global.KeepAliveTime?.TotalMilliseconds ?? 2000);

            this.ProxyAddress  = global.ProxyAddress;
            this.ProxyUsername = global.ProxyUsername;
            this.ProxyPassword = global.ProxyPassword;
            this.DisableAutomaticProxyDetection = global.DisableAutomaticProxyDetection;
            this.BasicAuthorizationCredentials  = local?.BasicAuthenticationCredentials ?? global.BasicAuthenticationCredentials;
            this.AllowedStatusCodes             = local?.AllowedStatusCodes ?? Enumerable.Empty <int>();
        }
Esempio n. 23
0
        public MediaEncoder(ILogger logger, IJsonSerializer jsonSerializer, string ffMpegPath, string ffProbePath, bool hasExternalEncoder, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILiveTvManager liveTvManager, IIsoManager isoManager, ILibraryManager libraryManager, IChannelManager channelManager, ISessionManager sessionManager, Func <ISubtitleEncoder> subtitleEncoder, Func <IMediaSourceManager> mediaSourceManager, IHttpClient httpClient, IZipClient zipClient, IMemoryStreamFactory memoryStreamProvider, IProcessFactory processFactory,
                            int defaultImageExtractionTimeoutMs,
                            bool enableEncoderFontFile, IEnvironmentInfo environmentInfo)
        {
            if (jsonSerializer == null)
            {
                throw new ArgumentNullException("jsonSerializer");
            }

            _logger                         = logger;
            _jsonSerializer                 = jsonSerializer;
            ConfigurationManager            = configurationManager;
            FileSystem                      = fileSystem;
            LiveTvManager                   = liveTvManager;
            IsoManager                      = isoManager;
            LibraryManager                  = libraryManager;
            ChannelManager                  = channelManager;
            SessionManager                  = sessionManager;
            SubtitleEncoder                 = subtitleEncoder;
            MediaSourceManager              = mediaSourceManager;
            _httpClient                     = httpClient;
            _zipClient                      = zipClient;
            _memoryStreamProvider           = memoryStreamProvider;
            _processFactory                 = processFactory;
            DefaultImageExtractionTimeoutMs = defaultImageExtractionTimeoutMs;
            EnableEncoderFontFile           = enableEncoderFontFile;
            _environmentInfo                = environmentInfo;
            FFProbePath                     = ffProbePath;
            FFMpegPath                      = ffMpegPath;
            _originalFFProbePath            = ffProbePath;
            _originalFFMpegPath             = ffMpegPath;

            _hasExternalEncoder = hasExternalEncoder;

            SetEnvironmentVariable();
        }
Esempio n. 24
0
 public PackageCreator(string basePath, IFileSystem fileSystem, ILogger logger, IServerConfigurationManager config, IMemoryStreamFactory memoryStreamFactory, IResourceFileManager resourceFileManager)
 {
     _fileSystem          = fileSystem;
     _logger              = logger;
     _config              = config;
     _memoryStreamFactory = memoryStreamFactory;
     _basePath            = basePath;
     _resourceFileManager = resourceFileManager;
 }
Esempio n. 25
0
 public SubtitleEncoder(ILibraryManager libraryManager, ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem, IMediaEncoder mediaEncoder, IJsonSerializer json, IHttpClient httpClient, IMediaSourceManager mediaSourceManager, IMemoryStreamFactory memoryStreamProvider, IProcessFactory processFactory, ITextEncoding textEncoding)
 {
     _libraryManager       = libraryManager;
     _logger               = logger;
     _appPaths             = appPaths;
     _fileSystem           = fileSystem;
     _mediaEncoder         = mediaEncoder;
     _json                 = json;
     _httpClient           = httpClient;
     _mediaSourceManager   = mediaSourceManager;
     _memoryStreamProvider = memoryStreamProvider;
     _processFactory       = processFactory;
     _textEncoding         = textEncoding;
 }
Esempio n. 26
0
 public IRequestPipeline Create(IConnectionConfigurationValues configurationValues, IDateTimeProvider dateTimeProvider,
                                IMemoryStreamFactory memoryStreamFactory, IRequestParameters requestParameters
                                ) =>
 new RequestPipeline(Settings, DateTimeProvider, MemoryStreamFactory, requestParameters ?? new SearchRequestParameters());
 public MemoryStreamFactory(IMemoryStreamFactory memoryStreamFactory)
 {
     _memoryStreamFactory = memoryStreamFactory;
 }
Esempio n. 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DashboardService" /> class.
 /// </summary>
 /// <param name="appHost">The app host.</param>
 /// <param name="serverConfigurationManager">The server configuration manager.</param>
 /// <param name="fileSystem">The file system.</param>
 public DashboardService(IServerApplicationHost appHost, IServerConfigurationManager serverConfigurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer, IAssemblyInfo assemblyInfo, ILogger logger, IHttpResultFactory resultFactory, IMemoryStreamFactory memoryStreamFactory)
 {
     _appHost = appHost;
     _serverConfigurationManager = serverConfigurationManager;
     _fileSystem          = fileSystem;
     _localization        = localization;
     _jsonSerializer      = jsonSerializer;
     _assemblyInfo        = assemblyInfo;
     _logger              = logger;
     _resultFactory       = resultFactory;
     _memoryStreamFactory = memoryStreamFactory;
 }
Esempio n. 29
0
        private static bool SetSpecialTypes <TResponse>(string mimeType, byte[] bytes, IMemoryStreamFactory memoryStreamFactory, out TResponse cs)
            where TResponse : class, IOpenSearchResponse, new()
        {
            cs = null;
            var responseType = typeof(TResponse);

            if (!SpecialTypes.Contains(responseType))
            {
                return(false);
            }

            if (responseType == typeof(StringResponse))
            {
                cs = new StringResponse(bytes.Utf8String()) as TResponse;
            }
            else if (responseType == typeof(BytesResponse))
            {
                cs = new BytesResponse(bytes) as TResponse;
            }
            else if (responseType == typeof(VoidResponse))
            {
                cs = new VoidResponse() as TResponse;
            }
            else if (responseType == typeof(DynamicResponse))
            {
                //if not json store the result under "body"
                if (mimeType == null || !mimeType.StartsWith(RequestData.MimeType))
                {
                    var dictionary = new DynamicDictionary();
                    dictionary["body"] = new DynamicValue(bytes.Utf8String());
                    cs = new DynamicResponse(dictionary) as TResponse;
                }
                else
                {
                    using var ms = memoryStreamFactory.Create(bytes);
                    var body = LowLevelRequestResponseSerializer.Instance.Deserialize <DynamicDictionary>(ms);
                    cs = new DynamicResponse(body) as TResponse;
                }
            }
            return(cs != null);
        }
		public RequestData(HttpMethod method, string path, PostData<object> data, IConnectionConfigurationValues global, IMemoryStreamFactory memoryStreamFactory)
			: this(method, path, data, global, (IRequestConfiguration)null, memoryStreamFactory)
		{ }
Esempio n. 31
0
        private RequestData(
            HttpMethod method,
            PostData data,
            IConnectionConfigurationValues global,
            IRequestConfiguration local,
            IMemoryStreamFactory memoryStreamFactory
            )
        {
            ConnectionSettings  = global;
            MemoryStreamFactory = memoryStreamFactory;
            Method   = method;
            PostData = data;

            if (data != null)
            {
                data.DisableDirectStreaming = local?.DisableDirectStreaming ?? global.DisableDirectStreaming;
            }

            Pipelined       = local?.EnableHttpPipelining ?? global.HttpPipeliningEnabled;
            HttpCompression = global.EnableHttpCompression;
            RequestMimeType = local?.ContentType ?? MimeType;
            Accept          = local?.Accept ?? MimeType;

            if (global.Headers != null)
            {
                Headers = new NameValueCollection(global.Headers);
            }

            if (local?.Headers != null)
            {
                Headers ??= new NameValueCollection();
                foreach (var key in local.Headers.AllKeys)
                {
                    Headers[key] = local.Headers[key];
                }
            }

            if (!string.IsNullOrEmpty(local?.OpaqueId))
            {
                Headers ??= new NameValueCollection();
                Headers.Add(OpaqueIdHeader, local.OpaqueId);
            }

            RunAs = local?.RunAs;
            SkipDeserializationForStatusCodes = global?.SkipDeserializationForStatusCodes;
            ThrowExceptions = local?.ThrowExceptions ?? global.ThrowExceptions;

            RequestTimeout = local?.RequestTimeout ?? global.RequestTimeout;
            PingTimeout    =
                local?.PingTimeout
                ?? global.PingTimeout
                ?? (global.ConnectionPool.UsingSsl ? ConnectionConfiguration.DefaultPingTimeoutOnSSL : ConnectionConfiguration.DefaultPingTimeout);

            KeepAliveInterval = (int)(global.KeepAliveInterval?.TotalMilliseconds ?? 2000);
            KeepAliveTime     = (int)(global.KeepAliveTime?.TotalMilliseconds ?? 2000);

            ProxyAddress  = global.ProxyAddress;
            ProxyUsername = global.ProxyUsername;
            ProxyPassword = global.ProxyPassword;
            DisableAutomaticProxyDetection  = global.DisableAutomaticProxyDetection;
            BasicAuthorizationCredentials   = local?.BasicAuthenticationCredentials ?? global.BasicAuthenticationCredentials;
            ApiKeyAuthenticationCredentials = local?.ApiKeyAuthenticationCredentials ?? global.ApiKeyAuthenticationCredentials;
            AllowedStatusCodes      = local?.AllowedStatusCodes ?? EmptyReadOnly <int> .Collection;
            ClientCertificates      = local?.ClientCertificates ?? global.ClientCertificates;
            UserAgent               = global.UserAgent;
            TransferEncodingChunked = local?.TransferEncodingChunked ?? global.TransferEncodingChunked;
        }
		public RequestData(HttpMethod method, string path, PostData<object> data, IConnectionConfigurationValues global, IRequestParameters local, IMemoryStreamFactory memoryStreamFactory)
			: this(method, path, data, global, (IRequestConfiguration)local?.RequestConfiguration, memoryStreamFactory)
		{
			this.CustomConverter = local?.DeserializationOverride;
			this.Path = this.CreatePathWithQueryStrings(path, this.ConnectionSettings, local);
		}
Esempio n. 33
0
 private HttpConnection(ILogger logger, IAcceptSocket socket, EndPointListener epl, bool secure, ICertificate cert, ICryptoProvider cryptoProvider, IStreamFactory streamFactory, IMemoryStreamFactory memoryStreamFactory, ITextEncoding textEncoding, IFileSystem fileSystem, IEnvironmentInfo environment)
 {
     _logger              = logger;
     this._socket         = socket;
     this._epl            = epl;
     this.secure          = secure;
     this.cert            = cert;
     _cryptoProvider      = cryptoProvider;
     _memoryStreamFactory = memoryStreamFactory;
     _textEncoding        = textEncoding;
     _fileSystem          = fileSystem;
     _environment         = environment;
     _streamFactory       = streamFactory;
 }
Esempio n. 34
0
 public MonoAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, IMemoryStreamFactory memoryStreamFactory, MediaBrowser.Common.Net.INetworkManager networkManager, Action <string, string> certificateGenerator, Func <string> defaultUsernameFactory) : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, memoryStreamFactory, networkManager, certificateGenerator, defaultUsernameFactory)
 {
 }
Esempio n. 35
0
		public RequestData(HttpMethod method, string path, PostData<object> data, IConnectionConfigurationValues global, IMemoryStreamFactory memoryStreamFactory)
#pragma warning disable CS0618 // Type or member is obsolete
			: this(method, path, data, global, (IRequestConfiguration)null, memoryStreamFactory)
#pragma warning restore CS0618 // Type or member is obsolete
		{ }
 public AesEncryptionStrategy(IAesCryptoServiceProviderFactory aesCryptoServiceProviderFactory, IMemoryStreamFactory memoryStreamFactory, ICryptoStreamFactory cryptoStreamFactory)
 {
     _aesCryptoServiceProviderFactory = aesCryptoServiceProviderFactory;
     _memoryStreamFactory = memoryStreamFactory;
     _cryptoStreamFactory = cryptoStreamFactory;
 }
		public IRequestPipeline Create(IConnectionConfigurationValues configurationValues, IDateTimeProvider dateTimeProvider, IMemoryStreamFactory memorystreamFactory, IRequestParameters requestParameters) =>
			new RequestPipeline(configurationValues, dateTimeProvider, memorystreamFactory, requestParameters);
Esempio n. 38
0
        public HttpListenerHost(IServerApplicationHost applicationHost,
                                ILogger logger,
                                IServerConfigurationManager config,
                                string serviceName,
                                string defaultRedirectPath, INetworkManager networkManager, IMemoryStreamFactory memoryStreamProvider, ITextEncoding textEncoding, ISocketFactory socketFactory, ICryptoProvider cryptoProvider, IJsonSerializer jsonSerializer, IXmlSerializer xmlSerializer, IEnvironmentInfo environment, ICertificate certificate, IStreamFactory streamFactory, Func <Type, Func <string, object> > funcParseFn, bool enableDualModeSockets, IFileSystem fileSystem)
        {
            Instance = this;

            _appHost               = applicationHost;
            DefaultRedirectPath    = defaultRedirectPath;
            _networkManager        = networkManager;
            _memoryStreamProvider  = memoryStreamProvider;
            _textEncoding          = textEncoding;
            _socketFactory         = socketFactory;
            _cryptoProvider        = cryptoProvider;
            _jsonSerializer        = jsonSerializer;
            _xmlSerializer         = xmlSerializer;
            _environment           = environment;
            _certificate           = certificate;
            _streamFactory         = streamFactory;
            _funcParseFn           = funcParseFn;
            _enableDualModeSockets = enableDualModeSockets;
            _fileSystem            = fileSystem;
            _config = config;

            _logger = logger;

            RequestFilters  = new List <Action <IRequest, IResponse, object> >();
            ResponseFilters = new List <Action <IRequest, IResponse, object> >();
        }
Esempio n. 39
0
 public TargetDataProvider(IServerSyncProvider provider, SyncTarget target, IServerApplicationHost appHost, ILogger logger, IJsonSerializer json, IFileSystem fileSystem, IApplicationPaths appPaths, IMemoryStreamFactory memoryStreamProvider)
 {
     _logger               = logger;
     _json                 = json;
     _provider             = provider;
     _target               = target;
     _fileSystem           = fileSystem;
     _appPaths             = appPaths;
     _memoryStreamProvider = memoryStreamProvider;
     _appHost              = appHost;
 }
Esempio n. 40
0
        public static async Task <HttpConnection> Create(ILogger logger, IAcceptSocket sock, EndPointListener epl, bool secure, ICertificate cert, ICryptoProvider cryptoProvider, IStreamFactory streamFactory, IMemoryStreamFactory memoryStreamFactory, ITextEncoding textEncoding, IFileSystem fileSystem, IEnvironmentInfo environment)
        {
            var connection = new HttpConnection(logger, sock, epl, secure, cert, cryptoProvider, streamFactory, memoryStreamFactory, textEncoding, fileSystem, environment);

            await connection.InitStream().ConfigureAwait(false);

            return(connection);
        }
		public IRequestPipeline Create(IConnectionConfigurationValues configurationValues, IDateTimeProvider dateTimeProvider, IMemoryStreamFactory memorystreamFactory, IRequestParameters requestParameters) => 
			new RequestPipeline(this.Settings, this.DateTimeProvider, this.MemoryStreamFactory, requestParameters ?? new SearchRequestParameters());