예제 #1
0
        public object Post([FromBody] dynamic model)
        {
            // Create Site
            Site site = SiteHelper.CreateSite(model, _fileProvider);

            // Check if site with name already exists
            if (ManagementUnit.ServerManager.Sites.Any(s => s.Name.Equals(site.Name, StringComparison.OrdinalIgnoreCase)))
            {
                throw new AlreadyExistsException("name");
            }

            // Save it
            ManagementUnit.ServerManager.Sites.Add(site);
            ManagementUnit.Current.Commit();

            // Refresh
            site = SiteHelper.GetSite(site.Id);

            WaitForSiteStatusResolve(site);

            //
            // Create response
            dynamic website = (dynamic)SiteHelper.ToJsonModel(site, Context.Request.GetFields());

            return(Created((string)SiteHelper.GetLocation(website.id), website));
        }
예제 #2
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            // Set settings
            Site site = SiteHelper.UpdateSite(new SiteId(id).Id, model, _fileProvider);

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

            // Start/Stop
            if (model.status != null)
            {
                Status status = DynamicHelper.To <Status>(model.status);
                try {
                    switch (status)
                    {
                    case Status.Stopped:
                        site.Stop();
                        break;

                    case Status.Started:
                        site.Start();
                        break;
                    }
                }
                catch (COMException e) {
                    // If site is fresh and status is still unknown then COMException will be thrown when manipulating status
                    throw new ApiException("Error setting site status", e);
                }
                catch (ServerManagerException e) {
                    throw new ApiException(e.Message, e);
                }
            }

            // Update changes
            ManagementUnit.Current.Commit();

            // Refresh data
            site = ManagementUnit.ServerManager.Sites[site.Name];

            //
            // Create response
            dynamic sModel = SiteHelper.ToJsonModel(site, Context.Request.GetFields());

            // The Id could change by changing the sites key
            if (sModel.id != id)
            {
                return(LocationChanged(SiteHelper.GetLocation(sModel.id), sModel));
            }

            return(sModel);
        }
예제 #3
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}" });
        }
예제 #4
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");
            }
        }