Esempio n. 1
0
        public async Task IniClientInfo(bool reload = false)
        {
            try
            {
                string clientKey = "ClientKey";
                if (reload)
                {
                    _httpClient.DefaultRequestHeaders.Remove("ClientKey");
                }
                _httpClient.DefaultRequestHeaders.Remove("ApiKey");
                _httpClient.DefaultRequestHeaders.Add("ApiKey", "xxxxxxxxxxxxxxxxxxx");
                var key = await _sessionStorage.GetItemAsync <string>(clientKey);

                if (!reload && !key.isNOEOW())
                {
                    var info = await _api.Get($"key/{key}");

                    if (info != null && info.Status == 200)
                    {
                        await _sessionStorage.RemoveItemAsync(clientKey);

                        await _sessionStorage.SetItemAsync(clientKey, key);

                        _httpClient.DefaultRequestHeaders.Add("clientKey", key);
                    }
                    else
                    {
                        _httpClient.DefaultRequestHeaders.Remove(clientKey);
                        _httpClient.DefaultRequestHeaders.Add(clientKey, key);
                    }
                }
                else if (reload || key.isNOEOW())
                {
                    await this.RequestKey(clientKey);
                }
                else if (!key.isNOEOW())
                {
                    _httpClient.DefaultRequestHeaders.Remove(clientKey);
                    _httpClient.DefaultRequestHeaders.Add(clientKey, key);
                }
                else
                {
                    await this.RequestKey(clientKey);
                }
            }
            catch (Exception)
            {
                if (retry > 0)
                {
                    await Task.Delay(300);

                    retry--;
                    await IniClientInfo(true);
                }
            }
        }
Esempio n. 2
0
        private InitialSetupApiResponseModel CallApiInitialSetup()
        {
            try
            {
                var response = new InitialSetupApiResponseModel();

                response = _apiClientService.Get <InitialSetupApiResponseModel>(ApiAddress, ApiClientConstant.StocktakeUri.InitialSetup);

                return(response);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }