コード例 #1
0
ファイル: Global.asax.cs プロジェクト: webluddite/Rock-ChMS
        private void RegisterRoutes(RouteCollection routes)
        {
            PageRouteService pageRouteService = new PageRouteService();

            // find each page that has defined a custom routes.
            foreach (PageRoute pageRoute in pageRouteService.Queryable())
            {
                // Create the custom route and save the page id in the DataTokens collection
                Route route = new Route(pageRoute.Route, new Rock.Web.RockRouteHandler());
                route.DataTokens = new RouteValueDictionary();
                route.DataTokens.Add("PageId", pageRoute.PageId.ToString());
                route.DataTokens.Add("RouteId", pageRoute.Id.ToString());
                routes.Add(route);
            }

            // Add API Service routes
            routes.MapPageRoute("", "REST/help", "~/RESTHelp.aspx");
            new Rock.REST.ServiceHelper(this.Server.MapPath("~/Extensions")).AddRoutes(routes, "REST/");

            // Add a default page route
            routes.Add(new Route("page/{PageId}", new Rock.Web.RockRouteHandler()));

            // Add a default route for when no parameters are passed
            routes.Add(new Route("", new Rock.Web.RockRouteHandler()));
        }
コード例 #2
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            PageRouteService pageRouteService = new PageRouteService(new RockContext());
            SortProperty     sortProperty     = gPageRoutes.SortProperty;

            gPageRoutes.EntityTypeId = EntityTypeCache.Get <PageRoute>().Id;

            var queryable = pageRouteService.Queryable();

            int?siteId = gFilter.GetUserPreference("Site").AsIntegerOrNull();

            if (siteId.HasValue)
            {
                queryable = queryable.Where(d => d.Page.Layout.SiteId == siteId.Value);
            }

            if (sortProperty != null)
            {
                gPageRoutes.DataSource = queryable.Sort(sortProperty).ToList();
            }
            else
            {
                gPageRoutes.DataSource = queryable.OrderBy(p => p.Route).ToList();
            }

            gPageRoutes.DataBind();
        }
コード例 #3
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            PageRouteService pageRouteService = new PageRouteService(new RockContext());
            SortProperty     sortProperty     = gPageRoutes.SortProperty;

            var qry = pageRouteService.Queryable().Select(a =>
                                                          new
            {
                a.Id,
                a.Route,
                PageName = a.Page.InternalName,
                PageId   = a.Page.Id,
                a.IsSystem
            });

            if (sortProperty != null)
            {
                gPageRoutes.DataSource = qry.Sort(sortProperty).ToList();
            }
            else
            {
                gPageRoutes.DataSource = qry.OrderBy(p => p.Route).ToList();
            }

            gPageRoutes.DataBind();
        }
コード例 #4
0
        /// <summary>
        /// Handles the Delete event of the gPageRoutes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gPageRoutes_Delete(object sender, RowEventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                PageRouteService pageRouteService = new PageRouteService();
                PageRoute pageRoute = pageRouteService.Get((int)e.RowKeyValue);

                if (pageRoute != null)
                {
                    string errorMessage;
                    if (!pageRouteService.CanDelete(pageRoute, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    pageRouteService.Delete(pageRoute, CurrentPersonId);
                    pageRouteService.Save(pageRoute, CurrentPersonId);

                    RemovePageRoute(pageRoute);
                }
            });

            BindGrid();
        }
コード例 #5
0
        /// <summary>
        /// Reads new values entered by the user for the field.  Returns with Page.Guid,PageRoute.Guid or just Page.Guid
        /// </summary>
        /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns></returns>
        public override string GetEditValue(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues)
        {
            PagePicker ppPage = control as PagePicker;
            string     result = null;

            if (ppPage != null)
            {
                //// Value is in format "Page.Guid,PageRoute.Guid"
                //// If only a Page is specified, this is just a reference to a page without a special route

                if (ppPage.IsPageRoute)
                {
                    int?pageRouteId = ppPage.PageRouteId;
                    var pageRoute   = new PageRouteService(new RockContext()).Get(pageRouteId ?? 0);
                    if (pageRoute != null)
                    {
                        result = string.Format("{0},{1}", pageRoute.Page.Guid, pageRoute.Guid);
                    }
                }
                else
                {
                    var page = new PageService(new RockContext()).Get(ppPage.PageId ?? 0);
                    if (page != null)
                    {
                        result = page.Guid.ToString();
                    }
                }
            }

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            nbErrorMessage.Visible = false;

            var pageRouteId = PageParameter("pageRouteId").AsInteger();

            if (!Page.IsPostBack)
            {
                ShowDetail(pageRouteId);
            }

            // Add any attribute controls.
            // This must be done here regardless of whether it is a postback so that the attribute values will get saved.
            var pageRoute = new PageRouteService(new RockContext()).Get(pageRouteId);

            if (pageRoute == null)
            {
                pageRoute = new PageRoute();
            }
            if (!pageRoute.IsSystem)
            {
                pageRoute.LoadAttributes();
                phAttributes.Controls.Clear();
                Helper.AddEditControls(pageRoute, phAttributes, true, BlockValidationGroup);
            }
        }
