public Component() { Application.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); var connection = new Connection(); _client = new Gw2Client(connection); LoadCheckpoints(); LoadSettings(); }
public DiscordRichPresence() { _api = new Gw2Client(); //Load the json using var stream = Application.GetResourceStream(new Uri("Assets/maps.jsonc", UriKind.Relative)).Stream; using var reader = new StreamReader(stream); using var maps = new JsonTextReader(reader); _maps = JsonConvert.DeserializeObject <Dictionary <string, int> >(JToken.ReadFrom(maps).ToString()); }
private void debugMap() { using Gw2Client apiclient = new Gw2Client(); apiclient.Mumble.Update(); var mapData = apiclient.WebApi.V2.Maps.GetAsync(apiclient.Mumble.MapId); mapData.Wait(); WriteToChat($"{mapData.Result.RegionName}"); WriteToChat($"\"{hashRectangle(mapData.Result.ContinentRect)}\": , //{mapData.Result.Name}"); }
private async void ValidateKey() { if (apiKeyFormat.IsMatch(txtApiKey.Text)) { txtApiKey.IsEnabled = false; var connection = new Connection(txtApiKey.Text); var client = new Gw2Client(connection); var tokeninfo = await client.WebApi.V2.TokenInfo.GetAsync(); var hasAccount = false; var hasCharacters = false; var hasGuilds = false; //Set all to bad imgAccount.Source = new BitmapImage(new Uri("pack://application:,,,/Assets/1444524.png")); imgCharacters.Source = new BitmapImage(new Uri("pack://application:,,,/Assets/1444524.png")); imgGuilds.Source = new BitmapImage(new Uri("pack://application:,,,/Assets/1444524.png")); //Check Permissions if (HasPermission(tokeninfo, TokenPermission.Account)) { hasAccount = true; imgAccount.Source = new BitmapImage(new Uri("pack://application:,,,/Assets/1444520.png")); } if (HasPermission(tokeninfo, TokenPermission.Characters)) { hasCharacters = true; imgCharacters.Source = new BitmapImage(new Uri("pack://application:,,,/Assets/1444520.png")); } if (HasPermission(tokeninfo, TokenPermission.Guilds)) { hasGuilds = true; imgGuilds.Source = new BitmapImage(new Uri("pack://application:,,,/Assets/1444520.png")); } ValidKey = (hasAccount && hasCharacters && hasGuilds); client.Dispose(); txtApiKey.IsEnabled = true; } }
public ApiProcessor(ApiData apiData, Gw2Client apiClient) { ApiData = apiData ?? throw new ArgumentNullException(nameof(apiData)); this.apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient)); }
private static async Task Main(string[] args) { using var http = new HttpClient(); var gw2 = new Gw2Client(http); var(ingredients, recipes) = await Progress() .StartAsync( async ctx => { var recipesProgress = ctx.AddTask( "Fetching recipes", new ProgressTaskSettings { AutoStart = false } ); var ingredientsProgress = ctx.AddTask( "Fetching ingredients", new ProgressTaskSettings { AutoStart = false } ); var craftingRecipes = await GetRecipes(gw2.Crafting, recipesProgress); var groupedByIngredient = craftingRecipes .SelectMany( recipe => recipe.Ingredients .Where(ingredient => ingredient.Kind == IngredientKind.Item) .Select(ingredient => (Ingredient: ingredient.Id, Recipe: recipe)) ) .ToLookup(grouping => grouping.Ingredient, grouping => grouping.Recipe); var ingredientIndex = groupedByIngredient.Select(grouping => grouping.Key) .ToHashSet(); var craftingIngredients = await GetItems( ingredientIndex, gw2.Items, ingredientsProgress ); var ingredientsById = craftingIngredients.ToDictionary(item => item.Id); var mostCommon = groupedByIngredient .OrderByDescending(grouping => grouping.Count()) .Select(grouping => ingredientsById[grouping.Key]) .ToList(); return(Ingredients: mostCommon, Craftable: groupedByIngredient); } ); do { AnsiConsole.Clear(); var choice = AnsiConsole.Prompt( new SelectionPrompt <Item>().Title("Pick an ingredient to see the available recipes") .MoreChoicesText("Scroll down for less commonly used ingredients") .AddChoices(ingredients) .UseConverter(item => item.Name) .PageSize(20) ); await using var ingredientIcon = await http.GetStreamAsync(choice.Icon !); var choiceTable = new Table().AddColumn("Icon") .AddColumn("Ingredient") .AddColumn("Description"); choiceTable.AddRow( new CanvasImage(ingredientIcon).MaxWidth(32), new Markup(choice.Name.EscapeMarkup()), new Markup(choice.Description.EscapeMarkup()) ); AnsiConsole.Write(choiceTable); var outputs = await Progress() .StartAsync( async ctx => { var itemIds = recipes[choice.Id] .Select(recipe => recipe.OutputItemId) .ToHashSet(); return(await GetItems( itemIds, gw2.Items, ctx.AddTask("Fetching output items") )); } ); var recipesTable = new Table().AddColumn("Recipe").AddColumn("Description"); foreach (var recipe in outputs) { recipesTable.AddRow(recipe.Name.EscapeMarkup(), recipe.Description.EscapeMarkup()); } AnsiConsole.Write(recipesTable); } while (AnsiConsole.Confirm("Do you want to choose again?")); }