Ejemplo n.º 1
0
 public Worker(
     IWebApiClient webApiClient,
     ILogger <Worker> logger)
 {
     _webApiClient = webApiClient;
     _logger       = logger;
 }
Ejemplo n.º 2
0
 public static Task <TResult> GetAsync <TResult>(this IWebApiClient webApiClient, Priority priority, string path, int retryCount, int sleepDuration, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(PollyDecorator(
                () => webApiClient.GetAsync <TResult>(priority, path, cancellationToken),
                retryCount,
                sleepDuration));
 }
Ejemplo n.º 3
0
 public WebApi(IBitmovinApiClientFactory apiClientFactory)
 {
     _apiClient = apiClientFactory.CreateClient <IWebApiClient>();
     Domains    = new DomainsApi(apiClientFactory);
     Status     = new StatusApi(apiClientFactory);
     Download   = new DownloadApi(apiClientFactory);
 }
Ejemplo n.º 4
0
        public MockDataStore()
        {
            _webApiClient = WebApiClientFactory.Get <IStarwarsApi>("https://swapi.co/api", false, () => new SampleHttpClientHandler());
            items         = new List <Starships>();
            var mockItems = new List <Starships>
            {
                new Starships {
                    Id = Guid.NewGuid().ToString(), name = "First starship", model = "This is an item description."
                },
                new Starships {
                    Id = Guid.NewGuid().ToString(), name = "Second starship", model = "This is an item description."
                },
                new Starships {
                    Id = Guid.NewGuid().ToString(), name = "Third starship", model = "This is an item description."
                },
                new Starships {
                    Id = Guid.NewGuid().ToString(), name = "Fourth starship", model = "This is an item description."
                },
                new Starships {
                    Id = Guid.NewGuid().ToString(), name = "Fifth starship", model = "This is an item description."
                },
                new Starships {
                    Id = Guid.NewGuid().ToString(), name = "Sixth starship", model = "This is an item description."
                }
            };

            foreach (var item in mockItems)
            {
                items.Add(item);
            }
        }
Ejemplo n.º 5
0
        // test post call
        public static async Task <string> PostRawPostmanEcho(bool forceRefresh = false)
        {
            IWebApiClient <IPostmanEcho> webApiClient = WebApiClientFactory.Get <IPostmanEcho>("https://postman-echo.com/", false);

            PostObject postObject = new PostObject();

            postObject.testName = "hello world";
            postObject.testDate = DateTime.Now.ToString();

            var postObjectResult = await webApiClient.Call(
                (service) => service.PostObject(postObject),
                Priority.UserInitiated,
                2,
                (ex) => true,
                60);

            var postResult = await webApiClient.Call(
                (service) => service.Post("test"),
                Priority.UserInitiated,
                2,
                (ex) => true,
                60);

            Console.WriteLine("\t Post string: ");
            ConvertJson(postResult);
            Console.WriteLine("\t Post object: ");
            ConvertJson(postObjectResult);
            return(postResult);
        }
Ejemplo n.º 6
0
        // 2 ways to check an object. One from json printed, the other an object from the api
        // the first way is more modular and works for any json, the second more adjusted for SWAPI
        public static async Task <IEnumerable <Starships> > GetStarShipItemsAsync(bool forceRefresh = false)
        {
            IWebApiClient <IStarwarsApi> _webApiClient = WebApiClientFactory.Get <IStarwarsApi>("https://swapi.co/api", true);
            var jsonresult = await _webApiClient.Call(
                (service) => service.GetTask(),
                Priority.UserInitiated,
                2,
                (ex) => true,
                60);

            var result = await _webApiClient.Call(
                (service) => service.GetStarships(),
                Priority.UserInitiated,
                2,
                (ex) => true,
                60);

            // checking the get call with a quick timeout
            try
            {
                var timeoutresult = await _webApiClient.Call(
                    (service) => service.GetTask(),
                    Priority.UserInitiated,
                    2,
                    (ex) => true,
                    3);
            }
            catch (Exception e)
            {
                Console.WriteLine("This call is longer then 3 seconds, but will display anyway of working correctly");
            }

            ConvertJson(jsonresult);
            return(result.Results);
        }
Ejemplo n.º 7
0
 public static Task <TResult> DeleteAsync <TResult>(this IWebApiClient webApiClient, Priority priority, string path, int retryCount, Func <int, TimeSpan> sleepDurationProvider, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(PollyDecorator(
                () => webApiClient.DeleteAsync <TResult>(priority, path, cancellationToken),
                retryCount,
                sleepDurationProvider));
 }
