Пример #1
0
        public Client(IHttpClientFactory clientFactory, IRequestGenerator requestGenerator, Options options)
        {
            _options = options;
            IRequestExecuter requestExecuter = new RequestExecuter(
                clientFactory.CreateHttpClient(new HttpClientOptions
                    {
                        AddTokenToRequests = true,
                        TokenRetriever = () => _options.AccessToken,
                        ReadRequestsPerSecond = options.ReadRequestsPerSecond,
                        WriteRequestsPerSecond = options.WriteRequestsPerSecond,
                    }),
                clientFactory.CreateHttpClient(new HttpClientOptions()));

            if (options.AutoRetry)
            {
                requestExecuter = new AutoRetryRequestExecuter(requestExecuter)
                    {
                        NumberOfRetries = options.NumberOfRetries
                    };
            }

            RequestGenerator = requestGenerator;

            Core = new Core(requestExecuter, requestGenerator.Core, options);
            Business = new Business(requestExecuter, requestGenerator, options);
        }
Пример #2
0
		/// <summary>Constructor</summary>
        public Pusher(Database db, Uri remote, bool continuous, IHttpClientFactory clientFactory
            , TaskFactory workExecutor) : base(db, remote, continuous, clientFactory
			, workExecutor)
		{
			CreateTarget = false;
			observing = false;
		}
Пример #3
0
 public AppVeyor(Logger logger, IEnvironment environment, IHttpClientFactory httpClientFactory)
 {
     _logger = logger;
     _environment = environment;
     _httpClientFactory = httpClientFactory;
     _appVeyorApiUrl = _environment.GetEnvironmentVariable("APPVEYOR_API_URL");
 }
Пример #4
0
        public CloudSearchSettings(string endpoint, IHttpClientFactory httpClientFactory = null)
        {
            if (endpoint == null) throw new ArgumentNullException(nameof(endpoint));

            Endpoint = endpoint;
            HttpClientFactory = httpClientFactory ?? new DefaultHttpClientFactory();
        }
Пример #5
0
        public Client(IHttpClientFactory clientFactory, IRequestGenerator requestGenerator, Options options)
        {
            _options = options;

            _clientOAuth = clientFactory.CreateHttpClient(new HttpClientOptions());
            _clientContent = clientFactory.CreateHttpClient(new HttpClientOptions {AddTokenToRequests = true, TokenRetriever = () => _options.AccessToken});
            _clientContentNoRedirection = clientFactory.CreateHttpClient(new HttpClientOptions {AllowAutoRedirect = false, AddTokenToRequests = true, TokenRetriever = () => _options.AccessToken});


            RequestGenerator = requestGenerator;
        }
Пример #6
0
        public HttpClientWebReaderManager(IHttpClientFactory httpClientFactory, IContentTypeDetector contentTypeDetector, IRetryManager retryManager)
        {
            if (null == httpClientFactory)
                throw new ArgumentNullException(nameof(httpClientFactory));
            if (null == contentTypeDetector)
                throw new ArgumentNullException(nameof(contentTypeDetector));
            if (null == retryManager)
                throw new ArgumentNullException(nameof(retryManager));

            _httpClientFactory = httpClientFactory;
            _contentTypeDetector = contentTypeDetector;
            _retryManager = retryManager;
        }
        IHttpClient ICouchbaseClientConfiguration.CreateHttpClient(Uri baseUri)
        {
            if (this.clientFactory == null)
            {
                var tmp = this.HttpClientFactory;

                this.clientFactory = tmp == null ? HammockHttpClientFactory.Instance : tmp.CreateInstance();
            }

            Debug.Assert(this.clientFactory != null);

            return this.clientFactory.Create(baseUri);
        }
        public HttpEndpointLogProvider(
            string endpoint,
            LogLevel loggingLevel,
            string contentType = DefaultContentType,
            ISerializer serializer = null,
            IHttpClientFactory httpClientFactory = null)
        {
            serializer = serializer ?? GetDefaultSerializer();
            httpClientFactory = httpClientFactory ?? GetDefaultHttpClientFactory();

            _endpoint = endpoint;
            _loggingLevel = loggingLevel;
            _contentType = contentType;
            _serializer = serializer;
            _httpClientFactory = httpClientFactory;
        }
