本文整理汇总了C#中IJsonSerializer.DeserializeFromFile方法的典型用法代码示例。如果您正苦于以下问题:C# IJsonSerializer.DeserializeFromFile方法的具体用法?C# IJsonSerializer.DeserializeFromFile怎么用?C# IJsonSerializer.DeserializeFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJsonSerializer
的用法示例。
在下文中一共展示了IJsonSerializer.DeserializeFromFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImageProcessor
public ImageProcessor(ILogger logger, IServerApplicationPaths appPaths, IFileSystem fileSystem, IJsonSerializer jsonSerializer)
{
_logger = logger;
_fileSystem = fileSystem;
_jsonSerializer = jsonSerializer;
_appPaths = appPaths;
_saveImageSizeTimer = new Timer(SaveImageSizeCallback, null, Timeout.Infinite, Timeout.Infinite);
Dictionary<Guid, ImageSize> sizeDictionary;
try
{
sizeDictionary = jsonSerializer.DeserializeFromFile<Dictionary<Guid, ImageSize>>(ImageSizeFile) ??
new Dictionary<Guid, ImageSize>();
}
catch (FileNotFoundException)
{
// No biggie
sizeDictionary = new Dictionary<Guid, ImageSize>();
}
catch (Exception ex)
{
logger.ErrorException("Error parsing image size cache file", ex);
sizeDictionary = new Dictionary<Guid, ImageSize>();
}
_cachedImagedSizes = new ConcurrentDictionary<Guid, ImageSize>(sizeDictionary);
}
示例2: ImageProcessor
public ImageProcessor(ILogger logger,
IServerApplicationPaths appPaths,
IFileSystem fileSystem,
IJsonSerializer jsonSerializer,
IImageEncoder imageEncoder,
int maxConcurrentImageProcesses, Func<ILibraryManager> libraryManager)
{
_logger = logger;
_fileSystem = fileSystem;
_jsonSerializer = jsonSerializer;
_imageEncoder = imageEncoder;
_libraryManager = libraryManager;
_appPaths = appPaths;
ImageEnhancers = new List<IImageEnhancer>();
_saveImageSizeTimer = new Timer(SaveImageSizeCallback, null, Timeout.Infinite, Timeout.Infinite);
Dictionary<Guid, ImageSize> sizeDictionary;
try
{
sizeDictionary = jsonSerializer.DeserializeFromFile<Dictionary<Guid, ImageSize>>(ImageSizeFile) ??
new Dictionary<Guid, ImageSize>();
}
catch (FileNotFoundException)
{
// No biggie
sizeDictionary = new Dictionary<Guid, ImageSize>();
}
catch (DirectoryNotFoundException)
{
// No biggie
sizeDictionary = new Dictionary<Guid, ImageSize>();
}
catch (Exception ex)
{
logger.ErrorException("Error parsing image size cache file", ex);
sizeDictionary = new Dictionary<Guid, ImageSize>();
}
_cachedImagedSizes = new ConcurrentDictionary<Guid, ImageSize>(sizeDictionary);
_logger.Info("ImageProcessor started with {0} max concurrent image processes", maxConcurrentImageProcesses);
_imageProcessingSemaphore = new SemaphoreSlim(maxConcurrentImageProcesses, maxConcurrentImageProcesses);
}
示例3: FetchImages
/// <summary>
/// Fetches the images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="language">The language.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{MovieImages}.</returns>
private async Task<MovieDbSeriesProvider.Images> FetchImages(BaseItem item, string language, IJsonSerializer jsonSerializer,
CancellationToken cancellationToken)
{
var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);
if (string.IsNullOrEmpty(tmdbId))
{
return null;
}
await MovieDbSeriesProvider.Current.EnsureSeriesInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
var path = MovieDbSeriesProvider.Current.GetDataFilePath(tmdbId, language);
if (!string.IsNullOrEmpty(path))
{
var fileInfo = new FileInfo(path);
if (fileInfo.Exists)
{
return jsonSerializer.DeserializeFromFile<MovieDbSeriesProvider.RootObject>(path).images;
}
}
return null;
}
示例4: FetchImages
/// <summary>
/// Fetches the images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{MovieImages}.</returns>
private async Task<MovieDbProvider.Images> FetchImages(BaseItem item, IJsonSerializer jsonSerializer,
CancellationToken cancellationToken)
{
await MovieDbProvider.Current.EnsureMovieInfo(item, cancellationToken).ConfigureAwait(false);
var path = MovieDbProvider.Current.GetDataFilePath(item);
if (!string.IsNullOrEmpty(path))
{
var fileInfo = new FileInfo(path);
if (fileInfo.Exists)
{
return jsonSerializer.DeserializeFromFile<MovieDbProvider.CompleteMovieData>(path).images;
}
}
return null;
}
示例5: FetchImages
/// <summary>
/// Fetches the images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="language">The language.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{MovieImages}.</returns>
private async Task<MovieDbProvider.Images> FetchImages(BaseItem item, string language, IJsonSerializer jsonSerializer, CancellationToken cancellationToken)
{
var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);
if (string.IsNullOrWhiteSpace(tmdbId))
{
var imdbId = item.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(imdbId))
{
var movieInfo = await MovieDbProvider.Current.FetchMainResult(imdbId, false, language, cancellationToken).ConfigureAwait(false);
if (movieInfo != null)
{
tmdbId = movieInfo.id.ToString(CultureInfo.InvariantCulture);
}
}
}
if (string.IsNullOrWhiteSpace(tmdbId))
{
return null;
}
await MovieDbProvider.Current.EnsureMovieInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
var path = MovieDbProvider.Current.GetDataFilePath(tmdbId, language);
if (!string.IsNullOrEmpty(path))
{
var fileInfo = new FileInfo(path);
if (fileInfo.Exists)
{
return jsonSerializer.DeserializeFromFile<MovieDbProvider.CompleteMovieData>(path).images;
}
}
return null;
}
示例6: Read
/// <summary>
/// Find and reads a chutzpah test settings file given a direcotry. If none is found a default settings object is created
/// </summary>
/// <param name="directory"></param>
/// <param name="fileProbe"></param>
/// <param name="serializer"></param>
/// <returns></returns>
public static ChutzpahTestSettingsFile Read(string directory, IFileProbe fileProbe, IJsonSerializer serializer)
{
if (string.IsNullOrEmpty(directory)) return new ChutzpahTestSettingsFile();
directory = directory.TrimEnd('/', '\\');
ChutzpahTestSettingsFile settings;
if (!ChutzpahSettingsFileCache.TryGetValue(directory, out settings))
{
var testSettingsFilePath = fileProbe.FindTestSettingsFile(directory);
if(string.IsNullOrEmpty(testSettingsFilePath))
{
settings = new ChutzpahTestSettingsFile();
}
else if (!ChutzpahSettingsFileCache.TryGetValue(testSettingsFilePath, out settings))
{
settings = serializer.DeserializeFromFile<ChutzpahTestSettingsFile>(testSettingsFilePath);
settings.SettingsFileDirectory = Path.GetDirectoryName(testSettingsFilePath);
ValidateTestHarnessLocationMode(settings, fileProbe);
// Add a mapping in the cache for the directory that contains the test settings file
ChutzpahSettingsFileCache.TryAdd(settings.SettingsFileDirectory, settings);
}
// Add mapping in the cache for the original directory tried to skip needing to traverse the tree again
ChutzpahSettingsFileCache.TryAdd(directory, settings);
}
return settings;
}
示例7: FetchImages
/// <summary>
/// Fetches the images.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <returns>Task{MovieImages}.</returns>
private MovieDbProvider.Images FetchImages(BaseItem item, IJsonSerializer jsonSerializer)
{
var path = MovieDbProvider.Current.GetImagesDataFilePath(item);
if (!string.IsNullOrEmpty(path))
{
var fileInfo = new FileInfo(path);
if (fileInfo.Exists)
{
return jsonSerializer.DeserializeFromFile<MovieDbProvider.CompleteMovieData>(path).images;
}
}
return null;
}