protected void ClearCache(object sender = null, EventArgs args = null) { if (StopProcessing) { return; } // Clear the cache CacheHelper.ClearCache(null, true); Functions.ClearHashtables(); // Drop the routes CMSDocumentRouteHelper.DropAllRoutes(); // Disposes all zip files ZipStorageProvider.DisposeAll(); // Collect the memory GC.Collect(); GC.WaitForPendingFinalizers(); // Log event EventLogProvider.LogEvent(EventType.INFORMATION, "System", "CLEARCACHE", GetString("Administration-System.ClearCacheSuccess")); ShowConfirmation(GetString("Administration-System.ClearCacheSuccess")); LoadData(); }
protected void ClearCache(object sender = null, EventArgs args = null) { if (StopProcessing) { return; } // Clear the cache CacheHelper.ClearCache(null, true); Functions.ClearHashtables(); // Disposes all zip files ZipStorageProvider.DisposeAll(); // Collect the memory GC.Collect(); GC.WaitForPendingFinalizers(); // Log event Service.Resolve <IEventLogService>().LogInformation("System", "CLEARCACHE", GetString("Administration-System.ClearCacheSuccess")); ShowConfirmation(GetString("Administration-System.ClearCacheSuccess")); LoadData(); }
protected void btnClearCache_Click(object sender, EventArgs e) { if (StopProcessing) { return; } // Clear the cache CacheHelper.ClearCache(null, true); Functions.ClearHashtables(); // Drop the routes CMSMvcHandler.DropAllRoutes(); // Disposes all zip files ZipStorageProvider.DisposeAll(); // Collect the memory GC.Collect(); GC.WaitForPendingFinalizers(); // Log event EventLogProvider eventLog = new EventLogProvider(); eventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "System", "CLEARCACHE", null, GetString("Administration-System.ClearCacheSuccess")); ShowConfirmation(GetString("Administration-System.ClearCacheSuccess")); LoadData(); }
private void EnsureTemplateSelection() { try { var webPathMapper = Service.Resolve <IWebPathMapper>(); var path = webPathMapper.MapPath(BLANK_SITE_PATH); if (!File.Exists(Path.Combine(path, "template.zip"))) { siteDetails.StopProcessing = true; pnlWrapper.Visible = false; ShowError(GetString("NewSite.NoWebTemplate")); return; } path = Path.Combine(path, ZipStorageProvider.GetZipFileName("template.zip")); ImportSettings.SourceFilePath = path; ImportSettings.TemporaryFilesPath = path; ImportSettings.TemporaryFilesCreated = true; ImportSettings.RefreshMacroSecurity = true; ImportSettings.IsNewSite = true; ImportProvider.CreateTemporaryFiles(ImportSettings); // Import all, but only add new data ImportSettings.ImportType = ImportTypeEnum.AllNonConflicting; ImportSettings.ImportOnlyNewObjects = true; ImportSettings.CopyFiles = false; // Allow bulk inserts for faster import, web templates must be consistent enough to allow this without collisions ImportSettings.AllowBulkInsert = true; 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();"); // Preselect objects asynchronously ctrlAsyncSelection.RunAsync(SelectObjects, WindowsIdentity.GetCurrent()); } catch (Exception ex) { SetErrorLabel(ex.Message); } }
/// <summary> /// Registers zipped folders based on the /// </summary> /// <param name="dir">Directory info</param> /// <param name="subFolder">Current subfolder</param> private static void RegisterZippedFiles(DirectoryInfo dir, string subFolder) { // Register zipped files FileInfo[] files = dir.GetFiles("*.zip"); foreach (FileInfo zippedFile in files) { // Map the corresponding folder to the zip file string fileName = zippedFile.Name; string folderName = Path.GetFileNameWithoutExtension(fileName); string sourcePath = "~/" + subFolder + folderName; string targetPath = null; if (StorageHelper.UseZippedResources) { targetPath = ZIPPED_FILES_FOLDER + "/" + subFolder + ZipStorageProvider.GetZipFileName(fileName); } else { targetPath = ZIPPED_FILES_FOLDER + "/" + subFolder + folderName; } Path.RegisterMappedPath(sourcePath, targetPath); } // Register zipped subfolders DirectoryInfo[] subDirs = dir.GetDirectories(); foreach (DirectoryInfo subDir in subDirs) { subFolder += subDir.Name + "/"; RegisterZippedFiles(subDir, subFolder); } }
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; } }
/// <summary> /// Node populating. /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Particular node arguments</param> protected void treeFileSystem_TreeNodePopulate(object sender, TreeNodeEventArgs e) { e.Node.ChildNodes.Clear(); e.Node.PopulateOnDemand = false; try { DirectoryInfo dirInfo; dirInfo = DirectoryInfo.New(e.Node.Value); // Get the child directories DirectoryInfo[] childDirs = dirInfo.GetDirectories(); for (int i = 0, index = 0; i < childDirs.Length; i++) { TreeNode newNode = CreateNode(childDirs[i], index); if (newNode != null) { e.Node.ChildNodes.Add(newNode); // More content node was inserted if (newNode.Value == "") { return; } index++; } } // Get the zip directories FileInfo[] childZips = dirInfo.GetFiles("*.zip"); for (int i = 0, index = 0; i < childZips.Length; i++) { // Convert zip file to directory FileInfo zipFile = childZips[i]; string fileName = ZipStorageProvider.GetZipFileName(zipFile.Name); string parentDir = zipFile.Directory.FullName; DirectoryInfo zipDir = DirectoryInfo.New(parentDir + "\\" + fileName); TreeNode newNode = CreateNode(zipDir, index); if (newNode != null) { e.Node.ChildNodes.Add(newNode); // More content node was inserted if (newNode.Value == "") { return; } index++; } } } catch (Exception ex) { // Log the error EventLogProvider.LogException("FileSystemTree", "POPULATE", ex); } }
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; } }