/// <summary>
        /// Handles the Delete event of the gSites 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 gSites_Delete( object sender, RowEventArgs e )
        {
            bool canDelete = false;

            var rockContext = new RockContext();
            SiteService siteService = new SiteService( rockContext );
            Site site = siteService.Get( e.RowKeyId );
            if ( site != null )
            {
                string errorMessage;
                canDelete = siteService.CanDelete( site, out errorMessage, includeSecondLvl: true );
                if ( !canDelete )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Alert );
                    return;
                }

                siteService.Delete( site );

                rockContext.SaveChanges();

                SiteCache.Flush( site.Id );
            }

            BindGrid();
        }
示例#2
0
        // default error handling
        /// <summary>
        /// Handles the Error event of the Application 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 Application_Error( object sender, EventArgs e )
        {
            HttpContext context = HttpContext.Current;

            // If the current context is null, there's nothing that can be done. Just return.
            if ( context == null )
            {
                return;
            }

            // log error
            var ex = Context.Server.GetLastError();

            if ( ex != null )
            {
                bool logException = true;

                // string to send a message to the error page to prevent infinite loops
                // of error reporting from incurring if there is an exception on the error page
                string errorQueryParm = "?type=exception&error=1";

                string errorCount = context.Request["error"];
                if ( !string.IsNullOrWhiteSpace( errorCount ) )
                {
                    if ( errorCount == "1" )
                    {
                        errorQueryParm = "?type=exception&error=2";
                    }
                    else if ( errorCount == "2" )
                    {
                        // something really bad is occurring stop logging errors as we're in an infinate loop
                        logException = false;
                    }
                }

                if ( logException )
                {
                    string status = "500";

                    var globalAttributesCache = GlobalAttributesCache.Read();

                    // determine if 404's should be tracked as exceptions
                    bool track404 = Convert.ToBoolean( globalAttributesCache.GetValue( "Log404AsException" ) );

                    // set status to 404
                    if ( ex.Message == "File does not exist." && ex.Source == "System.Web" )
                    {
                        status = "404";
                    }

                    if ( status == "500" || track404 )
                    {
                        LogError( ex, context );
                        context.Server.ClearError();

                        string errorPage = string.Empty;

                        // determine error page based on the site
                        SiteService service = new SiteService();
                        string siteName = string.Empty;

                        if ( context.Items["Rock:SiteId"] != null )
                        {
                            int siteId;
                            Int32.TryParse( context.Items["Rock:SiteId"].ToString(), out siteId );

                            // load site
                            Site site = service.Get( siteId );
                            siteName = site.Name;
                            errorPage = site.ErrorPage;
                        }

                        // Attempt to store exception in session. Session state may not be available
                        // within the context of an HTTP handler or the REST API.
                        try { Session["Exception"] = ex; }
                        catch ( HttpException ) { }

                        // email notifications if 500 error
                        if ( status == "500" )
                        {
                            // setup merge codes for email
                            var mergeObjects = new Dictionary<string, object>();
                            mergeObjects.Add( "ExceptionDetails", "An error occurred on the " + siteName + " site on page: <br>" + context.Request.Url.OriginalString + "<p>" + FormatException( ex, "" ) );

                            // get email addresses to send to
                            string emailAddressesList = globalAttributesCache.GetValue( "EmailExceptionsList" );

                            if ( !string.IsNullOrWhiteSpace( emailAddressesList ) )
                            {
                                string[] emailAddresses = emailAddressesList.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries );
                                var recipients = new Dictionary<string, Dictionary<string, object>>();

                                foreach ( string emailAddress in emailAddresses )
                                {
                                    recipients.Add( emailAddress, mergeObjects );
                                }

                                if ( recipients.Count > 0 )
                                {
                                    Email email = new Email( Rock.SystemGuid.EmailTemplate.CONFIG_EXCEPTION_NOTIFICATION );
                                    email.Send( recipients );
                                }
                            }
                        }

                        // redirect to error page
                        if ( !string.IsNullOrEmpty( errorPage ) )
                        {
                            Response.Redirect( errorPage + errorQueryParm, false );
                            Context.ApplicationInstance.CompleteRequest();
                        }
                        else
                        {
                            Response.Redirect( "~/error.aspx" + errorQueryParm, false );  // default error page
                            Context.ApplicationInstance.CompleteRequest();
                        }

                        // intentially throw ThreadAbort
                        Response.End();
                    }
                }
            }
        }
        /// <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 )
        {
            Site site;

            if ( Page.IsValid )
            {
                var rockContext = new RockContext();
                SiteService siteService = new SiteService( rockContext );
                SiteDomainService siteDomainService = new SiteDomainService( rockContext );
                bool newSite = false;

                int siteId = int.Parse( hfSiteId.Value );

                if ( siteId == 0 )
                {
                    newSite = true;
                    site = new Rock.Model.Site();
                    siteService.Add( site );
                }
                else
                {
                    site = siteService.Get( siteId );
                }

                site.Name = tbSiteName.Text;
                site.Description = tbDescription.Text;
                site.Theme = ddlTheme.Text;
                site.DefaultPageId = ppDefaultPage.PageId;
                site.DefaultPageRouteId = ppDefaultPage.PageRouteId;
                site.LoginPageId = ppLoginPage.PageId;
                site.LoginPageRouteId = ppLoginPage.PageRouteId;
                site.CommunicationPageId = ppCommunicationPage.PageId;
                site.CommunicationPageRouteId = ppCommunicationPage.PageRouteId;
                site.RegistrationPageId = ppRegistrationPage.PageId;
                site.RegistrationPageRouteId = ppRegistrationPage.PageRouteId;
                site.PageNotFoundPageId = ppPageNotFoundPage.PageId;
                site.PageNotFoundPageRouteId = ppPageNotFoundPage.PageRouteId;
                site.ErrorPage = tbErrorPage.Text;
                site.GoogleAnalyticsCode = tbGoogleAnalytics.Text;
                site.FacebookAppId = tbFacebookAppId.Text;
                site.FacebookAppSecret = tbFacebookAppSecret.Text;

                var currentDomains = tbSiteDomains.Text.SplitDelimitedValues().ToList<string>();
                site.SiteDomains = site.SiteDomains ?? new List<SiteDomain>();

                // Remove any deleted domains
                foreach ( var domain in site.SiteDomains.Where( w => !currentDomains.Contains( w.Domain ) ).ToList() )
                {
                    site.SiteDomains.Remove( domain );
                    siteDomainService.Delete( domain );
                }

                foreach ( string domain in currentDomains )
                {
                    SiteDomain sd = site.SiteDomains.Where( d => d.Domain == domain ).FirstOrDefault();
                    if ( sd == null )
                    {
                        sd = new SiteDomain();
                        sd.Domain = domain;
                        sd.Guid = Guid.NewGuid();
                        site.SiteDomains.Add( sd );
                    }
                }

                if ( !site.DefaultPageId.HasValue && !newSite )
                {
                    ppDefaultPage.ShowErrorMessage( "Default Page is required." );
                    return;
                }

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

                rockContext.WrapTransaction( () =>
                {
                    rockContext.SaveChanges();

                    if ( newSite )
                    {
                        Rock.Security.Authorization.CopyAuthorization( RockPage.Layout.Site, site, rockContext );
                    }
                } );

                SiteCache.Flush( site.Id );

                // Create the default page is this is a new site
                if ( !site.DefaultPageId.HasValue && newSite )
                {
                    var siteCache = SiteCache.Read( site.Id );

                    // Create the layouts for the site, and find the first one
                    LayoutService.RegisterLayouts( Request.MapPath( "~" ), siteCache );

                    var layoutService = new LayoutService( rockContext );
                    var layouts = layoutService.GetBySiteId( siteCache.Id );
                    Layout layout = layouts.FirstOrDefault( l => l.FileName.Equals( "FullWidth", StringComparison.OrdinalIgnoreCase ) );
                    if ( layout == null )
                    {
                        layout = layouts.FirstOrDefault();
                    }
                    if ( layout != null )
                    {
                        var pageService = new PageService( rockContext );
                        var page = new Page();
                        page.LayoutId = layout.Id;
                        page.PageTitle = siteCache.Name + " Home Page";
                        page.InternalName = page.PageTitle;
                        page.BrowserTitle = page.PageTitle;
                        page.EnableViewState = true;
                        page.IncludeAdminFooter = true;
                        page.MenuDisplayChildPages = true;

                        var lastPage = pageService.GetByParentPageId( null ).
                            OrderByDescending( b => b.Order ).FirstOrDefault();

                        page.Order = lastPage != null ? lastPage.Order + 1 : 0;
                        pageService.Add( page );

                        rockContext.SaveChanges();

                        site = siteService.Get( siteCache.Id );
                        site.DefaultPageId = page.Id;

                        rockContext.SaveChanges();

                        SiteCache.Flush( site.Id );
                    }
                }

                var qryParams = new Dictionary<string, string>();
                qryParams["siteId"] = site.Id.ToString();

                NavigateToPage( RockPage.Guid, qryParams );
            }
        }
        /// <summary>
        /// Handles the Click event of the btnDelete 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 btnDelete_Click( object sender, EventArgs e )
        {
            bool canDelete = false;

            var rockContext = new RockContext();
            SiteService siteService = new SiteService( rockContext );
            Site site = siteService.Get( int.Parse( hfSiteId.Value ) );
            if ( site != null )
            {
                string errorMessage;
                canDelete = siteService.CanDelete( site, out errorMessage, includeSecondLvl: true );
                if ( !canDelete )
                {
                    mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert );
                    return;
                }

                siteService.Delete( site );

                rockContext.SaveChanges();

                SiteCache.Flush( site.Id );
            }

            NavigateToParentPage();
        }