Ejemplo n.º 8
0
 public static Task <TResult> PutAsync <TContent, TResult>(this IWebApiClient webApiClient, Priority priority, string path, int retryCount, Func <int, TimeSpan> sleepDurationProvider, TContent content = default(TContent), IHttpContentResolver contentResolver = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(PollyDecorator(
                () => webApiClient.PutAsync <TContent, TResult>(priority, path, cancellationToken: cancellationToken),
                retryCount,
                sleepDurationProvider));
 }
Ejemplo n.º 9
0
        public ApiFactory(IApiServiceLocator apiLocator)
        {
            var apiBaseUrl = apiLocator.GetServiceLocation(typeof(TService).Name);

            this.client         = new WebApiClient();
            this.client.BaseUrl = apiBaseUrl;
            this.executeMethods = new ConcurrentDictionary <Type, Action <Castle.DynamicProxy.IInvocation> >();
        }
Ejemplo n.º 10
0
        public ApiFactory(IServiceProvider serviceProvider)
        {
            var locator         = (IApiServiceLocator)serviceProvider.GetService(typeof(IApiServiceLocator));
            var serviceLocation = locator.GetServiceLocation(typeof(TService).Name);

            this.client         = new WebApiClient();
            this.client.BaseUrl = serviceLocation;
            this.executeMethods = new ConcurrentDictionary <Type, Action <Castle.DynamicProxy.IInvocation> >();
        }
Ejemplo n.º 11
0
        public TaskManager(ITasksStorage tasksStorage, IServerStorage serversStorage, IWebApiClient apiClient)
        {
            this.tasksStorage = tasksStorage;
            this.serversStorage = serversStorage;
            this.apiClient = apiClient;

            this.RunAddOrUpdateProductTasks();
            this.RunDeleteProductTasks();
        }
Ejemplo n.º 12
0
 internal AdminApi(IWebApiClient client)
 {
     Apps           = new AdminAppsApi(client);
     Conversations  = new AdminConversationsApi(client);
     Emoji          = new AdminEmojiApi(client);
     InviteRequests = new AdminInviteRequestsApi(client);
     Teams          = new AdminTeamsApi(client);
     Users          = new AdminUsersApi(client);
 }
Ejemplo n.º 13
0
        public BaseClient(IWebApiClient apiClient)
        {
            if (apiClient == null)
            {
                throw new ArgumentNullException(nameof(apiClient));
            }

            this.apiClient = apiClient;
        }
        public override async Task Prepare <TConfiguration>(IWebApiClient <TConfiguration> client)
        {
            await base.Prepare <TConfiguration>(client).ConfigureAwait(false);

            if (!IsTokenUseable())
            {
                await this.RefreshToken(client).ConfigureAwait(false);
            }
        }
Ejemplo n.º 15
0
 public MovieService(IRepository <Movie> movieRepository, IRepository <Director> directorRepository, IRepository <Actor> actorRepository, IRepository <Country> countryRepository, IRepository <Genre> genreRepository, IWebApiClient movieWebApiClient)
 {
     _movieRepository   = movieRepository;
     _directoRepository = directorRepository;
     _actorRepository   = actorRepository;
     _movieWebApiClient = movieWebApiClient;
     _countryRepository = countryRepository;
     _genreRepository   = genreRepository;
 }
 public SendSmsRequestReceivedConsumerShould()
 {
     _configuration = new SmsConfiguration
     {
         Password   = "******",
         ServiceUrl = "http://localhost/send-sms",
         User       = "******",
     };
     _webApiClient = Substitute.For <IWebApiClient>();
 }
Ejemplo n.º 17
0
        public ServerManager(IServerStorage storage, IWebApiClient apiClient, ITaskManager taskManager)
        {
            this.storage = storage;
            this.storage.Servers.CollectionChanged += (s, e) => { this.Initialize(); };
            this.apiClient = apiClient;
            this.taskManager = taskManager;
            this.Cache = new Cache();

            this.Initialize();
        }