Пример #9
0
        public TentClientFactory(
            IHttpRequestFactory httpRequestFactory,
            IHttpClientFactory httpClientFactory,
            IQueryStringHelpers queryStringHelpers,
            IBewitLogic bewitLogic,
            IUriHelpers uriHelpers,
            ITentConstants tentConstants)
        {
            Ensure.Argument.IsNotNull(httpRequestFactory, nameof(httpRequestFactory));
            Ensure.Argument.IsNotNull(httpClientFactory, nameof(httpClientFactory));
            Ensure.Argument.IsNotNull(queryStringHelpers, nameof(queryStringHelpers));
            Ensure.Argument.IsNotNull(bewitLogic, nameof(bewitLogic));
            Ensure.Argument.IsNotNull(uriHelpers, nameof(uriHelpers));
            Ensure.Argument.IsNotNull(tentConstants, nameof(tentConstants));

            this.httpRequestFactory = httpRequestFactory;
            this.httpClientFactory = httpClientFactory;
            this.queryStringHelpers = queryStringHelpers;
            this.bewitLogic = bewitLogic;
            this.uriHelpers = uriHelpers;
            this.tentConstants = tentConstants;
        }
 public CompaniesHouseSearchCompanyClient(IHttpClientFactory httpClientFactory, ICompanySearchUriBuilder companySearchUriBuilder)
 {
     _httpClientFactory = httpClientFactory;
     _companySearchUriBuilder = companySearchUriBuilder;
 }
 public RestServiceFactory(IHttpClientFactory clientFactory)
 {
     _clientFactory = clientFactory;
 }
Пример #12
0
 public ReCaptchaService(RecaptchaSettings settings, IHttpClientFactory httpClientFactory)
 {
     _recaptchaSettings = settings;
     _clientFactory     = httpClientFactory;
 }
Пример #13
0
 public JwtReqiurementHandler(IHttpClientFactory httpClientFactory, IHttpContextAccessor httpContextAccessor)
 {
     _client      = httpClientFactory.CreateClient();
     _httpContext = httpContextAccessor.HttpContext;
 }
Пример #14
0
 public IndexModel(IMemoryCache memoryCache, IHttpClientFactory clientFactory, ILogger <IndexModel> logger)
 {
     _cache         = memoryCache;
     _clientFactory = clientFactory;
     _logger        = logger;
 }
Пример #15
0
 public ParserApiClient(IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
 }
Пример #16
0
 public ObterUltimaAtualizacaoPorProcessoQueryHandler(IHttpClientFactory httpClientFactory)
 {
     this.httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
 }
 public SendMessage(IHttpClientFactory httpClient)
 {
     _httpClient = httpClient;
 }
Пример #18
0
 /// <summary>
 /// hangfire后台任务
 /// </summary>
 /// <param name="userInfoService"></param>
 /// <param name="postService"></param>
 /// <param name="settingService"></param>
 /// <param name="searchDetailsService"></param>
 /// <param name="linksService"></param>
 /// <param name="httpClientFactory"></param>
 /// <param name="HostEnvironment"></param>
 /// <param name="searchEngine"></param>
 public HangfireBackJob(IUserInfoService userInfoService, IPostService postService, ISystemSettingService settingService, ISearchDetailsService searchDetailsService, ILinksService linksService, IHttpClientFactory httpClientFactory, IWebHostEnvironment HostEnvironment, ISearchEngine <DataContext> searchEngine, IAdvertisementService advertisementService)
 {
     _userInfoService      = userInfoService;
     _postService          = postService;
     _settingService       = settingService;
     _searchDetailsService = searchDetailsService;
     _linksService         = linksService;
     _httpClientFactory    = httpClientFactory;
     _hostEnvironment      = HostEnvironment;
     _searchEngine         = searchEngine;
     _advertisementService = advertisementService;
 }
Пример #19
0
 public EmployeeDataService2(IHttpClientFactory httpClientFactory, IMapper mapper)
 {
     _httpClientFactory = httpClientFactory;
     _mapper            = mapper;
 }
