Esempio n. 1
0
        public void Delete(string id)
        {
            var fileId = new FileId(id);

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

            if (fileId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
                return;
            }

            File file = FilesHelper.GetFiles(site, fileId.Path).Where(f => f.Name.Equals(fileId.Name)).FirstOrDefault();

            if (file != null)
            {
                var section = DefaultDocumentHelper.GetDefaultDocumentSection(site, fileId.Path, ManagementUnit.ResolveConfigScope());

                FilesHelper.DeleteFile(file, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
Esempio n. 2
0
        public override void Start()
        {
            var host = Environment.Host;

            // Register all controller routes in mvc framework
            host.RouteBuilder.MapWebApiRoute(Defines.FilesResource.Guid, $"{Defines.FILES_PATH}/{{id?}}", new { controller = "defaultdocumentfiles" });
            host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "defaultdocument" });

            //
            // Provide HAL
            //

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

            // Files
            Environment.Hal.ProvideLink(Defines.Resource.Guid, "files", doc => new { href = $"/{Defines.FILES_PATH}?{Defines.IDENTIFIER}={doc.id}" });

            // DefaultDocument File
            Environment.Hal.ProvideLink(Defines.FilesResource.Guid, "self", file => new { href = FilesHelper.GetLocation(file.id) });


            // Web Server
            Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.Resource.Name, _ => {
                var id = GetDefaultDocumentId(null, null);
                return(new { href = DefaultDocumentHelper.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     = GetDefaultDocumentId(s, "/");
                return(new { href = DefaultDocumentHelper.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    = GetDefaultDocumentId(s, appId.Path);
                return(new { href = DefaultDocumentHelper.GetLocation(id.Uuid) });
            });
        }