public async Task WriteLanguageFiles()
        {
            const string translationExportUrl = "https://api.assistantapps.com/TranslationExport/{0}/{1}";
            const string appGuid = "dfe0dbc7-8df4-47fb-a5a5-49af1937c4e2";

            BaseExternalApiRepository apiRepo = new BaseExternalApiRepository();
            ResultWithValue <List <LanguageViewModel> > langResult = await apiRepo.Get <List <LanguageViewModel> >("https://api.assistantapps.com/Language");

            if (langResult.HasFailed)
            {
                Console.WriteLine("Could not get Server Languages");
                return;
            }

            foreach (string languageFile in LangFile.LanguagesInTheApp)
            {
                string            langCode      = languageFile.Replace("language.", string.Empty).Replace(".json", string.Empty);
                LanguageViewModel langViewModel = langResult.Value.FirstOrDefault(l => l.LanguageCode.Equals(langCode));
                if (langViewModel == null)
                {
                    continue;
                }

                ResultWithValue <Dictionary <string, string> > languageContent = await apiRepo.Get <Dictionary <string, string> >(translationExportUrl.Replace("{0}", appGuid).Replace("{1}", langViewModel.Guid.ToString()));

                if (languageContent.HasFailed)
                {
                    continue;
                }

                _languageFileSysRepo.WriteBackToJsonFile(languageContent.Value, languageFile);
            }
        }
Esempio n. 2
0
        private static async Task <List <string> > LangUpToDateAudit(bool persist = false)
        {
            const string  translationExportUrl = "https://api.assistantapps.com/TranslationExport/{0}/{1}";
            const string  appGuid       = "dfe0dbc7-8df4-47fb-a5a5-49af1937c4e2";
            List <string> consoleOutput = new List <string>();

            BaseExternalApiRepository apiRepo = new BaseExternalApiRepository();
            ResultWithValue <List <LanguageViewModel> > langResult = await apiRepo.Get <List <LanguageViewModel> >("https://api.assistantapps.com/Language");

            if (langResult.HasFailed)
            {
                consoleOutput.Add("Could not get Server Languages");
                return(consoleOutput);
            }

            FileSystemRepository appLangRepo = new FileSystemRepository(AppLangDirectory);

            foreach (LanguageType langType in AvailableLangs)
            {
                LanguageDetail language = LanguageHelper.GetLanguageDetail(langType);

                string languageFile = $"language.{language.LanguageAppFolder}.json";
                Dictionary <string, dynamic> langJson = appLangRepo.LoadJsonDict <dynamic>(languageFile);
                langJson.TryGetValue("hashCode", out dynamic localHashCode);

                LanguageViewModel langViewModel = langResult.Value.FirstOrDefault(l => l.LanguageCode.Equals(language.LanguageAppFolder));
                if (langViewModel == null)
                {
                    continue;
                }

                ResultWithValue <Dictionary <string, string> > languageContent = await apiRepo.Get <Dictionary <string, string> >(translationExportUrl.Replace("{0}", appGuid).Replace("{1}", langViewModel.Guid.ToString()));

                if (languageContent.HasFailed)
                {
                    continue;
                }
                languageContent.Value.TryGetValue("hashCode", out string serverHashCode);

                bool hashCodeMatches = serverHashCode != null && localHashCode != null && localHashCode.Equals(serverHashCode);
                if (hashCodeMatches)
                {
                    continue;
                }

                if (persist)
                {
                    appLangRepo.WriteBackToJsonFile(languageContent.Value, languageFile);
                }

                consoleOutput.Add($"{languageFile} Language Hashcode Audit has failed");
            }

            return(consoleOutput);
        }
        public async Task WriteSteamNewsFile()
        {
            Console.WriteLine("\nGenerating Steam News data");
            const string patronUrl            = "https://api.scrapassistant.com/Steam/News";
            BaseExternalApiRepository apiRepo = new BaseExternalApiRepository();

            ResultWithValue <List <SteamNewsItemViewModel> > steamNewsResult = await apiRepo.Get <List <SteamNewsItemViewModel> >(patronUrl);

            if (steamNewsResult.HasFailed)
            {
                return;
            }

            Console.WriteLine($"Writing SteamNews Data to {AppFile.DataSteamNews}");
            _appDataSysRepo.WriteBackToJsonFile(steamNewsResult.Value, AppFile.DataSteamNews);
        }
        public async Task WritePatreonFile()
        {
            Console.WriteLine("\nGenerating Patron data");
            const string patronUrl            = "https://api.assistantapps.com/Patreon";
            BaseExternalApiRepository apiRepo = new BaseExternalApiRepository();

            ResultWithValue <List <PatreonViewModel> > patreonResult = await apiRepo.Get <List <PatreonViewModel> >(patronUrl);

            if (patreonResult.HasFailed)
            {
                return;
            }

            Console.WriteLine($"Writing Patron Data to {AppFile.DataPatreon}");
            _appDataSysRepo.WriteBackToJsonFile(patreonResult.Value, AppFile.DataPatreon);
        }
        public async Task WriteDonatorsFile()
        {
            Console.WriteLine("\nGenerating Donators data");
            const string donationUrl          = "https://api.assistantapps.com/Donation";
            BaseExternalApiRepository apiRepo = new BaseExternalApiRepository();

            ResultWithValue <ResultWithPagination <DonationViewModel> > donationResult = await apiRepo.Get <ResultWithPagination <DonationViewModel> >(donationUrl);

            if (donationResult.HasFailed)
            {
                return;
            }

            List <DonationViewModel> allDonations = new List <DonationViewModel>();

            allDonations.AddRange(donationResult.Value.Value);
            for (int donationPage = donationResult.Value.CurrentPage; donationPage < donationResult.Value.TotalPages; donationPage++)
            {
                string pagedDonationUrl = donationUrl + $"?page={(donationPage + 1)}";
                ResultWithValue <ResultWithPagination <DonationViewModel> > pagedDonationResult = await apiRepo.Get <ResultWithPagination <DonationViewModel> >(pagedDonationUrl);

                if (donationResult.HasFailed)
                {
                    continue;
                }

                allDonations.AddRange(pagedDonationResult.Value.Value);
            }

            Console.WriteLine($"Writing Patron Data to {AppFile.DataDonation}");
            _appDataSysRepo.WriteBackToJsonFile(allDonations, AppFile.DataDonation);
        }
        public async Task WriteContributorsFile()
        {
            Console.WriteLine("\nGenerating Contributors data");
            const string contributorUrl       = "https://raw.githubusercontent.com/AssistantSMS/App/master/contributors.json";
            BaseExternalApiRepository apiRepo = new BaseExternalApiRepository();

            ResultWithValue <List <ContributorViewModel> > contributorsResult = await apiRepo.Get <List <ContributorViewModel> >(contributorUrl);

            if (contributorsResult.HasFailed)
            {
                return;
            }

            Console.WriteLine($"Writing Patron Data to {AppFile.DataContributors}");
            _appDataSysRepo.WriteBackToJsonFile(contributorsResult.Value, AppFile.DataContributors);
        }