コード例 #7
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="routeId">The route identifier.</param>
        public void ShowDetail(int routeId)
        {
            pnlDetails.Visible = true;

            PageRoute pageRoute = null;

            if (!routeId.Equals(0))
            {
                pageRoute         = new PageRouteService(new RockContext()).Get(routeId);
                lActionTitle.Text = ActionTitle.Edit(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
                pdAuditDetails.SetEntity(pageRoute, ResolveRockUrl("~"));
            }

            if (pageRoute == null)
            {
                pageRoute = new PageRoute {
                    Id = 0
                };
                lActionTitle.Text = ActionTitle.Add(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            hfPageRouteId.Value = pageRoute.Id.ToString();
            ppPage.SetValue(pageRoute.Page);

            ShowSite();

            tbRoute.Text       = pageRoute.Route;
            cbIsGlobal.Checked = pageRoute.IsGlobal;

            // render UI based on Authorized and IsSystem. Do IsSystem check first so the IsUserAuthorized check can overwrite the settings.
            nbEditModeMessage.Text = string.Empty;

            if (pageRoute.IsSystem)
            {
                nbEditModeMessage.Text = EditModeMessage.System(PageRoute.FriendlyTypeName);

                ppPage.Enabled     = false;
                tbRoute.ReadOnly   = true;
                cbIsGlobal.Enabled = true;
                btnSave.Visible    = true;
            }

            if (!IsUserAuthorized(Authorization.EDIT))
            {
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(PageRoute.FriendlyTypeName);

                lActionTitle.Text = ActionTitle.View(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
                btnCancel.Text    = "Close";

                ppPage.Enabled     = false;
                tbRoute.ReadOnly   = true;
                cbIsGlobal.Enabled = false;
                btnSave.Visible    = false;
            }
        }
コード例 #8
0
        /// <summary>
        /// Handles the Click event of the _btnSelectPageRoute control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void _btnSelectPageRoute_Click(object sender, EventArgs e)
        {
            _rblSelectPageRoute.Visible = false;

            // pluck the selectedValueId of the Page Params in case the ViewState is shut off
            int       selectedValueId = this.Page.Request.Params[_rblSelectPageRoute.UniqueID].AsInteger();
            PageRoute pageRoute       = new PageRouteService(new RockContext()).Get(selectedValueId);

            SetValue(pageRoute);
        }
コード例 #9
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        public void ShowDetail(string itemKey, int itemKeyValue)
        {
            if (!itemKey.Equals("pageRouteId"))
            {
                return;
            }

            pnlDetails.Visible = true;

            PageRoute pageRoute = null;

            if (!itemKeyValue.Equals(0))
            {
                pageRoute         = new PageRouteService().Get(itemKeyValue);
                lActionTitle.Text = ActionTitle.Edit(PageRoute.FriendlyTypeName);
            }
            else
            {
                pageRoute = new PageRoute {
                    Id = 0
                };
                lActionTitle.Text = ActionTitle.Add(PageRoute.FriendlyTypeName);
            }

            hfPageRouteId.Value = pageRoute.Id.ToString();
            ppPage.SetValue(pageRoute.Page);
            tbRoute.Text = pageRoute.Route;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized("Edit"))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(PageRoute.FriendlyTypeName);
            }

            if (pageRoute.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(PageRoute.FriendlyTypeName);
            }

            if (readOnly)
            {
                lActionTitle.Text = ActionTitle.View(PageRoute.FriendlyTypeName);
                btnCancel.Text    = "Close";
            }

            ppPage.Enabled   = !readOnly;
            tbRoute.ReadOnly = readOnly;
            btnSave.Visible  = !readOnly;
        }
コード例 #10
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            PageRoute        pageRoute;
            var              rockContext      = new RockContext();
            PageRouteService pageRouteService = new PageRouteService(rockContext);

            int pageRouteId = int.Parse(hfPageRouteId.Value);

            if (pageRouteId == 0)
            {
                pageRoute = new PageRoute();
                pageRouteService.Add(pageRoute);
            }
            else
            {
                pageRoute = pageRouteService.Get(pageRouteId);
            }

            pageRoute.Route = tbRoute.Text.Trim();
            int selectedPageId = int.Parse(ppPage.SelectedValue);

            pageRoute.PageId = selectedPageId;

            if (!pageRoute.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            if (pageRouteService.Queryable().Any(r => r.Route == pageRoute.Route && r.Id != pageRoute.Id))
            {
                // Duplicate
                nbErrorMessage.Title   = "Duplicate Route";
                nbErrorMessage.Text    = "<p>There is already an existing route with this name and route names must be unique. Please choose a different route name.</p>";
                nbErrorMessage.Visible = true;
            }
            else
            {
                rockContext.SaveChanges();

                // new or updated route
                var existingRoute = RouteTable.Routes.OfType <Route>().FirstOrDefault(a => a.RouteId() == pageRoute.Id);
                if (existingRoute != null)
                {
                    RouteTable.Routes.Remove(existingRoute);
                }

                RouteTable.Routes.AddPageRoute(pageRoute);

                NavigateToParentPage();
            }
        }
コード例 #11
0
        /// <summary>
        /// Determines whether [is block configured to allow retakes] [the specified assessment type list item].
        /// </summary>
        /// <param name="assessmentTypeListItem">The assessment type list item.</param>
        /// <returns>
        ///   <c>true</c> if [is block configured to allow retakes] [the specified assessment type list item]; otherwise, <c>false</c>.
        /// </returns>
        private bool IsBlockConfiguredToAllowRetakes(AssessmentTypeListItem assessmentTypeListItem)
        {
            string domain = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority).Replace("https://", string.Empty).Replace("http://", string.Empty);
            string route  = assessmentTypeListItem.AssessmentPath.Replace("/", string.Empty);

            var rockContext      = new RockContext();
            var pageRouteService = new PageRouteService(rockContext);
            var pageId           = pageRouteService
                                   .Queryable()
                                   .Where(r => r.Route == route)
                                   .Where(r => r.Page.Layout.Site.SiteDomains.Select(d => d.Domain == domain).FirstOrDefault())
                                   .Select(r => r.PageId)
                                   .FirstOrDefault();

            Guid blockTypeGuid = Guid.Empty;

            switch (route)
            {
            case "ConflictProfile":
                blockTypeGuid = Rock.SystemGuid.BlockType.CONFLICT_PROFILE.AsGuid();
                break;

            case "EQ":
                blockTypeGuid = Rock.SystemGuid.BlockType.EQ_INVENTORY.AsGuid();
                break;

            case "Motivators":
                blockTypeGuid = Rock.SystemGuid.BlockType.MOTIVATORS.AsGuid();
                break;

            case "SpiritualGifts":
                blockTypeGuid = Rock.SystemGuid.BlockType.GIFTS_ASSESSMENT.AsGuid();
                break;

            case "DISC":
                blockTypeGuid = Rock.SystemGuid.BlockType.DISC.AsGuid();
                break;
            }

            int?blockTypeId  = BlockTypeCache.GetId(blockTypeGuid);
            var blockService = new BlockService(rockContext);
            var block        = blockTypeGuid != Guid.Empty ? blockService.GetByPageAndBlockType(pageId, blockTypeId.Value).FirstOrDefault() : null;

            if (block != null)
            {
                block.LoadAttributes();
                return(block.GetAttributeValue("AllowRetakes").AsBooleanOrNull() ?? true);
            }

            return(true);
        }
コード例 #12
0
ファイル: RockRouteHandler.cs プロジェクト: marcoramzy/Rock
        /// <summary>
        /// Removes the rock page and default routes from RouteTable.Routes but leaves the ones created by ODataService.
        /// </summary>
        public static void RemoveRockPageRoutes()
        {
            RouteCollection  routes           = RouteTable.Routes;
            PageRouteService pageRouteService = new PageRouteService(new Rock.Data.RockContext());
            var pageRoutes = pageRouteService.Queryable().ToList();

            // First we have to remove the routes stored in the DB without removing the ODataService routes because we can't reload them.
            // Routes that were removed from the DB have already been removed from the RouteTable in PreSaveChanges()
            foreach (var pageRoute in pageRoutes)
            {
                var route = routes.OfType <Route>().Where(a => a.Url == pageRoute.Route).FirstOrDefault();

                if (route != null)
                {
                    routes.Remove(route);
                }
            }

            // Remove the shortlink route
            var shortLinkRoute = routes.OfType <Route>().Where(r => r.Url == "{shortlink}").FirstOrDefault();

            if (shortLinkRoute != null)
            {
                routes.Remove(shortLinkRoute);
            }

            // Remove the page route
            var pageIdRoute = routes.OfType <Route>().Where(r => r.Url == "page/{PageId}").FirstOrDefault();

            if (pageIdRoute != null)
            {
                routes.Remove(pageIdRoute);
            }

            // Remove the default route for when no parameters are passed
            var defaultRoute = routes.OfType <Route>().Where(r => r.Url == "").FirstOrDefault();

            if (defaultRoute != null)
            {
                routes.Remove(pageIdRoute);
            }

            // Remove scriptmanager ignore route
            var scriptmanagerRoute = routes.OfType <Route>().Where(r => r.Url == "{resource}.axd/{*pathInfo}").FirstOrDefault();

            if (scriptmanagerRoute != null)
            {
                routes.Remove(scriptmanagerRoute);
            }
        }
コード例 #13
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="routeId">The route identifier.</param>
        public void ShowDetail(int routeId)
        {
            pnlDetails.Visible = true;

            PageRoute pageRoute = null;

            if (!routeId.Equals(0))
            {
                pageRoute         = new PageRouteService(new RockContext()).Get(routeId);
                lActionTitle.Text = ActionTitle.Edit(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
            }

            if (pageRoute == null)
            {
                pageRoute = new PageRoute {
                    Id = 0
                };
                lActionTitle.Text = ActionTitle.Add(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
            }

            hfPageRouteId.Value = pageRoute.Id.ToString();
            ppPage.SetValue(pageRoute.Page);
            tbRoute.Text = pageRoute.Route;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized(Authorization.EDIT))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(PageRoute.FriendlyTypeName);
            }

            if (pageRoute.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(PageRoute.FriendlyTypeName);
            }

            if (readOnly)
            {
                lActionTitle.Text = ActionTitle.View(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
                btnCancel.Text    = "Close";
            }

            ppPage.Enabled   = !readOnly;
            tbRoute.ReadOnly = readOnly;
            btnSave.Visible  = !readOnly;
        }
コード例 #14
0
ファイル: PageRoutes.ascx.cs プロジェクト: jh2mhs8/Rock-ChMS
        /// <summary>
        /// Handles the Delete event of the gPageRoutes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gPageRoutes_Delete(object sender, RowEventArgs e)
        {
            PageRouteService pageRouteService = new PageRouteService();
            PageRoute        pageRoute        = pageRouteService.Get((int)gPageRoutes.DataKeys[e.RowIndex]["id"]);

            if (CurrentBlock != null)
            {
                pageRouteService.Delete(pageRoute, CurrentPersonId);
                pageRouteService.Save(pageRoute, CurrentPersonId);
            }

            RemovePageRoute(pageRoute);

            BindGrid();
        }
コード例 #15
0
ファイル: PageRoutes.ascx.cs プロジェクト: jh2mhs8/Rock-ChMS
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            PageRouteService pageRouteService = new PageRouteService();
            SortProperty     sortProperty     = gPageRoutes.SortProperty;

            if (sortProperty != null)
            {
                gPageRoutes.DataSource = pageRouteService.Queryable().Sort(sortProperty).ToList();
            }
            else
            {
                gPageRoutes.DataSource = pageRouteService.Queryable().OrderBy(p => p.Route).ToList();
            }

            gPageRoutes.DataBind();
        }
コード例 #16
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            RouteCollection routes = RouteTable.Routes;

            PageRouteService pageRouteService = new PageRouteService(new Rock.Data.RockContext());
            var pageRoutes = pageRouteService.Queryable().ToList();


            // Check to see if we have any missing routes.  If so, simply run reregister.
            foreach (var pageRoute in pageRoutes)
            {
                var route = routes.OfType <Route>().Where(a => a.Url == pageRoute.Route && a.PageIds().Contains(pageRoute.PageId)).FirstOrDefault();

                if (route == null)
                {
                    nbNotification.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Warning;
                    nbNotification.Text = "Routes were out-of-date.  Running reregister routes.";

                    ReRegisterRoutes();
                    break;
                }
            }

            // Check to see if we have any missing shortcodes
            var outOfDate = RockDateTime.Now.AddMinutes(-30);
            var sc        = new LavaShortcodeService(new Rock.Data.RockContext()).Queryable().Where(l => l.CreatedDateTime > outOfDate || l.ModifiedDateTime > outOfDate).ToList();

            if (sc.Count > 0)
            {
                nbNotification.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Warning;
                nbNotification.Text = "Shortcodes were out-of-date.  Running register shortcodes. " + sc.Count;
                foreach (var code in sc)
                {
                    // register shortcode
                    if (code.TagType == TagType.Block)
                    {
                        Template.RegisterShortcode <DynamicShortcodeBlock>(code.TagName);
                    }
                    else
                    {
                        Template.RegisterShortcode <DynamicShortcodeInline>(code.TagName);
                    }
                }

                LavaShortcodeCache.Clear();
            }
        }