Ejemplo n.º 18
0
 public ServiceUnitTest()
 {
     _movieRepositoryMock    = new Mock <IRepository <Movie> >();
     _actorRepositoryMock    = new Mock <IRepository <Actor> >();
     _directorRepositoryMock = new Mock <IRepository <Director> >();
     _countryRepositoryMock  = new Mock <IRepository <Country> >();
     _genreRepositoryMock    = new Mock <IRepository <Genre> >();
     _movieWebApiClientMock  = new CsfdWebApiClient();
     _service = new MovieService(_movieRepositoryMock.Object, _directorRepositoryMock.Object, _actorRepositoryMock.Object, _countryRepositoryMock.Object, _genreRepositoryMock.Object, _movieWebApiClientMock);
 }
 public Worker(
     IWebApiClient webApiClient,
     IGrpcClient grpcClient,
     IMyConfiguration myConfiguration,
     ILogger <Worker> logger)
 {
     _webApiClient    = webApiClient;
     _grpcClient      = grpcClient;
     _myConfiguration = myConfiguration;
     _logger          = logger;
 }
Ejemplo n.º 20
0
        public SellersViewModel(IServerManager manager, IWebApiClient apiClient)
        {
            this.manager = manager;
            this.manager.SelectedServerChanged += this.OnSelectedServerChanged;
            this.apiClient = apiClient;

            this.Waste = new ObservableCollection<Waste>();
            this.Sells = new ObservableCollection<Sell>();

            this.Search = new RelayCommand(this.HandleSearch, this.CanSearch);
        }
        private async Task RefreshToken <TConfiguration>(IWebApiClient <TConfiguration> client)
            where TConfiguration : IWebApiConfiguration
        {
            var token = await this.TokenProvider.GetToken(this).ConfigureAwait(false);

            var encoder = new DeflatedSamlTokenHeaderEncoder();
            var bearer  = encoder.Encode(((GenericXmlSecurityToken)token).TokenXml.OuterXml);

            this.TokenValidTo = token.ValidTo;
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearer);
        }
Ejemplo n.º 22
0
        public ShardService(IWebApiClient webApiClient)
        {
            this.webApiClient        = webApiClient ?? new WebApiClient();
            this.webApiClient.Scheme = "http";
            this.webApiClient.Host   = "drsantesupervisorapidevsk.azurewebsites.net";

            WebApiClient.OnResponseReceived += (sender, args) =>
            {
                httpStatusCode = args.ResponseStatusCode;
            };
        }
Ejemplo n.º 23
0
        internal Action(IWebApiClient webApiClient)
        {
            _webApiClient = webApiClient;

            _user = new Lazy<IUser>(() => new User(_webApiClient));
            _project = new Lazy<IProject>(() => new Project(_webApiClient));
            _invitation = new Lazy<IInvitation>(() => new Invitation(_webApiClient));
            _application = new Lazy<IApplication>(() => new Application(_webApiClient));
            _version = new Lazy<IVersion>(() => new Version(_webApiClient));
            _serverSetting = new Lazy<IServerSetting>(() => new ServerSetting(_webApiClient));
            _service = new Lazy<IService>(() => new Service(_webApiClient));
        }
 public SendSmsRequestReceivedConsumer(
     IWebApiClient webApiClient,
     IPublishEndpoint publishEndpoint,
     ISmsClient smsClient,
     ISmsRepository smsRepository,
     ILogger <SendSmsRequestReceivedConsumer> logger)
 {
     _webApiClient    = webApiClient;
     _publishEndpoint = publishEndpoint;
     _smsClient       = smsClient;
     _smsRepository   = smsRepository;
     _logger          = logger;
 }
 public NotificationManager(
     IEmailClient emailClient,
     ITemplateService templateEngine,
     IWebApiClient webApiClient,
     ISmsClient smsClient,
     ISmsRepository smsRepository)
 {
     _emailClient    = emailClient ?? throw new ArgumentNullException(nameof(emailClient));
     _templateEngine = templateEngine ?? throw new ArgumentNullException(nameof(templateEngine));
     _webApiClient   = webApiClient ?? throw new ArgumentNullException(nameof(webApiClient));
     _smsClient      = smsClient ?? throw new ArgumentNullException(nameof(smsClient));
     _smsRepository  = smsRepository ?? throw new ArgumentNullException(nameof(smsRepository));
 }
        public ReportDetailsViewModel(IWebApiClient apiClient, DateTime date, HttpClient client)
        {
            this.apiClient = apiClient;
            this.date = date;

            this.Waste = new ObservableCollection<Waste>();
            this.Sells = new ObservableCollection<Sell>();
            this.Shipments = new ObservableCollection<Shipment>();

            this.Cancel = new RelayCommand(this.HandleCancel);
            this.ShowPdf = new RelayCommand(this.HandleShowPdf, this.CanShowPdf);

            this.Initialize(client, date);
        }
