public void RegisterExpandoAttribute(string id, string attribute, string value)
        {
            if (expandoBlocks == null)
            {
                expandoBlocks = new Dictionary <string, Dictionary <string, string> >();
            }
            if (expandoKeys == null)
            {
                expandoKeys = new List <string>();
            }

            bool containsKey = expandoBlocks.ContainsKey(id);

            if (containsKey && expandoBlocks[id].ContainsKey(attribute))
            {
                return;
            }

            if (containsKey)
            {
                PortalTrace.Write("PortalScriptManager", "RegisterExpandoAttribute", "id='{0}', attribute='{1}', value='{2}'", id, attribute, value);
                expandoBlocks[id][attribute] = value;
                return;
            }

            PortalTrace.Write("PortalScriptManager", "RegisterExpandoAttribute", "id='{0}', attribute='{1}', value='{2}'", id, attribute, value);
            Dictionary <string, string> attributes = new Dictionary <string, string>();

            attributes[attribute] = value;
            expandoBlocks[id]     = attributes;
            expandoKeys.Add(id);
        }
        public void RegisterClientScriptHeadInclude(Type type, string key, string url)
        {
            if (type == null)
            {
                type = typeof(PortalView);
            }

            if (headIncludes == null)
            {
                headIncludes = new Dictionary <ClientIncludeKey, ScriptInclude>();
            }
            if (headIncludeKeys == null)
            {
                headIncludeKeys = new List <ClientIncludeKey>();
            }

            ClientIncludeKey clientIncludeKey = new ClientIncludeKey(type, key, true);

            if (headIncludes.ContainsKey(clientIncludeKey))
            {
                return;
            }

            PortalTrace.Write("PortalScriptManager", "RegisterClientScriptInclude", "type='{0}', key='{1}', url='{2}'", type.Name, key, url);
            headIncludes.Add(clientIncludeKey, new ScriptInclude(url));
            headIncludeKeys.Add(clientIncludeKey);
        }
Exemple #3
0
        public void RegisterEmbeddedCss(Type type, string key, string script)
        {
            if (type == null)
            {
                type = typeof(PortalView);
            }

            if (embeddedBlocks == null)
            {
                embeddedBlocks = new Dictionary <ClientIncludeKey, string>();
            }
            if (embeddedKeys == null)
            {
                embeddedKeys = new List <ClientIncludeKey>();
            }

            ClientIncludeKey clientIncludeKey = new ClientIncludeKey(type, key, true);

            if (embeddedBlocks.ContainsKey(clientIncludeKey))
            {
                return;
            }

            PortalTrace.Write("PortalStyleManager", "RegisterEmbeddedCss", "type='{0}', key='{1}'", type.Name, key);
            embeddedBlocks.Add(clientIncludeKey, script);
            embeddedKeys.Add(clientIncludeKey);
        }
Exemple #4
0
        public void RegisterCssInclude(Type type, string key, string url, string ifCondition = null)
        {
            if (type == null)
            {
                type = typeof(PortalView);
            }

            if (includes == null)
            {
                includes = new Dictionary <ClientIncludeKey, CssInclude>();
            }
            if (includeKeys == null)
            {
                includeKeys = new List <ClientIncludeKey>();
            }

            ClientIncludeKey clientIncludeKey = new ClientIncludeKey(type, key, true);

            if (includes.ContainsKey(clientIncludeKey))
            {
                return;
            }

            PortalTrace.Write("PortalStyleManager", "RegisterCssInclude", "type='{0}', key='{1}', url='{2}'", type.Name, key, url);

            includes.Add(clientIncludeKey, new CssInclude(url)
            {
                Condition = ifCondition
            });
            includeKeys.Add(clientIncludeKey);
        }
        public void RegisterBodyScript(Type type, string key, string script)
        {
            if (type == null)
            {
                type = typeof(PortalView);
            }

            if (body == null)
            {
                body = new Dictionary <ClientIncludeKey, string>();
            }
            if (bodyKeys == null)
            {
                bodyKeys = new List <ClientIncludeKey>();
            }

            ClientIncludeKey clientIncludeKey = new ClientIncludeKey(type, key, true);

            if (body.ContainsKey(clientIncludeKey))
            {
                return;
            }

            PortalTrace.Write("PortalScriptManager", "RegisterBodyScript", "type='{0}', key='{1}'", type.Name, key);
            body.Add(clientIncludeKey, script);
            bodyKeys.Add(clientIncludeKey);
        }