Пример #20
0
 public UserRepository(IHttpClientFactory clientFactory)
 {
     _client = clientFactory.CreateClient("Spotify");
 }
Пример #21
0
 public TestController(IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory = httpClientFactory;
 }
Пример #22
0
 public BasketApi(IApiSettings settings, IHttpClientFactory factory) : base(factory)
 {
     _settings = settings;
     _builder  = new HttpRequestBuilder(_settings.BaseAddress);
     _builder.AddToPath(_settings.BasketPath);
 }
Пример #23
0
        protected void SetClientFactory(IHttpClientFactory clientFactory)
        {
            if (clientFactory != null)
            {
                this.clientFactory = clientFactory;
            }
            else
            {
                Manager manager = null;
                if (LocalDatabase != null)
                {
                    manager = LocalDatabase.Manager;
                }

                IHttpClientFactory managerClientFactory = null;
                if (manager != null)
                {
                    managerClientFactory = manager.DefaultHttpClientFactory;
                }

                if (managerClientFactory != null)
                {
                    this.clientFactory = managerClientFactory;
                }
                else
                {
                    CookieStore cookieStore = null;
                    if (manager != null)
                    {
                        cookieStore = manager.SharedCookieStore;
                    }

                    if (cookieStore == null)
                    {
                        cookieStore = new CookieStore();
                    }

                    this.clientFactory = new CouchbaseLiteHttpClientFactory(cookieStore);
                }
            }
        }
Пример #24
0
 public BaseRepository(IHttpClientFactory client)
 {
     _client = client;
 }
Пример #25
0
 public Authenticator(IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory = httpClientFactory;
 }
Пример #26
0
 public ApnsClientFactory(IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory = httpClientFactory;
 }
Пример #27
0
 public GitHubUserSearchService(IHttpClientFactory factory)
 {
     _factory = factory;
 }
Пример #28
0
 protected HttpBenchmarkService(IConfiguration configuration, IHttpClientFactory httpClientFactory)
     : base(configuration, httpClientFactory)
 {
 }
Пример #29
0
 protected void SetClientFactory(IHttpClientFactory clientFactory)
 {
     ClientFactory = clientFactory;
 }
 public TestController(IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
 }
Пример #31
0
 public ReCaptchaService(IOptions <RecaptchaSettings> settings, IHttpClientFactory httpClientFactory)
 {
     _recaptchaSettings = settings.Value;
     _clientFactory     = httpClientFactory;
 }
Пример #32
0
 /// <summary>
 /// Creates a new instance sets the default values
 /// </summary>
 /// <param name="clientFactory">Reference to HTTP client; from dependency injection</param>
 /// <param name="memoryCache">Reference to memory cache; from dependency injection</param>
 public ApiAppointmentDataAccess(IHttpClientFactory clientFactory, IMemoryCache memoryCache)
 {
     _clientFactory    = clientFactory;
     _appointmentCache = memoryCache;
 }
Пример #33
0
 public static void SetParameter(this IMediaStreamFacadeBase mediaStreamFacade, IHttpClientFactory httpClientFactory)
 {
     mediaStreamFacade.Builder.RegisterSingleton(httpClientFactory);
 }
