Exemplo n.º 1
0
    private void Page_Load(object sender, EventArgs e)
    {
        bool IsRunning = EkThreads.URLCheckerClass.ThreadRunning;
            StyleSheetJS.Text = m_refStyle.GetClientScript();
            SiteAPI m_refSiteApi = new SiteAPI();
            m_refMsg = m_refSiteApi.EkMsgRef;
            btnCheck.ToolTip = m_refMsg.GetMessage("btn Check Links");
            if (m_RequestInfo == null)
            {
                ContentAPI refContentApi = new ContentAPI();
                m_RequestInfo = refContentApi.RequestInformationRef;
            }
            RegisterResources();
            Utilities.ValidateUserLogin();
            if ( Convert.ToBoolean( m_RequestInfo.IsMembershipUser ) || m_RequestInfo.UserId == 0)
            {
                Response.Redirect("blank.htm", false);
                return;
            }

            if (IsRunning)
            {
                Response.AppendHeader("Refresh", "5");
            }

            // set initial values of fields on page
            if (Page.IsPostBack == false)
            {
                var m_refContentApi = new ContentAPI();
                var styleHelper = new StyleHelper();

                if (IsRunning)
                {
                    checkWrapper.Visible = false;
                    btnCheck.Visible = false;
                    //printWrapper.Visible = false;
                    //btnPrint.Visible = false;
                    cancelWrapper.Visible = true;
                    btnCancel.Visible = true;
                    //CancelButton.Text = styleHelper.GetButtonEventsWCaption(m_refContentApi.AppPath + "images/UI/Icons/cancel.png", "javascript:btnCancel_Click();", m_refMsg.GetMessage("generic cancel"), m_refMsg.GetMessage("generic cancel"), "", StyleHelper.CancelButtonCssClass, true);
                    lnkTabTestURL.Visible = false;
                    lnkTabStatus.Enabled = false;
                    // purge page state
                    HttpContext.Current.Session["_PAGE_STATE_" + Request.Url.AbsolutePath] = null;
                }
                else
                {
                    //CancelButton.Text = String.Empty;
                    PrintButton.Text = styleHelper.GetButtonEventsWCaption(m_refContentApi.AppPath + "images/UI/Icons/print.png", "#", m_refMsg.GetMessage("Print Report button text"), m_refMsg.GetMessage("btn print"), "onclick=\"PrintReport();\"", StyleHelper.PrintButtonCssClass, true);

                    btnCancel.Visible = false;
                    cancelWrapper.Visible = false;
                }

                if (ConfigurationManager.AppSettings["ek_DebugLinkCheck"] != "True")
                {
                    lnkTabTestURL.Visible = false;
                }

                if (! IsRunning)
                {
                    txtStatus.Text = m_refMsg.GetMessage("txt linkcheck idle");
                    txtStatus.ToolTip = txtStatus.Text;
                }
                else
                {
                    txtStatus.Text = EkThreads.URLCheckerClass.ThreadStatus;
                    txtStatus.ToolTip = txtStatus.Text;
                }

                if (EkThreads.URLCheckerClass.ThreadLog.Length == 0)
                {
                    ApplicationAPI m_AppRef = new ApplicationAPI();
                    string reportfile = m_AppRef.RequestInformationRef.PhysicalAppPath + "ekbadlinkrpt.html";
                    if (File.Exists(reportfile))
                    {
                        System.IO.StreamReader oRead;
                        try
                        {
                            oRead = System.IO.File.OpenText(reportfile);
                            EkThreads.URLCheckerClass.ThreadLog = new StringBuilder(oRead.ReadToEnd());
                        }
                        catch
                        {
                            // ignore errors reading from report file
                        }
                    }
                    else
                    {
                        txtStatus.Text = ""; // don't display status if it was never run
                        txtStatus.ToolTip = txtStatus.Text;
                    }
                }

                if (EkThreads.URLCheckerClass.ThreadLog.Length > 0)
                {
                    txtReport.Text = txtReport.Text;
                    if (IsRunning)
                    {
                        txtReport.Text = txtReport.Text + "<ul style=\'margin: .5em 2em\'>" + "<li>Objects Checked: " + EkThreads.URLCheckerClass.CountObjsChecked.ToString();
                        txtReport.Text = txtReport.Text + "</ li>" + "<li>Links Checked: " + EkThreads.URLCheckerClass.CountLinksChecked.ToString();
                        txtReport.Text = txtReport.Text + "</li>" + "<li>Bad Links: " + EkThreads.URLCheckerClass.CountBadLinks.ToString() + "</li></ul>";

                        if (EkThreads.URLCheckerClass.CountBadLinks > 500)
                        {
                            txtReport.Text = txtReport.Text + "Too many errors.  Please wait for report to be completed.";
                        }
                        else
                        {
                            txtReport.Text = txtReport.Text + EkThreads.URLCheckerClass.ThreadLog.ToString();
                        }
                    }
                    else
                    {
                        txtReport.Text = txtReport.Text + "<span id=\"ReportDataGrid\">";
                        txtReport.Text = txtReport.Text + "<span id=\"viewApprovalList_ViewGrid\">";
                        txtReport.Text = txtReport.Text + "<table><tr><td>";
                        txtReport.Text = txtReport.Text + EkThreads.URLCheckerClass.ThreadLog.ToString();
                        txtReport.Text = txtReport.Text + "</td></tr></table>";
                        txtReport.Text = txtReport.Text + "</span>";
                        txtReport.Text = txtReport.Text + "</span>";
                    }
                }

                // handle localization text
                StyleHelper m_refStyle1 = new StyleHelper();
                if (! IsRunning)
                {
                    m_refStyle1.MakeToolbarButton(btnCheck, m_refMsg.GetMessage("alt linkcheck button text"), m_refMsg.GetMessage("alt linkcheck button text"));
                    //m_refStyle1.MakeToolbarButton(btnPrint, m_refMsg.GetMessage("btn print"), m_refMsg.GetMessage("btn print"));
                }
                else
                {
                    //m_refStyle1.MakeToolbarButton(btnCancel, m_refMsg.GetMessage("generic cancel"), m_refMsg.GetMessage("generic cancel"));
                }
                lnkTabStatus.Text = m_refMsg.GetMessage("tab linkcheck status");
                lnkTabStatus.ToolTip = lnkTabStatus.Text;
                lnkTabTestURL.Text = m_refMsg.GetMessage("tab linkcheck testurl");
                lnkTabTestURL.ToolTip = lnkTabTestURL.Text;
                lblStatus.Text = m_refMsg.GetMessage("lbl linkcheck status");
                lblStatus.ToolTip = lblStatus.Text;
                lblURL.Text = m_refMsg.GetMessage("lbl linkcheck testurl");
                lblURL.ToolTip = lblURL.Text;
                btnHelp.Text = m_refStyle.GetHelpButton("badlinkcheck", "");
            }
    }