コード例 #17
0
ファイル: PageRoutes.ascx.cs プロジェクト: jh2mhs8/Rock-ChMS
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            PageRoute        pageRoute;
            PageRouteService pageRouteService = new PageRouteService();

            int pageRouteId = int.Parse(hfPageRouteId.Value);

            if (pageRouteId == 0)
            {
                pageRoute = new PageRoute();
                pageRouteService.Add(pageRoute, CurrentPersonId);
            }
            else
            {
                pageRoute = pageRouteService.Get(pageRouteId);
            }

            pageRoute.Route = tbRoute.Text.Trim();
            int selectedPageId = int.Parse(ddlPageName.SelectedValue);

            pageRoute.PageId = selectedPageId;

            // check for duplicates
            if (pageRouteService.Queryable().Count(a => a.Route.Equals(pageRoute.Route, StringComparison.OrdinalIgnoreCase) && !a.Id.Equals(pageRoute.Id)) > 0)
            {
                nbMessage.Text    = WarningMessage.DuplicateFoundMessage("route", Rock.Model.Page.FriendlyTypeName);
                nbMessage.Visible = true;
                return;
            }

            if (!pageRoute.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            pageRouteService.Save(pageRoute, CurrentPersonId);

            RemovePageRoute(pageRoute);

            // new or updated route
            RouteTable.Routes.AddPageRoute(pageRoute);

            BindGrid();
            pnlDetails.Visible = false;
            pnlList.Visible    = true;
        }
