Exemple #1
0
        private void BeginSection(string line)
        {
            var    tokens = line.Substring(2).Split(':', 2);
            object vitaEntryType;

            if (!Enum.TryParse(typeof(VitaEntryType), tokens[0], true, out vitaEntryType))
            {
                throw new InvalidDataException($"unkown vita type: {tokens[0]}");
            }

            if (tokens.Length != 2)
            {
                throw new InvalidDataException($"missing title in line: {line}");
            }

            if ((VitaEntryType)vitaEntryType == VitaEntryType.Include)
            {
                var currentFileName = (this.stream as FileStream)?.Name;
                var fileItem        = Path.Join(Path.GetDirectoryName(currentFileName), tokens[1].Trim().Trim('"'));
                var stream          = new FileStream(fileItem, FileMode.Open, FileAccess.Read);
                var reader          = new VitaStreamReader(stream, Encoding.UTF8);
                this.includedItems = reader.ReadEntries().ToArray();
                return;
            }

            this.builder         = new VitaEntryBuilder((VitaEntryType)vitaEntryType, tokens[1].Trim());
            this.inHeaderSection = true;
        }
Exemple #2
0
        private void LoadOnDemand()
        {
            if (this.database != null && Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                return;
            }

            var itemList  = new List <VitaEntry>();
            var fileItems = this.configuration.GetSection("DataSourceFileSystem").AsEnumerable().Select(x => x.Value).ToArray();

            foreach (var fileItem in fileItems)
            {
                if (File.Exists(fileItem))
                {
                    var reader = new VitaStreamReader(new FileStream(fileItem, FileMode.Open, FileAccess.Read), Encoding.UTF8);
                    itemList.AddRange(reader.ReadEntries());
                }
            }

            this.database = itemList.ToArray();

            this.knownCodes = itemList.SelectMany(x => x.Codes).Where(x => x != "*").ToHashSet();
        }