コード例 #1
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));
        }
コード例 #2
0
        public static object ToJsonModel(Site site, string path, Fields fields = null, bool full = true)
        {
            if (fields == null)
            {
                fields = Fields.All;
            }

            dynamic   obj       = new ExpandoObject();
            RewriteId rewriteId = new RewriteId(site?.Id, path);

            //
            // id
            if (fields.Exists("id"))
            {
                obj.id = rewriteId.Uuid;
            }

            //
            // scope
            if (fields.Exists("scope"))
            {
                obj.scope = site == null ? string.Empty : site.Name + path;
            }

            //
            // website
            if (fields.Exists("website"))
            {
                obj.website = SiteHelper.ToJsonModelRef(site);
            }

            return(Core.Environment.Hal.Apply(Defines.Resource.Guid, obj, full));
        }
コード例 #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);
            RewriteMapsSection section    = RewriteMapsHelper.GetSection(site, parentId.Path, configPath);

            RewriteMap map = RewriteMapsHelper.CreateMap(model, section);

            RewriteMapsHelper.AddMap(map, section);

            ManagementUnit.Current.Commit();

            dynamic r = RewriteMapsHelper.MapToJsonModel(map, site, parentId.Path, Context.Request.GetFields(), true);

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

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

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

            // Create rule
            InboundRule rule = InboundRulesHelper.CreateRule(model, site, parentId.Path, ManagementUnit.ResolveConfigScope(model));

            // Add it
            InboundRulesHelper.AddRule(rule, section, model);

            // Save
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic r = InboundRulesHelper.RuleToJsonModel(rule, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(InboundRulesHelper.GetRuleLocation(r.id), r));
        }
コード例 #5
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);
            ProvidersSection section    = ProvidersHelper.GetSection(site, parentId.Path, configPath);

            Provider provider = ProvidersHelper.CreateProvider(model, section);

            // Add it
            ProvidersHelper.AddProvider(provider, section);

            // Save
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic p = ProvidersHelper.ProviderToJsonModel(provider, site, parentId.Path, Context.Request.GetFields(), true);

            return(Created(ProvidersHelper.GetProviderLocation(p.id), p));
        }
コード例 #6
0
        public object Get(string id)
        {
            var serverVariablesId = new RewriteId(id);

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

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

            return(ServerVariablesHelper.ToJsonModel(site, serverVariablesId.Path));
        }
コード例 #7
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(ProvidersHelper.SectionToJsonModel(site, rewriteId.Path));
        }
コード例 #8
0
        public static object SectionToJsonModel(Site site, string path, Fields fields = null, bool full = true)
        {
            if (fields == null)
            {
                fields = Fields.All;
            }

            RewriteId id      = new RewriteId(site?.Id, path);
            var       section = GetSection(site, path);

            dynamic obj = new ExpandoObject();

            //
            // id
            if (fields.Exists("id"))
            {
                obj.id = id.Uuid;
            }

            //
            // scope
            if (fields.Exists("scope"))
            {
                obj.scope = site == null ? string.Empty : site.Name + path;
            }

            //
            // use_original_url_encoding
            if (fields.Exists("use_original_url_encoding") && section.Schema.HasAttribute(InboundRulesSection.UseOriginalUrlEncodingAttribute))
            {
                obj.use_original_url_encoding = section.UseOriginalURLEncoding;
            }

            //
            // metadata
            if (fields.Exists("metadata"))
            {
                obj.metadata = ConfigurationUtility.MetadataToJson(section.IsLocallyStored, section.IsLocked, section.OverrideMode, section.OverrideModeEffective);
            }

            //
            // url_rewrite
            if (fields.Exists("url_rewrite"))
            {
                obj.url_rewrite = RewriteHelper.ToJsonModelRef(site, path);
            }

            return(Core.Environment.Hal.Apply(Defines.InboundRulesSectionResource.Guid, obj, full));
        }
コード例 #9
0
        public static object SectionToJsonModel(Site site, string path, Fields fields = null, bool full = true)
        {
            if (fields == null)
            {
                fields = Fields.All;
            }

            RewriteId id      = new RewriteId(site?.Id, path);
            var       section = GetSection(site, path);

            dynamic obj = new ExpandoObject();

            //
            // id
            if (fields.Exists("id"))
            {
                obj.id = id.Uuid;
            }

            //
            // scope
            if (fields.Exists("scope"))
            {
                obj.scope = site == null ? string.Empty : site.Name + path;
            }

            //
            // metadata
            if (fields.Exists("metadata"))
            {
                obj.metadata = ConfigurationUtility.MetadataToJson(section.IsLocallyStored, section.IsLocked, section.OverrideMode, section.OverrideModeEffective);
            }

            //
            // rewrite_before_cache
            if (fields.Exists("rewrite_before_cache"))
            {
                obj.rewrite_before_cache = section.RewriteBeforeCache;
            }

            //
            // url_rewrite
            if (fields.Exists("url_rewrite"))
            {
                obj.url_rewrite = RewriteHelper.ToJsonModelRef(site, path);
            }

            return(Core.Environment.Hal.Apply(Defines.OutboundRulesSectionResource.Guid, obj, full));
        }