コード例 #18
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!IsPostBack)
            {
                var settings = GlobalAttributesCache.Value(GetAttributeValue("OAuthConfigAttributeKey")).AsDictionary();

                int OAuthSiteId = GetAttributeValue("OAuthSite").AsInteger();

                PageRouteService pageRouteService = new PageRouteService(new RockContext());
                List <PageRoute> routes           = new List <PageRoute>();
                routes.Add(new PageRoute()
                {
                    Route = "Select One"
                });
                routes.AddRange(pageRouteService.Queryable().Where(pr => pr.Page.Layout.SiteId == OAuthSiteId).ToList());

                ddlAuthorizeRoute.DataSource = routes;
                ddlAuthorizeRoute.DataBind();
                ddlAuthorizeRoute.SelectedValue = settings["OAuthAuthorizePath"].Trim('/');

                ddlLoginRoute.DataSource = routes;
                ddlLoginRoute.DataBind();
                ddlLoginRoute.SelectedValue = settings["OAuthLoginPath"].Trim('/');

                ddlLogoutRoute.DataSource = routes;
                ddlLogoutRoute.DataBind();
                ddlLogoutRoute.SelectedValue = settings["OAuthLogoutPath"].Trim('/');

                ddlTokenRoute.DataSource = routes;
                ddlTokenRoute.DataBind();
                ddlTokenRoute.SelectedValue = settings["OAuthTokenPath"].Trim('/');

                cbSSLRequired.Checked = settings["OAuthRequireSsl"].AsBoolean();

                tbTokenLifespan.Text = settings["OAuthTokenLifespan"];
                if (settings.ContainsKey("OAuthRefreshTokenLifespan"))
                {
                    tbRefreshTokenLifespan.Text = settings["OAuthRefreshTokenLifespan"];
                }

                gOAuthClients_Bind(null, e);
                gOAuthScopes_Bind(null, e);
            }
        }
コード例 #19
0
        protected void ReRegisterRoutes()
        {
            RouteCollection routes         = RouteTable.Routes;
            var             routesToDelete = routes.OfType <Route>().Where(r => r.RouteHandler is Rock.Web.RockRouteHandler).ToList();

            foreach (Route oldRoute in routesToDelete)
            {
                routes.Remove(oldRoute);
            }


            PageRouteService pageRouteService = new PageRouteService(new Rock.Data.RockContext());

            var routesToInsert = new RouteCollection();

            // Add ignore rule for asp.net ScriptManager files.
            routesToInsert.Ignore("{resource}.axd/{*pathInfo}");

            //Add page routes, order is very important here as IIS takes the first match
            IOrderedEnumerable <PageRoute> pageRoutes = pageRouteService.Queryable().AsNoTracking().ToList().OrderBy(r => r.Route, StringComparer.OrdinalIgnoreCase);

            foreach (var pageRoute in pageRoutes)
            {
                routesToInsert.AddPageRoute(pageRoute.Route, new Rock.Web.PageAndRouteId {
                    PageId = pageRoute.PageId, RouteId = pageRoute.Id
                });
            }

            // Add a default page route
            routesToInsert.Add(new Route("page/{PageId}", new Rock.Web.RockRouteHandler()));

            // Add a default route for when no parameters are passed
            routesToInsert.Add(new Route("", new Rock.Web.RockRouteHandler()));

            // Add a default route for shortlinks
            routesToInsert.Add(new Route("{shortlink}", new Rock.Web.RockRouteHandler()));

            // Insert the list of routes to the beginning of the Routes so that PageRoutes, etc are before OdataRoutes. Even when Re-Registering routes
            // Since we are inserting at 0, reverse the list to they end up in the original order
            foreach (var pageRoute in routesToInsert.Reverse())
            {
                routes.Insert(0, pageRoute);
            }
        }
コード例 #20
0
ファイル: Global.asax.cs プロジェクト: gitter-badger/RockRMS
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes(RockContext rockContext, RouteCollection routes)
        {
            routes.Clear();

            PageRouteService pageRouteService = new PageRouteService(rockContext);

            // find each page that has defined a custom routes.
            foreach (PageRoute pageRoute in pageRouteService.Queryable())
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute(pageRoute);
            }

            // Add a default page route
            routes.Add(new Route("page/{PageId}", new Rock.Web.RockRouteHandler()));

            // Add a default route for when no parameters are passed
            routes.Add(new Route("", new Rock.Web.RockRouteHandler()));
        }
コード例 #21
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            PageRoute        pageRoute;
            var              rockContext      = new RockContext();
            PageRouteService pageRouteService = new PageRouteService(rockContext);

            int pageRouteId = int.Parse(hfPageRouteId.Value);

            if (pageRouteId == 0)
            {
                pageRoute = new PageRoute();
                pageRouteService.Add(pageRoute);
            }
            else
            {
                pageRoute = pageRouteService.Get(pageRouteId);
            }

            pageRoute.Route = tbRoute.Text.Trim();
            int selectedPageId = int.Parse(ppPage.SelectedValue);

            pageRoute.PageId = selectedPageId;

            if (!pageRoute.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            // new or updated route
            var existingRoute = RouteTable.Routes.OfType <Route>().FirstOrDefault(a => a.RouteId() == pageRoute.Id);

            if (existingRoute != null)
            {
                RouteTable.Routes.Remove(existingRoute);
            }

            RouteTable.Routes.AddPageRoute(pageRoute);

            NavigateToParentPage();
        }
