Пример #1
0
        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));
        }
Пример #2
0
        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));
        }
Пример #3
0
        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();
        }
Пример #4
0
        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));
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
        }
Пример #7
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;
        }
Пример #8
0
 public static List <File> GetFiles(Site site, string path)
 {
     return(DefaultDocumentHelper.GetDefaultDocumentSection(site, path).Files.ToList());
 }