Exemple #6
0
        public void AddPrimaryRoute(Route route)
        {
            Argument.Assert.IsNotNull(route, nameof(route));

            PortalTrace.Write("Routes", "AddPrimaryRoute", "Adding route {0}.", route.Expression);

            primaryRoutes.Insert(0, route.RouteName, route);
        }
Exemple #7
0
        public virtual string GetVirtualPath(string virtualPath)
        {
            int    length = virtualPath.StartsWith("~") ? 2 : HttpContext.Current.Request.ApplicationPath.Length;
            string result = length == 1 ? virtualPath : virtualPath.Substring(length);

            PortalTrace.Write("ResourceFileProvider", "GetVirtualPath(string)", "Using virtual path {0}", virtualPath);
            return(result);
        }
Exemple #8
0
        protected virtual void OnRedirect(string url, ControllerContext context)
        {
            PortalTrace.Write("RedirectResult", "Execute", "Redirecting to '" + url + "'.");

            url = WebPath.FullyQualify(url);
            context.PortalContext.Response.IsRedirected     = true;
            context.PortalContext.Response.RedirectLocation = new Uri(url);
            context.PortalContext.HttpContext.Response.Redirect(url, true);
        }
Exemple #9
0
        protected sealed override void Render(HtmlTextWriter writer)
        {
            PortalTrace.Write("PortalView", "Render", "Begin Render");
            ViewRenderer renderer = ViewRenderer.Create(this, viewTemplate);

            renderer.RenderAll();
            writer.Write(renderer.ToString());

            PortalTrace.Write("PortalView", "Render", "End Render");
        }
        public ResourceStreamResult([NotNull] string path, [NotNull] Assembly assembly)
        {
            Argument.Assert.IsNotNullOrEmpty(path, nameof(path));
            Argument.Assert.IsNotNull(assembly, "assembly");

            Path     = path;
            Assembly = assembly;

            PortalTrace.Write("ResourceResult", "ResourceResult", "Instantiated with path '{0}' and assembly '{1}'.", path, assembly.ToString());
        }
Exemple #11
0
        public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            if (!IsScriptResource())
            {
                return(base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart));
            }

            PortalTrace.Write("ScriptProvider", "GetCacheDependency", "Creating new CacheDependency for path '{0}'.", virtualPath);
            return(new CacheDependency(HttpContext.Current.Server.MapPath("~/bin/Loom.Web.Portal.dll")));
        }
Exemple #12
0
        public void AddSecondaryRoute(Route route)
        {
            if (secondaryRoutes == null)
            {
                secondaryRoutes = new OrderedDictionary <string, Route>();
            }

            PortalTrace.Write("Routes", "AddSecondaryRoute", "Adding route {0}.", route.Expression);
            secondaryRoutes.Add(route.RouteName, route);
        }
Exemple #13
0
        public void AddSecondaryRoute(string routeName, string expression, string controllerName = null, string pageTitle = null)
        {
            if (secondaryRoutes == null)
            {
                secondaryRoutes = new OrderedDictionary <string, Route>();
            }

            PortalTrace.Write("Routes", "AddSecondaryRoute", "Adding route {0}.", expression);
            secondaryRoutes.Add(routeName, new Route(routeName, expression, controllerName, pageTitle));
        }
Exemple #14
0
        public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            IViewResult result = PortalContext.Current.Request.Result as IViewResult;

            if (!IsRouteFile(virtualPath) || result == null)
            {
                return(Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart));
            }

            PortalTrace.Write("RoutePathProvider", "GetCacheDependency", "Creating new CacheDependency for path '{0}'.", virtualPath);
            return(new CacheDependency(HttpContext.Current.Server.MapPath(result.DependencyPath)));
        }
Exemple #15
0
        public override CacheDependency GetCacheDependency([NotNull] string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            Argument.Assert.IsNotNullOrEmpty(virtualPath, nameof(virtualPath));

            if (!IsResourceFile(virtualPath))
            {
                return(base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart));
            }

            PortalTrace.Write("ImageProvider", "GetCacheDependency", "Creating new CacheDependency for path '{0}'.", virtualPath);
            return(new CacheDependency(HttpContext.Current.Server.MapPath("~/bin/Loom.Web.Portal.dll")));
        }