コード例 #22
0
        /// <summary>
        /// Sets the value ( as either Page.Guid,PageRoute.Guid or just Page.Guid if not specific to a route )
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="value">The value.</param>
        public override void SetEditValue(System.Web.UI.Control control, Dictionary <string, ConfigurationValue> configurationValues, string value)
        {
            if (value != null)
            {
                PagePicker ppPage = control as PagePicker;
                if (ppPage != null)
                {
                    string[] valuePair = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    Page      page      = null;
                    PageRoute pageRoute = null;

                    //// Value is in format "Page.Guid,PageRoute.Guid"
                    //// If only the Page.Guid is specified this is just a reference to a page without a special route
                    //// In case the PageRoute record can't be found from PageRoute.Guid (maybe the pageroute was deleted), fall back to the Page without a PageRoute

                    var rockContext = new RockContext();

                    if (valuePair.Length == 2)
                    {
                        Guid pageRouteGuid;
                        Guid.TryParse(valuePair[1], out pageRouteGuid);
                        pageRoute = new PageRouteService(rockContext).Get(pageRouteGuid);
                    }

                    if (pageRoute != null)
                    {
                        ppPage.SetValue(pageRoute);
                    }
                    else
                    {
                        if (valuePair.Length > 0)
                        {
                            Guid pageGuid;
                            Guid.TryParse(valuePair[0], out pageGuid);
                            page = new PageService(rockContext).Get(pageGuid);
                        }

                        ppPage.SetValue(page);
                    }
                }
            }
        }
コード例 #23
0
ファイル: PageRoutes.ascx.cs プロジェクト: jh2mhs8/Rock-ChMS
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="pageRouteId">The page route id.</param>
        protected void ShowEdit(int pageRouteId)
        {
            pnlList.Visible    = false;
            pnlDetails.Visible = true;

            PageRouteService pageRouteService = new PageRouteService();
            PageRoute        pageRoute        = pageRouteService.Get(pageRouteId);
            bool             readOnly;

            if (pageRoute != null)
            {
                hfPageRouteId.Value = pageRoute.Id.ToString();
                ddlPageName.SetValue(pageRoute.PageId);
                tbRoute.Text = pageRoute.Route;
                readOnly     = pageRoute.IsSystem;

                if (pageRoute.IsSystem)
                {
                    lActionTitle.Text = ActionTitle.View(PageRoute.FriendlyTypeName);
                    btnCancel.Text    = "Close";
                }
                else
                {
                    lActionTitle.Text = ActionTitle.Edit(PageRoute.FriendlyTypeName);
                    btnCancel.Text    = "Cancel";
                }
            }
            else
            {
                lActionTitle.Text   = ActionTitle.Add(PageRoute.FriendlyTypeName);
                hfPageRouteId.Value = 0.ToString();
                ddlPageName.SetValue(string.Empty);
                tbRoute.Text = string.Empty;
                readOnly     = false;
            }

            iconIsSystem.Visible = readOnly;
            ddlPageName.Enabled  = !readOnly;
            tbRoute.ReadOnly     = readOnly;
            btnSave.Visible      = !readOnly;
        }
コード例 #24
0
        /// <summary>
        /// Handles the Delete event of the gPageRoutes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gPageRoutes_Delete(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            PageRouteService pageRouteService = new PageRouteService(rockContext);
            PageRoute        pageRoute        = pageRouteService.Get(e.RowKeyId);

            if (pageRoute != null)
            {
                string errorMessage;
                if (!pageRouteService.CanDelete(pageRoute, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                pageRouteService.Delete(pageRoute);

                rockContext.SaveChanges();
            }

            BindGrid();
        }
コード例 #25
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            RouteCollection routes = RouteTable.Routes;

            PageRouteService pageRouteService = new PageRouteService(new Rock.Data.RockContext());
            var pageRoutes = pageRouteService.Queryable().ToList();


            // Check to see if we have any missing routes.  If so, simply run reregister.
            foreach (var pageRoute in pageRoutes)
            {
                var route = routes.OfType <Route>().Where(a => a.Url == pageRoute.Route && a.PageIds().Contains(pageRoute.PageId)).FirstOrDefault();

                if (route == null)
                {
                    nbNotification.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Warning;
                    nbNotification.Text = "Routes were out-of-date.  Running reregister routes.";

                    ReRegisterRoutes();
                    break;
                }
            }
        }
コード例 #26
0
        /// <summary>
        /// Handles the RowDataBound event of the gEmailTemplates control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridViewRowEventArgs"/> instance containing the event data.</param>
        protected void gEmailTemplates_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            var lSupports     = e.Row.FindControl("lSupports") as Literal;
            var lEmailPreview = e.Row.FindControl("lEmailPreview") as Literal;

            var systemCommunication = e.Row.DataItem as SystemCommunication;

            if (systemCommunication == null)
            {
                return;
            }

            var html = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(systemCommunication.SMSMessage))
            {
                html.AppendLine("<span class='label label-info'>SMS</span>");
            }
            if (!string.IsNullOrWhiteSpace(systemCommunication.PushMessage))
            {
                html.AppendLine("<span class='label label-info'>Push</span>");
            }

            lSupports.Text = html.ToString();

            var page = PageCache.Get(Rock.SystemGuid.Page.SYSTEM_COMMUNICATION_PREVIEW.AsGuid());

            if (page != null)
            {
                var route = new PageRouteService(new RockContext()).GetByPageId(page.Id).First();
                if (route != null)
                {
                    var url = ResolveRockUrl($"~/{route.Route}/?SystemCommunicationId={systemCommunication.Id}");
                    lEmailPreview.Text = $"<a href='{url}' title='Preview' class='text-black'><i class='fa fa-search'></i></a>";
                }
            }
        }
コード例 #27
0
        /// <summary>
        /// Registers the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void RegisterRoutes(RouteCollection routes)
        {
            PageRouteService pageRouteService = new PageRouteService();

            // find each page that has defined a custom routes.
            foreach (PageRoute pageRoute in pageRouteService.Queryable())
            {
                // Create the custom route and save the page id in the DataTokens collection
                routes.AddPageRoute(pageRoute);
            }

            // Add any custom api routes
            foreach (var type in Rock.Reflection.FindTypes(
                         typeof(Rock.Rest.IHasCustomRoutes),
                         new DirectoryInfo[] { new DirectoryInfo(Server.MapPath("~/bin")), new DirectoryInfo(Server.MapPath("~/Plugins")) }))
            {
                var controller = (Rock.Rest.IHasCustomRoutes)Activator.CreateInstance(type.Value);
                if (controller != null)
                {
                    controller.AddRoutes(routes);
                }
            }

            // Add API Service routes
            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = System.Web.Http.RouteParameter.Optional }
                );

            // Add a default page route
            routes.Add(new Route("page/{PageId}", new Rock.Web.RockRouteHandler()));

            // Add a default route for when no parameters are passed
            routes.Add(new Route("", new Rock.Web.RockRouteHandler()));
        }
