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 static File AddFile(File file, DefaultDocumentSection section) { if (section == null) { throw new ArgumentNullException("section"); } // Try to get default document with name specified to ensure it doesn't exist File element = section.Files[file.Name]; if (element != null) { throw new ApiArgumentException("Default Document already exists.", "document"); } try { element = section.Files.AddAt(0, file.Name); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } return(file); }
public static File CreateFile(dynamic model, DefaultDocumentSection section) { // Ensure integrity of model if (model == null) { throw new ApiArgumentException("model"); } if (section == null) { throw new ArgumentNullException("section"); } string name = DynamicHelper.Value(model.name); if (String.IsNullOrEmpty(name)) { throw new ApiArgumentException("name"); } File file = section.Files.CreateElement(); file.Name = name; return(file); }
public static void DeleteFile(File document, DefaultDocumentSection section) { if (document == null) { throw new ArgumentNullException("document"); } File element = section.Files[document.Name]; if (element == null) { return; } try { // Delete the document section.Files.Remove(element); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } }
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 static void UpdateFeatureSettings(dynamic model, DefaultDocumentSection section) { try { 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); } }
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 static File UpdateFile(File file, dynamic model, DefaultDocumentSection section) { if (model == null) { throw new ArgumentNullException("model"); } string name = DynamicHelper.Value(model.name); if (!string.IsNullOrEmpty(name)) { if (!name.Equals(file.Name, StringComparison.OrdinalIgnoreCase) && section.Files.Any(f => name.Equals(f.Name, StringComparison.OrdinalIgnoreCase))) { throw new AlreadyExistsException("name"); } file.Name = name; } return(file); }