Beispiel #1
0
        public async Task <IList <Pie> > GetAllPiesAsync()
        {
            try
            {
                var cachePies = await _cache.GetCache <List <Pie> >(CacheNameContants.AllPies);

                if (cachePies != null)
                {
                    return(cachePies);
                }

                UriBuilder uri = new UriBuilder(ApiConstants.BaseApiUrl)
                {
                    Path = ApiConstants.CatalogEndpoint
                };

                var requestResult = await _request.GetAsync <IList <Pie> >(uri.ToString());

                await _cache.InsertObject(CacheNameContants.AllPies, requestResult, DateTimeOffset.Now.AddSeconds(20));

                return(requestResult);
            }
            catch (Exception ex)
            {
                throw new CatalogDataServiceException(ex.Message);
            }
        }
Beispiel #2
0
        public async Task <GetProfileResponse> GetProfileAsync() =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            GetProfileRequest getProfileRequest = new GetProfileRequest {
                Url         = GlobalSettings.Instance.Endpoints.ProfileEndpoints.GetProfileEndPoints,
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken
            };

            GetProfileResponse getProfileResponse = null;

            try {
                getProfileResponse =
                    await _requestProvider.GetAsync <GetProfileRequest, GetProfileResponse>(getProfileRequest);
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);

                Debug.WriteLine($"ERROR:{ex.Message}");
                Debugger.Break();
                throw new Exception(ex.Message);
            }

            return(getProfileResponse);
        });
Beispiel #3
0
        public async Task <IEnumerable <TResource> > GetResourcesAsync <TResource, TJsonObject>(string uri, string exceptionMessage)
            where TResource : class
            where TJsonObject : JsonObject <TResource>
        {
            var resources = new List <TResource>();

            try
            {
                var jsonObjects = await _requestProvider.GetAsync <IEnumerable <TJsonObject> >(uri);

                foreach (var jsonObject in jsonObjects)
                {
                    resources.Add(jsonObject.ToDomainModel());
                }
            }
            catch (InternetConnectionException)
            {
                throw;
            }
            catch (AuthenticationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new DataRepositoryException(exceptionMessage, ex);
            }

            return(resources);
        }
        public async Task <List <PersonalData> > GetPersonalDataAsync()
        {
            //https://ai.deskit.ru/api/V1/cabinet/PersonalData
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.PaySlipEndpoint, GlobalSetting.Instance.CurrentUserId);

            return(await _requestProvider.GetAsync <List <PersonalData> >(uri, GlobalSetting.Instance.Token));
        }
Beispiel #5
0
        private async Task <IEnumerable <AssetForecast> > GetProviderAssetsForecast(int pageSize, int quantity)
        {
            IList <AssetForecast> assetsForecast;

            try
            {
                var assets        = GetAssets(pageSize);
                var arrSymbol     = assets.Select(q => q.Symbol).ToArray();
                var quantityFunds = arrSymbol.Length;
                var symbols       = string.Join(",", arrSymbol);
                var limit         = (quantityFunds * quantity);
                var uri           = $"{API_URL_BASE}/intraday?limit={limit}&access_key={ACCESS_KEY}&symbols={symbols}";

                var response = await _requestProvider.GetAsync <IntradayModel>(uri);

                assetsForecast = response.Data
                                 .GroupBy(q => q.Symbol)
                                 .OrderByDescending(o => o.Take(quantity).Average(a => a.Close))
                                 .Select(s => new AssetForecast(assets.FirstOrDefault(q => q.Symbol == s.Key).Id, s.FirstOrDefault().Close))
                                 .ToList();
            }
            catch (HttpRequestExceptionEx exception) when(exception.HttpCode == System.Net.HttpStatusCode.NotFound)
            {
                assetsForecast = null;
            }

            return(assetsForecast);
        }
