public object Get()
        {
            IEnumerable <Site> sites = null;

            //
            // Filter by AppPool
            string appPoolUuid = Context.Request.Query[AppPools.Defines.IDENTIFIER];

            if (!string.IsNullOrEmpty(appPoolUuid))
            {
                ApplicationPool pool = AppPoolHelper.GetAppPool(AppPoolId.CreateFromUuid(appPoolUuid).Name);

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

                sites = SiteHelper.GetSites(pool);
            }

            //
            // Get All Sites
            if (sites == null)
            {
                sites = ManagementUnit.ServerManager.Sites;
            }


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

            Fields fields = Context.Request.GetFields();

            // Return the site reference model collection
            return(new {
                websites = sites.Select(s => SiteHelper.ToJsonModelRef(s, fields))
            });
        }
Example #2
0
        public override void Start()
        {
            // Provide mvc with route for sites requests
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "sites" });

            //
            // Hal
            var hal = Environment.Hal;

            // Register self hypermedia
            hal.ProvideLink(Defines.Resource.Guid, "self", site => new { href = SiteHelper.GetLocation(site.id) });

            // Provide hypermedia for other plugins
            hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.Resource.Name, _ => new { href = $"/{Defines.PATH}" });
            hal.ProvideLink(AppPools.Defines.Resource.Guid, Defines.Resource.Name, pool => new { href = $"/{Defines.PATH}?{AppPools.Defines.IDENTIFIER}={pool.id}" });

            // Mark appropriate website fields as nonsensitive for resources that use site references
            INonsensitiveAuditingFields nonsensitiveFields = (INonsensitiveAuditingFields)Environment.Host.ApplicationBuilder.ApplicationServices.GetService(typeof(INonsensitiveAuditingFields));

            if (nonsensitiveFields != null)
            {
                nonsensitiveFields.Add("website.key");
            }
        }
Example #3
0
        public static Site ResolveSite(dynamic model = null)
        {
            Site   site     = null;
            string scope    = null;
            string siteUuid = null;

            // Resolve from model
            if (model != null)
            {
                //
                // website.id
                if (model.website != null)
                {
                    if (!(model.website is JObject))
                    {
                        throw new ApiArgumentException("website");
                    }

                    siteUuid = DynamicHelper.Value(model.website.id);
                }

                //
                // scope
                if (model.scope != null)
                {
                    scope = DynamicHelper.Value(model.scope);
                }
            }

            var context = HttpHelper.Current;

            //
            // Resolve {site_id} from query string
            if (siteUuid == null)
            {
                siteUuid = context.Request.Query[Defines.IDENTIFIER];
            }

            if (!string.IsNullOrEmpty(siteUuid))
            {
                SiteId siteId = new SiteId(siteUuid);

                site = SiteHelper.GetSite(new SiteId(siteUuid).Id);
                if (site == null)
                {
                    throw new NotFoundException("site");
                }

                return(site);
            }


            //
            // Resolve {scope} from query string
            if (scope == null)
            {
                scope = context.Request.Query[SCOPE_KEY];
            }

            if (!string.IsNullOrEmpty(scope))
            {
                int    index    = scope.IndexOf('/');
                string siteName = index >= 0 ? scope.Substring(0, index) : scope;

                site = ManagementUnit.Current.ServerManager.Sites.FirstOrDefault(s => s.Name.Equals(siteName, StringComparison.OrdinalIgnoreCase));

                // Scope points to non existant site
                if (site == null)
                {
                    throw new ScopeNotFoundException(scope);
                }
            }

            return(site);
        }