コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(this.Page);

        // Handle export settings
        if (!Page.IsCallback && !RequestHelper.IsPostBack())
        {
            // Initialize virtual path provider
            VirtualPathHelper.Init(Page);

            ExportSettings = GetNewSettings();
        }

        if (!Page.IsCallback)
        {
            // Display BETA warning
            lblBeta.Visible = CMSContext.IsBetaVersion();
            lblBeta.Text    = string.Format(GetString("export.BETAwarning"), CMSContext.GetFriendlySystemVersion(false));

            bool notTargetPermissions = false;
            bool notTempPermissions   = false;

            ctrlAsync.OnFinished += ctrlAsync_OnFinished;
            ctrlAsync.OnError    += ctrlAsync_OnError;

            // Init steps
            if (wzdExport.ActiveStepIndex < 2)
            {
                configExport.Settings = ExportSettings;
                if (!RequestHelper.IsPostBack())
                {
                    configExport.SiteId = SiteId;
                }

                pnlExport.Settings = ExportSettings;

                // Ensure directories and check permissions
                try
                {
                    DirectoryHelper.EnsureDiskPath(ExportSettings.TargetPath + "\\temp.file", ExportSettings.WebsitePath);
                    notTargetPermissions = !DirectoryHelper.CheckPermissions(ExportSettings.TargetPath, true, true, false, false);
                }
                catch (UnauthorizedAccessException)
                {
                    notTargetPermissions = true;
                }
                try
                {
                    DirectoryHelper.EnsureDiskPath(ExportSettings.TemporaryFilesPath + "\\temp.file", ExportSettings.WebsitePath);
                    notTempPermissions = !DirectoryHelper.CheckPermissions(ExportSettings.TemporaryFilesPath, true, true, false, false);
                }
                catch (UnauthorizedAccessException)
                {
                    notTempPermissions = true;
                }
            }

            if (notTargetPermissions || notTempPermissions)
            {
                string folder = (notTargetPermissions) ? ExportSettings.TargetPath : ExportSettings.TemporaryFilesPath;
                pnlWrapper.Visible         = false;
                lblError.Text              = string.Format(GetString("ExportSite.ErrorPermissions"), folder, System.Security.Principal.WindowsIdentity.GetCurrent().Name);
                pnlPermissions.Visible     = true;
                lnkPermissions.Target      = "_blank";
                lnkPermissions.Text        = GetString("Install.ErrorPermissions");
                lnkPermissions.NavigateUrl = ResolveUrl("~/CMSMessages/ConfigurePermissions.aspx");
            }
            else
            {
                // Try to delete temporary files from previous export
                if (!RequestHelper.IsPostBack())
                {
                    try
                    {
                        ExportProvider.DeleteTemporaryFiles(ExportSettings, false);
                    }
                    catch (Exception ex)
                    {
                        pnlWrapper.Visible = false;
                        lblError.Text      = GetString("ImportSite.ErrorDeletionTemporaryFiles") + ex.Message;
                        return;
                    }
                }

                PortalHelper.EnsureScriptManager(this.Page).EnablePageMethods = true;

                // Javascript functions
                string script =
                    @"var exMessageText = '';
var exErrorText = '';
var exWarningText = '';
var exMachineName = '" + SqlHelperClass.MachineName.ToLower() + @"';
var getBusy = false;

function GetExportState(cancel) { 
    if (window.Activity) { 
        window.Activity(); 
    } 
    if (getBusy) return; 
    getBusy = true; 
    setTimeout('getBusy = false;', 2000);
    var argument = cancel + ';' + exMessageText.length + ';' + exErrorText.length + ';' + exWarningText.length + ';' + exMachineName; 
    " + Page.ClientScript.GetCallbackEventReference(this, "argument", "SetExportStateMssg", "argument", false) + @";
}

function SetExportStateMssg(rValue, context) {
    getBusy = false;
    if (rValue!='') {
        var args = context.split(';');
        var values = rValue.split('" + SiteExportSettings.SEPARATOR + @"');
        var messageElement = document.getElementById('" + lblProgress.ClientID + @"');
        var errorElement = document.getElementById('" + lblError.ClientID + @"');
        var warningElement = document.getElementById('" + lblWarning.ClientID + @"');
        var messageText = exMessageText;
        messageText = values[1] + messageText.substring(messageText.length - args[1]);
        if (messageText.length > exMessageText.length) { 
            exMessageText = messageElement.innerHTML = messageText; 
        }
        var errorText = exErrorText;
        errorText = values[2] + errorText.substring(errorText.length - args[2]);
        if (errorText.length > exErrorText.length) { 
            exErrorText = errorElement.innerHTML = errorText; 
        }
        var warningText = exWarningText;
        warningText = values[3] + warningText.substring(warningText.length - args[3]);
        if (warningText.length > exWarningText.length) { 
            exWarningText = warningElement.innerHTML = warningText; 
        }
        if ((values=='') || (values[0]=='F')) {
            StopExportStateTimer();
            BTN_Enable('" + FinishButton.ClientID + @"');
            try {
                BTN_Disable('" + CancelButton.ClientID + @"');
            }
            catch(err) {
            }
        }
    }
}";

                // Register the script to perform get flags for showing buttons retrieval callback
                ScriptHelper.RegisterClientScriptBlock(this, GetType(), "GetSetExportState", ScriptHelper.GetScript(script));

                // Add cancel button attribute
                CancelButton.Attributes.Add("onclick", "BTN_Disable('" + CancelButton.ClientID + "'); return CancelExport();");

                wzdExport.NextButtonClick     += wzdExport_NextButtonClick;
                wzdExport.PreviousButtonClick += wzdExport_PreviousButtonClick;
                wzdExport.FinishButtonClick   += wzdExport_FinishButtonClick;

                if (!RequestHelper.IsPostBack())
                {
                    configExport.InitControl();
                }
            }
        }
    }
