Exemple #1
0
        public HostedApplication Add(HostedApplicationMeta request, bool isDefault)
        {
            if (string.IsNullOrWhiteSpace(request.Name))
            {
                throw new ApplicationHostException("You must specify a name for the application.");
            }

            if (_apps.Any(a => a.Meta.Name == request.Name))
            {
                throw new ApplicationHostException($"An application with the name '{request.Name}' exists.");
            }

            if (!request.Aliases.Any(a => !string.IsNullOrWhiteSpace(a)))
            {
                throw new ApplicationHostException($"You must specify at least one alias for this application.");
            }

            var newApp = new HostedApplication(request);

            _apps.Add(newApp);

            if (isDefault)
            {
                DefaultApp = newApp;
            }

            return(newApp);
        }
        private IHttpActionResult GetRootContent(string aliasOrAppId)
        {
            HostedApplication app = null;

            try
            {
                app = _applicationManager.Get(aliasOrAppId);
            }
            catch (ApplicationHostException)
            {
                try
                {
                    app = _applicationManager.FromAlias(aliasOrAppId);
                }
                catch (ApplicationHostException)
                {
                    app = _applicationManager.DefaultApp;
                }
            }

            if (app == null)
            {
                return(SendResource(ReadTextResource("NoTenantRoot.html"), "text/html"));
            }

            var appRoot = GetApplicationRoot(app.Meta);

            var resource = string.IsNullOrWhiteSpace(appRoot)
                ? ReadTextResource("TenantRoot.html")
                : ReadTextContent(appRoot);

            resource = resource.Replace("[[TenantName]]", app.Meta.Name);
            resource = resource.Replace("[[TenantAppId]]", app.AppId.ToString());

            return(SendResource(resource, "text/html"));
        }