Ejemplo n.º 27
0
 public LicenseExpirationNoticeTask(
     INotificationFacade notificationFacade,
     IOAuthClient oAuthClient,
     IWebApiClient webApiClient,
     ApplicationConfiguration applicationConfiguration,
     IWebHostEnvironment hostingEnvironment,
     ILogger <LicenseExpirationNoticeTask> logger)
 {
     _notificationFacade       = notificationFacade;
     _oAuthClient              = oAuthClient;
     _webApiClient             = webApiClient;
     _applicationConfiguration = applicationConfiguration;
     _hostingEnvironment       = hostingEnvironment;
     _logger = logger;
 }
Ejemplo n.º 28
0
        // test login and authorization methods
        public static async Task <string> AuthenticatePostmanEcho(bool forceRefresh = false)
        {
            // this is how you do a basic auth, todo: how to convert to dictionary headers, i would use value?

            //var authData = string.Format("{0}:{1}", "postman", "password");
            //var authHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(authData));
            //AuthenticationHeaderValue value = new AuthenticationHeaderValue(authHeaderValue, authData);

            // this basic auth way is working now but less clear imo
            IDictionary <string, string> authValues = new Dictionary <string, string>
            {
                { "postman", "password" }
            };

            // OAuth isn't working, how do you add the headers for these
            //IDictionary<string, string> oAuthValues = new Dictionary<string, string>
            //{
            //    {"oauth_consumer_key", "D+EdQ-RKCGzna7bv9YD57c-%@2Nu7" },
            //    {"oauth_signature_method", "HMAC-SHA1" },
            //    {"oauth_timestamp", "1472121261"},
            //    {"oauth_nonce", "oauth_nonce" },
            //    {"oauth_version", "1.0" },
            //    {"oauth_signature", "s0rK92Myxx7ceUBVzlMaxiiXU00"}
            //};

            IWebApiClient <IPostmanEcho> basicAuthWebApiClient = WebApiClientFactory.Get <IPostmanEcho>("https://postman-echo.com/", false, defaultHeaders: authValues);
            //IWebApiClient<IPostmanEcho> oAuthWebApiClient = WebApiClientFactory.Get<IPostmanEcho>("https://postman-echo.com/", false, () => new SampleHttpClientHandler(), oAuthValues);

            var basicAuthResult = await basicAuthWebApiClient.Call(
                (service) => service.BasicAuth(),
                Xablu.WebApiClient.Enums.Priority.UserInitiated,
                2,
                (ex) => true,
                60);

            //var oAuthResult = await oAuthWebApiClient.Call(
            //    (service) => service.OAuth(),
            //    Xablu.WebApiClient.Enums.Priority.UserInitiated,
            //    2,
            //    (ex) => true,
            //    60);

            Console.WriteLine("\t basic auth: ");
            ConvertJson(basicAuthResult);
            //Console.WriteLine("\t oauth: ");
            //ConvertJson(oAuthResult);
            return(basicAuthResult);
        }
Ejemplo n.º 29
0
        public WebDownloadProjectViewModel(IRegionManager regionManager, IUntappdService untappdService,
                                           IWebApiClient webApiClient,
                                           IModuleManager moduleManager,
                                           IInteractionRequestService interactionRequestService) : base(moduleManager, regionManager)
        {
            this.untappdService            = untappdService;
            this.webApiClient              = webApiClient;
            this.moduleManager             = moduleManager;
            this.interactionRequestService = interactionRequestService;

            CheckAccessTokenCommand    = new DelegateCommand <string>(CheckAccessToken);
            FulllDownloadButtonCommand = new DelegateCommand(FulllDownloadCheckins);
            FirstDownloadButtonCommand = new DelegateCommand(FirstDownloadCheckins);
            ToEndDownloadButtonCommand = new DelegateCommand(ToEndDownloadCheckins);
            BeerUpdateButtonCommand    = new DelegateCommand(UpdateBeers);
            OkButtonCommand            = new DelegateCommand(Exit);
        }
Ejemplo n.º 30
0
 public DailyReportTask(
     INotificationFacade notificationFacade,
     IWebHostEnvironment hostingEnvironment,
     ILogger <DailyReportTask> logger,
     IWebApiClient webApiClient,
     IOAuthClient oAuthClient,
     IReportClient reportClient,
     IStatsRepository statsRepository)
 {
     _notificationFacade = notificationFacade;
     _hostingEnvironment = hostingEnvironment;
     _logger             = logger;
     _webApiClient       = webApiClient;
     _oAuthClient        = oAuthClient;
     _reportClient       = reportClient;
     _statsRepository    = statsRepository;
 }