コード例 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(Page);

        // Handle Import settings
        if (!Page.IsCallback && !RequestHelper.IsPostBack())
        {
            // Initialize virtual path provider
            VirtualPathHelper.Init(Page);

            // Initialize import settings
            ImportSettings = GetNewSettings();
        }

        if (!Page.IsCallback)
        {
            if (!SettingsKeyProvider.UsingVirtualPathProvider)
            {
                lblWarning.Visible = true;
                lblWarning.Text    = GetString("ImportSite.VirtualPathProviderNotRunning");
            }

            ctrlAsync.OnFinished += ctrlAsync_OnFinished;
            ctrlAsync.OnError    += ctrlAsync_OnError;

            bool notTempPermissions = false;

            if (wzdImport.ActiveStepIndex < 3)
            {
                stpConfigImport.Settings = ImportSettings;
                stpSiteDetails.Settings  = ImportSettings;
                stpImport.Settings       = ImportSettings;

                // Ensure directory
                DirectoryHelper.EnsureDiskPath(ImportSettings.TemporaryFilesPath + "\\temp.file", ImportSettings.WebsitePath);
                // Check permissions
                notTempPermissions = !DirectoryHelper.CheckPermissions(ImportSettings.TemporaryFilesPath, true, true, false, false);
            }

            if (notTempPermissions)
            {
                pnlWrapper.Visible         = false;
                lblError.Text              = string.Format(GetString("ImportSite.ErrorPermissions"), ImportSettings.TemporaryFilesPath, WindowsIdentity.GetCurrent().Name);
                pnlPermissions.Visible     = true;
                lnkPermissions.Target      = "_blank";
                lnkPermissions.Text        = GetString("Install.ErrorPermissions");
                lnkPermissions.NavigateUrl = ResolveUrl("~/CMSMessages/ConfigurePermissions.aspx");
            }
            else
            {
                if (!RequestHelper.IsPostBack())
                {
                    // Delete temporary files
                    try
                    {
                        // Delete only folder structure if there is not special folder
                        bool onlyFolderStructure = !Directory.Exists(DirectoryHelper.CombinePath(ImportSettings.TemporaryFilesPath, ImportExportHelper.FILES_FOLDER));
                        ImportProvider.DeleteTemporaryFiles(ImportSettings, onlyFolderStructure);
                    }
                    catch (Exception ex)
                    {
                        pnlWrapper.Visible = false;
                        lblError.Text      = GetString("ImportSite.ErrorDeletionTemporaryFiles") + ex.Message;
                        return;
                    }
                }

                // Javascript functions
                string script =
                    "var imMessageText = '';\n" +
                    "var imErrorText = '';\n" +
                    "var imWarningText = '';\n" +
                    "var imMachineName = '" + SqlHelperClass.MachineName.ToLowerCSafe() + "';\n" +
                    "var getBusy = false;\n" +
                    "function GetImportState(cancel)\n" +
                    "{ if(window.Activity){window.Activity();} if (getBusy && !cancel) return; getBusy = true; setTimeout(\"getBusy = false;\", 2000); var argument = cancel + ';' + imMessageText.length + ';' + imErrorText.length + ';' + imWarningText.length + ';' + imMachineName; return " + Page.ClientScript.GetCallbackEventReference(this, "argument", "SetImportStateMssg", "argument", true) + " }\n";

                script +=
                    "function SetImportStateMssg(rValue, context)\n" +
                    "{\n" +
                    "   getBusy = false;\n" +
                    "   if(rValue != '')\n" +
                    "   {\n" +
                    "       var args = context.split(';');\n" +
                    "       var values = rValue.split('" + SiteExportSettings.SEPARATOR + "');\n" +
                    "       var messageElement = document.getElementById('" + lblProgress.ClientID + "');\n" +
                    "       var errorElement = document.getElementById('" + lblError.ClientID + "');\n" +
                    "       var warningElement = document.getElementById('" + lblWarning.ClientID + "');\n" +
                    "       var messageText = imMessageText;\n" +
                    "       messageText = values[1] + messageText.substring(messageText.length - args[1]);\n" +
                    "       if(messageText.length > imMessageText.length){ imMessageText = messageElement.innerHTML = messageText; }\n" +
                    "       var errorText = imErrorText;\n" +
                    "       errorText = values[2] + errorText.substring(errorText.length - args[2]);\n" +
                    "       if(errorText.length > imErrorText.length){ imErrorText = errorElement.innerHTML = errorText; }\n" +
                    "       var warningText = imWarningText;\n" +
                    "       warningText = values[3] + warningText.substring(warningText.length - args[3]);\n" +
                    "       if(warningText.length > imWarningText.length){ imWarningText = warningElement.innerHTML = warningText; }\n" +
                    "       if((values=='') || (values[0]=='F'))\n" +
                    "       {\n" +
                    "           StopImportStateTimer();\n" +
                    "           BTN_Disable('" + CancelButton.ClientID + "');\n" +
                    "           BTN_Enable('" + FinishButton.ClientID + "');\n" +
                    "       }\n" +
                    "   }\n" +
                    "}\n";

                // Register the script to perform get flags for showing buttons retrieval callback
                ScriptHelper.RegisterClientScriptBlock(this, GetType(), "GetSetImportState", ScriptHelper.GetScript(script));

                // Add cancel button attribute
                CancelButton.Attributes.Add("onclick", "BTN_Disable('" + CancelButton.ClientID + "');" + "return CancelImport();");

                wzdImport.NextButtonClick     += wzdImport_NextButtonClick;
                wzdImport.PreviousButtonClick += wzdImport_PreviousButtonClick;
                wzdImport.FinishButtonClick   += wzdImport_FinishButtonClick;

                if (!RequestHelper.IsPostBack())
                {
                    stpConfigImport.InitControl();
                }
            }
        }
    }