Beispiel #6
0
        public async Task <IEnumerable <FoundGroupDataItem> > SearchAsync(string value = "", string type = "") =>
        await Task <IEnumerable <FoundGroupDataItem> > .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            SearchRequest searchRequest = new SearchRequest {
                Url         = string.Format(GlobalSettings.Instance.Endpoints.SearchEndPoints.SimpleSearchEndPoints, value, type),
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken
            };

            SearchResponse searchResponse = null;
            IEnumerable <FoundGroupDataItem> foundUserGroups = null;

            try {
                searchResponse = await _requestProvider.GetAsync <SearchRequest, SearchResponse>(searchRequest);

                if (searchResponse != null)
                {
                    foundUserGroups = _foundUserGroupDataItemFactory.BuildFoundGroupDataItems(searchResponse);
                }
            } catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            } catch (Exception ex) {
                Crashes.TrackError(ex);

                throw;
            }

            return(foundUserGroups);
        });
        public async Task <ObservableCollection <ResponderModel> > GetRespondersAsync()
        {
            UriBuilder builder = new UriBuilder(Settings.ServiceEndpoint);

            builder.Path = $"api/city/{Settings.SelectedCity}/responders";

            string uri = builder.ToString();

            try
            {
                IEnumerable <ResponderModel> respondersRoutes =
                    await _requestProvider.GetAsync <IEnumerable <ResponderModel> >(uri);

                if (respondersRoutes != null)
                {
                    return(respondersRoutes.ToObservableCollection());
                }
                else
                {
                    return(default(ObservableCollection <ResponderModel>));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Error on routes api {ex} ");
                return(default(ObservableCollection <ResponderModel>));
            }
        }
Beispiel #8
0
 private async Task <QueryResult <Terminal> > GetTerminalByIdInternal(string avatarUrl, string id, NeuronQuery neuronQuery, string bearerToken, CancellationToken token = default(CancellationToken))
 {
     return(await requestProvider.GetAsync <QueryResult <Terminal> >(
                $"{avatarUrl}{HttpTerminalQueryClient.GetTerminalsPathTemplate}/{id}{neuronQuery.ToString()}",
                bearerToken,
                token
                ));
 }
        public async Task <ObservableCollection <Models.Orders.Order> > GetOrdersAsync(string token)
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayShoppingEndpoint, $"{ApiUrlBase}/all");

            ObservableCollection <Models.Orders.Order> orders =
                await _requestProvider.GetAsync <ObservableCollection <Models.Orders.Order> >(uri, token);

            return(orders);
        }
Beispiel #10
0
 public Task <UserModel> GetUserById(string id)
 {
     return(requestProvider.GetAsync <UserModel>(GetUserProfileInfoByIdEndpoint, new List <ReqestParameter> {
         new ReqestParameter()
         {
             Name = "userId", Value = id
         }
     }));
 }
Beispiel #11
0
        /// <summary>
        /// 获取传统普查配置
        /// </summary>
        /// <returns></returns>
        public Task <TraditionSetting> GetTraditionSetting()
        {
            var userId  = _authenticationService.GetCurrentUserId();
            var builder = new UriBuilder(GlobalSettings.AuthenticationEndpoint);

            builder.Path = $"api/app/android/traditionsetting";
            var uri = builder.ToString();

            return(_requestProvider.GetAsync <TraditionSetting>(uri));
        }
Beispiel #12
0
        public async Task <ObservableCollection <CatalogItem> > FilterAsync(int catalogBrandId, int catalogTypeId)
        {
            UriBuilder builder = new UriBuilder(GlobalSetting.Instance.CatalogEndpoint);

            builder.Path = $"api/v1/catalog/items/type/{catalogTypeId}/brand/{catalogBrandId}";
            string uri = builder.ToString();

            CatalogRoot catalog = await _requestProvider.GetAsync <CatalogRoot>(uri);

            return(catalog?.Data?.ToObservableCollection() ?? new ObservableCollection <CatalogItem>());
        }
Beispiel #13
0
        public async Task <Movie> GetMovieByIdAsync(int movieId)
        {
            var uri = $"{_settingsService.UrlBase}{MOVIEAPIURL}/{movieId}?api_key={_settingsService.ApiKey}" +
                      $"&language=en-US";

            var movie = await _requestProvider.GetAsync <Movie>(uri);

            await FillGenre(movie);

            return(movie);
        }
Beispiel #14
0
        public async Task <ObservableCollection <Models.Orders.Order> > GetOrdersAsync(string token)
        {
            UriBuilder builder = new UriBuilder(GlobalSetting.Instance.OrdersEndpoint);

            builder.Path = "api/v1/orders";
            string uri = builder.ToString();

            ObservableCollection <Models.Orders.Order> orders =
                await _requestProvider.GetAsync <ObservableCollection <Models.Orders.Order> >(uri, token);

            return(orders);
        }
Beispiel #15
0
        public async Task <Booking> GetBooking(int bookingId)
        {
            UriBuilder builder = new UriBuilder(GlobalSettings.RidesEndpoint);

            builder.Path = $"api/bookings/{bookingId}";

            string uri = builder.ToString();

            Booking booking = await _requestProvider.GetAsync <Booking>(uri);

            return(booking);
        }
Beispiel #16
0
        public async Task <ObservableCollection <Models.Order.Order> > GetAllPendingOrdersAsync(string token)
        {
            var orders = await _requestProvider.GetAsync <OrderList>(GlobalSetting.Instance.OrderEndpoint,
                                                                     Settings.AccessToken);

            if (orders?.Orders != null)
            {
                return(orders?.Orders.ToObservableCollection());
            }

            return(new ObservableCollection <Models.Order.Order>());
        }