Ejemplo n.º 31
0
 public GitHubUserInfoService(IWebApiClient client, IGitHubRepoConfig config)
 {
     this.client = client;
     this.config = config;
 }
Ejemplo n.º 32
0
 public AdminAnalyticsApi(IWebApiClient client)
 {
     _client = client;
 }
Ejemplo n.º 33
0
 public ReportsController(IStoresService storesService, IWebApiClient apiClient)
 {
     this.storesService = storesService;
     this.apiClient = apiClient;
 }
Ejemplo n.º 34
0
 public FinMindApi(IWebApiClient webApi)
 {
     _webApi = webApi;
     //_token = File.ReadAllText(@"D:/VDisk/SNL/finmind.key");
 }
Ejemplo n.º 35
0
 internal Invitation(IWebApiClient webApiClient)
 {
     _webApiClient = webApiClient;
 }
Ejemplo n.º 36
0
 public MeasureService(IWebApiClient apiClient)
 {
     _apiClient = apiClient;
 }
Ejemplo n.º 37
0
 internal Version(IWebApiClient webApiClient)
 {
     _webApiClient = webApiClient;
 }
Ejemplo n.º 38
0
 public PlantPowerService(IWebApiClient apiClient)
 {
     _apiClient = apiClient;
 }
Ejemplo n.º 39
0
 internal Project(IWebApiClient webApiClient)
 {
     _webApiClient = webApiClient;
 }
Ejemplo n.º 40
0
 public AppsApi(IWebApiClient client)
 {
     _client = client;
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseController"/> class.
 /// </summary>
 protected BaseController()
 {
     this.client = new WebApiClient();
 }
Ejemplo n.º 42
0
 public WebIssueTypeCommand(IIssueHandler issueHandler, IWebApiClient client)
     : base("IssueType", "Simulate the web issue type command")
 {
     _issueHandler = issueHandler;
     _client = client;
 }
Ejemplo n.º 43
0
 public WebCommands(IIssueHandler issueHandler, IWebApiClient client)
     : base("Web")
 {
     RegisterCommand(new WebIssueTypeCommand(issueHandler, client));
 }
        public void Setup()
        {
            var mockClient = new Mock <IWebApiClient>();

            mockClient.Setup(method =>
                             method.GetData(It.IsAny <string>(), null))
            .Returns(JsonConvert.SerializeObject(items));

            mockClient.Setup(method =>
                             method.GetData(It.IsAny <string>(), It.Is <string>(x => x != null)))
            .Returns <string, string>((name, data) =>
            {
                var item = items.FirstOrDefault(x => x.Code == data);
                if (item != null)
                {
                    return(JsonConvert.SerializeObject(item));
                }
                return(null);
            });

            mockClient.Setup(method =>
                             method.AddData(It.IsAny <string>(), It.IsAny <string>()))
            .Returns <string, string>((name, data) =>
            {
                try
                {
                    var item = JsonConvert.DeserializeObject <Item>(data);
                    items.Add(item);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            });

            mockClient.Setup(method =>
                             method.EditData(It.IsAny <string>(), It.IsAny <string>()))
            .Returns <string, string>((name, data) =>
            {
                try
                {
                    var item   = JsonConvert.DeserializeObject <Item>(data);
                    var edited = items.FirstOrDefault(x => x.Code == item.Code);
                    if (edited != null)
                    {
                        edited.Description = item.Description;
                        edited.Rate        = item.Rate;
                        return(true);
                    }
                    return(false);
                }
                catch (Exception)
                {
                    return(false);
                }
            });

            mockClient.Setup(method =>
                             method.DeleteData(It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string>((name, data) =>
            {
                var item = items.FirstOrDefault(x => x.Code == data);
                if (item != null)
                {
                    items.Remove(item);
                }
            })
            .Verifiable("Failed");

            client = mockClient.Object;
        }
Ejemplo n.º 45
0
 internal Application(IWebApiClient webApiClient)
 {
     _webApiClient = webApiClient;
 }
Ejemplo n.º 46
0
 internal Service(IWebApiClient webApiClient)
 {
     _webApiClient = webApiClient;
     Log = new Log(webApiClient);
 }
Ejemplo n.º 47
0
 internal ServerSetting(IWebApiClient webApiClient)
 {
     _webApiClient = webApiClient;
 }