Exemplo n.º 1
0
        public async Task Register()
        {
            var del = (AppDelegate)UIApplication.SharedApplication.Delegate;

            if (string.IsNullOrEmpty(del.DeviceToken))
            {
                throw new InvalidOperationException("Push notifications has not been enabled for this app!");
            }

            var user = _applicationService.Account;

            if (user.IsEnterprise)
            {
                throw new InvalidOperationException("Push notifications are for GitHub.com accounts only!");
            }

            var client  = _httpClientService.Create();
            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("token", del.DeviceToken),
                new KeyValuePair <string, string>("user", user.Username),
                new KeyValuePair <string, string>("domain", "https://api.github.com"),
                new KeyValuePair <string, string>("oauth", user.OAuth)
            });

            client.Timeout = new TimeSpan(0, 0, 30);
            var response = await client.PostAsync(RegisterUri, content);

            if (response.StatusCode != System.Net.HttpStatusCode.OK && response.StatusCode != System.Net.HttpStatusCode.Conflict)
            {
                throw new InvalidOperationException("Unable to register! Server returned a " + response.StatusCode + " status code");
            }
            System.Diagnostics.Debug.WriteLine("Push notifications registered for: " + user.Username + " (" + user.OAuth + ") on device <" + del.DeviceToken + ">");
        }
Exemplo n.º 2
0
        private HttpClient CreateApiClient()
        {
            var apiClient = httpClientService.Create();

            apiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            apiClient.DefaultRequestHeaders.Add("x-functions-key", AppSettings.Instance.ApiSecret);
            apiClient.DefaultRequestHeaders.Add("x-api-key", AppSettings.Instance.ApiKey);

            return(apiClient);
        }
Exemplo n.º 3
0
        private async Task GetExposureNotificationConfig()
        {
            loggerService.StartMethod();
            try
            {
                string     container  = AppSettings.Instance.BlobStorageContainerName;
                string     url        = AppSettings.Instance.CdnUrlBase + $"{container}/Configration.json";
                HttpClient httpClient = httpClientService.Create();
                Task <HttpResponseMessage> response = httpClient.GetAsync(url);
                HttpResponseMessage        result   = await response;
                if (result.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    loggerService.Info("Success to download configuration");
                    var content = await result.Content.ReadAsStringAsync();

                    preferencesService.SetValue(PreferenceKey.ExposureNotificationConfiguration, content);
                }
                else
                {
                    loggerService.Error("Fail to download configuration");
                }
            }
            catch (Exception ex)
            {
                loggerService.Exception("Failed download of exposure notification configuration.", ex);
            }
            finally
            {
                loggerService.EndMethod();
            }
        }
Exemplo n.º 4
0
 public ErrorService(IHttpClientService httpClient, IJsonSerializationService jsonSerialization, IEnvironmentalService environmentService)
 {
     _jsonSerialization  = jsonSerialization;
     _environmentService = environmentService;
     _httpClient         = httpClient.Create();
     _httpClient.Timeout = new TimeSpan(0, 0, 10);
     _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
 }
Exemplo n.º 5
0
 public DiagnosisKeyRepository(
     IHttpClientService httpClientService,
     ILoggerService loggerService
     )
 {
     _httpClient    = httpClientService.Create();
     _loggerService = loggerService;
 }
Exemplo n.º 6
0
 public ErrorService(IHttpClientService httpClient, IJsonSerializationService jsonSerialization, IEnvironmentService environmentService, IAccountsService accountsService)
 {
     _jsonSerialization = jsonSerialization;
     _environmentService = environmentService;
     _accountsService = accountsService;
     _httpClient = httpClient.Create();
     _httpClient.Timeout = new TimeSpan(0, 0, 10);
     _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
 }
Exemplo n.º 7
0
 public DebugExposureDataCollectServer(
     ILoggerService loggerService,
     IServerConfigurationRepository serverConfigurationRepository,
     IHttpClientService httpClientService
     )
 {
     _loggerService = loggerService;
     _serverConfigurationRepository = serverConfigurationRepository;
     _httpClient = httpClientService.Create();
 }
Exemplo n.º 8
0
 public CheckVersionService(
     IHttpClientService httpClientService,
     IEssentialsService essentialsService,
     ILoggerService loggerService
     )
 {
     _httpClient        = httpClientService.Create();
     _essentialsService = essentialsService;
     _loggerService     = loggerService;
 }
        public async Task <TMessage> Get <TMessage>(string url)
        {
            var client = _httpClientService.Create();

            client.Timeout = new TimeSpan(0, 0, 30);
            var response = await client.GetAsync(url);

            var data = await response.Content.ReadAsStringAsync();

            return(_jsonSerializationService.Deserialize <TMessage>(data));
        }
Exemplo n.º 10
0
 public DiagnosisKeyRepository(
     IHttpClientService httpClientService,
     ILoggerService loggerService
     )
 {
     _httpClient = httpClientService.Create(new HttpClientHandler
     {
         AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
     });
     _loggerService = loggerService;
 }
Exemplo n.º 11
0
        public async Task <IEnumerable <string> > GetAvailableFeatureIds()
        {
            var client = _httpClientService.Create();

            client.Timeout = new TimeSpan(0, 0, 15);
            var response = await client.GetAsync("http://push.codehub-app.com/in-app");

            var data = await response.Content.ReadAsStringAsync();

            return(_jsonSerializationService.Deserialize <List <string> >(data).ToArray());
        }
Exemplo n.º 12
0
        public TermsUpdateService(
            ILoggerService loggerService,
            IHttpClientService httpClientService,
            IUserDataRepository userDataRepository
            )
        {
            this.loggerService      = loggerService;
            this.userDataRepository = userDataRepository;

            _httpClient         = httpClientService.Create();
            _httpClient.Timeout = TimeSpan.FromSeconds(TimeoutSeconds);
        }
