protected void Page_Load(object sender, EventArgs e) { // Check permissions string permissionName = IsBackupMode ? "BackupObjects" : "ExportObjects"; if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.globalpermissions", permissionName, SiteContext.CurrentSiteName)) { RedirectToAccessDenied("cms.globalpermissions", permissionName); } // Register script for pendingCallbacks repair ScriptHelper.FixPendingCallbacks(Page); // Async control events binding ucAsyncControl.OnFinished += ucAsyncControl_OnFinished; ucAsyncControl.OnError += ucAsyncControl_OnError; if (!RequestHelper.IsCallback()) { try { // Clean previous export files up ExportProvider.DeleteTemporaryFiles(); } catch (Exception ex) { DisplayError(ex); } SetTitle(GetString(IsBackupMode ? "BackupObject.Title" : "ExportObject.Title")); btnOk.ResourceString = IsBackupMode ? "General.backup" : "General.export"; btnOk.Click += btnOk_Click; // Display BETA warning lblBeta.Visible = CMSVersion.IsBetaVersion(); lblBeta.Text = String.Format(GetString("export.BETAwarning"), CMSVersion.GetFriendlySystemVersion(false)); string errorMessage = ValidateExportObject(); if (!String.IsNullOrEmpty(errorMessage)) { plcExportDetails.Visible = false; btnOk.Enabled = false; ShowError(errorMessage); } else { // Check permissions CheckObjectPermissions(); lblIntro.Text = String.Format(GetString(IsBackupMode ? "BackupObject.Intro" : "ExportObject.Intro"), ExportedObjectDisplayName); if (!RequestHelper.IsPostBack()) { lblIntro.Visible = true; txtFileName.Text = GetExportFileName(ExportedObjectInfo, IsBackupMode); } } } }
static void Main(string[] args) { string packagePath = args[0] ?? ""; string userName = args[1] ?? ""; string applicationPath = args[2] ?? ""; bool moduleExport = false; string moduleName = ""; if (string.IsNullOrEmpty(packagePath)) { Console.Error.WriteLine("No package path provided"); return; } if (string.IsNullOrEmpty(applicationPath)) { Console.Error.WriteLine("No main application path provided"); return; } //Initialize Kentico API for external application CMSApplication.Init(); SystemContext.WebApplicationPhysicalPath = applicationPath; ImportModule(packagePath, userName); ImportObject(packagePath, userName); string objectType = ""; int objectID = 0; SiteExportSettings siteExportSettings = new SiteExportSettings(UserInfoProvider.GetUserInfo(userName)) { WebsitePath = SystemContext.WebApplicationPhysicalPath, TargetPath = packagePath + "Export", CreatePackage = true, TargetFileName = $"ExportPackage_{DateTime.Now.ToString()}", TemporaryFilesPath = "/path", }; //switch on one object vs global object selection var selectedObjects = ObjectSelections(objectType); if (objectID > 0) { var singleObject = SingleObjectSelection(objectID, selectedObjects); siteExportSettings.Select(singleObject.TypeInfo.ObjectType, singleObject.TypeInfo.ObjectClassName, singleObject.TypeInfo.IsSiteObject); } if (moduleExport) { siteExportSettings.SetInfo(ImportExportHelper.MODULE_NAME, moduleName); } siteExportSettings.Select(selectedObjects.TypeInfo.ObjectType, selectedObjects.TypeInfo.ObjectClassName, selectedObjects.TypeInfo.IsSiteObject); //Preset for global object selection siteExportSettings.SelectGlobalObjects(new List <string>(), ""); // Make sure no data is in temp folder (possibly from previous unsuccessful export) ExportProvider.DeleteTemporaryFiles(siteExportSettings, true); ExportManager exportManager = new ExportManager(siteExportSettings); exportManager.Export(null); //Cleanup ExportProvider.DeleteTemporaryFiles(siteExportSettings, true); return; }
private void wzdExport_NextButtonClick(object sender, WizardNavigationEventArgs e) { switch (e.CurrentStepIndex) { case 0: // Apply settings if (!configExport.ApplySettings()) { e.Cancel = true; return; } // Update settings ExportSettings = configExport.Settings; if (!configExport.ExportHistory) { ltlScriptAfter.Text = ScriptHelper.GetScript( @"var actDiv = document.getElementById('actDiv'); if (actDiv != null) { actDiv.style.display='block'; } var buttonsDiv = document.getElementById('buttonsDiv'); if (buttonsDiv != null) { buttonsDiv.disabled=true; } BTN_Disable('" + NextButton.ClientID + @"'); StartSelectionTimer();"); // Select objects asynchronously ctrlAsyncSelection.RunAsync(SelectObjects, WindowsIdentity.GetCurrent()); e.Cancel = true; } else { pnlExport.Settings = ExportSettings; pnlExport.ReloadData(); wzdExport.ActiveStepIndex = e.NextStepIndex; } break; case 1: // Apply settings if (!pnlExport.ApplySettings()) { e.Cancel = true; return; } ExportSettings = pnlExport.Settings; // Delete temporary files try { ExportProvider.DeleteTemporaryFiles(ExportSettings, true); } catch (Exception ex) { SetErrorLabel(ex.Message); e.Cancel = true; return; } try { // Save export history ExportHistoryInfo history = new ExportHistoryInfo { ExportDateTime = DateTime.Now, ExportFileName = ExportSettings.TargetFileName, ExportSettings = ExportSettings.GetXML(), ExportSiteID = ExportSettings.SiteId, ExportUserID = MembershipContext.AuthenticatedUser.UserID }; ExportHistoryInfoProvider.SetExportHistoryInfo(history); } catch (Exception ex) { SetErrorLabel(ex.Message); pnlError.ToolTip = EventLogProvider.GetExceptionLogMessage(ex); e.Cancel = true; return; } if (ExportSettings.SiteId > 0) { ExportSettings.EventLogSource = String.Format(ExportSettings.GetAPIString("ExportSite.EventLogSiteSource", "Export '{0}' site"), ResHelper.LocalizeString(ExportSettings.SiteInfo.DisplayName)); } // Start asynchronous export var manager = ExportManager; ExportSettings.LogContext = ctlAsyncExport.CurrentLog; manager.Settings = ExportSettings; ctlAsyncExport.RunAsync(manager.Export, WindowsIdentity.GetCurrent()); wzdExport.ActiveStepIndex = e.NextStepIndex; break; } }
protected void Page_Load(object sender, EventArgs e) { // Register script for pendingCallbacks repair ScriptHelper.FixPendingCallbacks(Page); // Handle export settings if (!RequestHelper.IsCallback() && !RequestHelper.IsPostBack()) { ExportSettings = GetNewSettings(); } if (!RequestHelper.IsCallback()) { // Display BETA warning lblBeta.Visible = CMSVersion.IsBetaVersion(); lblBeta.Text = string.Format(GetString("export.BETAwarning"), CMSVersion.GetFriendlySystemVersion(false)); bool notTargetPermissions = false; bool notTempPermissions = false; ctrlAsyncSelection.OnFinished += CtrlAsyncSelectionOnFinished; ctrlAsyncSelection.OnError += CtrlAsyncSelectionOnError; ctlAsyncExport.OnCancel += ctlAsyncExport_OnCancel; // 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; } catch (IOExceptions.IOException ex) { pnlWrapper.Visible = false; SetAlertLabel(lblErrorBlank, ex.Message); return; } try { DirectoryHelper.EnsureDiskPath(ExportSettings.TemporaryFilesPath + "\\temp.file", ExportSettings.WebsitePath); notTempPermissions = !DirectoryHelper.CheckPermissions(ExportSettings.TemporaryFilesPath, true, true, false, false); } catch (UnauthorizedAccessException) { notTempPermissions = true; } catch (IOExceptions.IOException ex) { pnlWrapper.Visible = false; SetAlertLabel(lblErrorBlank, ex.Message); return; } } if (notTargetPermissions || notTempPermissions) { string folder = (notTargetPermissions) ? ExportSettings.TargetPath : ExportSettings.TemporaryFilesPath; pnlWrapper.Visible = false; pnlPermissions.Visible = true; SetAlertLabel(lblErrorBlank, String.Format(GetString("ExportSite.ErrorPermissions"), folder, WindowsIdentity.GetCurrent().Name)); lnkPermissions.Target = "_blank"; lnkPermissions.Text = GetString("Install.ErrorPermissions"); lnkPermissions.NavigateUrl = DocumentationHelper.GetDocumentationTopicUrl(HELP_TOPIC_DISKPERMISSIONS_LINK); } else { // Try to delete temporary files from previous export if (!RequestHelper.IsPostBack()) { try { ExportProvider.DeleteTemporaryFiles(ExportSettings, false); } catch (Exception ex) { pnlWrapper.Visible = false; SetAlertLabel(lblErrorBlank, GetString("ImportSite.ErrorDeletionTemporaryFiles") + " " + ex.Message); return; } } ControlsHelper.EnsureScriptManager(Page).EnablePageMethods = true; // Javascript functions string script = String.Format( @" function Finished(sender) {{ var errorElement = document.getElementById('{2}'); var errorText = sender.getErrors(); if (errorText != '') {{ errorElement.innerHTML = errorText; document.getElementById('{4}').style.removeProperty('display'); }} var warningElement = document.getElementById('{3}'); var warningText = sender.getWarnings(); if (warningText != '') {{ warningElement.innerHTML = warningText; document.getElementById('{5}').style.removeProperty('display'); }} var actDiv = document.getElementById('actDiv'); if (actDiv != null) {{ actDiv.style.display = 'none'; }} BTN_Disable('{0}'); BTN_Enable('{1}'); }} ", CancelButton.ClientID, FinishButton.ClientID, lblError.LabelClientID, lblWarning.LabelClientID, pnlError.ClientID, pnlWarning.ClientID ); // Register the script to perform get flags for showing buttons retrieval callback ScriptHelper.RegisterClientScriptBlock(this, GetType(), "Finished", ScriptHelper.GetScript(script)); // Add cancel button attribute CancelButton.Attributes.Add("onclick", ctlAsyncExport.GetCancelScript(true) + "return false;"); wzdExport.NextButtonClick += wzdExport_NextButtonClick; wzdExport.PreviousButtonClick += wzdExport_PreviousButtonClick; wzdExport.FinishButtonClick += wzdExport_FinishButtonClick; if (!RequestHelper.IsPostBack()) { configExport.InitControl(); } } } }
protected void Page_Load(object sender, EventArgs e) { backup = QueryHelper.GetBoolean("backup", false); // Check permissions if (backup) { if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.globalpermissions", "BackupObjects", CMSContext.CurrentSiteName)) { RedirectToCMSDeskAccessDenied("cms.globalpermissions", "BackupObjects"); } } else if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.globalpermissions", "ExportObjects", CMSContext.CurrentSiteName)) { RedirectToCMSDeskAccessDenied("cms.globalpermissions", "ExportObjects"); } // Register script for pendingCallbacks repair ScriptHelper.FixPendingCallbacks(Page); // Async control events binding ucAsyncControl.OnFinished += ucAsyncControl_OnFinished; ucAsyncControl.OnError += ucAsyncControl_OnError; if (!IsCallback) { try { // Delete temporary files ExportProvider.DeleteTemporaryFiles(); } catch (Exception ex) { DisplayError(ex); } if (backup) { SetTitle("CMSModules/CMS_ImportExport/backupobject.png", GetString("BackupObject.Title"), null, null); } else { SetTitle("CMSModules/CMS_ImportExport/exportobject.png", GetString("ExportObject.Title"), null, null); } // Display BETA warning lblBeta.Visible = CMSContext.IsBetaVersion(); lblBeta.Text = string.Format(GetString("export.BETAwarning"), CMSContext.GetFriendlySystemVersion(false)); // Get data from parameters objectId = ValidationHelper.GetInteger(Request.QueryString["objectId"], 0); objectType = ValidationHelper.GetString(Request.QueryString["objectType"], ""); // Get the object infoObj = CMSObjectHelper.GetReadOnlyObject(objectType); if (infoObj == null) { plcExportDetails.Visible = false; lblIntro.Text = GetString("ExportObject.ObjectTypeNotFound"); lblIntro.CssClass = "ErrorLabel"; return; } // Get exported object exportObj = infoObj.GetObject(objectId); if (exportObj == null) { plcExportDetails.Visible = false; lblIntro.Text = GetString("ExportObject.ObjectNotFound"); lblIntro.CssClass = "ErrorLabel"; btnOk.Visible = false; return; } // Store display name exportObjectDisplayName = HTMLHelper.HTMLEncode(exportObj.ObjectDisplayName); if (backup) { lblIntro.Text = string.Format(GetString("BackupObject.Intro"), ResHelper.LocalizeString(exportObjectDisplayName)); } else { lblIntro.Text = string.Format(GetString("ExportObject.Intro"), ResHelper.LocalizeString(exportObjectDisplayName)); } btnOk.Click += btnOk_Click; if (!RequestHelper.IsPostBack()) { lblIntro.Visible = true; lblFileName.Visible = true; txtFileName.Text = GetExportFileName(exportObj, backup); if (backup) { btnOk.Text = GetString("General.backup"); } else { btnOk.Text = GetString("General.export"); } btnCancel.Text = GetString("General.Close"); } string path = null; if (backup) { path = ImportExportHelper.GetObjectBackupFolder(exportObj); targetFolder = Server.MapPath(path); targetUrl = ResolveUrl(path) + "/" + txtFileName.Text; } else { targetFolder = ImportExportHelper.GetSiteUtilsFolder() + "Export"; path = ImportExportHelper.GetSiteUtilsFolderRelativePath(); if (path != null) { string externalUrl = null; string fullPath = path + "Export/" + txtFileName.Text; // Handle external storage URL if (StorageHelper.IsExternalStorage(fullPath)) { externalUrl = File.GetFileUrl(fullPath, CMSContext.CurrentSiteName); } // Ensure default target URL if not set if (string.IsNullOrEmpty(externalUrl)) { targetUrl = ResolveUrl(path) + "Export/" + txtFileName.Text; } else { targetUrl = externalUrl; } } else { targetUrl = null; } } } }
protected void Page_Load(object sender, EventArgs e) { var currentSiteName = SiteContext.CurrentSiteName; if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.globalpermissions", "RestoreObjects", currentSiteName)) { RedirectToAccessDenied("cms.globalpermissions", "RestoreObjects"); } // Register script for pendingCallbacks repair ScriptHelper.FixPendingCallbacks(Page); // Async control events binding ucAsyncControl.OnFinished += ucAsyncControl_OnFinished; ucAsyncControl.OnError += ucAsyncControl_OnError; if (!RequestHelper.IsCallback()) { try { // Delete temporary files ExportProvider.DeleteTemporaryFiles(); } catch (Exception ex) { DisplayError(ex); } SetTitle(GetString("RestoreObject.Title")); // Get data from parameters siteId = QueryHelper.GetInteger("siteId", 0); objectId = QueryHelper.GetInteger("objectId", 0); objectType = QueryHelper.GetString("objectType", ""); // Get the object infoObj = ModuleManager.GetReadOnlyObject(objectType); if (infoObj == null) { lblIntro.Text = GetString("ExportObject.ObjectTypeNotFound"); lblIntro.CssClass = "ErrorLabel"; return; } // Get exported object exportObj = infoObj.GetObject(objectId); if (exportObj == null) { lblIntro.Text = GetString("ExportObject.ObjectNotFound"); lblIntro.CssClass = "ErrorLabel"; btnRestore.Visible = false; return; } if (!CheckSpecialSecurityCases(exportObj)) { return; } if (!CurrentUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)) { if (!exportObj.CheckPermissions(PermissionsEnum.Modify, CurrentSiteName, CurrentUser)) { RedirectToAccessDenied(exportObj.TypeInfo.ModuleName, PermissionsEnum.Modify.ToString()); } } // Store display name exportObjectDisplayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(exportObj.ObjectDisplayName)); codeName = exportObj.ObjectCodeName; lblIntro.Text = string.Format(GetString("RestoreObject.Intro"), exportObjectDisplayName); targetFolder = ImportExportHelper.GetObjectBackupFolder(exportObj); btnRestore.Click += btnRestore_Click; if (!RequestHelper.IsPostBack()) { lblIntro.Visible = true; // Load the available backups if (lstImports.Items.Count == 0) { RefreshPackageList(); } } } }
protected void Page_Load(object sender, EventArgs e) { if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.globalpermissions", "RestoreObjects", CMSContext.CurrentSiteName)) { RedirectToCMSDeskAccessDenied("cms.globalpermissions", "RestoreObjects"); } // Register script for pendingCallbacks repair ScriptHelper.FixPendingCallbacks(Page); imgDelete.ImageUrl = GetImageUrl("Design/Controls/EditModeButtons/delete.png"); // Async control events binding ucAsyncControl.OnFinished += ucAsyncControl_OnFinished; ucAsyncControl.OnError += ucAsyncControl_OnError; if (!IsCallback) { try { // Delete temporary files ExportProvider.DeleteTemporaryFiles(); } catch (Exception ex) { DisplayError(ex); } SetTitle("CMSModules/CMS_ImportExport/restoreobject.png", GetString("RestoreObject.Title"), null, null); // Get data from parameters siteId = ValidationHelper.GetInteger(Request.QueryString["siteId"], 0); objectId = ValidationHelper.GetInteger(Request.QueryString["objectId"], 0); objectType = ValidationHelper.GetString(Request.QueryString["objectType"], ""); // Get the object infoObj = CMSObjectHelper.GetReadOnlyObject(objectType); if (infoObj == null) { lblIntro.Text = GetString("ExportObject.ObjectTypeNotFound"); lblIntro.CssClass = "ErrorLabel"; return; } // Get exported object exportObj = infoObj.GetObject(objectId); if (exportObj == null) { lblIntro.Text = GetString("ExportObject.ObjectNotFound"); lblIntro.CssClass = "ErrorLabel"; btnOk.Visible = false; return; } // Store display name exportObjectDisplayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(exportObj.ObjectDisplayName)); codeName = exportObj.ObjectCodeName; lblIntro.Text = string.Format(GetString("RestoreObject.Intro"), exportObjectDisplayName); targetFolder = ImportExportHelper.GetObjectBackupFolder(exportObj); btnOk.Click += btnOk_Click; if (!RequestHelper.IsPostBack()) { lblIntro.Visible = true; btnOk.Text = GetString("General.Restore"); btnCancel.Text = GetString("General.Close"); // Load the available backups if (lstImports.Items.Count == 0) { RefreshPackageList(); } } } }
protected void Page_Load(object sender, EventArgs e) { backup = QueryHelper.GetBoolean("backup", false); // Check permissions if (backup) { if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.globalpermissions", "BackupObjects", SiteContext.CurrentSiteName)) { RedirectToAccessDenied("cms.globalpermissions", "BackupObjects"); } } else if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.globalpermissions", "ExportObjects", SiteContext.CurrentSiteName)) { RedirectToAccessDenied("cms.globalpermissions", "ExportObjects"); } // Register script for pendingCallbacks repair ScriptHelper.FixPendingCallbacks(Page); // Async control events binding ucAsyncControl.OnFinished += ucAsyncControl_OnFinished; ucAsyncControl.OnError += ucAsyncControl_OnError; if (!RequestHelper.IsCallback()) { try { // Delete temporary files ExportProvider.DeleteTemporaryFiles(); } catch (Exception ex) { DisplayError(ex); } if (backup) { SetTitle(GetString("BackupObject.Title")); } else { SetTitle(GetString("ExportObject.Title")); } // Display BETA warning lblBeta.Visible = CMSVersion.IsBetaVersion(); lblBeta.Text = string.Format(GetString("export.BETAwarning"), CMSVersion.GetFriendlySystemVersion(false)); // Get data from parameters objectId = QueryHelper.GetInteger("objectId", 0); objectType = QueryHelper.GetString("objectType", ""); // Get the object infoObj = ModuleManager.GetReadOnlyObject(objectType); if (infoObj == null) { plcExportDetails.Visible = false; lblIntro.Text = GetString("ExportObject.ObjectTypeNotFound"); lblIntro.CssClass = "ErrorLabel"; return; } // Get exported object exportObj = infoObj.GetObject(objectId); if (exportObj == null) { plcExportDetails.Visible = false; lblIntro.Text = GetString("ExportObject.ObjectNotFound"); lblIntro.CssClass = "ErrorLabel"; btnOk.Visible = false; return; } // Check permissions var info = (BaseInfo)exportObj; if (!CurrentUser.IsGlobalAdministrator) { try { if (info.Generalized.ObjectSiteID > 0) { CurrentUser.IsAuthorizedPerObject(PermissionsEnum.Read, info, SiteInfoProvider.GetSiteName(info.Generalized.ObjectSiteID), true); } else if ((info.TypeInfo.SiteBindingObject != null) && (info.AssignedSites[CurrentSiteName] == null)) { // Do not allow to clone objects with site binding which are not assigned to current site RedirectToAccessDenied(info.TypeInfo.ModuleName, PermissionsEnum.Read.ToString()); } else { CurrentUser.IsAuthorizedPerObject(PermissionsEnum.Read, info, CurrentSiteName, true); } } catch (PermissionCheckException ex) { RedirectToAccessDenied(ex.ModuleName, ex.PermissionFailed); } } // Store display name exportObjectDisplayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(exportObj.ObjectDisplayName)); lblIntro.Text = string.Format(GetString(backup ? "BackupObject.Intro" : "ExportObject.Intro"), exportObjectDisplayName); btnOk.Click += btnOk_Click; if (!RequestHelper.IsPostBack()) { lblIntro.Visible = true; lblFileName.Visible = true; txtFileName.Text = GetExportFileName(exportObj, backup); } btnOk.Text = GetString(backup ? "General.backup" : "General.export"); string path; if (backup) { path = ImportExportHelper.GetObjectBackupFolder(exportObj); targetFolder = Server.MapPath(path); targetUrl = ResolveUrl(path) + "/" + txtFileName.Text; } else { targetFolder = ImportExportHelper.GetSiteUtilsFolder() + "Export"; path = ImportExportHelper.GetSiteUtilsFolderRelativePath(); if (path != null) { string externalUrl = null; string fullPath = path + "Export/" + txtFileName.Text; // Handle external storage URL if (StorageHelper.IsExternalStorage(fullPath)) { externalUrl = File.GetFileUrl(fullPath, SiteContext.CurrentSiteName); } // Ensure default target URL if not set if (string.IsNullOrEmpty(externalUrl)) { targetUrl = ResolveUrl(path) + "Export/" + txtFileName.Text; } else { targetUrl = externalUrl; } } else { targetUrl = null; } } } }
private void wzdExport_NextButtonClick(object sender, WizardNavigationEventArgs e) { switch (e.CurrentStepIndex) { case 0: // Apply settings if (!configExport.ApplySettings()) { e.Cancel = true; return; } // Update settings ExportSettings = configExport.Settings; if (!configExport.ExportHistory) { ltlScriptAfter.Text = ScriptHelper.GetScript( "var actDiv = document.getElementById('actDiv'); \n" + "if (actDiv != null) { actDiv.style.display='block'; } \n" + "var buttonsDiv = document.getElementById('buttonsDiv'); if (buttonsDiv != null) { buttonsDiv.disabled=true; } \n" + "BTN_Disable('" + NextButton.ClientID + "'); \n" + "StartSelectionTimer();" ); // Select objects asynchronously ctrlAsync.RunAsync(SelectObjects, WindowsIdentity.GetCurrent()); e.Cancel = true; } else { pnlExport.Settings = ExportSettings; pnlExport.ReloadData(); } break; case 1: // Apply settings if (!pnlExport.ApplySettings()) { e.Cancel = true; return; } ExportSettings = pnlExport.Settings; // Delete temporary files try { ExportProvider.DeleteTemporaryFiles(ExportSettings, true); } catch (Exception ex) { SetErrorLabel(ex.Message); e.Cancel = true; return; } try { // Save export history ExportHistoryInfo history = new ExportHistoryInfo(); history.ExportDateTime = DateTime.Now; history.ExportFileName = ExportSettings.TargetFileName; history.ExportSettings = ExportSettings.GetXML(); history.ExportSiteID = ExportSettings.SiteId; history.ExportUserID = MembershipContext.AuthenticatedUser.UserID; ExportHistoryInfoProvider.SetExportHistoryInfo(history); } catch (Exception ex) { SetErrorLabel(ex.Message); pnlError.ToolTip = EventLogProvider.GetExceptionLogMessage(ex); e.Cancel = true; return; } // Init the Mimetype helper (required for the export) MimeTypeHelper.LoadMimeTypes(); if (ExportSettings.SiteId > 0) { ExportSettings.EventLogSource = string.Format(ExportSettings.GetAPIString("ExportSite.EventLogSiteSource", "Export '{0}' site"), ResHelper.LocalizeString(ExportSettings.SiteInfo.DisplayName)); } // Start asynchronnous export ExportManager.Settings = ExportSettings; AsyncWorker worker = new AsyncWorker(); worker.OnFinished += worker_OnFinished; worker.OnError += worker_OnError; worker.RunAsync(ExportManager.Export, WindowsIdentity.GetCurrent()); lblProgress.Text = GetString("SiteExport.PreparingExport"); break; } ReloadSteps(); wzdExport.ActiveStepIndex = e.NextStepIndex; }
protected void Page_Load(object sender, EventArgs e) { // Register script for pendingCallbacks repair ScriptHelper.FixPendingCallbacks(Page); // Handle export settings if (!RequestHelper.IsCallback() && !RequestHelper.IsPostBack()) { ExportSettings = GetNewSettings(); } if (!RequestHelper.IsCallback()) { // Display BETA warning lblBeta.Visible = CMSVersion.IsBetaVersion(); lblBeta.Text = string.Format(GetString("export.BETAwarning"), CMSVersion.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; } catch (IOExceptions.IOException ex) { pnlWrapper.Visible = false; SetErrorLabel(ex.Message); return; } try { DirectoryHelper.EnsureDiskPath(ExportSettings.TemporaryFilesPath + "\\temp.file", ExportSettings.WebsitePath); notTempPermissions = !DirectoryHelper.CheckPermissions(ExportSettings.TemporaryFilesPath, true, true, false, false); } catch (UnauthorizedAccessException) { notTempPermissions = true; } catch (IOExceptions.IOException ex) { pnlWrapper.Visible = false; SetErrorLabel(ex.Message); return; } } if (notTargetPermissions || notTempPermissions) { string folder = (notTargetPermissions) ? ExportSettings.TargetPath : ExportSettings.TemporaryFilesPath; pnlWrapper.Visible = false; SetErrorLabel(String.Format(GetString("ExportSite.ErrorPermissions"), folder, WindowsIdentity.GetCurrent().Name)); pnlPermissions.Visible = true; lnkPermissions.Target = "_blank"; lnkPermissions.Text = GetString("Install.ErrorPermissions"); lnkPermissions.NavigateUrl = UIContextHelper.GetDocumentationTopicUrl(HELP_TOPIC_DISKPERMISSIONS_LINK); } else { // Try to delete temporary files from previous export if (!RequestHelper.IsPostBack()) { try { ExportProvider.DeleteTemporaryFiles(ExportSettings, false); } catch (Exception ex) { pnlWrapper.Visible = false; SetErrorLabel(GetString("ImportSite.ErrorDeletionTemporaryFiles") + ex.Message); return; } } PortalHelper.EnsureScriptManager(Page).EnablePageMethods = true; // Javascript functions string script = @"var exMessageText = ''; var exErrorText = ''; var exWarningText = ''; var exMachineName = '" + SystemContext.MachineName.ToLowerCSafe() + @"'; 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; document.getElementById('" + pnlError.ClientID + @"').style.removeProperty('display'); } var warningText = exWarningText; warningText = values[3] + warningText.substring(warningText.length - args[3]); if (warningText.length > exWarningText.length) { exWarningText = warningElement.innerHTML = warningText; document.getElementById('" + pnlWarning.ClientID + @"').style.removeProperty('display'); } if ((values=='') || (values[0]=='F')) { StopExportStateTimer(); var actDiv = document.getElementById('actDiv'); if (actDiv != null) { actDiv.style.display = 'none'; } 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(); } } } }