Ejemplo n.º 1
0
        public static List <BhePatternItem> ListFromFile(string fileName)
        {
            var items = new List <BhePatternItem>();

            using (var file = new StreamReader(fileName))
            {
                int count = int.Parse(file.ReadLine().Split(',')[0], CultureInfo.InvariantCulture);

                for (int i = 0; i < count; i++)
                {
                    var      item  = new BhePatternItem();
                    string[] parts = file.ReadLine().Split(',');

                    item.Offset   = int.Parse(parts[0], CultureInfo.InvariantCulture);
                    item.Name     = parts[1];
                    item.DataType = (BheDataType)int.Parse(parts[2], CultureInfo.InvariantCulture);

                    if (!string.IsNullOrEmpty(parts[3]))
                    {
                        item.DataLength = int.Parse(parts[3], CultureInfo.InvariantCulture);
                    }

                    item.CommentId = int.Parse(parts[4], CultureInfo.InvariantCulture);

                    items.Add(item);
                }
            }

            return(items);
        }
Ejemplo n.º 2
0
        public static BheProject FromFile(string fileName)
        {
            string directory = Path.GetDirectoryName(fileName);

            var project = new BheProject();

            project.FileName      = fileName;
            project.DirectoryName = directory;

            project.ProjectText = File.ReadAllText(Path.Combine(directory, "Project.txt"), Encoding.Default);
            project.Summary     = BheSummary.FromFile(Path.Combine(directory, "Summary.txt"));
            project.Sections.AddRange(BheSection.ListFromFile(Path.Combine(directory, "Sections.csv")));

            foreach (string pattern in project.Summary.Patterns)
            {
                string path = Path.Combine(directory, "pat_" + pattern + ".csv");
                project.Patterns.Add(BhePatternItem.ListFromFile(path));
            }

            project.Comments.Add(string.Empty);

            foreach (string comment in project.Summary.Comments.Skip(1))
            {
                string path = Path.Combine(directory, "com_" + comment + ".txt");
                project.Comments.Add(File.ReadAllText(path, Encoding.Default));
            }

            return(project);
        }