public object Patch(string id, [FromBody] dynamic model) { if (model == null) { throw new ApiArgumentException("model"); } // Decode default document id from uuid parameter DefaultDocumentId docId = new DefaultDocumentId(id); Site site = docId.SiteId == null ? null : SiteHelper.GetSite(docId.SiteId.Value); if (docId.SiteId != null && site == null) { // The document id specified a site but we couldn't find it, // therefore we can't get the settings for that site return(NotFound()); } string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model); DefaultDocumentSection section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, configPath); DefaultDocumentHelper.UpdateFeatureSettings(model, section); ManagementUnit.Current.Commit(); return(DefaultDocumentHelper.ToJsonModel(site, docId.Path)); }
public object Get(string id) { // Decode default document id from uuid parameter DefaultDocumentId docId = new DefaultDocumentId(id); Site site = docId.SiteId == null ? null : SiteHelper.GetSite(docId.SiteId.Value); return(DefaultDocumentHelper.ToJsonModel(site, docId.Path)); }
public async Task <object> Post() { if (DefaultDocumentHelper.IsFeatureEnabled()) { throw new AlreadyExistsException(DefaultDocumentHelper.FEATURE_NAME); } await DefaultDocumentHelper.SetFeatureEnabled(true); dynamic settings = DefaultDocumentHelper.ToJsonModel(null, null); return(Created(DefaultDocumentHelper.GetLocation(settings.id), settings)); }
public object Post([FromBody] dynamic model) { File file = null; DefaultDocumentId docId = null; Site site = null; if (model == null) { throw new ApiArgumentException("model"); } if (model.default_document == null) { throw new ApiArgumentException("default_document"); } if (!(model.default_document is JObject)) { throw new ApiArgumentException("default_document"); } // Creating a a file instance requires referencing the target feature string docUuid = DynamicHelper.Value(model.default_document.id); if (docUuid == null) { throw new ApiArgumentException("default_document.id"); } // Get the default document feature id docId = new DefaultDocumentId(docUuid); site = docId.SiteId == null ? null : SiteHelper.GetSite(docId.SiteId.Value); // Get target configuration section for addition of file string configPath = ManagementUnit.ResolveConfigScope(model); DefaultDocumentSection section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, configPath); // Create default document file = FilesHelper.CreateFile(model, section); // Add it FilesHelper.AddFile(file, section); // Save ManagementUnit.Current.Commit(); // // Create response dynamic f = FilesHelper.ToJsonModel(file, site, docId.Path); return(Created(FilesHelper.GetLocation(f.id), f)); }
public object Get() { // Check if the scope of the request is for site or application Site site = ApplicationHelper.ResolveSite(); string path = ApplicationHelper.ResolvePath(); if (path == null) { return(NotFound()); } dynamic d = DefaultDocumentHelper.ToJsonModel(site, path); return(LocationChanged(DefaultDocumentHelper.GetLocation(d.id), d)); }
internal static object ToJsonModel(File file, Site site, string path) { if (file == null) { return(null); } // FileId for uniquely identifying the file FileId fileId = new FileId(site?.Id, path, file.Name); var obj = new { name = file.Name, id = fileId.Uuid, default_document = DefaultDocumentHelper.ToJsonModelRef(site, path) }; return(Core.Environment.Hal.Apply(Defines.FilesResource.Guid, obj)); }
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) }); }); }
public void Delete(string id) { DefaultDocumentId docId = new DefaultDocumentId(id); Context.Response.StatusCode = (int)HttpStatusCode.NoContent; Site site = (docId.SiteId != null) ? SiteHelper.GetSite(docId.SiteId.Value) : null; if (site == null) { return; } var section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, ManagementUnit.ResolveConfigScope()); section.RevertToParent(); ManagementUnit.Current.Commit(); }
public object Patch(string id, [FromBody] dynamic model) { if (model == null) { throw new ApiArgumentException("model"); } // Decode default document id from uuid parameter DefaultDocumentId docId = new DefaultDocumentId(id); Site site = docId.SiteId == null ? null : SiteHelper.GetSite(docId.SiteId.Value); if (docId.SiteId != null && site == null) { // The document id specified a site but we couldn't find it, // therefore we can't get the settings for that site return(NotFound()); } string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model); DefaultDocumentSection section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, configPath); try { // Handle patching of any feature settings DynamicHelper.If <bool>((object)model.enabled, v => section.Enabled = v); if (model.metadata != null) { DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => section.OverrideMode = v); } } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } ManagementUnit.Current.Commit(); return(DefaultDocumentHelper.ToJsonModel(site, docId.Path)); }
public async Task Delete(string id) { DefaultDocumentId docId = new DefaultDocumentId(id); Context.Response.StatusCode = (int)HttpStatusCode.NoContent; Site site = (docId.SiteId != null) ? SiteHelper.GetSite(docId.SiteId.Value) : null; if (site != null) { var section = DefaultDocumentHelper.GetDefaultDocumentSection(site, docId.Path, ManagementUnit.ResolveConfigScope()); section.RevertToParent(); ManagementUnit.Current.Commit(); } // When target is webserver, uninstall if (docId.SiteId == null && DefaultDocumentHelper.IsFeatureEnabled()) { await DefaultDocumentHelper.SetFeatureEnabled(false); } }
public object Patch([FromBody] dynamic model, string id) { FileId fileId = new FileId(id); Site site = fileId.SiteId == null ? null : SiteHelper.GetSite(fileId.SiteId.Value); if (fileId.SiteId != null && site == null) { // The file id specified a site but we couldn't find it, // therefore we can't get the file return(NotFound()); } File file = FilesHelper.GetFiles(site, fileId.Path).Where(f => f.Name.Equals(fileId.Name)).FirstOrDefault(); if (file == null) { return(NotFound()); } if (model == null) { throw new ApiArgumentException("model"); } var section = DefaultDocumentHelper.GetDefaultDocumentSection(site, fileId.Path, ManagementUnit.ResolveConfigScope(model)); FilesHelper.UpdateFile(file, model, section); ManagementUnit.Current.Commit(); dynamic fle = FilesHelper.ToJsonModel(file, site, fileId.Path); if (fle.id != id) { return(LocationChanged(FilesHelper.GetLocation(fle.id), fle)); } return(fle); }
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; }
private DefaultDocumentId GetDefaultDocumentId(Site site, string path) { return(new DefaultDocumentId(site?.Id, path, DefaultDocumentHelper.IsSectionLocal(site, path))); }
public static List <File> GetFiles(Site site, string path) { return(DefaultDocumentHelper.GetDefaultDocumentSection(site, path).Files.ToList()); }