示例#5
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 )
        {
            Site site;
            SiteDomain sd;
            bool newSite = false;

            using ( new UnitOfWorkScope() )
            {
                SiteService siteService = new SiteService();
                SiteDomainService siteDomainService = new SiteDomainService();

                int siteId = 0;
                if ( !int.TryParse( hfSiteId.Value, out siteId ) )
                {
                    siteId = 0;
                }

                if ( siteId == 0 )
                {
                    newSite = true;
                    site = new Rock.Model.Site();
                    siteService.Add( site, CurrentPersonId );
                }
                else
                {
                    site = siteService.Get( siteId );
                    foreach ( var domain in site.SiteDomains.ToList() )
                    {
                        siteDomainService.Delete( domain, CurrentPersonId );
                    }

                    site.SiteDomains.Clear();
                }

                site.Name = tbSiteName.Text;
                site.Description = tbDescription.Text;
                site.Theme = ddlTheme.Text;
                site.DefaultPageId = int.Parse( ddlDefaultPage.SelectedValue );

                foreach ( string domain in tbSiteDomains.Text.SplitDelimitedValues() )
                {
                    sd = new SiteDomain();
                    sd.Domain = domain;
                    sd.Guid = Guid.NewGuid();
                    site.SiteDomains.Add( sd );
                }

                site.FaviconUrl = tbFaviconUrl.Text;
                site.AppleTouchIconUrl = tbAppleTouchIconUrl.Text;
                site.FacebookAppId = tbFacebookAppId.Text;
                site.FacebookAppSecret = tbFacebookAppSecret.Text;

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

                siteService.Save( site, CurrentPersonId );

                if ( newSite )
                {
                    Rock.Security.Authorization.CopyAuthorization( CurrentPage.Site, site, CurrentPersonId );
                }

                SiteCache.Flush( site.Id );

                BindGrid();

                pnlDetails.Visible = false;
                pnlList.Visible = true;
            }
        }