Пример #34
0
 // private readonly ILoggingBroker loggingBroker;
 public StarWarsApiClient(IHttpClientFactory httpClientFactory) => this.httpClientFactory = httpClientFactory;
        private async Task TestOAuth10(IHttpClientFactory httpClientFactory, ISignatureProvider signatureProvider)
        {
            var client = new RestClient("http://oauthbin.com/v1/")
            {
                HttpClientFactory = httpClientFactory,
            };

            var consumerKey = "key";
            var consumerSecret = "secret";

            var authenticator = OAuth1Authenticator.ForRequestToken(consumerKey, consumerSecret, "http://localhost/test");
            authenticator.SignatureProvider = signatureProvider;
            client.Authenticator = authenticator;

            string requestToken, requestTokenSecret;

            {
                var request = new RestRequest("request-token");
                var response = await client.Execute(request);
                var requestTokenResponse = Encoding.UTF8.GetString(response.RawBytes);
                Assert.DoesNotContain('\n', requestTokenResponse);

                var tokenInfo = (from part in requestTokenResponse.Split('&')
                                 let equalSignPos = part.IndexOf('=')
                                 let partKey = part.Substring(0, equalSignPos)
                                 let partValue = part.Substring(equalSignPos + 1)
                                 select new
                                 {
                                     partKey,
                                     partValue
                                 }).ToDictionary(x => x.partKey, x => x.partValue);

                Assert.Contains("oauth_token", tokenInfo.Keys);
                Assert.Contains("oauth_token_secret", tokenInfo.Keys);

                requestToken = tokenInfo["oauth_token"];
                requestTokenSecret = tokenInfo["oauth_token_secret"];
            }

            authenticator = OAuth1Authenticator.ForAccessToken(consumerKey, consumerSecret, requestToken, requestTokenSecret);
            authenticator.SignatureProvider = signatureProvider;
            client.Authenticator = authenticator;

            string accessKey, accessSecret;

            {
                var request = new RestRequest("access-token");
                var response = await client.Execute(request);
                var accessTokenResponse = Encoding.UTF8.GetString(response.RawBytes);
                Assert.DoesNotContain('\n', accessTokenResponse);

                var tokenInfo = (from part in accessTokenResponse.Split('&')
                                 let equalSignPos = part.IndexOf('=')
                                 let partKey = part.Substring(0, equalSignPos)
                                 let partValue = part.Substring(equalSignPos + 1)
                                 select new
                                 {
                                     partKey,
                                     partValue
                                 }).ToDictionary(x => x.partKey, x => x.partValue);

                Assert.Contains("oauth_token", tokenInfo.Keys);
                Assert.Contains("oauth_token_secret", tokenInfo.Keys);

                accessKey = tokenInfo["oauth_token"];
                accessSecret = tokenInfo["oauth_token_secret"];
            }

            authenticator = OAuth1Authenticator.ForProtectedResource(consumerKey, consumerSecret, accessKey, accessSecret);
            authenticator.SignatureProvider = signatureProvider;
            client.Authenticator = authenticator;

            {
                var request = new RestRequest("echo", Method.POST);
                request.AddParameter("one", "1");
                request.AddParameter("two", "2");
                var response = await client.Execute(request);
                var text = Encoding.UTF8.GetString(response.RawBytes);
                Assert.DoesNotContain('\n', text);

                var data = (from part in text.Split('&')
                            let equalSignPos = part.IndexOf('=')
                            let partKey = part.Substring(0, equalSignPos)
                            let partValue = part.Substring(equalSignPos + 1)
                            select new
                            {
                                partKey,
                                partValue
                            }).ToDictionary(x => x.partKey, x => x.partValue);
                Assert.Contains("one", data.Keys);
                Assert.Contains("two", data.Keys);
                Assert.Equal("1", data["one"]);
                Assert.Equal("2", data["two"]);
            }
        }
Пример #36
0
 public WebhookClient(IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory = httpClientFactory;
 }
        internal void SetupHttpClientFactory(IHttpClientFactory newValue, Database db)
        {
            if(newValue != null) {
                ClientFactory = newValue;
            } else {
                var manager = db?.Manager;
                var managerClientFactory = manager?.DefaultHttpClientFactory;
                ClientFactory = managerClientFactory ?? new CouchbaseLiteHttpClientFactory();
            }

            CookieStore = new CookieStore(db, null);
        }
 public BooksController(ILogger <HomeController> logger, IHttpClientFactory clientFactory)
 {
     _logger        = logger;
     _clientFactory = clientFactory;
 }
