Docnet.Config.Load C# (CSharp) Method

Load() private method

private Load ( string configFile ) : bool
configFile string
return bool
        internal bool Load(string configFile)
        {
            _configFileSourcePath = Path.GetDirectoryName(configFile);

            var configData = File.ReadAllText(configFile, Encoding.UTF8);
            if(string.IsNullOrWhiteSpace(configData))
            {
                Console.WriteLine("[ERROR] '{0}' is empty.", configFile);
                return false;
            }
            _configData = JObject.Parse(configData);
            if(_configData == null)
            {
                Console.WriteLine("[ERROR] Parsing '{0}' failed!", configFile);
                return false;
            }
            if(string.IsNullOrWhiteSpace(this.ThemeFolder) || !Directory.Exists(this.ThemeFolder))
            {
                Console.WriteLine("[ERROR] Theme '{0}' or Themes folder not found.", this.ThemeFolder);
                return false;
            }
            _templateContents = File.ReadAllText(this.PageTemplateFile, Encoding.UTF8);
            if(string.IsNullOrWhiteSpace(_templateContents))
            {
                Console.WriteLine("[ERROR] Page template '{0}' is empty.", _configData.PageTemplate);
                return false;
            }
            return true;
        }

Usage Example

示例#1
0
        public Config LoadConfig()
        {
            if(string.IsNullOrWhiteSpace(_input.StartFolder))
            {
                Console.WriteLine("[ERROR] Nothing to do, no start folder specified");
                return null;
            }

            var configFile = Path.Combine(_input.StartFolder, "docnet.json");
            if(!File.Exists(configFile))
            {
                Console.WriteLine("[ERROR] {0} not found.", configFile);
                return null;
            }

            var config = new Config();
            if(!config.Load(configFile))
            {
                Console.WriteLine("Errors occurred, can't continue!");
                return null;
            }
            if(config.Pages.IndexElement == null)
            {
                Console.WriteLine("[ERROR] Root __index not found. The root navigationlevel is required to have an __index element");
                return null;
            }
            return config;
        }