示例#6
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="siteId">The site id.</param>
        protected void ShowEdit( int siteId )
        {
            SiteService siteService = new SiteService();
            Site site = siteService.Get( siteId );

            if ( site != null )
            {
                lAction.Text = "Edit";
                hfSiteId.Value = site.Id.ToString();

                tbSiteName.Text = site.Name;
                tbDescription.Text = site.Description;
                ddlTheme.SetValue( site.Theme );
                if ( site.DefaultPageId.HasValue )
                {
                    ddlDefaultPage.SelectedValue = site.DefaultPageId.Value.ToString();
                }

                tbSiteDomains.Text = string.Join( "\n", site.SiteDomains.Select( dom => dom.Domain ).ToArray() );
                tbFaviconUrl.Text = site.FaviconUrl;
                tbAppleTouchIconUrl.Text = site.AppleTouchIconUrl;
                tbFacebookAppId.Text = site.FacebookAppId;
                tbFacebookAppSecret.Text = site.FacebookAppSecret;
            }
            else
            {
                lAction.Text = "Add";
                tbSiteName.Text = string.Empty;
                tbDescription.Text = string.Empty;
                ddlTheme.Text = CurrentPage.Site.Theme;
                tbSiteDomains.Text = string.Empty;
                tbFaviconUrl.Text = string.Empty;
                tbAppleTouchIconUrl.Text = string.Empty;
                tbFacebookAppId.Text = string.Empty;
                tbFacebookAppSecret.Text = string.Empty;
            }

            pnlList.Visible = false;
            pnlDetails.Visible = true;
        }