コード例 #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register script for pendingCallbacks repair
        ScriptHelper.FixPendingCallbacks(Page);

        // Handle Import settings
        if (!Page.IsCallback && !RequestHelper.IsPostBack())
        {
            // Check if any template is present on the disk
            if (!WebTemplateInfoProvider.IsAnyTemplatePresent())
            {
                selectTemplate.StopProcessing = true;
                pnlWrapper.Visible            = false;
                lblError.Visible = true;
                lblError.Text    = GetString("NewSite.NoWebTemplate");
            }

            // Initialize virtual path provider
            VirtualPathHelper.Init(Page);

            // Initialize import settings
            ImportSettings                       = new SiteImportSettings(CMSContext.CurrentUser);
            ImportSettings.WebsitePath           = Server.MapPath("~/");
            ImportSettings.PersistentSettingsKey = PersistentSettingsKey;
        }

        if (Page.IsCallback)
        {
            // Stop processing when callback
            selectTemplate.StopProcessing = true;
            selectMaster.StopProcessing   = true;
        }
        else
        {
            selectTemplate.StopProcessing = (CausedPostback(PreviousButton) && (wzdImport.ActiveStepIndex == 2)) ? false : (wzdImport.ActiveStepIndex != 1);
            selectMaster.StopProcessing   = (wzdImport.ActiveStepIndex != 5);

            PreviousButton.Enabled = true;
            PreviousButton.Visible = (wzdImport.ActiveStepIndex <= 4);
            NextButton.Enabled     = true;

            // Bind async controls events
            ctrlAsync.OnFinished  += ctrlAsync_OnFinished;
            ctrlAsync.OnError     += ctrlAsync_OnError;
            ctrlImport.OnFinished += ctrlImport_OnFinished;

            if (wzdImport.ActiveStepIndex < 4)
            {
                siteDetails.Settings = ImportSettings;
                pnlImport.Settings   = ImportSettings;
            }

            // Javascript functions
            string script =
                "var nMessageText = '';\n" +
                "var nErrorText = '';\n" +
                "var nWarningText = '';\n" +
                "var nMachineName = '" + SqlHelperClass.MachineName.ToLowerCSafe() + "';\n" +
                "var getBusy = false; \n" +
                "function GetImportState(cancel) \n" +
                "{ if(window.Activity){window.Activity();} if (getBusy && !cancel) return; getBusy = true; setTimeout(\"getBusy = false;\", 2000); var argument = cancel + ';' + nMessageText.length + ';' + nErrorText.length + ';' + nWarningText.length + ';' + nMachineName; return " + Page.ClientScript.GetCallbackEventReference(this, "argument", "SetImportStateMssg", "argument", true) + " } \n";

            script +=
                "function SetImportStateMssg(rValue, context) \n" +
                "{ \n" +
                "   getBusy = false; \n" +
                "   if(rValue!='') \n" +
                "   { \n" +
                "       var args = context.split(';');\n" +
                "       var values = rValue.split('" + SiteExportSettings.SEPARATOR + "');\n" +
                "       var messageElement = document.getElementById('" + lblProgress.ClientID + "');\n" +
                "       var errorElement = document.getElementById('" + lblError.ClientID + "');\n" +
                "       var warningElement = document.getElementById('" + lblWarning.ClientID + "');\n" +
                "       var messageText = nMessageText;\n" +
                "       messageText = values[1] + messageText.substring(messageText.length - args[1]);\n" +
                "       if(messageText.length > nMessageText.length){ nMessageText = messageElement.innerHTML = messageText; }\n" +
                "       var errorText = nErrorText;\n" +
                "       errorText = values[2] + errorText.substring(errorText.length - args[2]);\n" +
                "       if(errorText.length > nErrorText.length){ nErrorText = errorElement.innerHTML = errorText; }\n" +
                "       var warningText = nWarningText;\n" +
                "       warningText = values[3] + warningText.substring(warningText.length - args[3]);\n" +
                "       if(warningText.length > nWarningText.length){ nWarningText = warningElement.innerHTML = warningText; }\n" +
                "       if((values=='') || (values[0]=='F')) \n" +
                "       { \n" +
                "           StopImportStateTimer(); \n" +
                "           if (!document.importCancelled) { \n" +
                "              if(values[2] == '') { \n" +
                "                  BTN_Enable('" + NextButton.ClientID + "'); \n" +
                "              } \n" +
                "              else { \n" +
                "                  BTN_Enable('" + PreviousButton.ClientID + "'); \n" +
                "              } \n" +
                "              BTN_Disable('" + CancelButton.ClientID + "'); \n" +
                "           } \n" +
                "       } \n" +
                "   } \n" +
                "} \n";

            // Register the script to perform get flags for showing buttons retrieval callback
            ScriptHelper.RegisterClientScriptBlock(this, GetType(), "GetSetImportState", ScriptHelper.GetScript(script));

            // Add cancel button attribute
            CancelButton.Attributes.Add("onclick",
                                        "BTN_Disable('" + CancelButton.ClientID + "'); " +
                                        "CancelImport();" +
                                        ((wzdImport.ActiveStepIndex == 3) ? string.Empty : "BTN_Enable('" + PreviousButton.ClientID + "'); ") +
                                        "document.importCancelled = true;return false;"
                                        );

            wzdImport.NextButtonClick     += wzdImport_NextButtonClick;
            wzdImport.PreviousButtonClick += wzdImport_PreviousButtonClick;
            wzdImport.FinishButtonClick   += wzdImport_FinishButtonClick;
        }
    }