コード例 #1
0
        public async Task <bool> IsUserLoggedIn()
        {
            var idToken = await _localStorageService.GetItemAsync <string>(idTokenStorageKey);

            return(idToken != null);
        }
コード例 #2
0
 private async Task <string> getAuthToken()
 {
     return(await _localStorage.GetItemAsync <string>("authToken"));
 }
コード例 #3
0
        private async Task <string> GetBearerToken()
        {
            var savedToken = await _localStorage.GetItemAsync <string>("authToken");

            return(savedToken);
        }
コード例 #4
0
 private async Task <List <FamilyMember> > RetrieveFamilyMembersAsync()
 {
     return(await _localStorageService.GetItemAsync <List <FamilyMember> >(LocalStorageKey)
            ?? new List <FamilyMember>());
 }
コード例 #5
0
ファイル: BaseHttp.cs プロジェクト: James-H33/Campers
 private async Task <string> GetAuthToken()
 {
     return(await _storage.GetItemAsync <string>("access_token"));
 }
コード例 #6
0
        public async Task <ArticleAggregatedVM> GetArticle(Guid id, Guid?commitId)
        {
            //if (devMode)
            //{
            //    if (await _localStorageService.ContainKeyAsync(devKey + id))
            //    {
            //        var article = await _localStorageService.GetItemAsync<ArticleViewModel>(devKey + id);
            //        return ArticleConverter.FromStorage(article);
            //    }
            //    else
            //    {
            //        if ((await _courseService.GetCourse(1, devMode)).Records.Any(r => r.TargetId == id))
            //        {
            //            var article = GetExample(id);
            //            await AddArticleToLocalStorage(ArticleConverter.ToStorage(article));
            //            return article;
            //        }
            //    }
            //}
            if (await _localStorageService.ContainKeyAsync("workbanch_" + id))
            {
                var commit1 = new ArticleCommitMainInfoVM
                {
                    Id          = new Guid(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }),
                    Title       = "Created",
                    CreatedAt   = new DateTime(2021, 05, 15, 22, 23, 22),
                    CreatedBy   = "artbiel",
                    Description = "Article created",
                    CommitState = CommitState.Commited,
                    Type        = ArticleCommitType.Addition,
                    Content     = ""
                };
                var commits = new List <ArticleCommitMainInfoVM>()
                {
                    commit1
                };
                if (await _localStorageService.ContainKeyAsync(key + id))
                {
                    var commitsFromStorage = await _localStorageService.GetItemAsync <List <ArticleCommitMainInfoVM> >(key + id);

                    commits.AddRange(commitsFromStorage);
                }
                var article = await _localStorageService.GetItemAsync <ArticleVM>("workbanch_" + id);

                return(new ArticleAggregatedVM {
                    ArticleInfo = article, Commits = commits
                });
            }
            Guid courseId = new Guid(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 });

            if ((await _courseService.GetCourse(courseId)).RootRecord.Find(r => r.Id == id) != null)
            {
                var article = await GetExample(id, commitId);

                //if (await _localStorageService.ContainKeyAsync(key + article.Id))
                //{
                //    var unsendCommits = await _localStorageService.GetItemAsync<List<ArticleCommitVM>>(key + article.Id);
                //    if (unsendCommits != null && unsendCommits.Count > 0)
                //        article.Commits.AddRange(unsendCommits);
                //}
                return(article);
            }
            return(null);
        }
コード例 #7
0
        public async Task <string> GetToken()
        {
            var token = await _localStorage.GetItemAsync <string>("authToken");

            return(token);
        }
コード例 #8
0
 public async Task <bool> HasVoted()
 {
     return(await _localStorage.GetItemAsync <bool>("voted"));
 }
コード例 #9
0
 public async Task <IPlayer> LoadAsync()
 {
     return(await _localStorageService.GetItemAsync <IPlayer>(DATA_NAME));
 }
コード例 #10
0
 public async Task <string> GetTokenAsync()
 {
     return(await _localStorage.GetItemAsync <string>(Constants.AuthTokenKey));
 }
コード例 #11
0
 public static Task <T> GetItemAsync <T>(this ILocalStorageService localStorage)
 {
     return(localStorage.GetItemAsync <T>(typeof(T).Name));
 }
