Пример #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 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));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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));
        }
Пример #5
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));
        }