Пример #39
0
        /// <summary>Private Constructor</summary>
        protected Replication(Database db, Uri remote, bool continuous, IHttpClientFactory clientFactory, TaskFactory workExecutor)
        {
            LocalDatabase = db;
            Continuous = continuous;
            // NOTE: Consider running a separate scheduler for all http requests.
            WorkExecutor = workExecutor;
            CancellationTokenSource = new CancellationTokenSource();
            RemoteUrl = remote;
            Status = ReplicationStatus.Stopped;
            online = Manager.SharedInstance.NetworkReachabilityManager.CurrentStatus == NetworkReachabilityStatus.Reachable;
            RequestHeaders = new Dictionary<String, Object>();
            requests = new HashSet<HttpClient>();

            // FIXME: Refactor to visitor pattern.
            if (RemoteUrl.GetQuery() != null && !RemoteUrl.GetQuery().IsEmpty())
            {
                var uri = new Uri(remote.ToString());
                var personaAssertion = URIUtils.GetQueryParameter(uri, PersonaAuthorizer.QueryParameter);

                if (personaAssertion != null && !personaAssertion.IsEmpty())
                {
                    var email = PersonaAuthorizer.RegisterAssertion(personaAssertion);
                    var authorizer = new PersonaAuthorizer(email);
                    Authenticator = authorizer;
                }

                var facebookAccessToken = URIUtils.GetQueryParameter(uri, FacebookAuthorizer.QueryParameter);

                if (facebookAccessToken != null && !facebookAccessToken.IsEmpty())
                {
                    var email = URIUtils.GetQueryParameter(uri, FacebookAuthorizer.QueryParameterEmail);
                    var authorizer = new FacebookAuthorizer(email);
                    Uri remoteWithQueryRemoved = null;

                    try
                    {
                        remoteWithQueryRemoved = new UriBuilder(remote.Scheme, remote.GetHost(), remote.Port, remote.AbsolutePath).Uri;
                    }
                    catch (UriFormatException e)
                    {
                        throw new ArgumentException("Invalid URI format.", "remote", e);
                    }

                    FacebookAuthorizer.RegisterAccessToken(facebookAccessToken, email, remoteWithQueryRemoved.ToString());

                    Authenticator = authorizer;
                }
                // we need to remove the query from the URL, since it will cause problems when
                // communicating with sync gw / couchdb
                try
                {
                    RemoteUrl = new UriBuilder(remote.Scheme, remote.GetHost(), remote.Port, remote.AbsolutePath).Uri;
                }
                catch (UriFormatException e)
                {
                    throw new ArgumentException("Invalid URI format.", "remote", e);
                }
            }

            Batcher = new Batcher<RevisionInternal>(workExecutor, InboxCapacity, ProcessorDelay, inbox =>
            {
                try 
                {
                    Log.V(Tag, "*** BEGIN ProcessInbox ({0} sequences)", inbox.Count);
                    ProcessInbox (new RevisionList(inbox));
                    Log.V(Tag, "*** END ProcessInbox (lastSequence={0})", LastSequence);
                    UpdateActive();
                } 
                catch (Exception e) 
                {
                    Log.E(Tag, "ERROR: ProcessInbox failed: ", e);
                    throw new RuntimeException(e);
                }
            });

            SetClientFactory(clientFactory);
        }
Пример #40
0
 public OrdersController(IHttpContextAccessor httpContextAccessor,
                         ITouristRouteRepository touristRouteRepository, IMapper mapper, IHttpClientFactory httpClientFactory)
 {
     _httpContextAccessor    = httpContextAccessor;
     _touristRouteRepository = touristRouteRepository;
     _mapper            = mapper;
     _httpClientFactory = httpClientFactory;
 }
 public LeagueOfLegendsApiService(IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory = httpClientFactory;
 }