Exemple #16
0
        public void RenderCssIncludes()
        {
            PortalTrace.Write("ViewRenderer", "RenderCssIncludes", "Begin RenderCssIncludes");

            string cssIncludes = portalStyle.GetCssIncludes();

            if (!Compare.IsAnyNullOrEmpty(cssIncludes))
            {
                builder.Insert(HeadCloseIndex == -1 ? 0 : HeadCloseIndex, Environment.NewLine + cssIncludes);
            }

            PortalTrace.Write("ViewRenderer", "RenderCssIncludes", "End RenderCssIncludes");
        }
Exemple #17
0
        public void RenderEmbeddedCss()
        {
            PortalTrace.Write("ViewRenderer", "RenderEmbeddedCss", "Begin RenderEmbeddedCss");

            string embeddedCss = portalStyle.GetEmbeddedCss();

            if (!Compare.IsAnyNullOrEmpty(embeddedCss))
            {
                builder.Insert(HeadCloseIndex == -1 ? 0 : HeadCloseIndex, Environment.NewLine + embeddedCss);
            }

            PortalTrace.Write("ViewRenderer", "RenderEmbeddedCss", "End RenderEmbeddedCss");
        }
Exemple #18
0
        protected override void OnExecute(ControllerContext context)
        {
            PortalTrace.Write("ResourceResult", "GetStream", "Getting resource stream at '{0}'.", Path);

            string applicationPath = context.PortalContext.HttpContext.Request.ApplicationPath + "/";

            if (Path.StartsWith(applicationPath, StringComparison.OrdinalIgnoreCase))
            {
                Path = Path.Substring(applicationPath.Length);
            }

            context.ResponseStream = File.Open(context.HttpContext.Server.MapPath(Path), FileMode.Open, FileAccess.Read);
        }
Exemple #19
0
        public void RenderBodyScript()
        {
            PortalTrace.Write("ViewRenderer", "RenderBodyScript", "Begin RenderBodyScript");

            string bodyScript = portalScript.GetBodyScript();

            if (!Compare.IsNullOrEmpty(bodyScript))
            {
                builder.Insert(BodyAttributeIndex, " onload=\"" + bodyScript + "\"");
            }

            PortalTrace.Write("ViewRenderer", "RenderBodyScript", "End RenderBodyScript");
        }
        protected override void OnExecute(ControllerContext context)
        {
            PortalTrace.Write("ResourceResult", "GetStream", "Getting resource stream at '{0}'.", Path);

            string applicationPath = context.PortalContext.HttpContext.Request.ApplicationPath + "/";

            if (Path.StartsWith(applicationPath, StringComparison.OrdinalIgnoreCase))
            {
                Path = Path.Substring(applicationPath.Length);
            }

            context.ResponseStream = Assembly.GetManifestResourceStream(Path);
        }
Exemple #21
0
        internal List <Route> GetMatchedRoutes(string path)
        {
            PortalTrace.Write("Routes", "GetMatchedRoutes", "Begin GetMatchedRoutes.");

            List <Route> matchedRoutes = new List <Route>();

            foreach (KeyValuePair <string, Route> route in primaryRoutes)
            {
                if (!route.Value.IsMatch(path))
                {
                    continue;
                }

                PortalTrace.Write("Routes", "GetMatchedRoutes", "Found matching primary route '{0}'", route.Value.RouteName);
                matchedRoutes.Add(route.Value);
                break;
            }

            if (matchedRoutes.Count == 0)
            {
                PortalTrace.Warn("Routes", "GetMatchedRoutes", "No matching primary routes found.");
                if (!defaultRoute.IsMatch(path))
                {
                    return(matchedRoutes);
                }

                PortalTrace.Warn("Routes", "GetMatchedRoutes", "Using default '/controller/action/parameters' route.");
                matchedRoutes.Add(defaultRoute);
            }

            if (secondaryRoutes != null && secondaryRoutes.Count > 0)
            {
                foreach (KeyValuePair <string, Route> pair in secondaryRoutes)
                {
                    Route route = pair.Value;
                    if (!route.IsMatch(path))
                    {
                        continue;
                    }

                    PortalTrace.Write("Routes", "GetMatchedRoutes", "Found matching secondary route {0}", route.RouteName);
                    matchedRoutes.Add(route);
                }
            }

            PortalTrace.Write("Routes", "GetMatchedRoutes", "End GetMatchedRoutes. {1} routes found", path, matchedRoutes.Count);

            return(matchedRoutes);
        }
