Exemple #1
0
        public override void OnModLoad()
        {
            AutoRegisteredTranslations = new Dictionary <string, ModTranslation>();

            foreach (string culture in GetCultures())
            {
                foreach (string fileName in ExistingJsonFiles)
                {
                    string filePath = GetFilePath(culture, fileName);
                    if (!Mod.FileExists(filePath))
                    {
                        break;
                    }
                    using Stream stream = Mod.GetFileStream(filePath);
                    foreach ((string s, Dictionary <string, string> dictionary) in
                             JsonUtilities.DeserializeJsonFromStream <Dictionary <string, Dictionary <string, string> > >(stream))
                    {
                        foreach ((string key, string value) in dictionary)
                        {
                            GetOrCreateTranslation($"{s}.{key}").AddTranslation(culture, value);
                        }
                    }
                }
            }

            foreach (ModTranslation translation in AutoRegisteredTranslations.Values)
            {
                LocalizationLoader.AddTranslation(translation);
            }
        }
        public override void OnModLoad()
        {
            AutoRegisteredTranslations = new Dictionary <string, ModTranslation>();

            foreach (string culture in GetCultures())
            {
                foreach (string fileName in ExistingJsonFiles)
                {
                    try
                    {
                        using Stream stream = Mod.GetFileStream(GetFilePath(culture, fileName));
                        foreach ((string s, Dictionary <string, string> dictionary) in
                                 JsonUtilities.DeserializeJsonFromStream <Dictionary <string, Dictionary <string, string> > >(stream))
                        {
                            foreach ((string key, string value) in dictionary)
                            {
                                GetOrCreateTranslation($"{s}.{key}").AddTranslation(culture, value);
                            }
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                        // ignore if localization file doesn't exist
                    }
                }
            }

            foreach (ModTranslation translation in AutoRegisteredTranslations.Values)
            {
                Mod.AddTranslation(translation);
            }
        }
        public async Task <IEnumerable <NoteModel> > GetPatientHistoryAsync(int patientId)
        {
            IEnumerable <NoteModel> result = null;

            var retry = Policy.Handle <HttpRequestException>()
                        .WaitAndRetry(new[]
            {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(3),
                TimeSpan.FromSeconds(5)
            });

            try
            {
                await retry.Execute(async() =>
                {
                    var response =
                        await _httpClient.GetAsync($"/api/history/patient/{patientId}");

                    if (response.IsSuccessStatusCode)
                    {
                        var stream = await response.Content.ReadAsStreamAsync();
                        result     = JsonUtilities.DeserializeJsonFromStream <IEnumerable <NoteModel> >(stream);
                    }
                    else
                    {
                        result = new List <NoteModel>();
                    }
                });
            }
            catch (Exception e)
            {
                Log.Error("An error occurred while attempting to fetch data from an external API.", e.Message);
                throw;
            }

            return(result);
        }