public override void Start()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "directorybrowsing" });

            // Self
            Environment.Hal.ProvideLink(Defines.Resource.Guid, "self", dirb => new { href = DirectoryBrowsingHelper.GetLocation(dirb.id) });

            // Webserver
            Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.Resource.Name, _ => {
                var id = GetDirectoryBrowsingId(null, null);
                return(new { href = DirectoryBrowsingHelper.GetLocation(id.Uuid) });
            });

            // Site
            Environment.Hal.ProvideLink(Sites.Defines.Resource.Guid, Defines.Resource.Name, site => {
                var siteId = new SiteId((string)site.id);
                Site s     = SiteHelper.GetSite(siteId.Id);
                var id     = GetDirectoryBrowsingId(s, "/");
                return(new { href = DirectoryBrowsingHelper.GetLocation(id.Uuid) });
            });

            // Application
            Environment.Hal.ProvideLink(Applications.Defines.Resource.Guid, Defines.Resource.Name, app => {
                var appId = new ApplicationId((string)app.id);
                Site s    = SiteHelper.GetSite(appId.SiteId);
                var id    = GetDirectoryBrowsingId(s, appId.Path);
                return(new { href = DirectoryBrowsingHelper.GetLocation(id.Uuid) });
            });
        }
        public object Get(string id)
        {
            DirectoryBrowsingId dirbId = new DirectoryBrowsingId(id);

            Site site = dirbId.SiteId == null ? null : SiteHelper.GetSite(dirbId.SiteId.Value);

            return(DirectoryBrowsingHelper.ToJsonModel(site, dirbId.Path));
        }
        public async Task <object> Post()
        {
            if (DirectoryBrowsingHelper.IsFeatureEnabled())
            {
                throw new AlreadyExistsException(DISPLAY_NAME);
            }

            await DirectoryBrowsingHelper.SetFeatureEnabled(true);

            dynamic settings = DirectoryBrowsingHelper.ToJsonModel(null, null);

            return(Created(DirectoryBrowsingHelper.GetLocation(settings.id), settings));
        }
        public object Get()
        {
            Site   site = ApplicationHelper.ResolveSite();
            string path = ApplicationHelper.ResolvePath();

            if (path == null)
            {
                return(NotFound());
            }

            dynamic d = DirectoryBrowsingHelper.ToJsonModel(site, path);

            return(LocationChanged(DirectoryBrowsingHelper.GetLocation(d.id), d));
        }
        public object Patch(string id, [FromBody] dynamic model)
        {
            DirectoryBrowsingId dirbId = new DirectoryBrowsingId(id);

            Site site = dirbId.SiteId == null ? null : SiteHelper.GetSite(dirbId.SiteId.Value);

            if (dirbId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);

            DirectoryBrowsingHelper.UpdateSettings(model, site, dirbId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(DirectoryBrowsingHelper.ToJsonModel(site, dirbId.Path));
        }
        public void Delete(string id)
        {
            DirectoryBrowsingId dirbId = new DirectoryBrowsingId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

            Site site = (dirbId.SiteId != null) ? SiteHelper.GetSite(dirbId.SiteId.Value) : null;

            if (site == null)
            {
                return;
            }

            var section = DirectoryBrowsingHelper.GetDirectoryBrowseSection(site, dirbId.Path, ManagementUnit.ResolveConfigScope());

            section.RevertToParent();

            ManagementUnit.Current.Commit();
        }
        public async Task Delete(string id)
        {
            DirectoryBrowsingId dirbId = new DirectoryBrowsingId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

            Site site = (dirbId.SiteId != null) ? SiteHelper.GetSite(dirbId.SiteId.Value) : null;

            if (site != null)
            {
                var section = DirectoryBrowsingHelper.GetDirectoryBrowseSection(site, dirbId.Path, ManagementUnit.ResolveConfigScope());
                section.RevertToParent();
                ManagementUnit.Current.Commit();
            }

            if (dirbId.SiteId == null && DirectoryBrowsingHelper.IsFeatureEnabled())
            {
                await DirectoryBrowsingHelper.SetFeatureEnabled(false);
            }
        }
 private DirectoryBrowsingId GetDirectoryBrowsingId(Site s, string path)
 {
     return(new DirectoryBrowsingId(s?.Id, path, DirectoryBrowsingHelper.IsSectionLocal(s, path)));
 }