/// <summary> /// Orders the English version of sample queries and deserializes the file contents /// </summary> /// <param name="fileContents">The json files to be deserialized.</param> /// <param name="locale">The language code for the preferred localized file.</param> /// <returns>The deserialized instance of a <see cref="SampleQueriesList"/>.</returns> private SampleQueriesList DeserializeSamplesList(string fileContents, string locale) { /* Current business process only supports ordering of the English * translation of the sample queries. */ bool orderSamples = locale.Equals("en-us", StringComparison.OrdinalIgnoreCase); SampleQueriesList sampleQueriesList = SamplesService.DeserializeSampleQueriesList(fileContents, orderSamples); return(sampleQueriesList); }
/// <summary> /// Fetches the sample queries from the cache or a JSON file and returns a deserialized instance of a /// <see cref="SampleQueriesList"/> from this. /// </summary> /// <param name="locale">The language code for the preferred localized file.</param> /// <returns>The deserialized instance of a <see cref="SampleQueriesList"/>.</returns> public async Task <SampleQueriesList> FetchSampleQueriesListAsync(string locale) { // Fetch cached sample queries SampleQueriesList sampleQueriesList = await _samplesCache.GetOrCreateAsync(locale, cacheEntry => { // Localized copy of samples is to be seeded by only one executing thread. lock (_samplesLock) { /* Check whether a previous thread already seeded an * instance of the localized samples during the lock. */ var lockedLocale = locale; var seededSampleQueriesList = _samplesCache?.Get <SampleQueriesList>(lockedLocale); if (seededSampleQueriesList != null) { return(Task.FromResult(seededSampleQueriesList)); } cacheEntry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(_defaultRefreshTimeInHours); // Fetch the requisite sample path source based on the locale string queriesFilePathSource = FileServiceHelper.GetLocalizedFilePathSource(_sampleQueriesContainerName, _sampleQueriesBlobName, lockedLocale); // Get the file contents from source string jsonFileContents = _fileUtility.ReadFromFile(queriesFilePathSource).GetAwaiter().GetResult(); /* Current business process only supports ordering of the English * translation of the sample queries. */ bool orderSamples = lockedLocale.Equals("en-us", StringComparison.OrdinalIgnoreCase); // Return the list of the sample queries from the file contents return(Task.FromResult(SamplesService.DeserializeSampleQueriesList(jsonFileContents, orderSamples))); } }); return(sampleQueriesList); }