Пример #42
0
 public TaxApiClient(IHttpClientFactory httpFactory, ILogger <TaxApiClient> logger)
 {
     _logger      = logger;
     _httpFactory = httpFactory;
 }
        /// <summary>Creates an authorization code flow with the given parameters.</summary>
        /// <param name="dataStore">The data store.</param>
        /// <param name="scopes">The Scopes.</param>
        /// <param name="httpClientFactory">The HTTP client factory. If not set the default will be used.</param>
        /// <returns>Authorization code flow</returns>
        private AuthorizationCodeFlow CreateFlow(IDataStore dataStore = null, IEnumerable<string> scopes = null,
            IHttpClientFactory httpClientFactory = null)
        {
            var secrets = new ClientSecrets() { ClientId = "id", ClientSecret = "secret" };
            var initializer = new AuthorizationCodeFlow.Initializer(AuthorizationCodeUrl, TokenUrl)
            {
                ClientSecrets = secrets,
                HttpClientFactory = httpClientFactory
            };

            if (dataStore != null)
            {
                initializer.DataStore = dataStore;
            }
            if (scopes != null)
            {
                initializer.Scopes = scopes;
            }
            return new AuthorizationCodeFlow(initializer);
        }
 public static void SetCurrent(IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory.Value = httpClientFactory;
 }
 public RemoteRequest(TaskFactory workExecutor, IHttpClientFactory clientFactory, string method, Uri url, object body, Database db, IDictionary<string, object>requestHeaders, CancellationTokenSource tokenSource = null)
 {
     this.clientFactory = clientFactory;
     this.method = method;
     this.url = url;
     this.body = body;
     this.workExecutor = workExecutor;
     this.requestHeaders = requestHeaders;
     this.db = db;
     this.requestMessage = CreateConcreteRequest();
     _tokenSource = tokenSource == null 
         ? new CancellationTokenSource() 
         : CancellationTokenSource.CreateLinkedTokenSource(tokenSource.Token);
     Log.V(Tag, "RemoteRequest created, url: {0}", url);
 }
Пример #46
0
 public ProductController(VitecContext context, IHttpClientFactory clientFactory)
 {
     _context   = context;
     _apiHelper = new Helpers.APIHelper(clientFactory);
 }
Пример #47
0
		public Data (IHttpClientFactory httpClientFactory, ICache cache) {
			this.httpClientFactory = httpClientFactory;
			this.cache = cache;
		}
Пример #48
0
 public JobRunCrawlers(IHttpClientFactory httpFactory, IConfiguration configuration)
 {
     _httpFactory   = httpFactory;
     _configuration = configuration;
 }
Пример #49
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebServiceClientBase"/> class.
        /// </summary>
        /// <param name="httpClientFactory">The HTTP client factory.</param>
        public WebServiceClientBase(IHttpClientFactory httpClientFactory)
        {
            EnsureArg.IsNotNull(httpClientFactory, nameof(httpClientFactory));

            HttpClientFactory = httpClientFactory;
        }
 public TradeDetailsModel(PlayingForKeepersDbContext context, IAuthorizationService authorizationService, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager, IHttpClientFactory clientFactory)
     : base(context, authorizationService, userManager, roleManager, clientFactory)
 {
 }
 public DownloadService(IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory = httpClientFactory;
 }
		public static void RegisterHttpClientFactory (IHttpClientFactory factory) {
			httpClientFactory = factory;
		}
Пример #53
0
 public EstimationErrorHandler(IBus bus, IHttpClientFactory httpClientFactory, ILogger <EstimationReadyHandler> logger)
 {
     _bus = bus;
     _httpClientFactory = httpClientFactory;
     _logger            = logger;
 }
        IHttpClient ICouchbaseClientConfiguration.CreateHttpClient(Uri baseUri)
        {
            if (this.clientFactory == null) {
                var tmp = this.HttpClientFactory;

                this.clientFactory = tmp == null ? RestSharpHttpClientFactory.Instance : tmp.CreateInstance();
            }

            Debug.Assert(this.clientFactory != null);

            return this.clientFactory.Create(baseUri, Servers.Bucket, Servers.BucketPassword, HttpClient.Timeout, HttpClient.InitializeConnection);
        }
		public static void Reset () {
			cacheSvc = null;
			httpClientFactory = null;
		}
Пример #56
0
 public RouterFunction(IHttpClientFactory factory)
 {
     _clientFactory = factory;
 }
Пример #57
0
 /// <exception cref="System.Exception"></exception>
 public BulkDownloader(TaskFactory workExecutor, IHttpClientFactory clientFactory, Uri dbURL, IList<RevisionInternal> revs, Database database, IDictionary<string, object> requestHeaders, CancellationTokenSource tokenSource = null)
     : base(workExecutor, clientFactory, "POST", new Uri(AppendRelativeURLString(dbURL, "/_bulk_get?revs=true&attachments=true")), HelperMethod(revs, database), database, requestHeaders, tokenSource)
 { }