示例#7
0
        /// <summary>
        /// Handles the Delete event of the gSites 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 gSites_Delete( object sender, RowEventArgs e )
        {
            SiteService siteService = new SiteService();
            Site site = siteService.Get( (int)gSites.DataKeys[e.RowIndex]["id"] );
            if ( CurrentBlock != null )
            {
                siteService.Delete( site, CurrentPersonId );
                siteService.Save( site, CurrentPersonId );

                SiteCache.Flush( site.Id );
            }

            BindGrid();
        }
示例#8
0
        /// <summary>
        /// Binds the pages grid.
        /// </summary>
        protected void BindPagesGrid()
        {
            pnlPages.Visible = false;
            int siteId = PageParameter( "siteId" ).AsInteger();
            if ( siteId == 0 )
            {
                // quit if the siteId can't be determined
                return;
            }

            hfSiteId.SetValue( siteId );
            pnlPages.Visible = true;

            // Question: Is this RegisterLayouts necessary here?  Since if it's a new layout
            // there would not be any pages on them (which is our concern here).
            // It seems like it should be the concern of some other part of the puzzle.
            LayoutService.RegisterLayouts( Request.MapPath( "~" ), SiteCache.Read( siteId ) );
            //var layouts = layoutService.Queryable().Where( a => a.SiteId.Equals( siteId ) ).Select( a => a.Id ).ToList();

            // Find all the pages that are related to this site...
            // 1) pages used by one of this site's layouts and
            // 2) the site's 'special' pages used directly by the site.
            var rockContext = new RockContext();
            var siteService = new SiteService( rockContext );
            var pageService = new PageService( rockContext );

            var site = siteService.Get( siteId );
            if ( site != null )
            {
                var sitePages = new List<int> {
                    site.DefaultPageId ?? -1,
                    site.LoginPageId ?? -1,
                    site.RegistrationPageId ?? -1,
                    site.PageNotFoundPageId ?? -1
                };

                var qry = pageService.Queryable("Layout")
                    .Where( t =>
                        t.Layout.SiteId == siteId ||
                        sitePages.Contains( t.Id ) );

                string layoutFilter = gPagesFilter.GetUserPreference( "Layout" );
                if ( !string.IsNullOrWhiteSpace( layoutFilter ) && layoutFilter != Rock.Constants.All.Text )
                {
                    qry = qry.Where( a => a.Layout.ToString() == layoutFilter );
                }

                SortProperty sortProperty = gPages.SortProperty;
                if ( sortProperty != null )
                {
                    qry = qry.Sort( sortProperty );
                }
                else
                {
                    qry = qry
                        .OrderBy( t => t.Layout.Name )
                        .ThenBy( t => t.InternalName );
                }

                gPages.DataSource = qry.ToList();
                gPages.DataBind();
            }
        }
示例#9
0
        /// <summary>
        /// Handles the Click event of the btnDeleteConfirm 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 btnDeleteConfirm_Click( object sender, EventArgs e )
        {
            bool canDelete = false;

            var rockContext = new RockContext();
            SiteService siteService = new SiteService( rockContext );
            Site site = siteService.Get( int.Parse( hfSiteId.Value ) );
            LayoutService layoutService = new LayoutService( rockContext );
            PageService pageService = new PageService( rockContext );
            PageViewService pageViewService = new PageViewService( rockContext );

            if ( site != null )
            {
                var sitePages = new List<int> {
                    site.DefaultPageId ?? -1,
                    site.LoginPageId ?? -1,
                    site.RegistrationPageId ?? -1,
                    site.PageNotFoundPageId ?? -1
                };

                foreach ( var pageView in pageViewService
                    .Queryable()
                    .Where( t =>
                        t.Page != null &&
                        t.Page.Layout != null &&
                        t.Page.Layout.SiteId == site.Id ) )
                {
                    pageView.Page = null;
                    pageView.PageId = null;
                }

                var pageQry = pageService.Queryable( "Layout" )
                    .Where( t =>
                        t.Layout.SiteId == site.Id ||
                        sitePages.Contains( t.Id ) );

                pageService.DeleteRange( pageQry );

                var layoutQry = layoutService.Queryable()
                    .Where( l =>
                        l.SiteId == site.Id );
                layoutService.DeleteRange( layoutQry );
                rockContext.SaveChanges( true );

                string errorMessage;
                canDelete = siteService.CanDelete( site, out errorMessage, includeSecondLvl: true );
                if ( !canDelete )
                {
                    mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert );
                    return;
                }

                siteService.Delete( site );

                rockContext.SaveChanges();

                SiteCache.Flush( site.Id );
            }

            NavigateToParentPage();
        }