コード例 #28
0
        /// <summary>
        /// Handles the OnSave event of the masterPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void masterPage_OnSave(object sender, EventArgs e)
        {
            Page.Validate(BlockValidationGroup);
            if (Page.IsValid && _pageId.HasValue)
            {
                var rockContext    = new RockContext();
                var pageService    = new PageService(rockContext);
                var routeService   = new PageRouteService(rockContext);
                var contextService = new PageContextService(rockContext);

                var page = pageService.Get(_pageId.Value);

                int parentPageId = ppParentPage.SelectedValueAsInt() ?? 0;
                if (page.ParentPageId != parentPageId)
                {
                    if (page.ParentPageId.HasValue)
                    {
                        PageCache.Flush(page.ParentPageId.Value);
                    }

                    if (parentPageId != 0)
                    {
                        PageCache.Flush(parentPageId);
                    }
                }

                page.InternalName = tbPageName.Text;
                page.PageTitle    = tbPageTitle.Text;
                page.BrowserTitle = tbBrowserTitle.Text;
                if (parentPageId != 0)
                {
                    page.ParentPageId = parentPageId;
                }
                else
                {
                    page.ParentPageId = null;
                }

                page.LayoutId = ddlLayout.SelectedValueAsInt().Value;

                int?orphanedIconFileId = null;

                page.IconCssClass = tbIconCssClass.Text;

                page.PageDisplayTitle       = cbPageTitle.Checked;
                page.PageDisplayBreadCrumb  = cbPageBreadCrumb.Checked;
                page.PageDisplayIcon        = cbPageIcon.Checked;
                page.PageDisplayDescription = cbPageDescription.Checked;

                page.DisplayInNavWhen       = (DisplayInNavWhen)Enum.Parse(typeof(DisplayInNavWhen), ddlMenuWhen.SelectedValue);
                page.MenuDisplayDescription = cbMenuDescription.Checked;
                page.MenuDisplayIcon        = cbMenuIcon.Checked;
                page.MenuDisplayChildPages  = cbMenuChildPages.Checked;

                page.BreadCrumbDisplayName = cbBreadCrumbName.Checked;
                page.BreadCrumbDisplayIcon = cbBreadCrumbIcon.Checked;

                page.RequiresEncryption  = cbRequiresEncryption.Checked;
                page.EnableViewState     = cbEnableViewState.Checked;
                page.IncludeAdminFooter  = cbIncludeAdminFooter.Checked;
                page.OutputCacheDuration = int.Parse(tbCacheDuration.Text);
                page.Description         = tbDescription.Text;
                page.HeaderContent       = ceHeaderContent.Text;

                // new or updated route
                foreach (var pageRoute in page.PageRoutes.ToList())
                {
                    var existingRoute = RouteTable.Routes.OfType <Route>().FirstOrDefault(a => a.RouteId() == pageRoute.Id);
                    if (existingRoute != null)
                    {
                        RouteTable.Routes.Remove(existingRoute);
                    }

                    routeService.Delete(pageRoute);
                }

                page.PageRoutes.Clear();

                foreach (string route in tbPageRoute.Text.SplitDelimitedValues())
                {
                    var pageRoute = new PageRoute();
                    pageRoute.Route = route.TrimStart(new char[] { '/' });
                    pageRoute.Guid  = Guid.NewGuid();
                    page.PageRoutes.Add(pageRoute);
                }

                foreach (var pageContext in page.PageContexts.ToList())
                {
                    contextService.Delete(pageContext);
                }

                page.PageContexts.Clear();
                foreach (var control in phContext.Controls)
                {
                    if (control is RockTextBox)
                    {
                        var tbContext = control as RockTextBox;
                        if (!string.IsNullOrWhiteSpace(tbContext.Text))
                        {
                            var pageContext = new PageContext();
                            pageContext.Entity      = tbContext.ID.Substring(8).Replace('_', '.');
                            pageContext.IdParameter = tbContext.Text;
                            page.PageContexts.Add(pageContext);
                        }
                    }
                }

                if (page.IsValid)
                {
                    rockContext.SaveChanges();

                    foreach (var pageRoute in new PageRouteService(rockContext).GetByPageId(page.Id))
                    {
                        RouteTable.Routes.AddPageRoute(pageRoute);
                    }

                    if (orphanedIconFileId.HasValue)
                    {
                        BinaryFileService binaryFileService = new BinaryFileService(rockContext);
                        var binaryFile = binaryFileService.Get(orphanedIconFileId.Value);
                        if (binaryFile != null)
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = true;
                            rockContext.SaveChanges();
                        }
                    }

                    Rock.Web.Cache.PageCache.Flush(page.Id);

                    string script = "if (typeof window.parent.Rock.controls.modal.close === 'function') window.parent.Rock.controls.modal.close('PAGE_UPDATED');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", script, true);
                }
            }
        }
