Exemple #1
0
        public async Task <ResultWithValue <T> > Get <T>(string url, Action <HttpRequestHeaders> manipulateHeaders = null, bool useJsonApiSerializerSettings = true)
        {
            ResultWithValue <string> webGetResult = await Get(url, manipulateHeaders);

            if (webGetResult.HasFailed)
            {
                return(new ResultWithValue <T>(false, default, webGetResult.ExceptionMessage));
        public async Task WriteWhatIsNewFile(LanguageType langType)
        {
            const string versionSearchUrl     = "https://api.assistantapps.com/Version/Search";
            BaseExternalApiRepository apiRepo = new BaseExternalApiRepository();

            LanguageDetail language = LanguageHelper.GetLanguageDetail(langType);
            string         path     = $"{AppFile.DataWhatIsNewFolder}/{language.LanguageAppFolder}.json";

            VersionSearchViewModel searchVm = new VersionSearchViewModel
            {
                AppGuid      = Guid.Parse("dfe0dbc7-8df4-47fb-a5a5-49af1937c4e2"),
                LanguageCode = language.LanguageAppFolder,
                Page         = 1,
                Platforms    = new List <PlatformType> {
                    PlatformType.Android, PlatformType.iOS
                },
            };
            ResultWithValue <string> whatIsNewResult = await apiRepo.Post(versionSearchUrl, JsonConvert.SerializeObject(searchVm));

            if (whatIsNewResult.HasFailed)
            {
                return;
            }

            try
            {
                ResultWithPagination <VersionViewModel> versionItem = JsonConvert.DeserializeObject <ResultWithPagination <VersionViewModel> >(whatIsNewResult.Value);
                Console.WriteLine($"Writing WhatIsNew Data to {AppFile.DataWhatIsNewFolder} in {language.LanguageGameFolder}");
                _appDataSysRepo.WriteBackToJsonFile(versionItem.Value, path);
            }
            catch
            {
                Console.WriteLine($"FAILED writing WhatIsNew Data to {AppFile.DataWhatIsNewFolder} in {language.LanguageGameFolder}");
            }
        }
Exemple #3
0
        protected async Task <ResultWithValue <T> > Get <T>(string url, Action <HttpRequestHeaders> manipulateHeaders = null)
        {
            ResultWithValue <string> webGetResult = await Get(url, manipulateHeaders);

            if (webGetResult.HasFailed)
            {
                return(new ResultWithValue <T>(false, default, webGetResult.ExceptionMessage));
        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);
            }
        }
        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);
        }
Exemple #6
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);
        }
        static StockSplitInfo parseC(IEnumerable <string> ele)
        {
            var info = new StockSplitInfo();

            info.EffectiveDate        = ResultWithValue.Of <DateTime>(DateTime.TryParse, ele.ElementAt(0)).Value;
            info.TickerSymbol         = ResultWithValue.Of <int>(int.TryParse, ele.ElementAt(1)).Value;
            info.SymbolName           = ele.ElementAt(2);
            info.SplitRate            = parseCRate(ele.ElementAt(3));
            info.RightWithTheLastDate = ResultWithValue.Of <DateTime>(DateTime.TryParse, ele.ElementAt(4)).Value;
            info.AvailableForSaleDate = info.RightWithTheLastDate.AddDays(1);
            return(info);
        }
Exemple #8
0
 static IEnumerable <DateTime> getExistingDataDate(KdbData type)
 {
     try {
         return(Directory.GetFiles(localPath + type.ToString() + Path.DirectorySeparatorChar, "*", SearchOption.AllDirectories)
                .Select(a => Path.GetFileNameWithoutExtension(a))
                .Select(a => ResultWithValue.Of <string, DateTime>(DateTime.TryParse, a))
                .Where(a => a.Result)
                .Select(a => a.Value)
                .OrderBy(a => a));
     } catch (DirectoryNotFoundException) {
         return(new DateTime[0]);
     }
 }
        public static string GetString(this XmlNodeList list, string prop)
        {
            ResultWithValue <XmlAttribute> attributeResult = list.GetValueAttribute(prop);

            if (attributeResult.HasFailed)
            {
                return(string.Empty);
            }
            if (attributeResult.Value?.Value == null)
            {
                return(string.Empty);
            }

            return(attributeResult.Value.Value);
        }
        public static bool GetBool(this XmlNodeList list, string prop)
        {
            ResultWithValue <XmlAttribute> attributeResult = list.GetValueAttribute(prop);

            if (attributeResult.HasFailed)
            {
                return(false);
            }
            if (attributeResult.Value?.Value == null)
            {
                return(false);
            }

            return(attributeResult.Value.Value.Equals("True"));
        }
Exemple #11
0
        public async Task <string> GetFileContents(string filename)
        {
            if (IsMaliciousName(filename))
            {
                return("{}");
            }

            ResultWithValue <string> githubFileContents = await Get($"{_baseGithubUrl}{filename}");

            if (githubFileContents.HasFailed)
            {
                return("{}");
            }

            return(githubFileContents.Value);
        }
Exemple #12
0
        static void deflag()
        {
            var nonks = new List <Uri>();

            foreach (var kvp in wdic)
            {
                if (!ResultWithValue.Of <XbrlDocument>(kvp.Value.TryGetTarget))
                {
                    nonks.Add(kvp.Key);
                }
            }
            foreach (var k in nonks)
            {
                wdic.Remove(k);
            }
        }
        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 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);
        }
        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);
        }
Exemple #16
0
        XbrlDocument acqire(Uri url)
        {
            var r = ResultWithValue.Of <Uri, WeakReference <XbrlDocument> >(wdic.TryGetValue, url)
                    .TrueOrNot(
                o => ResultWithValue.Of <XbrlDocument>(o.TryGetTarget).Value,
                x => null);

            if (r != null)
            {
                return(r);
            }
            deflag();
            //var ins = XbrlParser.ParseXmlFile(xp.Acqire(url));
            var ins = new XbrlDocument();

            ins.Load(url.ToString());
            wdic.Add(url, new WeakReference <XbrlDocument>(ins));
            return(ins);
        }
        public static ResultWithValue <XmlAttribute> GetValueAttribute(this XmlNodeList list, string prop)
        {
            foreach (XmlNode property in list)
            {
                for (int attriIndex = 0; attriIndex < property.Attributes.Count; attriIndex++)
                {
                    ResultWithValue <XmlAttribute> attr = property.GetAttribute(prop);
                    if (attr.HasFailed)
                    {
                        continue;
                    }

                    XmlAttribute siblingPropertyAttribute = property.Attributes[attriIndex + 1];

                    return(new ResultWithValue <XmlAttribute>(true, siblingPropertyAttribute, string.Empty));
                }
            }

            return(new ResultWithValue <XmlAttribute>(false, null, "Attribute not found"));
        }