コード例 #10
0
        public void Delete(string id)
        {
            var providersId = new RewriteId(id);

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

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

            if (site != null)
            {
                var section = ProvidersHelper.GetSection(site, providersId.Path, ManagementUnit.ResolveConfigScope());
                section.RevertToParent();
                ManagementUnit.Current.Commit();
            }
        }
コード例 #11
0
        public static object ToJsonModel(Site site, string path)
        {
            RewriteId serverVariablesId = new RewriteId(site?.Id, path);
            var       section           = GetSection(site, path);

            var obj = new
            {
                id          = serverVariablesId.Uuid,
                scope       = site == null ? string.Empty : site.Name + path,
                entries     = section.AllowedServerVariables.Select(v => v.Name),
                metadata    = ConfigurationUtility.MetadataToJson(section.IsLocallyStored, section.IsLocked, section.OverrideMode, section.OverrideModeEffective),
                url_rewrite = RewriteHelper.ToJsonModelRef(site, path)
            };

            return(Environment.Hal.Apply(Defines.ServerVariablesResource.Guid, obj));
        }
コード例 #12
0
        public async Task Delete(string id)
        {
            RewriteId rewriteId = new RewriteId(id);

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

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

            var featureManager = new UrlRewriteFeatureManager();

            // When target is webserver, uninstall
            if (rewriteId.SiteId == null && featureManager.IsInstalled())
            {
                if (Os.IsNanoServer)
                {
                    throw new ApiNotAllowedException("Action not supported on current platform", null);
                }

                await featureManager.Uninstall();
            }
        }
コード例 #13
0
        public object Get()
        {
            string rewriteMapsId = Context.Request.Query[Defines.IDENTIFIER];

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

            var sectionId = new RewriteId(rewriteMapsId);

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

            RewriteMapCollection maps = RewriteMapsHelper.GetSection(site, sectionId.Path).RewriteMaps;

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

            return(new {
                entries = maps.Select(map => RewriteMapsHelper.MapToJsonModelRef(map, site, sectionId.Path, Context.Request.GetFields()))
            });
        }
コード例 #14
0
        public static void ResolveRewrite(HttpContext context, out Site site, out string path)
        {
            site = null;
            path = null;
            string rewriteUuid = null;

            site = ApplicationHelper.ResolveSite();
            path = ApplicationHelper.ResolvePath();

            if (path == null)
            {
                rewriteUuid = context.Request.Query[Defines.IDENTIFIER];
            }

            if (!string.IsNullOrEmpty(rewriteUuid))
            {
                var rewriteId = new RewriteId(rewriteUuid);
                site = rewriteId.SiteId == null ? null : SiteHelper.GetSite(rewriteId.SiteId.Value);
                path = rewriteId.Path;
            }
        }
コード例 #15
0
        public static RewriteId GetRewriteIdFromBody(dynamic model)
        {
            RewriteId rewriteId = null;

            if (model.url_rewrite != null)
            {
                if (!(model.url_rewrite is JObject))
                {
                    throw new ApiArgumentException("url_rewrite", ApiArgumentException.EXPECTED_OBJECT);
                }

                string id = DynamicHelper.Value(model.url_rewrite.id);

                if (!string.IsNullOrEmpty(id))
                {
                    rewriteId = new RewriteId(id);
                }
            }

            return(rewriteId);
        }
コード例 #16
0
        public object Get()
        {
            string globalRulesId = Context.Request.Query[Defines.IDENTIFIER];

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

            var sectionId = new RewriteId(globalRulesId);

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

            InboundRuleCollection rules = GlobalRulesHelper.GetSection(site, sectionId.Path).InboundRules;

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

            return(new {
                rules = rules.Select(rule => GlobalRulesHelper.RuleToJsonModelRef((InboundRule)rule, site, sectionId.Path, Context.Request.GetFields()))
            });
        }
コード例 #17
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()))
            });
        }
コード例 #18
0
        public object Get()
        {
            string providersId = Context.Request.Query[Defines.IDENTIFIER];

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

            var sectionId = new RewriteId(providersId);

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

            ProvidersCollection providers = ProvidersHelper.GetSection(site, sectionId.Path).Providers;

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

            return(new {
                entries = providers.Select(provider => ProvidersHelper.ProviderToJsonModelRef(provider, site, sectionId.Path, Context.Request.GetFields()))
            });
        }
コード例 #19
0
        public object Get()
        {
            string inboundRulesId = Context.Request.Query[Defines.IDENTIFIER];

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

            var sectionId = new RewriteId(inboundRulesId);

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

            InboundRuleCollection rules = InboundRulesHelper.GetSection(site, sectionId.Path).InboundRules;

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

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

            var providersId = new RewriteId(id);

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

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

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

            ProvidersHelper.UpdateSection(model, site, providersId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(ProvidersHelper.SectionToJsonModel(site, providersId.Path));
        }
コード例 #21
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            RewriteId serverVariablesId = new RewriteId(id);

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

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

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

            ServerVariablesHelper.UpdateFeatureSettings(model, site, serverVariablesId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(ServerVariablesHelper.ToJsonModel(site, serverVariablesId.Path));
        }