コード例 #12
0
 public ValueTask <T> GetValueAsync <T>(IIdentifyable pIdentifyable)
 {
     return(mLocalStorage.GetItemAsync <T>(GetKey(pIdentifyable)));
 }
コード例 #13
0
ファイル: AuthService.cs プロジェクト: daylanvig/PlannerApp
        public async Task <AuthenticationHeaderValue> GetAuthToken()
        {
            var tokenValue = await _localStorage.GetItemAsync <string>(tokenStore);

            return(new AuthenticationHeaderValue("bearer", tokenValue));
        }
コード例 #14
0
ファイル: Storage.cs プロジェクト: feruxmax/ties
 public Task <T> GetItemAsync <T>(string key)
 {
     return(_localStorage.GetItemAsync <T>(key));
 }
コード例 #15
0
 public async Task InitializeAsync()
 {
     User = await _localStorageService.GetItemAsync <User>("user");
 }
コード例 #16
0
 public async Task <Preference> GetPreference()
 {
     return(await _localStorageService.GetItemAsync <Preference>("preference") ?? new Preference());
 }
コード例 #17
0
ファイル: CartDataService.cs プロジェクト: Butzman/Showpage
 private async Task <IReadOnlyCollection <ProductInLocalCartModel> > GetCartFromLocalStore()
 {
     return(await _localStorageService.GetItemAsync <IReadOnlyCollection <ProductInLocalCartModel> >("Cart"));
 }
コード例 #18
0
 private async Task <StorageUser> GetUser()
 {
     return(await _localStorageService.GetItemAsync <StorageUser>("user"));
 }
コード例 #19
0
        public static async Task LoadListAggregatorsOrder(ILocalStorageService localStorage, User data, AuthenticationStateProvider authenticationStateProvider)
        {
            var user = await authenticationStateProvider.GetAuthenticationStateAsync();

            if (data == null || data.ListAggregators == null || !data.ListAggregators.Any())
            {
                return;
            }


            SetEntryOrder(data.ListAggregators);


            var tempListFromFile = await localStorage.GetItemAsync <List <OrderListAggrItem> >(user.User.Identity.Name);


            // if (tempListFromFile == null) return;  //????????????????? nie


            foreach (var listAggr in data.ListAggregators)
            {
                var itemAggrFromFile = tempListFromFile?.Where(a => a.Id == listAggr.ListAggregatorId).FirstOrDefault();

                if (itemAggrFromFile != null)
                {
                    listAggr.Order = itemAggrFromFile.Order;
                }


                ////////////////////
                SetEntryOrder(listAggr.Lists);


                foreach (var listList in listAggr.Lists)
                {
                    var itemListFromFile = itemAggrFromFile?.List.Where(a => a.Id == listList.ListId).FirstOrDefault();

                    if (itemListFromFile != null)
                    {
                        listList.Order = itemListFromFile.Order;
                    }


                    SetEntryOrder(listList.ListItems);


                    foreach (var listItem in listList.ListItems)
                    {
                        var itemItemFromFile = itemListFromFile?.List.Where(a => a.Id == listItem.ListItemId).FirstOrDefault();

                        if (itemItemFromFile != null)
                        {
                            listItem.Order = itemItemFromFile.Order;
                        }
                    }

                    ResolveDoubleOrderValue(listList.ListItems);

                    listList.ListItems = listList.ListItems.OrderByDescending(a => a.Order).ToList();
                }

                ResolveDoubleOrderValue(listAggr.Lists);

                listAggr.Lists = listAggr.Lists.OrderByDescending(a => a.Order).ToList();
                ////////////////////////////
            }


            ResolveDoubleOrderValue(data.ListAggregators);


            data.ListAggregators = data.ListAggregators.OrderByDescending(a => a.Order).ToList();
        }
コード例 #20
0
 public async Task <string> GetCurrentCultureFromLocalStorage()
 => await _localStorageService.GetItemAsync <string>(LocalStorageKeys.CURRENT_CULTURE);
