本文整理汇总了C#中ILoader.GetReader方法的典型用法代码示例。如果您正苦于以下问题:C# ILoader.GetReader方法的具体用法?C# ILoader.GetReader怎么用?C# ILoader.GetReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILoader
的用法示例。
在下文中一共展示了ILoader.GetReader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public static QueryBoostingContext Load(string fileName, ILoader loader, FrameworkLogger logger)
{
try
{
using (var reader = loader.GetReader(fileName))
{
var serializer = new JsonSerializer();
var value = serializer.Deserialize<QueryBoostingContext>(reader);
return value;
}
}
catch (Exception ex)
{
if (IndexingUtils.IsFatal(ex))
{
throw;
}
logger.LogError($"Unable to load {fileName}.", ex);
}
return Default;
}
示例2: Load
public void Load(string name, ILoader loader, FrameworkLogger logger)
{
// The data in downloads.v1.json will be an array of Package records - which has Id, Array of Versions and download count.
// Sample.json : [["AutofacContrib.NSubstitute",["2.4.3.700",406],["2.5.0",137]],["Assman.Core",["2.0.7",138]]....
using (var jsonReader = loader.GetReader(name))
{
try
{
jsonReader.Read();
while (jsonReader.Read())
{
try
{
if (jsonReader.TokenType == JsonToken.StartArray)
{
JToken record = JToken.ReadFrom(jsonReader);
string id = String.Intern(record[0].ToString().ToLowerInvariant());
// The second entry in each record should be an array of versions, if not move on to next entry.
// This is a check to safe guard against invalid entries.
if (record.Count() == 2 && record[1].Type != JTokenType.Array)
{
continue;
}
if (!_downloads.ContainsKey(id))
{
_downloads.Add(id, new DownloadsByVersion());
}
var versions = _downloads[id];
foreach (JToken token in record)
{
if (token != null && token.Count() == 2)
{
string version = String.Intern(token[0].ToString().ToLowerInvariant());
versions[version] = token[1].ToObject<int>();
}
}
}
}
catch (JsonReaderException ex)
{
logger.LogInformation("Invalid entry found in downloads.v1.json. Exception Message : {0}", ex.Message);
}
}
}
catch (JsonReaderException ex)
{
logger.LogError("Data present in downloads.v1.json is invalid. Couldn't get download data.", ex);
}
}
}
示例3: Load
public static void Load(string name, ILoader loader, FrameworkLogger logger, IDictionary<string, HashSet<string>> targetDictionary)
{
try
{
using (var jsonReader = loader.GetReader(name))
{
UpdateDictionary(jsonReader, targetDictionary);
}
}
catch (Exception e)
{
if (IsFatal(e))
{
throw;
}
logger.LogError($"Unable to load {name}.", e);
}
}
示例4: Load
public static IReadOnlyDictionary<string, int> Load(string name, ILoader loader, FrameworkLogger logger)
{
try
{
using (JsonReader jsonReader = loader.GetReader(name))
{
return CreateDictionary(jsonReader);
}
}
catch (Exception e)
{
if (IndexingUtils.IsFatal(e))
{
throw;
}
logger.LogInformation("Unable to load {0}. Exception Message : {1}", name, e.Message);
return new Dictionary<string, int>();
}
}