Exemple #22
0
        public override Stream Open()
        {
            PortalTrace.Write("RouteFile", "Open", "Getting the stream for the current view.");

            ControllerContext context = new ControllerContext(PortalContext.Current);

            Result.Execute(context);

            if (context.ResponseStream == null)
            {
                throw new InvalidOperationException("The ResponseStream property of the RouteFile has not been initialized.");
            }

            return(context.ResponseStream);
        }
Exemple #23
0
        public void RenderScriptBlocks()
        {
            PortalTrace.Write("ViewRenderer", "RenderScriptBlocks", "Begin RenderScriptBlocks");

            string allScriptBlocks = portalScript.GetAllScriptBlocks();

            if (!Compare.IsAnyNullOrEmpty(allScriptBlocks))
            {
                if (BodyCloseIndex == -1)
                {
                    builder.Append(Environment.NewLine + allScriptBlocks);
                }
                else
                {
                    builder.Insert(BodyCloseIndex, Environment.NewLine + allScriptBlocks);
                }
            }

            PortalTrace.Write("ViewRenderer", "RenderScriptBlocks", "End RenderScriptBlocks");
        }
        public ActionResult Execute([NotNull] IPortalContext context)
        {
            Argument.Assert.IsNotNull(context, ParamContext);
            if (context.Request == null)
            {
                throw new ArgumentException("The request has not been initialized.");
            }

            PortalTrace.Write("ControllerMetaWrapper", "Execute", "Begin Controller Execution '{0}'.", type.FullName);
            IController controller = (IController)Activator.CreateInstance(type);

            PortalTrace.Write("ControllerMetaWrapper", "Execute", "End Controller Execution '{0}'.", type.FullName);

            try
            {
                return(ExecuteControllerAction(context, controller));
            }
            catch (ControllerResultException ex)
            {
                return(ex.GetResult());
            }
        }
Exemple #25
0
        public override VirtualFile GetFile(string virtualPath)
        {
            IPortalRequest portalRequest = PortalContext.Current.Request;

            IViewResult result = portalRequest.Result as IViewResult;

            if (result != null && IsRouteFile(virtualPath))
            {
                return(new RouteFile(virtualPath, portalRequest.Result));
            }

            PortalTrace.Write("RoutePathProvider", "GetFile", "'{0}' is not a virtual portal file. Delegating to previous VirtualPathProvider.", virtualPath);

            if (Path.GetExtension(virtualPath) != ".aspx")
            {
                return(Previous.GetFile(virtualPath));
            }

            return(portalRequest.AllowPhysicalPages
                ? Previous.GetFile(virtualPath)
                : new RouteFile(virtualPath, new FileNotFoundResult()));
        }
Exemple #26
0
 protected override void OnRedirect(string url, ControllerContext context)
 {
     PortalTrace.Write("AjaxRedirectResult", "OnRedirect", "Redirecting to '" + url + "'.");
     context.PortalContext.Response.AjaxRedirect(url, true);
 }
Exemple #27
0
 protected override void OnExecute(ControllerContext context)
 {
     PortalTrace.Write("FileNotFoundResult", "GetStream", "Throwing FileNotFoundException.");
     throw new FileNotFoundException();
 }
Exemple #28
0
 protected FileStreamResult([NotNull] string path)
 {
     Path = path;
     PortalTrace.Write("FileStreamResult", "FileStreamResult", "Instantiated with path '{0}'.", path);
 }
