コード例 #1
0
        public void UpdateList(SortableBindingList <Language> dataSourceByProject, SortableBindingList <Language> dataSourceByLinesOfCode, string userName)
        {
            string json  = GetContentFromUrl($"https://api.github.com/users/{userName}/repos");
            JArray array = JArray.Parse(json);

            foreach (JToken element in array)
            {
                AddCountToList(dataSourceByProject, element["language"].ToString(), 1);
                string  repoName   = element["name"].ToString();
                string  subJson    = GetContentFromUrl($"https://api.github.com/repos/{userName}/{repoName}/languages");
                JObject repoObject = JObject.Parse(subJson);
                foreach (KeyValuePair <string, JToken> thing in repoObject)
                {
                    AddCountToList(dataSourceByLinesOfCode, thing.Key, (int)thing.Value);
                }
            }
            dataSourceByProject.OrderByDescending(x => x.Count);
            dataSourceByLinesOfCode.OrderByDescending(x => x.Count);
        }
コード例 #2
0
        public void AddColors(SortableBindingList <Language> dataSourceByProject, SortableBindingList <Language> dataSourceByLinesOfCode)
        {
            string yamlString = GetContentFromUrl("https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml");

            // Load the stream.
            YamlStream yaml = new YamlStream();

            using (StringReader input = new StringReader(yamlString))
                yaml.Load(input);

            // Examine the stream.
            YamlMappingNode mapping = (YamlMappingNode)yaml.Documents[0].RootNode;

            foreach (Language language in dataSourceByProject)
            {
                string colorHex = ((YamlScalarNode) new Dictionary <YamlNode, YamlNode>(((YamlMappingNode)mapping.Children.FirstOrDefault(x => x.Key.ToString() == language.LanguageName).Value).Children).FirstOrDefault(x => x.Key.ToString() == "color").Value).Value;
                language.Color = System.Drawing.ColorTranslator.FromHtml(colorHex);
            }
            foreach (Language language in dataSourceByLinesOfCode)
            {
                string colorHex = ((YamlScalarNode) new Dictionary <YamlNode, YamlNode>(((YamlMappingNode)mapping.Children.FirstOrDefault(x => x.Key.ToString() == language.LanguageName).Value).Children).FirstOrDefault(x => x.Key.ToString() == "color").Value).Value;
                language.Color = System.Drawing.ColorTranslator.FromHtml(colorHex);
            }
        }