Beispiel #17
0
        public async Task <ObservableCollection <Make> > GetMakes()
        {
            var values = new NameValueCollection
            {
                { "user_key", Key }
            };

            var uri = UriHelper.BuildUri(BaseUri + "makes/", values);

            var response = await _requestProvider.GetAsync <ObservableCollection <Make> >(uri);

            return(response);
        }
Beispiel #18
0
        public async Task <Models.Unit> GetUnit(int id, string token = "")
        {
            var builder = new UriBuilder(GlobalSettings.Instance.UnitEndpoint)
            {
                Path = $"{ApiUrlBase}/{id}"
            };

            var uri = builder.ToString();

            var result = await _requestProvider.GetAsync <Models.Unit>(uri, token);

            return(result);
        }
Beispiel #19
0
 public async Task <UpcomingMovieResult> GetUpcomingMovies(UpcomingMovieRequest upcomingMovieRequest)
 {
     try
     {
         var    uri         = UriHelper.CombineUri(Settings.TMDbBaseEndpoint, UpcomingURL);
         string queryString = _requestProvider.ConvertQueryString(upcomingMovieRequest);
         return(await _requestProvider.GetAsync <UpcomingMovieResult>(uri + queryString));
     }
     catch (System.Exception ex)
     {
         return(new UpcomingMovieResult());
     }
 }
Beispiel #20
0
        public async Task <ObservableCollection <CampaignItem> > GetAllCampaignsAsync(string token)
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayMarketingEndpoint, $"{ApiUrlBase}/user");

            CampaignRoot campaign = await _requestProvider.GetAsync <CampaignRoot>(uri, token);

            if (campaign?.Data != null)
            {
                _fixUriService.FixCampaignItemPictureUri(campaign?.Data);
                return(campaign?.Data.ToObservableCollection());
            }

            return(new ObservableCollection <CampaignItem>());
        }
Beispiel #21
0
        public Task <List <ResidentRequest> > GetUserVehicleDetailRequestsAsync(CancellationToken cancellationToken = default(CancellationToken)) =>
        Task.Run(async() => {
            List <ResidentRequest> residentRequests = null;

            string url         = BaseSingleton <GlobalSetting> .Instance.RestEndpoints.VehicleEndpoints.UserVehicleDetailRequestsEndpoint;
            string accessToken = BaseSingleton <GlobalSetting> .Instance.UserProfile.AccesToken;

            try {
                residentRequests = await _requestProvider.GetAsync <List <ResidentRequest> >(url, accessToken, cancellationToken);
            }
            catch (ConnectivityException ex) {
                throw ex;
            }
            catch (ServiceAuthenticationException ex) {
                await _identityService.LogOutAsync();
                throw ex;
            }
            catch (HttpRequestExceptionEx ex) {
                throw ex;
            }
            catch (Exception ex) {
                Debug.WriteLine($"ERROR:{ex.Message}");
                throw ex;
            }

            return(residentRequests);
        }, cancellationToken);
        public async Task <UserProfile> GetProfile()
        {
            AccessToken authToken = getAuthToken();

            if (authToken != null)
            {
                string uri         = Constants.PtBasedUrl + "user";
                var    userProfile = await _requestProvider.GetAsync <UserProfile>(uri, authToken.Token);

                return(userProfile);
            }

            throw new InvalidAuthTokenException();
        }
        public async Task <IEnumerable <Ride> > GetUserRides()
        {
            var userId = _authenticationService.GetCurrentUserId();

            UriBuilder builder = new UriBuilder(GlobalSettings.RidesEndpoint);

            builder.Path = $"api/rides/user/{userId}";

            string uri = builder.ToString();

            IEnumerable <Ride> rides = await _requestProvider.GetAsync <IEnumerable <Ride> >(uri);

            return(rides);
        }
