Пример #1
0
        private void LoadDataTypes(string directory, string subDirectory, CogsDtoModel model, IList list)
        {
            string itemTypesDirectory = Path.Combine(directory, subDirectory);

            foreach (string typeDir in Directory.GetDirectories(itemTypesDirectory))
            {
                string itemTypeName       = Path.GetFileName(typeDir);
                string readmePath         = Path.Combine(typeDir, "readme.markdown");
                string examplesPath       = Path.Combine(typeDir, "examples.markdown");
                string propertiesFileName = Path.Combine(typeDir, itemTypeName + ".csv");

                var itemType = new ItemType();
                list.Add(itemType);

                itemType.Name        = itemTypeName;
                itemType.Description = GetDescription(readmePath);
                itemType.Extends     = GetExtendsClass(typeDir);

                string abstractFileName = Path.Combine(typeDir, "Abstract");
                if (File.Exists(abstractFileName))
                {
                    itemType.IsAbstract = true;
                }

                string primitiveFileName = Path.Combine(typeDir, "Primitive");
                if (File.Exists(primitiveFileName))
                {
                    itemType.IsPrimitive = true;
                }

                // Read the properties
                if (File.Exists(propertiesFileName))
                {
                    string csvStr = File.ReadAllText(propertiesFileName, Encoding.UTF8);
                    using (var textReader = new StringReader(csvStr))
                    {
                        try
                        {
                            var csvReader = new CsvReader(textReader);
                            var records   = csvReader.GetRecords <Property>().ToList();
                            itemType.Properties = records;
                        }
                        catch (Exception e)
                        {
                            Errors.Add(new CogsError(ErrorLevel.Error, e.Message + " " + propertiesFileName, e));
                        }
                    }
                }


                // TODO DeprecatedNamespace
                // TODO IsDeprecated
            }
        }
Пример #2
0
        public CogsDtoModel Load(string directory)
        {
            var model = new CogsDtoModel();

            // create built in identification and reference types
            SettingsDirectoryName = Path.Combine(directory, "Settings");
            string identificationFile = Path.Combine(SettingsDirectoryName, "Identification.csv");

            if (!File.Exists(identificationFile))
            {
                Errors.Add(new CogsError(ErrorLevel.Error, "identification information is not present in the Settings directory."));
                return(model);
            }


            string idCsvStr = File.ReadAllText(identificationFile, Encoding.UTF8);

            using (var textReader = new StringReader(idCsvStr))
            {
                try
                {
                    var csvReader = new CsvReader(textReader);
                    var records   = csvReader.GetRecords <Property>();
                    model.Identification.AddRange(records);
                }
                catch (Exception e)
                {
                    Errors.Add(new CogsError(ErrorLevel.Error, e.Message + " " + identificationFile, e));
                    return(model);
                }
            }

            // Load settings
            string settingsFileName = Path.Combine(SettingsDirectoryName, "Settings.csv");
            string settingsCsvStr   = File.ReadAllText(settingsFileName, Encoding.UTF8);

            using (var textReader = new StringReader(settingsCsvStr))
            {
                try
                {
                    var csvReader = new CsvReader(textReader);
                    var records   = csvReader.GetRecords <Setting>();
                    model.Settings.AddRange(records);
                }
                catch (Exception e)
                {
                    Errors.Add(new CogsError(ErrorLevel.Error, e.Message + " " + identificationFile, e));
                    return(model);
                }
            }


            // Load information about articles.
            string articlesPath = Path.Combine(directory, "Articles");

            if (Directory.Exists(articlesPath))
            {
                model.ArticlesPath = articlesPath;
                string articlesIndexFileName = Path.Combine(articlesPath, "toc.txt");
                model.ArticleTocEntries.AddRange(File.ReadAllLines(articlesIndexFileName));
            }

            // Load all item types from the ItemTypes directory.
            LoadDataTypes(directory, "ItemTypes", model, model.ItemTypes);

            // Load all reusable types from the ReusableTypes directory.
            LoadDataTypes(directory, "CompositeTypes", model, model.ReusableDataTypes);

            // Load all topics from the Topics directory.
            string topicsDirectory = Path.Combine(directory, "Topics");
            string topicsListFile  = Path.Combine(topicsDirectory, "index.txt");

            string[] viewDirectoryNames = File.ReadAllLines(topicsListFile);
            foreach (string viewDirectoryName in viewDirectoryNames)
            {
                string viewDirectory = Path.Combine(topicsDirectory, viewDirectoryName);

                var view = new TopicIndex();
                view.Name = Path.GetFileName(viewDirectory);

                string viewReadmeFileName = Path.Combine(viewDirectory, "readme.markdown");
                if (File.Exists(viewReadmeFileName))
                {
                    view.Description = File.ReadAllText(viewReadmeFileName);
                }

                string   itemsFileName = Path.Combine(viewDirectory, "items.txt");
                string[] itemTypeNames = File.ReadAllLines(itemsFileName);
                foreach (string name in itemTypeNames)
                {
                    view.ItemTypes.Add(name);
                }

                model.TopicIndices.Add(view);
            }


            return(model);
        }