コード例 #21
0
        public static async Task <RouteOption> LoadTableOptionsAsync(string typeName, ILocalStorageService localStorage)
        {
            var objectsTask = default(Task <RouteOption>);

            lock (taskLock)
            {
                if (RefOptions.ContainsKey(typeName))
                {
                    return(RefOptions[typeName]);
                }

                if (!RefCalls.ContainsKey(typeName))
                {
                    var fetch = FetchRouteObjectsAsync();
                    RefCalls.Add(typeName, fetch);
                }
                objectsTask = RefCalls[typeName];
            }
            return(await objectsTask);

            async Task <RouteOption> FetchRouteObjectsAsync()
            {
                var routeString = await localStorage.GetItemAsync <string>(typeName);

                if (routeString.IsNullOrWhiteSpace())
                {
                    Console.WriteLine($"No route definition for `{typeName}`");
                    return(new RouteOption {
                        options = new object[] { }
                    });
                }
                var routeInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <Route>(routeString);
                var idProp    = routeInfo.Properties
                                .Where(prop => prop.IsIdentfier)
                                .First(
                    (prop, next) => prop.Name,
                    () => "id");

                Console.WriteLine($"ID PROP = `{idProp}`");
                var nameProp = routeInfo.Properties
                               .Where(prop => prop.IsTitle)
                               .First(
                    (prop, next) => prop.Name,
                    () => "id");
                var nameType = routeInfo.Properties
                               .Where(prop => prop.IsTitle)
                               .First(
                    (prop, next) => prop.Type,
                    () => "string");

                Console.WriteLine($"NAME PROP = `{nameProp}`");
                return(await TableData.TableAsync(typeName,
                                                  localStorage,
                                                  objs =>
                {
                    var options = objs
                                  .Select(
                        obj =>
                    {
                        var jValObjName = obj[nameProp];
                        var nameValue = (jValObjName as JValue).Value <string>();

                        var jValObjId = obj[idProp];
                        var idValue = (jValObjId as JValue).Value <string>();

                        return idValue.PairWithKey(nameValue);
                    })
                                  .Cast <object>()
                                  .ToArray();
                    var routeOption = new RouteOption
                    {
                        nameType = nameType,
                        options = options,
                    };
                    RefOptions.Add(typeName, routeOption);
                    return routeOption;
                },
                                                  (why) => new RouteOption { options = new object[] { } }));
            }
        }
コード例 #22
0
 private async Task <List <Meals> > GetAllMealsData() => await _localStorageService.GetItemAsync <List <Meals> >(_key);
コード例 #23
0
        private async Task <HttpResponse <T> > SendRequest <T>(HttpSettings settings, HttpMethod method,
                                                               HttpContent content, bool parseResult)
        {
            CheckSettings(settings);

            var url     = CreateUrl(settings);
            var request = new HttpRequestMessage(method, url);

            if (content != null)
            {
                request.Content = content;
            }

            if (_configuration.IsTokenBearer)
            {
                var token = await _localStorageService.GetItemAsync <string>(_configuration.TokenName);

                var isApiUrl = request.RequestUri?.IsAbsoluteUri ?? false;

                if (!string.IsNullOrEmpty(token) && isApiUrl)
                {
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
                }
            }

            try
            {
                using var response = await _httpClient.SendAsync(request);

                if (CheckActionWasUnauthorized(response))
                {
                    return(new HttpResponse <T> {
                        IsSuccess = false
                    });
                }

                if (settings.ToasterSettings.IsNeeded)
                {
                    await _helperService.AddToaster(response, settings.ToasterSettings.Caption);
                }

                if (!response.IsSuccessStatusCode)
                {
                    return(new HttpResponse <T> {
                        IsSuccess = false
                    });
                }

                try
                {
                    if (parseResult)
                    {
                        return(new HttpResponse <T>
                        {
                            IsSuccess = true, Content = await response.Content.ReadFromJsonAsync <T>()
                        });
                    }

                    return(new HttpResponse <T> {
                        IsSuccess = true
                    });
                }
                catch (Exception e)
                {
                    ConsoleSerializationError(e);
                    return(new HttpResponse <T> {
                        IsSuccess = false
                    });
                }
            }
            catch (Exception e)
            {
                ConsoleCallError(e, url);
                return(new HttpResponse <T> {
                    IsSuccess = false
                });
            }
        }
