示例#1
0
        /// <summary>
        /// Asynchronously reads the requested information from the cached JSON file and deserializes the response to the requested <typeparam name="TE">Type</typeparam>.
        /// </summary>
        /// <typeparam name="TE">Target type</typeparam>
        /// <param name="cacheFile">Name for the cached response</param>
        /// <returns>Cached object</returns>
        public async Task <TE> ReadCacheAsync <TE>(string cacheFile)
        {
            if (string.IsNullOrEmpty(cacheFile))
            {
                return(default(TE));
            }

            using (await _jsonLock.ReaderLockAsync(cacheFile).ConfigureAwait(false))
                return(ReadCacheInternal <TE>(cacheFile));
        }
示例#2
0
        /// <summary>
        /// Returns contents of a file <paramref name="downloadFile"/> downloaded earlier.
        /// </summary>
        /// <param name="downloadedFile">Target file name</param>
        /// <returns>File contents</returns>
        public async Task <byte[]> ReadDownloadedFileAsync(string downloadedFile)
        {
            if (!File.Exists(downloadedFile))
            {
                return(null);
            }

            using (await _fileLock.ReaderLockAsync(downloadedFile))
            {
                try
                {
                    if (!File.Exists(downloadedFile))
                    {
                        return(null);
                    }
                    return(File.ReadAllBytes(downloadedFile));
                }
                catch (Exception ex)
                {
                    ServiceRegistration.Get <ILogger>().Warn("OnlineLibraries.Downloader: Exception when reading file {0} ({1})", downloadedFile, ex.Message);
                    return(null);
                }
            }
        }