Exemple #29
0
        private static void InitializeDatabaseRoutes(Dictionary <string, TenantData> tenantDataCache)
        {
            List <Route>             primaryRoutes;
            List <Route>             secondaryRoutes;
            List <RouteModule>       routeModules;
            Dictionary <int, Module> modules;

            PortalTrace.Write("Routes", "InitializeDatabaseRoutes", "Begin initializing primary routes");
            using (PortalDataSession session = new PortalDataSession("portal"))
            {
                PortalTrace.Write("Routes", "InitializeDatabaseRoutes", " - Database session opened.");

                primaryRoutes = session.Routes
                                .Select(Data.Portal.Route.Columns.Name.As("RouteName"),
                                        Data.Portal.Route.Columns.RouteId.As("Id"),
                                        Data.Portal.Route.Columns.Expression,
                                        Data.Portal.Route.Columns.PageTitle,
                                        Data.Portal.Route.Columns.Controller.As("ControllerName"),
                                        Data.Portal.Route.Columns.Section.As("SectionName"),
                                        Tenant.Columns.Name.As("TenantName"))
                                .Where((Data.Portal.Route.Columns.Deleted == false) & (Data.Portal.Route.Columns.Primary == true)).End()
                                .OrderBy(Data.Portal.Route.Columns.Ordinal).Convert().ToList <Route>();

                secondaryRoutes = session.Routes
                                  .Select(Data.Portal.Route.Columns.Name.As("RouteName"),
                                          Data.Portal.Route.Columns.RouteId.As("Id"),
                                          Data.Portal.Route.Columns.Expression,
                                          Data.Portal.Route.Columns.PageTitle,
                                          Data.Portal.Route.Columns.Controller.As("ControllerName"),
                                          Data.Portal.Route.Columns.Section.As("SectionName"),
                                          Tenant.Columns.Name.As("TenantName"))
                                  .Where((Data.Portal.Route.Columns.Deleted == false) & (Data.Portal.Route.Columns.Primary == false)).End()
                                  .OrderBy(Data.Portal.Route.Columns.Ordinal).Convert().ToList <Route>();

                modules      = session.Modules.ToDictionary <int>(Module.Columns.ModuleId);
                routeModules = session.RouteModules.OrderBy(RouteModule.Columns.ContainerName, RouteModule.Columns.Ordinal).ToList();

                PortalTrace.Write("Routes", "InitializeDatabaseRoutes", " - Database session closed.");
            }

            foreach (Route route in primaryRoutes)
            {
                if (Compare.IsNullOrEmpty(route.ControllerName))
                {
                    route.ControllerName = "Portal";
                }

                Route tmpRoute = route;
                List <RouteModule> currentRouteModules = routeModules.FindAll(rm => rm.RouteId == tmpRoute.Id);

                foreach (RouteModule currentRouteModule in currentRouteModules)
                {
                    Module moduleDefinition;
                    modules.TryGetValue(currentRouteModule.ModuleId, out moduleDefinition);
                    if (moduleDefinition != null)
                    {
                        route.Tiles.Add(new TileDefinition(currentRouteModule.ContainerName, moduleDefinition.Path, currentRouteModule.Settings, currentRouteModule.Data));
                    }
                }

                string tenantName = route.TenantName ?? "DefaultTenant";

                if (!tenantDataCache.ContainsKey(tenantName))
                {
                    continue;
                }

                TenantData tenantData = tenantDataCache[tenantName];

                if (!Compare.IsNullOrEmpty(route.SectionName) && tenantData.Sections.ContainsKey(route.SectionName))
                {
                    tenantData.Sections[route.SectionName].AddPrimaryRoute(route);
                }
                else
                {
                    tenantData.DefaultSection.AddPrimaryRoute(route);
                }
            }

            PortalTrace.Write("Routes", "InitializeDatabaseRoutes", "End initializing primary routes. {0} routes found.", primaryRoutes.Count);
            PortalTrace.Write("Routes", "InitializeDatabaseRoutes", "Begin initializing secondary routes");

            foreach (Route route in secondaryRoutes)
            {
                if (Compare.IsNullOrEmpty(route.ControllerName))
                {
                    route.ControllerName = "Portal";
                }

                string tenantName = route.TenantName ?? "DefaultTenant";

                if (!tenantDataCache.ContainsKey(tenantName))
                {
                    continue;
                }

                TenantData tenantData = tenantDataCache[tenantName];

                if (!Compare.IsNullOrEmpty(route.SectionName) && tenantDataCache.ContainsKey(route.SectionName))
                {
                    tenantData.Sections[route.SectionName].AddPrimaryRoute(route);
                }
                else
                {
                    tenantData.DefaultSection.AddSecondaryRoute(route);
                }
            }

            PortalTrace.Write("Routes", "InitializeDatabaseRoutes", "End initializing secondary routes. {0} routes found.", secondaryRoutes.Count);
        }