コード例 #1
0
        /// <summary>
        /// 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 TE ReadCache <TE>(string cacheFile)
        {
            if (string.IsNullOrEmpty(cacheFile))
            {
                return(default(TE));
            }

            using (_jsonLock.ReaderLock(cacheFile))
                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 byte[] ReadDownloadedFile(string downloadedFile)
        {
            if (!File.Exists(downloadedFile))
            {
                return(null);
            }

            using (_fileLock.ReaderLock(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);
                }
            }
        }