示例#1
0
        private static void LoadListsFrom <TType>(
            string basePath,
            string filter,
            Func <string, TType> hasher,
            Func <string, string> modifier,
            HashList <TType> list)
        {
            if (Directory.Exists(basePath) == false)
            {
                return;
            }

            foreach (string listPath in Directory.GetFiles(basePath, filter, SearchOption.AllDirectories))
            {
                using (var input = File.Open(listPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    var reader = new StreamReader(input);

                    while (true)
                    {
                        string line = reader.ReadLine();
                        if (line == null)
                        {
                            break;
                        }

                        if (line.StartsWith(";") == true)
                        {
                            continue;
                        }

                        line = line.Trim();
                        if (line.Length <= 0)
                        {
                            continue;
                        }

                        if (modifier != null)
                        {
                            line = modifier(line);
                        }

                        TType hash = hasher(line);

                        if (list.Lookup.ContainsKey(hash) == true &&
                            list.Lookup[hash] != line)
                        {
                            string otherLine = list.Lookup[hash];
                            throw new InvalidOperationException(
                                      string.Format(
                                          "hash collision ('{0}' vs '{1}')",
                                          line,
                                          otherLine));
                        }

                        list.Lookup[hash] = line;
                    }
                }
            }
        }
示例#2
0
        public HashList <TType> LoadLists <TType>(
            string filter,
            Func <string, TType> hasher,
            Func <string, string> modifier)
        {
            var list = new HashList <TType>();

            foreach (var name in this.Dependencies)
            {
                var dependency = this.Manager[name];
                if (dependency != null)
                {
                    LoadListsFrom(
                        dependency.ListsPath,
                        filter,
                        hasher,
                        modifier,
                        list);
                }
            }

            LoadListsFrom(
                this.ListsPath,
                filter,
                hasher,
                modifier,
                list);

            return(list);
        }