The Blazor app discussed in a previous blog post A Generic App for displaying Sample Apps presents a tree view of sample apps in a repository as uploaded to the Service. This posts covers the recursive scanning of the samples on the Server. The next post covers the Client Blazor Component for displaying this information.

Recursing the Samples Folder

The nominated folder, either within the server’s folders (in ./Samples) or located elsewehere on the servicing system (useful for development) is set in the server app’s appsettings.json. This can also be toggled between the internal or external folder inapp.

At startup or as a command from the client, these folders are recursively scanned for C# projects and solutions. When the scanning reaches a leaf (no further subfolders) it unwinds. Where a folder has any of the following (or child folders that have such content) a FolderTree instance is created with lists of these files for that folder:

  • .sln
  • .csproj
  • .cs
  • .md
  • Image files (various formats)

The instance also has a reference to it’s parent folder and a list of references to its child folders. When created, each folder is added to a list of AllFolders and given a unique Id, in order of creation. References between folders then use those Ids. Initially the references where directly to the other Folder instance. This was found difficult to pass as Json over Http back to the client. The full list of Folders is sent to the client which then uses the Ids to traverse the Tree. Note also, that when the client requests a file from eth server, it sends the file’s folder Id and the filename to the server as a parameterised Get request.

public class FolderTree
{
    public static int Count = 0;
    public static List<FolderTree> AllFolderTrees=null;

    public int Id { get; set; }

    public FolderTree( FolderTree parent)
    {
        if (parent == null)
        {
            Parent = -1;
            Count = 0;
            Depth = 0;
        }
        else
        {
            Parent = parent.Id;
            Depth = parent.Depth + 1;
        }
        Id = Count++;
        Children = new List<int>();
        Projects = new List<int>();
        Solutions = new List<string>();
        SourceFiles = new List<string>();
        ReadMes = new List<string>();
        Images = new List<string>();
        if (AllFolderTrees == null)
            AllFolderTrees = new List<FolderTree>();
        AllFolderTrees.Add(this);
    }

    public int Parent { get; set; } = -1;
    public List<int> Children { get; set; }
    public List<string> Projects { get; set; }
    public List<string> Solutions { get; set; }
    public List<string> SourceFiles{ get; set; }
    public List<string> ReadMes { get; set; }
    public List<string> Images { get; set; }
}

(Simplified) The FolderTree Class

The Blazor Client Folder Component, see next blog, is then able to recursively display display the list as a tree.


 TopicSubtopic
<  Prev:   Jekyll-Markdown
   
 This Category Links 
Category:Blazor Index:Blazor
  Next: > Blazor
<  Prev:   Blazor How To