コード例 #1
0
        public object Patch([FromBody] dynamic model, string id)
        {
            var preConditionId = new PreConditionId(id);

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

            if (preConditionId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            OutboundRulesSection section      = OutboundRulesHelper.GetSection(site, preConditionId.Path);
            PreCondition         precondition = section.PreConditions.FirstOrDefault(pc => pc.Name.Equals(preConditionId.Name, StringComparison.OrdinalIgnoreCase));

            if (precondition == null)
            {
                return(NotFound());
            }

            OutboundRulesHelper.UpdatePreCondition(model, precondition, section);

            ManagementUnit.Current.Commit();

            dynamic updatedPreCondition = OutboundRulesHelper.PreConditionToJsonModel(precondition, site, preConditionId.Path, Context.Request.GetFields(), true);

            if (updatedPreCondition.id != id)
            {
                return(LocationChanged(OutboundRulesHelper.GetPreConditionLocation(updatedPreCondition.id), updatedPreCondition));
            }

            return(updatedPreCondition);
        }
コード例 #2
0
        public object Patch([FromBody] dynamic model, string id)
        {
            var customTagsId = new CustomTagsId(id);

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

            if (customTagsId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            OutboundRulesSection section = OutboundRulesHelper.GetSection(site, customTagsId.Path);
            TagsElement          tags    = section.Tags.FirstOrDefault(t => t.Name.Equals(customTagsId.Name, StringComparison.OrdinalIgnoreCase));

            if (tags == null)
            {
                return(NotFound());
            }

            OutboundRulesHelper.UpdateCustomTags(model, tags, section);

            ManagementUnit.Current.Commit();

            dynamic updatedCustomTags = OutboundRulesHelper.TagsToJsonModel(tags, site, customTagsId.Path, Context.Request.GetFields(), true);

            if (updatedCustomTags.id != id)
            {
                return(LocationChanged(OutboundRulesHelper.GetCustomTagsLocation(updatedCustomTags.id), updatedCustomTags));
            }

            return(updatedCustomTags);
        }
コード例 #3
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model);

            if (parentId == null)
            {
                throw new ApiArgumentException("url_rewrite");
            }

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

            string configPath            = ManagementUnit.ResolveConfigScope(model);
            OutboundRulesSection section = OutboundRulesHelper.GetSection(site, parentId.Path, configPath);

            TagsElement tags = OutboundRulesHelper.CreateCustomTags(model, section);

            OutboundRulesHelper.AddCustomTags(tags, section);

            ManagementUnit.Current.Commit();

            dynamic pc = OutboundRulesHelper.TagsToJsonModel(tags, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(OutboundRulesHelper.GetCustomTagsLocation(pc.id), pc));
        }
