using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Administration;

namespace DevDashEnabler_VisWP.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnDevDashEnabler_Click(object sender, EventArgs e)
        {
            VisualWebPart1 DeveloperDashboard = new VisualWebPart1();
            if (DeveloperDashboard.contentService.DeveloperDashboardSettings.DisplayLevel == SPDeveloperDashboardLevel.Off) //checking if the devdash is already on
            {
                DeveloperDashboard.contentService.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.On; //turning it on if it was off
                DeveloperDashboard.contentService.DeveloperDashboardSettings.MaximumCriticalEventsToTrack = 999; //maximizing the critical events that we trace
                DeveloperDashboard.contentService.DeveloperDashboardSettings.MaximumSQLQueriesToTrack = 999; //maximizing the SQL queries that we trace
                DeveloperDashboard.contentService.DeveloperDashboardSettings.RequiredPermissions = SPBasePermissions.ManageWeb; //define the base level for security -only users who can manage websites are allowed to install the webpart
                DeveloperDashboard.contentService.DeveloperDashboardSettings.Update();
                Response.Redirect(Request.RawUrl);
            }
            else {
                DeveloperDashboard.contentService.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.Off; //turning the devdash off if it was on
                //DeveloperDashboard.contentService.DeveloperDashboardSettings.MaximumCriticalEventsToTrack = 999;
                //DeveloperDashboard.contentService.DeveloperDashboardSettings.MaximumSQLQueriesToTrack = 999;
                //DeveloperDashboard.contentService.DeveloperDashboardSettings.RequiredPermissions = SPBasePermissions.ManageWeb;
                //DeveloperDashboard.contentService.DeveloperDashboardSettings.Update();
                Response.Redirect(Request.RawUrl);
            }

        }
    }
}