Пример #58
0
 public DeleteResourceFromPolicyOperation(IHttpClientFactory httpClientFactory)
 {
     _httpClientFactory = httpClientFactory;
 }
Пример #59
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="db">The local database to replicate to/from</param>
        /// <param name="remote">The remote Uri to sync with</param>
        /// <param name="continuous">If set to <c>true</c> continuous.</param>
        /// <param name="clientFactory">The client factory for instantiating the HttpClient used to create web requests</param>
        /// <param name="workExecutor">The TaskFactory to execute work on</param>
        protected Replication(Database db, Uri remote, bool continuous, IHttpClientFactory clientFactory, TaskFactory workExecutor)
        {
            LocalDatabase = db;
            Continuous = continuous;
            // NOTE: Consider running a separate scheduler for all http requests.
            WorkExecutor = workExecutor;
            CancellationTokenSource = new CancellationTokenSource();
            RemoteUrl = remote;
            RequestHeaders = new Dictionary<String, Object>();
            _requests = new ConcurrentDictionary<HttpRequestMessage, Task>();

            // FIXME: Refactor to visitor pattern.
            if (RemoteUrl.GetQuery() != null && !StringEx.IsNullOrWhiteSpace(RemoteUrl.GetQuery()))
            {
                var uri = new Uri(remote.ToString());
                var personaAssertion = URIUtils.GetQueryParameter(uri, PersonaAuthorizer.QueryParameter);

                if (personaAssertion != null && !StringEx.IsNullOrWhiteSpace(personaAssertion))
                {
                    var email = PersonaAuthorizer.RegisterAssertion(personaAssertion);
                    var authorizer = new PersonaAuthorizer(email);
                    Authenticator = authorizer;
                }

                var facebookAccessToken = URIUtils.GetQueryParameter(uri, FacebookAuthorizer.QueryParameter);

                if (facebookAccessToken != null && !StringEx.IsNullOrWhiteSpace(facebookAccessToken))
                {
                    var email = URIUtils.GetQueryParameter(uri, FacebookAuthorizer.QueryParameterEmail);
                    var authorizer = new FacebookAuthorizer(email);
                    Uri remoteWithQueryRemoved = null;

                    try
                    {
                        remoteWithQueryRemoved = new UriBuilder(remote.Scheme, remote.GetHost(), remote.Port, remote.AbsolutePath).Uri;
                    }
                    catch (UriFormatException e)
                    {
                        throw new ArgumentException("Invalid URI format.", "remote", e);
                    }

                    FacebookAuthorizer.RegisterAccessToken(facebookAccessToken, email, remoteWithQueryRemoved.ToString());

                    Authenticator = authorizer;
                }
                // we need to remove the query from the URL, since it will cause problems when
                // communicating with sync gw / couchdb
                try
                {
                    RemoteUrl = new UriBuilder(remote.Scheme, remote.GetHost(), remote.Port, remote.AbsolutePath).Uri;
                }
                catch (UriFormatException e)
                {
                    throw new ArgumentException("Invalid URI format.", "remote", e);
                }
            }

            Batcher = new Batcher<RevisionInternal>(workExecutor, INBOX_CAPACITY, PROCESSOR_DELAY, inbox =>
            {
                try {
                    Log.V(TAG, "*** BEGIN ProcessInbox ({0} sequences)", inbox.Count);
                    FireTrigger(ReplicationTrigger.Resume);
                    ProcessInbox (new RevisionList(inbox));

                    Log.V(TAG, "*** END ProcessInbox (lastSequence={0})", LastSequence);
                } catch (Exception e) {
                    Log.E(TAG, "ProcessInbox failed: ", e);
                    throw new RuntimeException(e);
                }
            });

            ClientFactory = clientFactory;

            _stateMachine = new StateMachine<ReplicationState, ReplicationTrigger>(ReplicationState.Initial);
            InitializeStateMachine();
        }
Пример #60
0
 public CommentController(IHttpClientFactory cf)
 {
     _clientFactory = cf;
 }