예제 #1
0
        private static void ReadCsv(string content)
        {
            string[] lines = content.Split(CharExtensions.LineBreakChars, StringSplitOptions.RemoveEmptyEntries);
            char[]   comma = new char[] { ',' };

            List <CranMirrorEntry> entries = new List <CranMirrorEntry>();

            for (int i = 1; i < lines.Length; i++)
            {
                // Name, Country, City, URL, Host, Maintainer, OK, CountryCode, Comment
                string[] items = lines[i].Split(comma);
                if (items.Length >= 4)
                {
                    CranMirrorEntry e = new CranMirrorEntry()
                    {
                        Name    = items[0].Replace("\"", string.Empty),
                        Country = items[1].Replace("\"", string.Empty),
                        City    = items[2].Replace("\"", string.Empty),
                        Url     = items[3].Replace("\"", string.Empty),
                    };

                    entries.Add(e);
                }
            }

            _mirrors = entries.ToArray();
        }
예제 #2
0
        /// <summary>
        /// Given CRAN mirror name returns its URL.
        /// If no mirror found, returns default URL
        /// of RStudio CRAN redirector.
        /// </summary>
        public static string UrlFromName(string name)
        {
            CranMirrorEntry e = _mirrors.FirstOrDefault((x) => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase));

            return(e != null ? e.Url : "https://cran.rstudio.com");
        }
예제 #3
0
        private static void ReadCsv(string content) {
            string[] lines = content.Split(CharExtensions.LineBreakChars, StringSplitOptions.RemoveEmptyEntries);
            char[] comma = new char[] { ',' };

            List<CranMirrorEntry> entries = new List<CranMirrorEntry>();

            for (int i = 1; i < lines.Length; i++) {
                // Name, Country, City, URL, Host, Maintainer, OK, CountryCode, Comment
                string[] items = lines[i].Split(comma);
                if (items.Length >= 4) {
                    CranMirrorEntry e = new CranMirrorEntry() {
                        Name = items[0].Replace("\"", string.Empty),
                        Country = items[1].Replace("\"", string.Empty),
                        City = items[2].Replace("\"", string.Empty),
                        Url = items[3].Replace("\"", string.Empty),
                    };

                    entries.Add(e);
                }
            }

            _mirrors = entries.ToArray();
        }