示例#1
0
 public void Load(JObject dataFromFile)
 {
     foreach (KeyValuePair <string, JToken> child in dataFromFile)
     {
         INavigationElement toAdd;
         if (child.Value.Type == JTokenType.String)
         {
             var nameToUse      = child.Key;
             var isIndexElement = child.Key == "__index";
             if (isIndexElement)
             {
                 nameToUse = this.Name;
             }
             toAdd = new SimpleNavigationElement()
             {
                 Name = nameToUse, Value = child.Value.ToObject <string>(), IsIndexElement = isIndexElement
             };
         }
         else
         {
             var subLevel = new NavigationLevel()
             {
                 Name = child.Key, IsRoot = false
             };
             subLevel.Load((JObject)child.Value);
             toAdd = subLevel;
         }
         toAdd.ParentContainer = this;
         this.Value.Add(toAdd);
     }
 }
示例#2
0
        public void Load(JObject dataFromFile)
        {
            foreach (KeyValuePair <string, JToken> child in dataFromFile)
            {
                INavigationElement toAdd;
                if (child.Value.Type == JTokenType.String)
                {
                    var nameToUse = child.Key;

                    var isIndexElement = child.Key == "__index";
                    if (isIndexElement)
                    {
                        nameToUse = this.Name;
                    }

                    var childValue = child.Value.ToObject <string>();
                    if (childValue.EndsWith("**"))
                    {
                        var path = childValue.Replace("**", string.Empty)
                                   .Replace('\\', Path.DirectorySeparatorChar)
                                   .Replace('/', Path.DirectorySeparatorChar);

                        if (!Path.IsPathRooted(path))
                        {
                            path = Path.Combine(_rootDirectory, path);
                        }

                        toAdd      = CreateGeneratedLevel(path);
                        toAdd.Name = nameToUse;
                    }
                    else
                    {
                        toAdd = new SimpleNavigationElement
                        {
                            Name           = nameToUse,
                            Value          = childValue,
                            IsIndexElement = isIndexElement
                        };
                    }
                }
                else
                {
                    var subLevel = new NavigationLevel(_rootDirectory)
                    {
                        Name   = child.Key,
                        IsRoot = false
                    };
                    subLevel.Load((JObject)child.Value);
                    toAdd = subLevel;
                }
                toAdd.ParentContainer = this;
                this.Value.Add(toAdd);
            }
        }
示例#3
0
        private NavigationLevel CreateGeneratedLevel(string path)
        {
            var root = new NavigationLevel(_rootDirectory)
            {
                ParentContainer = this,
                IsAutoGenerated = true
            };

            foreach (var mdFile in Directory.GetFiles(path, "*.md", SearchOption.TopDirectoryOnly))
            {
                var name = FindTitleInMdFile(mdFile);
                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }

                var item = new SimpleNavigationElement
                {
                    Name            = name,
                    Value           = Path.Combine(Utils.MakeRelativePath(_rootDirectory, path), Path.GetFileName(mdFile)),
                    ParentContainer = root,
                    IsAutoGenerated = true
                };

                root.Value.Add(item);
            }

            foreach (var directory in Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly))
            {
                var subDirectoryNavigationElement = CreateGeneratedLevel(directory);
                subDirectoryNavigationElement.Name            = new DirectoryInfo(directory).Name;
                subDirectoryNavigationElement.ParentContainer = root;

                root.Value.Add(subDirectoryNavigationElement);
            }

            return(root);
        }