Beispiel #24
0
        public async Task <ObservableCollection <CatalogItem> > FilterAsync(int catalogBrandId, int catalogTypeId)
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayShoppingEndpoint, $"{ApiUrlBase}/items/type/{catalogTypeId}/brand/{catalogBrandId}");

            CatalogRoot catalog = await _requestProvider.GetAsync <CatalogRoot>(uri);

            if (catalog?.Data != null)
            {
                return(catalog?.Data.ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
Beispiel #25
0
        public async Task <ObservableCollection <CatalogItem> > FilterAsync(string productfilter)
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayCatalogEndpoint, $"{ApiUrlBase}/items/productfilter/{productfilter}");

            CatalogRoot catalog = await _requestProvider.GetAsync <CatalogRoot>(uri);

            if (catalog?.Data != null)
            {
                return(catalog?.Data.OrderBy(x => x.Price).ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
        // GET api/v1/transactions/last[?count=10]
        public async Task <ObservableCollection <TransactionModel> > GetLastTransactions(string authToken, int count)
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayPWEndpoint, $"{ApiUrlBase}/last?count={count}");

            var transactionsList = await _requestProvider.GetAsync <IEnumerable <TransactionModel> >(uri, authToken);

            if (transactionsList != null)
            {
                return(transactionsList.ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <TransactionModel>());
            }
        }
Beispiel #27
0
        //public async Task<ObservableCollection<CatalogItem>> FilterAsync(int catalogBrandId, int catalogTypeId)
        //{
        //    var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayShoppingEndpoint, $"{ApiUrlBase}/items/type/{catalogTypeId}/brand/{catalogBrandId}");

        //    CatalogRoot catalog = await _requestProvider.GetAsync<CatalogRoot>(uri);

        //    if (catalog?.Data != null)
        //        return catalog?.Data.ToObservableCollection();
        //    else
        //        return new ObservableCollection<CatalogItem>();
        //}


        //public async Task<ObservableCollection<CatalogBrand>> GetCatalogBrandAsync()
        //{
        //    var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayShoppingEndpoint, $"{ApiUrlBase}/catalogbrands");

        //    IEnumerable<CatalogBrand> brands = await _requestProvider.GetAsync<IEnumerable<CatalogBrand>>(uri);

        //    if (brands != null)
        //        return brands?.ToObservableCollection();
        //    else
        //        return new ObservableCollection<CatalogBrand>();
        //}

        //public async Task<ObservableCollection<CatalogType>> GetCatalogTypeAsync()
        //{
        //    var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayShoppingEndpoint, $"{ApiUrlBase}/catalogtypes");

        //    IEnumerable<CatalogType> types = await _requestProvider.GetAsync<IEnumerable<CatalogType>>(uri);

        //    if (types != null)
        //        return types.ToObservableCollection();
        //    else
        //        return new ObservableCollection<CatalogType>();
        //}


        public async Task <ObservableCollection <CatalogItem> > GetCatalogAsync()
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayShoppingEndpoint, $"{ApiUrlBase}/items");

            IEnumerable <CatalogItem> catalog = await _requestProvider.GetAsync <IEnumerable <CatalogItem> >(uri);

            if (catalog != null)
            {
                return(catalog.ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
        // GET api/v1/userinfo/find[?username="******"]
        public async Task <ObservableCollection <UserInfoSimple> > FindUserAsync(string authToken, string username)
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayPWEndpoint, $"{ApiUrlBase}/find?username={username}");

            var transactionsList = await _requestProvider.GetAsync <IEnumerable <UserInfoSimple> >(uri, authToken);

            if (transactionsList != null)
            {
                return(transactionsList.ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <UserInfoSimple>());
            }
        }
Beispiel #29
0
        public async Task <List <TeamMember> > GetTeamMembersAsync(CancellationToken cancellationToken = default(CancellationToken), bool noRepeatings = false) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            List <TeamMember> teamMembers = new List <TeamMember>();

            GetTeamMembersRequest getTeamMembersRequest = new GetTeamMembersRequest {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = GlobalSettings.Instance.Endpoints.TeamMemberEndPoints.GetTeamMembersEndPoint
            };

            GetTeamMembersResponse getTeamMembersResponse = null;

            try {
                getTeamMembersResponse = await _requestProvider.GetAsync <GetTeamMembersRequest, GetTeamMembersResponse>(getTeamMembersRequest);

                if (getTeamMembersResponse != null)
                {
                    if (noRepeatings)
                    {
                        teamMembers = getTeamMembersResponse.TeamMembers.GroupBy <TeamMember, long>(teamMember => teamMember.Team.Id).Select <IGrouping <long, TeamMember>, TeamMember>(group => group.First()).ToList();
                    }
                    else
                    {
                        teamMembers = getTeamMembersResponse.TeamMembers.ToList();
                    }
                }
                else
                {
                    throw new InvalidOperationException(CANT_GET_TEAM_MEMBER_BY_MEMBER_ID_ERROR_MESSAGE);
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);

                throw;
            }

            return(teamMembers);
        }, cancellationToken);
Beispiel #30
0
        public async Task <ObservableCollection <Plant> > GetList()
        {
            AccessToken authToken = getAuthToken();

            string uri             = Constants.PtBasedUrl + "user/plants";
            var    plantCollection = await _requestProvider.GetAsync <BaseCollection <Plant> >(uri, authToken.Token);

            if (plantCollection?.Data != null)
            {
                return(plantCollection?.Data.ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <Plant>());
            }
        }