示例#10
0
        /// <summary>
        /// Handles the Click event of the btnCompileTheme 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 btnCompileTheme_Click( object sender, EventArgs e )
        {
            var rockContext = new RockContext();
            SiteService siteService = new SiteService( rockContext );
            Site site = siteService.Get( hfSiteId.Value.AsInteger() );

            string messages = string.Empty;
            var theme = new RockTheme( site.Theme );
            bool success = theme.Compile( out messages );

            if ( success )
            {
                mdThemeCompile.Show( "Theme was successfully compiled.", ModalAlertType.Information );
            }
            else
            {
                mdThemeCompile.Show( string.Format("An error occurred compiling the theme {0}. Message: {1}.", site.Theme, messages), ModalAlertType.Warning );
            }
        }
示例#11
0
 /// <summary>
 /// Build filter values/summary with user friendly data from filters
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The e.</param>
 protected void fExceptionList_DisplayFilterValue( object sender, GridFilter.DisplayFilterValueArgs e )
 {
     switch ( e.Key )
     {
         case "Site":
             int siteId;
             if ( int.TryParse( e.Value, out siteId ) )
             {
                 SiteService siteService = new SiteService();
                 var site = siteService.Get( siteId );
                 if ( site != null )
                 {
                     e.Value = site.Name;
                 }
             }
             break;
         case "Page":
             int pageId;
             if ( int.TryParse( e.Value, out pageId ) )
             {
                 PageService pageService = new PageService();
                 var page = pageService.Get( pageId );
                 if ( page != null )
                 {
                     e.Value = page.InternalName;
                 }
             }
             break;
         case "User":
             int userPersonId;
             if ( int.TryParse( e.Value, out userPersonId ) )
             {
                 PersonService personService = new PersonService();
                 var user = personService.Get( userPersonId );
                 if ( user != null )
                 {
                     e.Value = user.FullName;
                 }
             }
             break;
     }
 }
示例#12
0
        /// <summary>
        /// Handles the Delete event of the gSites 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 gSites_Delete( object sender, RowEventArgs e )
        {
            RockTransactionScope.WrapTransaction( () =>
            {
                SiteService siteService = new SiteService();
                Site site = siteService.Get( (int)e.RowKeyValue );
                if ( site != null )
                {
                    string errorMessage;
                    if ( !siteService.CanDelete( site, out errorMessage ) )
                    {
                        mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }
                    
                    siteService.Delete( site, CurrentPersonId );
                    siteService.Save( site, CurrentPersonId );

                    SiteCache.Flush( site.Id );
                }
            } );

            BindGrid();
        }
示例#13
0
        /// <summary>
        /// Binds the pages grid.
        /// </summary>
        protected void BindPagesGrid()
        {
            pnlPages.Visible = false;
            int siteId = PageParameter( "siteId" ).AsInteger() ?? 0;
            if ( siteId == 0 )
            {
                // quit if the siteId can't be determined
                return;
            }

            hfSiteId.SetValue( siteId );
            pnlPages.Visible = true;

            LayoutService layoutService = new LayoutService();
            layoutService.RegisterLayouts( Request.MapPath( "~" ), SiteCache.Read( siteId ), CurrentPersonId );
            var layouts = layoutService.Queryable().Where( a => a.SiteId.Equals( siteId ) ).Select( a => a.Id ).ToList();

            var siteService = new SiteService();
            var pageId = siteService.Get( siteId ).DefaultPageId;

            var pageService = new PageService();
            var qry = pageService.GetAllDescendents( (int)pageId ).AsQueryable().Where( a => layouts.Contains(a.LayoutId) );

            string layoutFilter = gPagesFilter.GetUserPreference( "Layout" );
            if ( !string.IsNullOrWhiteSpace( layoutFilter ) && layoutFilter != Rock.Constants.All.Text )
            {
                qry = qry.Where( a => a.Layout.ToString() == layoutFilter );
            }

            SortProperty sortProperty = gPages.SortProperty;
            if ( sortProperty != null )
            {
                qry = qry.Sort( sortProperty );
            }
            else
            {
                qry = qry.OrderBy( q => q.Id );
            }

            gPages.DataSource = qry.ToList();
            gPages.DataBind();
        }