Exemplo n.º 13
0
        public HttpDataService(ILoggerService loggerService, IHttpClientService httpClientService, ISecureStorageService secureStorageService, IApplicationPropertyService applicationPropertyService)
        {
            this.loggerService              = loggerService;
            this.secureStorageService       = secureStorageService;
            this.applicationPropertyService = applicationPropertyService;

            // Create API key based client.
            apiClient             = httpClientService.Create();
            apiClient.BaseAddress = new Uri(AppSettings.Instance.ApiUrlBase);
            apiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            apiClient.DefaultRequestHeaders.Add("x-functions-key", AppSettings.Instance.ApiSecret);
            apiClient.DefaultRequestHeaders.Add("x-api-key", AppSettings.Instance.ApiKey);

            // Create client.
            httpClient             = httpClientService.Create();
            httpClient.BaseAddress = new Uri(AppSettings.Instance.ApiUrlBase);
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Add("x-functions-key", AppSettings.Instance.ApiSecret);

            // Create download client.
            downloadClient = httpClientService.Create();
        }
        public ExposureRiskCalculationConfigurationRepository(
            IHttpClientService httpClientService,
            ILocalPathService localPathService,
            IServerConfigurationRepository serverConfigurationRepository,
            ILoggerService loggerService
            )
        {
            _localPathService = localPathService;
            _serverConfigurationRepository = serverConfigurationRepository;
            _loggerService = loggerService;

            _httpClient         = httpClientService.Create();
            _httpClient.Timeout = TimeSpan.FromSeconds(TIMEOUT_SECONDS);

            _configDir   = PrepareConfigDir();
            _currentPath = localPathService.CurrentExposureRiskCalculationConfigurationPath;
        }
Exemplo n.º 15
0
        public async Task <ImgurModel> SendImage(byte[] data)
        {
            var client = _httpClientService.Create();

            client.Timeout = new TimeSpan(0, 0, 30);
            client.DefaultRequestHeaders.Add("Authorization", "Client-ID " + AuthorizationClientId);
            var body     = _jsonSerializationService.Serialize(new { image = Convert.ToBase64String(data) });
            var content  = new StringContent(body, System.Text.Encoding.UTF8, "application/json");
            var response = await client.PostAsync(ImgurPostUrl, content).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                throw new InvalidOperationException("Unable to post to Imgur! " + response.ReasonPhrase);
            }
            var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(_jsonSerializationService.Deserialize <ImgurModel>(responseBody));
        }
Exemplo n.º 16
0
        public async Task <TMessage> Get <TMessage>(string url, Dictionary <string, string> headers = null)
        {
            var client = _httpClientService.Create();

            client.Timeout = new TimeSpan(0, 0, 30);
            if (headers != null)
            {
                foreach (var kv in headers)
                {
                    client.DefaultRequestHeaders.Add(kv.Key, kv.Value);
                }
            }
            var response = await client.GetAsync(url);

            var data = await response.Content.ReadAsStringAsync();

            return(_jsonSerializationService.Deserialize <TMessage>(data));
        }
Exemplo n.º 17
0
        public EventLogService(
            IUserDataRepository userDataRepository,
            IServerConfigurationRepository serverConfigurationRepository,
            IEssentialsService essentialsService,
            IDeviceVerifier deviceVerifier,
            IDateTimeUtility dateTimeUtility,
            IHttpClientService httpClientService,
            ILoggerService loggerService
            )
        {
            _userDataRepository            = userDataRepository;
            _serverConfigurationRepository = serverConfigurationRepository;
            _essentialsService             = essentialsService;
            _deviceVerifier  = deviceVerifier;
            _dateTimeUtility = dateTimeUtility;
            _loggerService   = loggerService;

            _httpClient = httpClientService.Create();
        }
        public ExposureConfigurationRepository(
            IHttpClientService httpClientService,
            ILocalPathService localPathService,
            IPreferencesService preferencesService,
            IServerConfigurationRepository serverConfigurationRepository,
            IDateTimeUtility dateTimeUtility,
            ILoggerService loggerService
            )
        {
            _localPathService              = localPathService;
            _preferencesService            = preferencesService;
            _serverConfigurationRepository = serverConfigurationRepository;
            _dateTimeUtility = dateTimeUtility;
            _loggerService   = loggerService;

            _httpClient         = httpClientService.Create();
            _httpClient.Timeout = TimeSpan.FromSeconds(TIMEOUT_SECONDS);

            _configDir = PrepareConfigDir();
            _currentExposureConfigurationPath = localPathService.CurrentExposureConfigurationPath;
        }
Exemplo n.º 19
0
        public async Task GetExposureNotificationConfig()
        {
            loggerService.StartMethod();

            string     container  = AppSettings.Instance.BlobStorageContainerName;
            string     url        = AppSettings.Instance.CdnUrlBase + $"{container}/Configration.json";
            HttpClient httpClient = httpClientService.Create();
            Task <HttpResponseMessage> response = httpClient.GetAsync(url);
            HttpResponseMessage        result   = await response;

            if (result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                loggerService.Info("Success to download configuration");
                Application.Current.Properties["ExposureNotificationConfigration"] = await result.Content.ReadAsStringAsync();

                await Application.Current.SavePropertiesAsync();
            }
            else
            {
                loggerService.Error("Fail to download configuration");
            }

            loggerService.EndMethod();
        }
Exemplo n.º 20
0
 public HttpDataServiceMock(IHttpClientService httpClientService)
 {
     downloadClient = httpClientService.Create();
 }