コード例 #1
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);
        }
コード例 #2
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);

            OutboundRule rule = OutboundRulesHelper.CreateRule(model, section);

            OutboundRulesHelper.AddRule(rule, section, model);

            ManagementUnit.Current.Commit();

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

            return(Created(OutboundRulesHelper.GetRuleLocation(r.id), r));
        }
コード例 #3
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}" });
        }