Exemplo n.º 1
0
        public SafeguardSessionsConnection(ISpsAuthenticator authenticator)
        {
            _authenticator = authenticator;

            _client = new RestClient($"https://{_authenticator.NetworkAddress}/api")
            {
                CookieContainer = new CookieContainer(),
                Authenticator   = new HttpBasicAuthenticator(_authenticator.UserName, _authenticator.Password.ToInsecureString()),
            };

            if (_authenticator.IgnoreSsl)
            {
                _client.RemoteCertificateValidationCallback += (sender, certificate, chain, errors) => true;
            }

            var authRequest = new RestRequest("authentication", RestSharp.Method.GET);

            _client.LogRequestDetails(authRequest);

            var response = _client.Get(new RestRequest("authentication", RestSharp.Method.GET));

            response.LogResponseDetails();

            if (!response.IsSuccessful)
            {
                throw new SafeguardDotNetException($"Error returned when authenticating to {_client.BaseUrl} sps api.", response.StatusCode, response.Content);
            }

            _lazyStreamingRequest = new Lazy <ISpsStreamingRequest>(() =>
            {
                return(new SpsStreamingRequest(_authenticator, () => _disposed));
            });
        }
 internal SpsStreamingRequest(ISpsAuthenticator authenticator, Func <bool> isDisposed)
 {
     _isDisposed     = isDisposed;
     _authenticator  = authenticator;
     _lazyHttpClient = new Lazy <HttpClient>(() => CreateHttpClient(_progressMessageHandler));
 }