コード例 #29
0
        /// <summary>
        /// Handles the OnSave event of the masterPage control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void masterPage_OnSave(object sender, EventArgs e)
        {
            Page.Validate(BlockValidationGroup);
            if (Page.IsValid && _pageId.HasValue)
            {
                var rockContext    = new RockContext();
                var pageService    = new PageService(rockContext);
                var routeService   = new PageRouteService(rockContext);
                var contextService = new PageContextService(rockContext);

                var page = pageService.Get(_pageId.Value);

                // validate/check for removed routes
                var editorRoutes       = tbPageRoute.Text.SplitDelimitedValues().Distinct();
                var databasePageRoutes = page.PageRoutes.ToList();
                var deletedRouteIds    = new List <int>();
                var addedRoutes        = new List <string>();

                if (editorRoutes.Any())
                {
                    int?siteId = null;
                    if (page != null && page.Layout != null)
                    {
                        siteId = page.Layout.SiteId;
                    }

                    // validate for any duplicate routes
                    var duplicateRouteQry = routeService.Queryable()
                                            .Where(r =>
                                                   r.PageId != _pageId &&
                                                   editorRoutes.Contains(r.Route));
                    if (siteId.HasValue)
                    {
                        duplicateRouteQry = duplicateRouteQry
                                            .Where(r =>
                                                   r.Page != null &&
                                                   r.Page.Layout != null &&
                                                   r.Page.Layout.SiteId == siteId.Value);
                    }

                    var duplicateRoutes = duplicateRouteQry
                                          .Select(r => r.Route)
                                          .Distinct()
                                          .ToList();

                    if (duplicateRoutes.Any())
                    {
                        // Duplicate routes
                        nbPageRouteWarning.Title       = "Duplicate Route(s)";
                        nbPageRouteWarning.Text        = string.Format("<p>The page route <strong>{0}</strong>, already exists for another page in the same site. Please choose a different route name.</p>", duplicateRoutes.AsDelimited("</strong> and <strong>"));
                        nbPageRouteWarning.Dismissable = true;
                        nbPageRouteWarning.Visible     = true;
                        CurrentTab = "Advanced Settings";

                        rptProperties.DataSource = _tabs;
                        rptProperties.DataBind();
                        ShowSelectedPane();
                        return;
                    }
                }

                // validate if removed routes can be deleted
                foreach (var pageRoute in databasePageRoutes)
                {
                    if (!editorRoutes.Contains(pageRoute.Route))
                    {
                        // make sure the route can be deleted
                        string errorMessage;
                        if (!routeService.CanDelete(pageRoute, out errorMessage))
                        {
                            nbPageRouteWarning.Text = string.Format("The page route <strong>{0}</strong>, cannot be removed. {1}", pageRoute.Route, errorMessage);
                            nbPageRouteWarning.NotificationBoxType = NotificationBoxType.Warning;
                            nbPageRouteWarning.Dismissable         = true;
                            nbPageRouteWarning.Visible             = true;
                            CurrentTab = "Advanced Settings";

                            rptProperties.DataSource = _tabs;
                            rptProperties.DataBind();
                            ShowSelectedPane();
                            return;
                        }
                    }
                }

                // take care of deleted routes
                foreach (var pageRoute in databasePageRoutes)
                {
                    if (!editorRoutes.Contains(pageRoute.Route))
                    {
                        // if they removed the Route, remove it from the database
                        page.PageRoutes.Remove(pageRoute);

                        routeService.Delete(pageRoute);
                        deletedRouteIds.Add(pageRoute.Id);
                    }
                }

                // take care of added routes
                foreach (string route in editorRoutes)
                {
                    // if they added the Route, add it to the database
                    if (!databasePageRoutes.Any(a => a.Route == route))
                    {
                        var pageRoute = new PageRoute();
                        pageRoute.Route = route.TrimStart(new char[] { '/' });
                        pageRoute.Guid  = Guid.NewGuid();
                        page.PageRoutes.Add(pageRoute);
                        addedRoutes.Add(route);
                    }
                }

                int parentPageId = ppParentPage.SelectedValueAsInt() ?? 0;
                if (page.ParentPageId != parentPageId)
                {
                    if (page.ParentPageId.HasValue)
                    {
                        PageCache.Flush(page.ParentPageId.Value);
                    }

                    if (parentPageId != 0)
                    {
                        PageCache.Flush(parentPageId);
                    }
                }

                page.InternalName = tbPageName.Text;
                page.PageTitle    = tbPageTitle.Text;
                page.BrowserTitle = tbBrowserTitle.Text;
                page.BodyCssClass = tbBodyCssClass.Text;

                if (parentPageId != 0)
                {
                    page.ParentPageId = parentPageId;
                }
                else
                {
                    page.ParentPageId = null;
                }

                page.LayoutId = ddlLayout.SelectedValueAsInt().Value;

                int?orphanedIconFileId = null;

                page.IconCssClass = tbIconCssClass.Text;

                page.PageDisplayTitle       = cbPageTitle.Checked;
                page.PageDisplayBreadCrumb  = cbPageBreadCrumb.Checked;
                page.PageDisplayIcon        = cbPageIcon.Checked;
                page.PageDisplayDescription = cbPageDescription.Checked;

                page.DisplayInNavWhen       = ddlMenuWhen.SelectedValue.ConvertToEnumOrNull <DisplayInNavWhen>() ?? DisplayInNavWhen.WhenAllowed;
                page.MenuDisplayDescription = cbMenuDescription.Checked;
                page.MenuDisplayIcon        = cbMenuIcon.Checked;
                page.MenuDisplayChildPages  = cbMenuChildPages.Checked;

                page.BreadCrumbDisplayName = cbBreadCrumbName.Checked;
                page.BreadCrumbDisplayIcon = cbBreadCrumbIcon.Checked;

                page.RequiresEncryption  = cbRequiresEncryption.Checked;
                page.EnableViewState     = cbEnableViewState.Checked;
                page.IncludeAdminFooter  = cbIncludeAdminFooter.Checked;
                page.AllowIndexing       = cbAllowIndexing.Checked;
                page.OutputCacheDuration = tbCacheDuration.Text.AsIntegerOrNull() ?? 0;
                page.Description         = tbDescription.Text;
                page.HeaderContent       = ceHeaderContent.Text;

                // update PageContexts
                foreach (var pageContext in page.PageContexts.ToList())
                {
                    contextService.Delete(pageContext);
                }

                page.PageContexts.Clear();
                foreach (var control in phContext.Controls)
                {
                    if (control is RockTextBox)
                    {
                        var tbContext = control as RockTextBox;
                        if (!string.IsNullOrWhiteSpace(tbContext.Text))
                        {
                            var pageContext = new PageContext();
                            pageContext.Entity      = tbContext.ID.Substring(8).Replace('_', '.');
                            pageContext.IdParameter = tbContext.Text;
                            page.PageContexts.Add(pageContext);
                        }
                    }
                }

                // save page and it's routes
                if (page.IsValid)
                {
                    rockContext.SaveChanges();

                    // remove any routes for this page that are no longer configured
                    foreach (var existingRoute in RouteTable.Routes.OfType <Route>().Where(a => a.PageIds().Contains(page.Id)))
                    {
                        if (!editorRoutes.Any(a => a == existingRoute.Url))
                        {
                            var pageAndRouteIds = existingRoute.DataTokens["PageRoutes"] as List <Rock.Web.PageAndRouteId>;
                            pageAndRouteIds = pageAndRouteIds.Where(p => p.PageId != page.Id).ToList();
                            if (pageAndRouteIds.Any())
                            {
                                existingRoute.DataTokens["PageRoutes"] = pageAndRouteIds;
                            }
                            else
                            {
                                RouteTable.Routes.Remove(existingRoute);
                            }
                        }
                    }

                    // Add any routes that were added
                    foreach (var pageRoute in new PageRouteService(rockContext).GetByPageId(page.Id))
                    {
                        if (addedRoutes.Contains(pageRoute.Route))
                        {
                            var pageAndRouteId = new Rock.Web.PageAndRouteId {
                                PageId = pageRoute.PageId, RouteId = pageRoute.Id
                            };

                            var existingRoute = RouteTable.Routes.OfType <Route>().FirstOrDefault(r => r.Url == pageRoute.Route);
                            if (existingRoute != null)
                            {
                                var pageAndRouteIds = existingRoute.DataTokens["PageRoutes"] as List <Rock.Web.PageAndRouteId>;
                                pageAndRouteIds.Add(pageAndRouteId);
                                existingRoute.DataTokens["PageRoutes"] = pageAndRouteIds;
                            }
                            else
                            {
                                var pageAndRouteIds = new List <Rock.Web.PageAndRouteId>();
                                pageAndRouteIds.Add(pageAndRouteId);
                                RouteTable.Routes.AddPageRoute(pageRoute.Route, pageAndRouteIds);
                            }
                        }
                    }

                    if (orphanedIconFileId.HasValue)
                    {
                        BinaryFileService binaryFileService = new BinaryFileService(rockContext);
                        var binaryFile = binaryFileService.Get(orphanedIconFileId.Value);
                        if (binaryFile != null)
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = true;
                            rockContext.SaveChanges();
                        }
                    }

                    Rock.Web.Cache.PageCache.Flush(page.Id);

                    string script = "if (typeof window.parent.Rock.controls.modal.close === 'function') window.parent.Rock.controls.modal.close('PAGE_UPDATED');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", script, true);
                }
            }
        }
