/// <summary> /// Gets and bulk updates web templates. Called when the "Get and bulk update templates" button is pressed. /// Expects the CreateWebTemplate method to be run first. /// </summary> private bool GetAndBulkUpdateWebTemplates() { // Prepare the parameters string where = "WebTemplateName LIKE N'MyNewTemplate%'"; // Get the data DataSet templates = WebTemplateInfoProvider.GetWebTemplates(where, null); if (!DataHelper.DataSourceIsEmpty(templates)) { // Loop through the individual items foreach (DataRow templateDr in templates.Tables[0].Rows) { // Create object from DataRow WebTemplateInfo modifyTemplate = new WebTemplateInfo(templateDr); // Update the properties modifyTemplate.WebTemplateDisplayName = modifyTemplate.WebTemplateDisplayName.ToUpper(); // Save the changes WebTemplateInfoProvider.SetWebTemplateInfo(modifyTemplate); } return(true); } return(false); }
/// <summary> /// Creates web template. Called when the "Create template" button is pressed. /// </summary> private bool CreateWebTemplate() { // Create new web template object WebTemplateInfo newTemplate = new WebTemplateInfo(); // Set the properties newTemplate.WebTemplateDisplayName = "My new template"; newTemplate.WebTemplateName = "MyNewTemplate"; newTemplate.WebTemplateDescription = "This is web template created by API Exapmle"; newTemplate.WebTemplateFileName = "~\\App_Data\\Templates\\MyNewTemplate"; newTemplate.WebTemplateLicenses = "F;S;B;N;C;P;R;E;U;"; newTemplate.WebTemplatePackages = "ECM;SCN;ADV;DOC;"; // Set the web template order DataSet webTemplates = WebTemplateInfoProvider.GetWebTemplates(null, null, 0, "WebTemplateID", false); if (!DataHelper.DataSourceIsEmpty(webTemplates)) { newTemplate.WebTemplateOrder = webTemplates.Tables[0].Rows.Count + 1; } else { newTemplate.WebTemplateOrder = 1; } // Save the web template WebTemplateInfoProvider.SetWebTemplateInfo(newTemplate); return(true); }
protected void Page_Load(object sender, EventArgs e) { rfvWebTemplateDisplayName.ErrorMessage = GetString("Administration-WebTemplate_New.ErrorEmptyWebTemplateDisplayName"); rfvWebTemplateName.ErrorMessage = GetString("Administration-WebTemplate_New.ErrorEmptyWebTemplateName"); rfvWebTemplateFileName.ErrorMessage = GetString("Administration-PageLayout_New.ErrorEmptyWebTemplateFileName"); rfvWebTemplateDescription.ErrorMessage = GetString("Administration-PageLayout_New.ErrorEmptyWebTemplateDescription"); // Gets 'webtemplateid' from querystring webTemplateId = QueryHelper.GetInteger("webtemplateid", 0); if (!RequestHelper.IsPostBack()) { if (!string.IsNullOrEmpty(Request.QueryString["saved"])) { lblInfo.Text = GetString("General.ChangesSaved"); } } string currentWebTemplate = GetString("Administration-WebTemplate_New.CurrentWebTemplate"); string title = GetString("Administration-WebTemplate_New.NewWebTemplate"); string image = GetImageUrl("Objects/CMS_WebTemplate/new.png"); if (webTemplateId > 0) { currentWebTemplateInfo = WebTemplateInfoProvider.GetWebTemplateInfo(webTemplateId); // Set edited object EditedObject = currentWebTemplateInfo; if (currentWebTemplateInfo != null) { if (!RequestHelper.IsPostBack()) { txtWebTemplateDisplayName.Text = currentWebTemplateInfo.WebTemplateDisplayName; txtWebTemplateName.Text = currentWebTemplateInfo.WebTemplateName; txtWebTemplateFileName.Text = currentWebTemplateInfo.WebTemplateFileName; txtWebTemplateDescription.Text = currentWebTemplateInfo.WebTemplateDescription; ucLicenseSelector.Value = currentWebTemplateInfo.WebTemplateLicenses; ucLicensePackageSelector.Value = currentWebTemplateInfo.WebTemplatePackages; // Init file uploader attachmentFile.ObjectID = webTemplateId; attachmentFile.ObjectType = SiteObjectType.WEBTEMPLATE; attachmentFile.Category = MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL; } // Update title for editing currentWebTemplate = currentWebTemplateInfo.WebTemplateDisplayName; } title = GetString("Administration-WebTemplate_New.EditWebTemplate"); image = GetImageUrl("Objects/CMS_WebTemplate/object.png"); } else { lblUploadFile.Visible = false; attachmentFile.Visible = false; } // Initialize master page elements InitializeMasterPage(currentWebTemplate, title, image); }
/// <summary> /// Deletes web template. Called when the "Delete template" button is pressed. /// Expects the CreateWebTemplate method to be run first. /// </summary> private bool DeleteWebTemplate() { // Get the web template WebTemplateInfo deleteTemplate = WebTemplateInfoProvider.GetWebTemplateInfo("MyNewTemplate"); // Delete the web template WebTemplateInfoProvider.DeleteWebTemplateInfo(deleteTemplate); return(deleteTemplate != null); }
/// <summary> /// Gets and moves web template up. Called when the "Get and move template up" button is pressed. /// Expects the CreateWebTemplate method to be run first. /// </summary> private bool GetAndMoveWebTemplateUp() { // Get the web template WebTemplateInfo moveUpTemplate = WebTemplateInfoProvider.GetWebTemplateInfo("MyNewTemplate"); if (moveUpTemplate != null) { // Move template up WebTemplateInfoProvider.MoveTemplateUp(moveUpTemplate.WebTemplateId); return(true); } return(false); }
/// <summary> /// Gets and updates web template. Called when the "Get and update template" button is pressed. /// Expects the CreateWebTemplate method to be run first. /// </summary> private bool GetAndUpdateWebTemplate() { // Get the web template WebTemplateInfo updateTemplate = WebTemplateInfoProvider.GetWebTemplateInfo("MyNewTemplate"); if (updateTemplate != null) { // Update the properties updateTemplate.WebTemplateDisplayName = updateTemplate.WebTemplateDisplayName.ToLower(); // Save the changes WebTemplateInfoProvider.SetWebTemplateInfo(updateTemplate); return(true); } return(false); }
/// <summary> /// Data bind. /// </summary> public void ReloadData() { if (WebTemplateInfoProvider.IsAnyTemplatePresent()) { DataSet dsTemplates = WebTemplateInfoProvider.GetWebTemplates(null, "WebTemplateOrder", 0, null, true); if (!DataHelper.DataSourceIsEmpty(dsTemplates)) { string firstTemplateName = ""; int firstTemplateId = 0; // Find first allowed template foreach (DataRow row in dsTemplates.Tables[0].Rows) { string templateEditions = ValidationHelper.GetString(row["WebTemplateLicenses"], ""); string templatePackages = ValidationHelper.GetString(row["WebTemplatePackages"], ""); if (IsTemplateAllowed(templateEditions, templatePackages)) { firstTemplateName = ValidationHelper.GetString(row["WebTemplateName"], ""); firstTemplateId = ValidationHelper.GetInteger(row["WebTemplateID"], 0); break; } } // Bind the list rptSites.DataSource = dsTemplates; rptSites.DataBind(); // Select Corporate site by default if (string.IsNullOrEmpty(hdnLastSelected.Value) || (hdnLastSelected.Value == "0")) { ltlScriptAfter.Text += ScriptHelper.GetScript("SelectTemplate('tpl" + firstTemplateId + "','" + firstTemplateName + "');"); } } } else { plcInfo.Visible = true; lblInfo.Text = ResHelper.GetFileString("Install.TemplatesWarning"); radWizard.Enabled = false; radTemplate.Enabled = false; plcTemplates.Visible = false; radExisting.Checked = true; } }
public void ReloadData() { // Load the data DataSet templates = WebTemplateInfoProvider.GetWebTemplates(null, "WebTemplateOrder", 0, "WebTemplateID,WebTemplateDisplayName,WebTemplateDescription,WebTemplateFileName", true); ucSelector.DataSource = templates; ucSelector.IDColumn = "WebTemplateID"; ucSelector.DisplayNameColumn = "WebTemplateDisplayName"; ucSelector.DescriptionColumn = "WebTemplateDescription"; if (ucSelector.SelectedId == 0) { if (!DataHelper.DataSourceIsEmpty(templates)) { int firstTemplateId = ValidationHelper.GetInteger(templates.Tables[0].Rows[0]["WebTemplateID"], 0); ucSelector.SelectedId = firstTemplateId; } } ucSelector.DataBind(); }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that threw event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void UniGridModules_OnAction(string actionName, object actionArgument) { if (actionName == "edit") { URLHelper.Redirect("WebTemplate_Edit.aspx?webtemplateid=" + actionArgument); } else if (actionName == "delete") { WebTemplateInfoProvider.DeleteWebTemplateInfo(ValidationHelper.GetInteger(actionArgument, 0)); } else if (actionName == "moveup") { // Move the item up in order WebTemplateInfoProvider.MoveTemplateUp(ValidationHelper.GetInteger(actionArgument, 0)); UniGridModules.ReloadData(); } else if (actionName == "movedown") { // Move the item down in order WebTemplateInfoProvider.MoveTemplateDown(ValidationHelper.GetInteger(actionArgument, 0)); UniGridModules.ReloadData(); } }
protected void wzdImport_NextButtonClick(object sender, WizardNavigationEventArgs e) { var settings = ImportSettings; ClearErrorLabel(); switch (e.CurrentStepIndex) { // Import type case 0: { if (!siteType.SelectTemplate) { try { // Get blank web template WebTemplateInfo wi = WebTemplateInfoProvider.GetWebTemplateInfo("BlankSite"); if (wi == null) { e.Cancel = true; return; } WebTemplateID = wi.WebTemplateId; string path = Server.MapPath(wi.WebTemplateFileName); if (File.Exists(path + "\\template.zip")) { // Template from zip file path += "\\" + ZipStorageProvider.GetZipFileName("template.zip"); settings.TemporaryFilesPath = path; settings.SourceFilePath = path; settings.TemporaryFilesCreated = true; settings.RefreshMacroSecurity = true; } else { // Init the settings settings.TemporaryFilesCreated = false; settings.SourceFilePath = Server.MapPath(wi.WebTemplateFileName); settings.RefreshMacroSecurity = true; } if (!File.Exists(settings.SourceFilePath)) { try { ImportProvider.CreateTemporaryFiles(settings); } catch (Exception ex) { SetErrorLabel(ex.Message); e.Cancel = true; return; } } // Import all, but only add new data settings.ImportType = ImportTypeEnum.AllNonConflicting; settings.ImportOnlyNewObjects = true; settings.CopyFiles = false; // Allow bulk inserts for faster import, web templates must be consistent enough to allow this without collisions settings.AllowBulkInsert = true; 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();" ); // Preselect objects asynchronously ctrlAsyncSelection.Parameter = "N"; ctrlAsyncSelection.RunAsync(SelectObjects, WindowsIdentity.GetCurrent()); e.Cancel = true; } catch (Exception ex) { SetErrorLabel(ex.Message); e.Cancel = true; return; } } else { siteDetails.SiteName = null; siteDetails.SiteDisplayName = null; selectTemplate.ReloadData(); } wzdImport.ActiveStepIndex++; } break; // Template selection case 1: { if (!selectTemplate.ApplySettings()) { e.Cancel = true; return; } // Init the settings WebTemplateInfo wi = WebTemplateInfoProvider.GetWebTemplateInfo(selectTemplate.WebTemplateId); if (wi == null) { throw new Exception("Web template not found."); } settings.IsWebTemplate = true; string path = Server.MapPath(wi.WebTemplateFileName); if (File.Exists(path + "\\template.zip")) { // Template from zip file path += "\\" + ZipStorageProvider.GetZipFileName("template.zip"); settings.TemporaryFilesPath = path; settings.SourceFilePath = path; settings.TemporaryFilesCreated = true; settings.RefreshMacroSecurity = true; } else { // Template from folder settings.TemporaryFilesCreated = false; settings.SourceFilePath = path; settings.RefreshMacroSecurity = true; try { ImportProvider.CreateTemporaryFiles(settings); } catch (Exception ex) { SetErrorLabel(ex.Message); e.Cancel = true; return; } } // Import all, but only add new data settings.ImportType = ImportTypeEnum.AllNonConflicting; settings.ImportOnlyNewObjects = true; settings.CopyFiles = false; // Allow bulk inserts for faster import, web templates must be consistent enough to allow this without collisions settings.AllowBulkInsert = true; ltlScriptAfter.Text = ScriptHelper.GetScript( "var actDiv = document.getElementById('actDiv');\n" + "if (actDiv != null) { actDiv.style.display='block'; }\n" + "var buttonsDiv = document.getElementById('buttonsDiv');\n" + "if (buttonsDiv != null) { buttonsDiv.disabled=true; }\n" + "BTN_Disable('" + NextButton.ClientID + "');\n" + "BTN_Disable('" + PreviousButton.ClientID + "');\n" + "StartSelectionTimer();" ); // Preselect objects asynchronously ctrlAsyncSelection.Parameter = "T"; ctrlAsyncSelection.RunAsync(SelectObjects, WindowsIdentity.GetCurrent()); e.Cancel = true; } break; // Site details case 2: if (!siteDetails.ApplySettings()) { e.Cancel = true; return; } // Update settings ImportSettings = siteDetails.Settings; if (!siteType.SelectTemplate && (ImportSettings.SiteName == InfoHelper.CODENAME_AUTOMATIC)) { ImportSettings.SiteName = ValidationHelper.GetCodeName(settings.SiteDisplayName); } Culture = siteDetails.Culture; pnlImport.ReloadData(true); wzdImport.ActiveStepIndex++; break; // Objects selection case 3: if (!pnlImport.ApplySettings()) { e.Cancel = true; return; } // Check licenses string error = ImportExportControl.CheckLicenses(settings); if (!string.IsNullOrEmpty(error)) { SetErrorLabel(error); e.Cancel = true; return; } ImportSettings = pnlImport.Settings; PreviousButton.Enabled = false; NextButton.Enabled = false; SiteName = settings.SiteName; Domain = settings.SiteDomain; // Start asynchronous Import settings.SetSettings(ImportExportHelper.SETTINGS_DELETE_TEMPORARY_FILES, false); settings.DefaultProcessObjectType = ProcessObjectEnum.Selected; var manager = ImportManager; settings.LogContext = ctlAsyncImport.CurrentLog; manager.Settings = settings; // Import site asynchronously ctlAsyncImport.RunAsync(ImportManager.Import, WindowsIdentity.GetCurrent()); wzdImport.ActiveStepIndex++; break; // Import progress case 4: PreviousButton.Visible = false; CultureHelper.SetPreferredCulture(Culture); if (siteType.SelectTemplate) { // Done finishSite.Domain = Domain; finishSite.SiteIsRunning = SiteIsRunning; wzdImport.ActiveStepIndex = 6; } else { if (ImportManager.Settings.IsWarning()) { try { // Convert default culture TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); tree.ChangeSiteDefaultCulture(SiteName, Culture, "en-US"); // Change root GUID TreeNode root = DocumentHelper.GetDocument(SiteName, "/", Culture, false, SystemDocumentTypes.Root, null, null, 1, false, null, tree); if (root != null) { root.NodeGUID = Guid.NewGuid(); DocumentHelper.UpdateDocument(root, tree); } } catch (Exception ex) { EventLogProvider.LogException("NewSiteWizard", "FINISH", ex); SetErrorLabel(ex.Message); e.Cancel = true; NextButton.Enabled = false; CancelButton.Enabled = false; mImportCanceled = true; return; } } selectMaster.SiteName = SiteName; selectMaster.ReloadData(); } break; case 5: if (!selectMaster.ApplySettings()) { e.Cancel = true; return; } finishSite.Domain = Domain; finishSite.SiteIsRunning = SiteIsRunning; break; // Other steps default: wzdImport.ActiveStepIndex = e.NextStepIndex; break; } }
protected void Page_Load(object sender, EventArgs e) { // Register script for pendingCallbacks repair ScriptHelper.FixPendingCallbacks(Page); // Handle Import settings if (!RequestHelper.IsCallback() && !RequestHelper.IsPostBack()) { // Check if any template is present on the disk if (!WebTemplateInfoProvider.IsAnyTemplatePresent()) { selectTemplate.StopProcessing = true; pnlWrapper.Visible = false; ShowError(GetString("NewSite.NoWebTemplate")); } // Initialize import settings ImportSettings = new SiteImportSettings(MembershipContext.AuthenticatedUser); ImportSettings.WebsitePath = Server.MapPath("~/"); ImportSettings.PersistentSettingsKey = PersistentSettingsKey; } if (RequestHelper.IsCallback()) { // Stop processing when callback selectTemplate.StopProcessing = true; selectMaster.StopProcessing = true; } else { selectTemplate.StopProcessing = (!CausedPostback(PreviousButton) || (wzdImport.ActiveStepIndex != 2)) && (wzdImport.ActiveStepIndex != 1); selectMaster.StopProcessing = (wzdImport.ActiveStepIndex != 5); PreviousButton.Enabled = true; PreviousButton.Visible = (wzdImport.ActiveStepIndex <= 4); NextButton.Enabled = true; // Bind async controls events ctrlAsyncSelection.OnFinished += ctrlAsyncSelection_OnFinished; ctrlAsyncSelection.OnError += ctrlAsyncSelection_OnError; ctlAsyncImport.OnCancel += ctlAsyncImport_OnCancel; ctlAsyncImport.OnFinished += ctlAsyncImport_OnFinished; if (wzdImport.ActiveStepIndex < 4) { siteDetails.Settings = ImportSettings; pnlImport.Settings = ImportSettings; } // 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}'); if ((errorText == null) || (errorText == '')) {{ BTN_Enable('{6}'); }} }} ", CancelButton.ClientID, FinishButton.ClientID, lblError.LabelClientID, lblWarning.LabelClientID, pnlError.ClientID, pnlWarning.ClientID, NextButton.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", ctlAsyncImport.GetCancelScript(true) + "return false;"); wzdImport.NextButtonClick += wzdImport_NextButtonClick; wzdImport.PreviousButtonClick += wzdImport_PreviousButtonClick; wzdImport.FinishButtonClick += wzdImport_FinishButtonClick; } }
/// <summary> /// Handles btnOK's OnClick event - Update web template info DB. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Finds whether required fields are not empty string result = new Validator().NotEmpty(txtWebTemplateDisplayName.Text, GetString("Administration-WebTemplate_New.ErrorEmptyWebTemplateDisplayName")) .NotEmpty(txtWebTemplateName.Text, GetString("Administration-WebTemplate_New.ErrorEmptyWebTemplateName")) .NotEmpty(txtWebTemplateFileName.Text, GetString("Administration-PageLayout_New.ErrorEmptyWebTemplateFileName")) .NotEmpty(txtWebTemplateDescription.Text, GetString("Administration-PageLayout_New.ErrorEmptyWebTemplateDescription")).Result; if (!ucLicenseSelector.IsValid()) { result = GetString("Administration-WebTemplate_New.ErrorEmptyWebTemplateNameLicenses"); } if (result == string.Empty) { WebTemplateInfo wi = WebTemplateInfoProvider.GetWebTemplateInfo(txtWebTemplateName.Text); // Check if entered code name is unique if (wi == null || wi.WebTemplateId == webTemplateId) { // New web template info if ((wi == null) && (currentWebTemplateInfo == null)) { wi = new WebTemplateInfo(); DataSet ds = WebTemplateInfoProvider.GetWebTemplates(null, null, 0, "WebTemplateID", false); if (!DataHelper.DataSourceIsEmpty(ds)) { wi.WebTemplateOrder = ds.Tables[0].Rows.Count + 1; } else { wi.WebTemplateOrder = 1; } } // Current template info else { wi = currentWebTemplateInfo; } wi.WebTemplateId = webTemplateId; wi.WebTemplateDisplayName = txtWebTemplateDisplayName.Text; wi.WebTemplateName = txtWebTemplateName.Text; wi.WebTemplateDescription = txtWebTemplateDescription.Text; wi.WebTemplateFileName = txtWebTemplateFileName.Text; wi.WebTemplateLicenses = (string)ucLicenseSelector.Value; wi.WebTemplatePackages = (string)ucLicensePackageSelector.Value; try { WebTemplateInfoProvider.SetWebTemplateInfo(wi); URLHelper.Redirect("WebTemplate_Edit.aspx?webtemplateid=" + wi.WebTemplateId + "&saved=1"); } catch (Exception ex) { // WebTemplateInfoProvider doesn't make any unique controls ShowError(GetString("general.saveerror"), ex.Message, null); } } else { ShowError(GetString("Administration-WebTemplate_New.ErrorWebTemplateNameNotUnique")); } } else { ShowError(result); } }
protected void wzdImport_NextButtonClick(object sender, WizardNavigationEventArgs e) { switch (e.CurrentStepIndex) { // Import type case 0: { if (!siteType.SelectTemplate) { try { // Get blank web template WebTemplateInfo wi = WebTemplateInfoProvider.GetWebTemplateInfo("BlankSite"); if (wi == null) { e.Cancel = true; return; } WebTemplateID = wi.WebTemplateId; string path = Server.MapPath(wi.WebTemplateFileName); if (File.Exists(path + "\\template.zip")) { // Template from zip file path += "\\" + ZipStorageProvider.GetZipFileName("template.zip"); ImportSettings.TemporaryFilesPath = path; ImportSettings.SourceFilePath = path; ImportSettings.TemporaryFilesCreated = true; ImportSettings.RefreshMacroSecurity = true; } else { // Init the settings ImportSettings.TemporaryFilesCreated = false; ImportSettings.SourceFilePath = Server.MapPath(wi.WebTemplateFileName); ImportSettings.RefreshMacroSecurity = true; } if (!File.Exists(ImportSettings.SourceFilePath)) { try { ImportProvider.CreateTemporaryFiles(ImportSettings); } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; e.Cancel = true; return; } } if (SiteInfoProvider.GetSitesCount() == 0) { // No site exists, overwrite all ImportSettings.ImportType = ImportTypeEnum.All; ImportSettings.CopyFiles = false; } else { // Some site exists, only new objects ImportSettings.ImportType = ImportTypeEnum.New; } 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();" ); // Preselect objects asynchronously ctrlAsync.Parameter = "N"; ctrlAsync.RunAsync(SelectObjects, WindowsIdentity.GetCurrent()); e.Cancel = true; } catch (Exception ex) { lblError.Text = ex.Message; e.Cancel = true; return; } } else { siteDetails.SiteName = null; siteDetails.SiteDisplayName = null; selectTemplate.ReloadData(); } wzdImport.ActiveStepIndex++; } break; // Template selection case 1: { if (!selectTemplate.ApplySettings()) { e.Cancel = true; return; } // Init the settings WebTemplateInfo wi = WebTemplateInfoProvider.GetWebTemplateInfo(selectTemplate.WebTemplateId); if (wi == null) { throw new Exception("Web template not found."); } ImportSettings.IsWebTemplate = true; string path = Server.MapPath(wi.WebTemplateFileName); if (File.Exists(path + "\\template.zip")) { // Template from zip file path += "\\" + ZipStorageProvider.GetZipFileName("template.zip"); ImportSettings.TemporaryFilesPath = path; ImportSettings.SourceFilePath = path; ImportSettings.TemporaryFilesCreated = true; ImportSettings.RefreshMacroSecurity = true; } else { // Template from folder ImportSettings.TemporaryFilesCreated = false; ImportSettings.SourceFilePath = path; ImportSettings.RefreshMacroSecurity = true; try { ImportProvider.CreateTemporaryFiles(ImportSettings); } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; e.Cancel = true; return; } } if (SiteInfoProvider.GetSitesCount() == 0) { // No site exists, overwrite all ImportSettings.ImportType = ImportTypeEnum.All; } else { // Some site exists, only new objects ImportSettings.ImportType = ImportTypeEnum.New; } ltlScriptAfter.Text = ScriptHelper.GetScript( "var actDiv = document.getElementById('actDiv');\n" + "if (actDiv != null) { actDiv.style.display='block'; }\n" + "var buttonsDiv = document.getElementById('buttonsDiv');\n" + "if (buttonsDiv != null) { buttonsDiv.disabled=true; }\n" + "BTN_Disable('" + NextButton.ClientID + "');\n" + "BTN_Disable('" + PreviousButton.ClientID + "');\n" + "StartSelectionTimer();" ); // Preselect objects asynchronously ctrlAsync.Parameter = "T"; ctrlAsync.RunAsync(SelectObjects, WindowsIdentity.GetCurrent()); e.Cancel = true; } break; // Site details case 2: if (!siteDetails.ApplySettings()) { e.Cancel = true; return; } // Update settings ImportSettings = siteDetails.Settings; Culture = siteDetails.Culture; pnlImport.ReloadData(true); wzdImport.ActiveStepIndex++; break; // Objects selection case 3: if (!pnlImport.ApplySettings()) { e.Cancel = true; return; } // Check licences string error = ImportExportControl.CheckLicenses(ImportSettings); if (!string.IsNullOrEmpty(error)) { lblError.Text = error; e.Cancel = true; return; } ImportSettings = pnlImport.Settings; PreviousButton.Enabled = false; NextButton.Enabled = false; SiteName = ImportSettings.SiteName; Domain = ImportSettings.SiteDomain; // Init the Mimetype helper (required for the Import) MimeTypeHelper.LoadMimeTypes(); // Start asynchronnous Import ImportSettings.SetSettings(ImportExportHelper.SETTINGS_DELETE_TEMPORARY_FILES, false); ImportSettings.DefaultProcessObjectType = ProcessObjectEnum.Selected; ImportManager.Settings = ImportSettings; // Import site asynchronously ctrlImport.RunAsync(ImportManager.Import, WindowsIdentity.GetCurrent()); ctrlImport.PostbackOnError = false; ltlScript.Text = ScriptHelper.GetScript("StartImportStateTimer();"); wzdImport.ActiveStepIndex++; break; // Import progress case 4: PreviousButton.Visible = false; CultureHelper.SetPreferredCulture(Culture); if (siteType.SelectTemplate) { // Done finishSite.Domain = Domain; finishSite.SiteIsRunning = SiteIsRunning; wzdImport.ActiveStepIndex = 7; } else { if (ImportManager.Settings.IsWarning()) { try { // Convert default culture TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); tree.ChangeSiteDefaultCulture(SiteName, Culture, "en-US"); // Change root GUID TreeNode root = DocumentHelper.GetDocument(SiteName, "/", Culture, false, "cms.root", null, null, 1, false, null, tree); if (root != null) { root.NodeGUID = Guid.NewGuid(); DocumentHelper.UpdateDocument(root, tree); } } catch (Exception ex) { EventLogProvider ev = new EventLogProvider(); ev.LogEvent("NewSiteWizard", "FINISH", ex); lblError.Text = ex.Message; e.Cancel = true; return; } } selectMaster.SiteName = SiteName; selectMaster.ReloadData(); } break; // Master template case 5: if (!selectMaster.ApplySettings()) { e.Cancel = true; return; } siteStructure.SiteName = SiteName; break; // Define site structure case 6: finishSite.Domain = Domain; finishSite.SiteIsRunning = SiteIsRunning; break; // Other steps default: wzdImport.ActiveStepIndex = e.NextStepIndex; break; } }
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; } }