using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Net.Http; using System.Threading.Tasks; using System.Windows; using Microsoft.Extensions.Configuration; using PipefyProspUpdate.Services; namespace PipefyProspUpdate { /// /// Interaction logic for App.xaml /// public partial class App : Application { private List? _users; private readonly HttpClient _httpClient = new(); private PipefyApiService? _pipefyApiService; public static IConfiguration config { get; private set; } = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); private class Settings { public string? Url { get; set; } public string? Username { get; set; } public string? Password { get; set; } } protected async override void OnStartup(StartupEventArgs e) { if (config.AsEnumerable().Where(c => c.Value == "").ToList().Any()) { throw new Exception("Falha ao acessar o arquivo de configuração"); } _pipefyApiService = new PipefyApiService(_httpClient); base.OnStartup(e); LoadUsersData(); await LoadSuggestions(); AppState.Instance.selectedUF = "Paraná (PR)"; AppState.Instance.MesoChangeBoxItems.Clear(); AppState.Instance.CityChangeBoxItems.Clear(); AppState.Instance.Prospectante.Clear(); AppState.Instance.Others.Clear(); AppState.Instance.KeepProsp = false; AppState.Instance.KeepResp = false; AppState.Instance.filterFlag = true; AppState.Instance.LastUpdated = DateTime.Now; AppState.Instance.Save(); } public async void LoadUsersData() { _users ??= await _pipefyApiService!.GetUsersAsync(); AppState.Instance.Users = _users.OrderBy(p => p.name).Distinct().ToList(); } public static async Task LoadSuggestions() { List? _sugs = await IBGEService.GetBrazilDataAsync(); AppState.Instance.Suggestions = _sugs.OrderBy(x => x.City).OrderBy(x => x.Meso).OrderBy(x => x.UF).ToList(); } } }