コード例 #4
0
        public object Patch([FromBody] dynamic model, string id)
        {
            var outboundRuleId = new OutboundRuleId(id);

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

            if (outboundRuleId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            OutboundRulesSection section = OutboundRulesHelper.GetSection(site, outboundRuleId.Path);
            OutboundRule         rule    = (OutboundRule)section.Rules.FirstOrDefault(r => r.Name.Equals(outboundRuleId.Name, StringComparison.OrdinalIgnoreCase));

            if (rule == null)
            {
                return(NotFound());
            }

            OutboundRulesHelper.UpdateRule(model, rule, section);

            ManagementUnit.Current.Commit();

            dynamic updatedRule = OutboundRulesHelper.RuleToJsonModel(rule, site, outboundRuleId.Path, Context.Request.GetFields(), true);

            if (updatedRule.id != id)
            {
                return(LocationChanged(OutboundRulesHelper.GetRuleLocation(updatedRule.id), updatedRule));
            }

            return(updatedRule);
        }
コード例 #5
0
        public object Get()
        {
            RewriteHelper.ResolveRewrite(Context, out Site site, out string path);

            if (path == null)
            {
                return(NotFound());
            }

            dynamic d = OutboundRulesHelper.SectionToJsonModel(site, path);

            return(LocationChanged(OutboundRulesHelper.GetSectionLocation(d.id), d));
        }
コード例 #6
0
        public object Get(string id)
        {
            var rewriteId = new RewriteId(id);

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

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

            return(OutboundRulesHelper.SectionToJsonModel(site, rewriteId.Path));
        }
コード例 #7
0
        public void Delete(string id)
        {
            var outboundRulesId = new RewriteId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

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

            if (site != null)
            {
                var section = OutboundRulesHelper.GetSection(site, outboundRulesId.Path, ManagementUnit.ResolveConfigScope());
                section.RevertToParent();
                ManagementUnit.Current.Commit();
            }
        }
コード例 #8
0
        public object Get(string id)
        {
            var preConditionId = new PreConditionId(id);

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

            if (preConditionId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            PreCondition precondition = OutboundRulesHelper.GetSection(site, preConditionId.Path).PreConditions.FirstOrDefault(pc => pc.Name.Equals(preConditionId.Name, StringComparison.OrdinalIgnoreCase));

            if (precondition == null)
            {
                return(NotFound());
            }

            return(OutboundRulesHelper.PreConditionToJsonModel(precondition, site, preConditionId.Path, Context.Request.GetFields()));
        }
コード例 #9
0
        public object Get(string id)
        {
            var customTagsId = new CustomTagsId(id);

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

            if (customTagsId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            TagsElement tag = OutboundRulesHelper.GetSection(site, customTagsId.Path).Tags.FirstOrDefault(tags => tags.Name.Equals(customTagsId.Name, StringComparison.OrdinalIgnoreCase));

            if (tag == null)
            {
                return(NotFound());
            }

            return(OutboundRulesHelper.TagsToJsonModel(tag, site, customTagsId.Path, Context.Request.GetFields()));
        }
コード例 #10
0
        public object Get(string id)
        {
            var outboundRuleId = new OutboundRuleId(id);

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

            if (outboundRuleId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            OutboundRule rule = (OutboundRule)OutboundRulesHelper.GetSection(site, outboundRuleId.Path).Rules.FirstOrDefault(r => r.Name.Equals(outboundRuleId.Name, StringComparison.OrdinalIgnoreCase));

            if (rule == null)
            {
                return(NotFound());
            }

            return(OutboundRulesHelper.RuleToJsonModel(rule, site, outboundRuleId.Path, Context.Request.GetFields()));
        }
コード例 #11
0
        public object Get()
        {
            string outboundRulesId = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(outboundRulesId))
            {
                return(NotFound());
            }

            var sectionId = new RewriteId(outboundRulesId);

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

            PreConditionCollection preconditions = OutboundRulesHelper.GetSection(site, sectionId.Path).PreConditions;

            this.Context.Response.SetItemsCount(preconditions.Count());

            return(new
            {
                preconditions = preconditions.Select(precondition => OutboundRulesHelper.PreConditionToJsonModelRef(precondition, site, sectionId.Path, Context.Request.GetFields()))
            });
        }
コード例 #12
0
        public void Delete(string id)
        {
            TagsElement tags   = null;
            var         tagsId = new CustomTagsId(id);

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

            if (tagsId.SiteId == null || site != null)
            {
                tags = OutboundRulesHelper.GetSection(site, tagsId.Path).Tags.FirstOrDefault(t => t.Name.Equals(tagsId.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (tags != null)
            {
                var section = OutboundRulesHelper.GetSection(site, tagsId.Path, ManagementUnit.ResolveConfigScope());

                OutboundRulesHelper.DeleteCustomTags(tags, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
コード例 #13
0
        public void Delete(string id)
        {
            PreCondition preCondition   = null;
            var          preConditionId = new PreConditionId(id);

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

            if (preConditionId.SiteId == null || site != null)
            {
                preCondition = OutboundRulesHelper.GetSection(site, preConditionId.Path).PreConditions.FirstOrDefault(pc => pc.Name.Equals(preConditionId.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (preCondition != null)
            {
                var section = OutboundRulesHelper.GetSection(site, preConditionId.Path, ManagementUnit.ResolveConfigScope());

                OutboundRulesHelper.DeletePreCondition(preCondition, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
コード例 #14
0
        public void Delete(string id)
        {
            OutboundRule rule           = null;
            var          outboundRuleId = new OutboundRuleId(id);

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

            if (outboundRuleId.SiteId == null || site != null)
            {
                rule = (OutboundRule)OutboundRulesHelper.GetSection(site, outboundRuleId.Path).Rules.FirstOrDefault(r => r.Name.Equals(outboundRuleId.Name, StringComparison.OrdinalIgnoreCase));
            }

            if (rule != null)
            {
                var section = OutboundRulesHelper.GetSection(site, outboundRuleId.Path, ManagementUnit.ResolveConfigScope());

                OutboundRulesHelper.DeleteRule(rule, section);
                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
コード例 #15
0
        public object Get()
        {
            string outboundRulesId = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(outboundRulesId))
            {
                return(NotFound());
            }

            var sectionId = new RewriteId(outboundRulesId);

            // Get site rule is for if applicable
            Site site = sectionId.SiteId == null ? null : SiteHelper.GetSite(sectionId.SiteId.Value);

            OutboundRulesCollection rules = OutboundRulesHelper.GetSection(site, sectionId.Path).Rules;

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(rules.Count());

            return(new
            {
                rules = rules.Select(rule => OutboundRulesHelper.RuleToJsonModelRef((OutboundRule)rule, site, sectionId.Path, Context.Request.GetFields()))
            });
        }
コード例 #16
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            var outboundRulesId = new RewriteId(id);

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

            if (outboundRulesId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);

            OutboundRulesHelper.UpdateSection(model, site, outboundRulesId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(OutboundRulesHelper.SectionToJsonModel(site, outboundRulesId.Path));
        }
コード例 #17
0
ファイル: Startup.cs プロジェクト: zyonet/IIS.Administration
        private void ConfigureOutboundRules()
        {
            var builder = Environment.Host.RouteBuilder;
            var hal     = Environment.Hal;

            builder.MapWebApiRoute(Defines.OutboundRulesSectionResource.Guid, $"{Defines.OUTBOUND_RULES_SECTION_PATH}/{{id?}}", new { controller = "OutboundRulesSection" });
            builder.MapWebApiRoute(Defines.OutboundRulesResource.Guid, $"{Defines.OUTBOUND_RULES_PATH}/{{id?}}", new { controller = "OutboundRules" });
            builder.MapWebApiRoute(Defines.PreConditionsResource.Guid, $"{Defines.PRECONDITIONS_PATH}/{{id?}}", new { controller = "PreConditions" });
            builder.MapWebApiRoute(Defines.CustomTagsResource.Guid, $"{Defines.CUSTOM_TAGS_PATH}/{{id?}}", new { controller = "CustomTags" });

            // () -> Self
            hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, "self", ir => new { href = OutboundRulesHelper.GetSectionLocation(ir.id) });
            hal.ProvideLink(Defines.OutboundRulesResource.Guid, "self", ir => new { href = OutboundRulesHelper.GetRuleLocation(ir.id) });
            hal.ProvideLink(Defines.PreConditionsResource.Guid, "self", pc => new { href = OutboundRulesHelper.GetPreConditionLocation(pc.id) });
            hal.ProvideLink(Defines.CustomTagsResource.Guid, "self", tags => new { href = OutboundRulesHelper.GetCustomTagsLocation(tags.id) });

            // Rewrite -> Section
            hal.ProvideLink(Defines.Resource.Guid, Defines.OutboundRulesSectionResource.Name, rewrite => new { href = OutboundRulesHelper.GetSectionLocation(rewrite.id) });

            // Section -> Rules
            hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.OutboundRulesResource.Name, outboundRulesSection => new { href = $"/{Defines.OUTBOUND_RULES_PATH}?{Defines.IDENTIFIER}={outboundRulesSection.id}" });

            // Section -> PreConditions
            hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.PreConditionsResource.Name, outboundRulesSection => new { href = $"/{Defines.PRECONDITIONS_PATH}?{Defines.IDENTIFIER}={outboundRulesSection.id}" });

            // Section -> CustomTags
            hal.ProvideLink(Defines.OutboundRulesSectionResource.Guid, Defines.CustomTagsResource.Name, outboundRulesSection => new { href = $"/{Defines.CUSTOM_TAGS_PATH}?{Defines.IDENTIFIER}={outboundRulesSection.id}" });
        }