当前位置: 首页>>代码示例>>C#>>正文


C# ILoader.GetReader方法代码示例

本文整理汇总了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;
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:25,代码来源:QueryBoostingContext.cs

示例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);
                }
            }
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:54,代码来源:Downloads.cs

示例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);
            }
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:19,代码来源:IndexingUtils.cs

示例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>();
            }
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:21,代码来源:DownloadRankings.cs


注:本文中的ILoader.GetReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。