コード例 #30
0
ファイル: Global.asax.cs プロジェクト: rowlek/Rock-ChMS
        private void RegisterRoutes( RouteCollection routes )
        {
            PageRouteService pageRouteService = new PageRouteService();

            // find each page that has defined a custom routes.
            foreach ( PageRoute pageRoute in pageRouteService.Queryable())
            {
                // Create the custom route and save the page id in the DataTokens collection
                Route route = new Route( pageRoute.Route, new Rock.Web.RockRouteHandler() );
                route.DataTokens = new RouteValueDictionary();
                route.DataTokens.Add( "PageId", pageRoute.PageId.ToString() );
                route.DataTokens.Add( "RouteId", pageRoute.Id.ToString() );
                routes.Add( route );
            }

            // Add API Service routes
            routes.MapPageRoute( "", "REST/help", "~/RESTHelp.aspx" );
            new Rock.REST.ServiceHelper( this.Server.MapPath("~/Extensions") ).AddRoutes( routes, "REST/" );

            // Add a default page route
            routes.Add( new Route( "page/{PageId}", new Rock.Web.RockRouteHandler() ) );

            // Add a default route for when no parameters are passed
            routes.Add( new Route( "", new Rock.Web.RockRouteHandler() ) );
        }
コード例 #31
0
        /// <summary>
        /// Recursively saves Pages and associated Blocks, PageRoutes and PageContexts.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="page">The current Page to save</param>
        /// <param name="newBlockTypes">List of BlockTypes not currently installed</param>
        /// <param name="parentPageId">Id of the current Page's parent</param>
        /// <param name="siteId">Id of the site the current Page is being imported into</param>
        private void SavePages(RockContext rockContext, Page page, IEnumerable <BlockType> newBlockTypes, int parentPageId, int siteId)
        {
            rockContext = rockContext ?? new RockContext();

            // find layout
            var    layoutService = new LayoutService(rockContext);
            Layout layout        = new Layout();

            if (page.Layout != null)
            {
                layout = layoutService.GetBySiteId(siteId).Where(l => l.Name == page.Layout.Name && l.FileName == page.Layout.FileName).FirstOrDefault();
                if (layout == null)
                {
                    layout          = new Layout();
                    layout.FileName = page.Layout.FileName;
                    layout.Name     = page.Layout.Name;
                    layout.SiteId   = siteId;
                    layoutService.Add(layout);
                    rockContext.SaveChanges();
                }
            }
            else
            {
                layout = layoutService.GetBySiteId(siteId).Where(l => l.Name.Contains("Full") || l.Name.Contains("Home")).First();
            }
            int layoutId = layout.Id;

            // Force shallow copies on entities so save operations are more atomic and don't get hosed
            // by nested object references.
            var pg         = page.Clone(deepCopy: false);
            var blockTypes = newBlockTypes.ToList();

            pg.ParentPageId = parentPageId;
            pg.LayoutId     = layoutId;

            var pageService = new PageService(rockContext);

            pageService.Add(pg);
            rockContext.SaveChanges();

            var blockService = new BlockService(rockContext);

            foreach (var block in page.Blocks ?? new List <Block>())
            {
                var blockType = blockTypes.FirstOrDefault(bt => block.BlockType.Path == bt.Path);
                var b         = block.Clone(deepCopy: false);
                b.PageId = pg.Id;

                if (blockType != null)
                {
                    b.BlockTypeId = blockType.Id;
                }

                blockService.Add(b);
            }
            rockContext.SaveChanges();

            var pageRouteService = new PageRouteService(rockContext);

            foreach (var pageRoute in page.PageRoutes ?? new List <PageRoute>())
            {
                var pr = pageRoute.Clone(deepCopy: false);
                pr.PageId = pg.Id;
                pageRouteService.Add(pr);
            }
            rockContext.SaveChanges();

            var pageContextService = new PageContextService(rockContext);

            foreach (var pageContext in page.PageContexts ?? new List <PageContext>())
            {
                var pc = pageContext.Clone(deepCopy: false);
                pc.PageId = pg.Id;
                pageContextService.Add(pc);
            }
            rockContext.SaveChanges();

            foreach (var p in page.Pages ?? new List <Page>())
            {
                SavePages(rockContext, p, blockTypes, pg.Id, siteId);
            }
        }