コード例 #24
0
 public async Task <IPreference> GetPreference()
 {
     return(await _localStorageService.GetItemAsync <ClientPreference>(StorageConstants.Local.Preference) ?? new ClientPreference());
 }
コード例 #25
0
ファイル: BaseRepository.cs プロジェクト: k-ravi/BookStoreAPI
 async Task <string> GetBearerToken()
 {
     return(await _localStorage.GetItemAsync <string>("authToken"));
 }
コード例 #26
0
 protected async Task AddBearerToken()
 {
     if (await _localStorage.ContainKeyAsync("token"))
     {
         _client.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await _localStorage.GetItemAsync <string>("token"));
     }
 }
コード例 #27
0
 /// <inheritdoc />
 public ValueTask <T> GetItemAsync <T>(string key)
 => m_storageService.GetItemAsync <T>(key);
コード例 #28
0
        public async Task <SpotifyPlaylist> CreatePlaylist(string name, List <LastFmTrack> tracks)
        {
            var notFound  = 0;
            var processed = 0;
            var toPost    = new List <SpotifyTrack>();

            _addedTracks = new List <SpotifyTrack>();
            var token = await _localStore.GetItemAsync <string>(Constants.SpotifyTokenKey);

            var user = await _localStore.GetItemAsync <SpotifyUser>(Constants.SpotifyUserKey);

            _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
            var playlist = new CreateSpotifyPlaylist
            {
                Name = name
            };
            var result = await _client.PostAsJsonAsync($"{_baseUrl}/users/{user.Id}/playlists", playlist);

            if (!result.IsSuccessStatusCode)
            {
                RequestRefresh?.Invoke(this, new MessageEventArgs {
                    Messages = new List <string> {
                        "Could not create playlist."
                    }
                });
                return(null);
            }
            var created = JsonSerializer.Deserialize <SpotifyPlaylist>(await result.Content.ReadAsStringAsync());

            foreach (var lfmTrack in tracks)
            {
                var track = await SearchTrack(lfmTrack.Artist.Name, lfmTrack.Name);

                if (track.NotFound)
                {
                    notFound++;
                }
                else
                {
                    toPost.Add(track);
                    _addedTracks.Add(track);
                }
                processed++;
                if (toPost.Count == 10)
                {
                    var query = string.Join(',', toPost.Select(_ => _.Uri?.ToString()));
                    await _client.PostAsync($"{_baseUrl}/playlists/{created.Id}/tracks?uris={query}", new StringContent(""));

                    toPost.Clear();
                    RequestRefresh?.Invoke(this, new MessageEventArgs
                    {
                        Messages = new List <string> {
                            $"Added {processed} of {tracks.Count}. {notFound} not found."
                        },
                        Type = UIUpdateType.Processing
                    });
                }
            }
            if (toPost.Any())
            {
                var query = string.Join(',', toPost.Select(_ => _.Uri?.ToString()));
                await _client.PostAsync($"{_baseUrl}/playlists/{created.Id}/tracks?uris={query}", new StringContent(""));
            }
            CreationDone?.Invoke(this, new MessageEventArgs
            {
                Type     = UIUpdateType.Done,
                Messages = new List <string>
                {
                    $"Your playlist {name} was created.",
                    $"{tracks.Count - notFound} added.",
                    $"{notFound} tracks could not be found on Spotify.",
                }
            });
            return(created);
        }
コード例 #29
0
        /// <summary>
        /// Returns the value of the <c> nightTheme </c> cookie.
        /// </summary>
        /// <param name="localStorage">A class containing methods for working with cookies.</param>
        /// <returns></returns>
        public static async Task <bool> GetNightThemeCookies(ILocalStorageService localStorage)
        {
            bool cookieResult = await localStorage.GetItemAsync <bool>("nightTheme");

            return(cookieResult);
        }
コード例 #30
0
 public static async Task <string> GetAccessTokenAsync(this ILocalStorageService localStorage)
 => await localStorage.GetItemAsync <string>(JwtConstants.AccessTokenName);