private void CommunityHome() { var migrationName = MethodBase.GetCurrentMethod().Name; try { var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt"); if (File.Exists(path)) return; var macroService = UmbracoContext.Current.Application.Services.MacroService; var macroAlias = "CommunityHome"; if (macroService.GetByAlias(macroAlias) == null) { // Run migration var macro = new Macro { Name = "[Community] Home", Alias = macroAlias, ScriptingFile = "~/Views/MacroPartials/Community/Home.cshtml", UseInEditor = true }; macro.Save(); } string[] lines = { "" }; File.WriteAllLines(path, lines); } catch (Exception ex) { LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex); } }
private void MemberActivationMigration() { var migrationName = MethodBase.GetCurrentMethod().Name; try { var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt"); if (File.Exists(path)) { return; } var macroService = UmbracoContext.Current.Application.Services.MacroService; var macroAlias = "MembersActivate"; if (macroService.GetByAlias(macroAlias) == null) { // Run migration var macro = new Macro { Name = "[Members] Activate", Alias = macroAlias, ScriptingFile = "~/Views/MacroPartials/Members/Activate.cshtml", UseInEditor = true }; macro.Save(); } var contentService = UmbracoContext.Current.Application.Services.ContentService; var rootNode = contentService.GetRootContent().OrderBy(x => x.SortOrder).First(x => x.ContentType.Alias == "Community"); var memberNode = rootNode.Children().FirstOrDefault(x => x.Name == "Member"); var pendingActivationPageName = "Pending activation"; if (memberNode != null && memberNode.Children().Any(x => x.Name == pendingActivationPageName) == false) { var pendingActivationPage = contentService.CreateContent(pendingActivationPageName, memberNode.Id, "Textpage"); pendingActivationPage.SetValue("bodyText", "<p>Thanks for signing up! <br />We\'ve sent you an email containing an activation link.</p><p>To be able to continue you need to click the link in that email. If you didn\'t get any mail from us, make sure to check your spam/junkmail folder for mail from [email protected].</p>"); contentService.SaveAndPublishWithStatus(pendingActivationPage); } var activatePageName = "Activate"; if (memberNode != null && memberNode.Children().Any(x => x.Name == activatePageName) == false) { var activatePage = contentService.CreateContent(activatePageName, memberNode.Id, "Textpage"); activatePage.SetValue("bodyText", string.Format("<?UMBRACO_MACRO macroAlias=\"{0}\" />", macroAlias)); contentService.SaveAndPublishWithStatus(activatePage); } string[] lines = { "" }; File.WriteAllLines(path, lines); } catch (Exception ex) { LogHelper.Error <MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex); } }
/// <summary> /// Converts a macro to a jsonPayload object /// </summary> /// <param name="macro"></param> /// <returns></returns> private static JsonPayload FromMacro(Macro macro) { var payload = new JsonPayload { Alias = macro.Alias, Id = macro.Id }; return(payload); }
public bool Save() { int id = -1; umbraco.cms.businesslogic.macro.Macro checkingMacro = umbraco.cms.businesslogic.macro.Macro.GetByAlias(_alias); if (checkingMacro != null) { id = checkingMacro.Id; } else { id = umbraco.cms.businesslogic.macro.Macro.MakeNew(_alias).Id; } m_returnUrl = string.Format("developer/Macros/editMacro.aspx?macroID={0}", id); return(true); }
private void SpamOverview() { var migrationName = MethodBase.GetCurrentMethod().Name; try { var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt"); if (File.Exists(path)) { return; } var macroService = UmbracoContext.Current.Application.Services.MacroService; var macroAlias = "AntiSpam"; if (macroService.GetByAlias(macroAlias) == null) { // Run migration var macro = new Macro { Name = "[Spam] Overview", Alias = macroAlias, ScriptingFile = "~/Views/MacroPartials/Spam/Overview.cshtml", UseInEditor = true }; macro.Save(); } var contentService = UmbracoContext.Current.Application.Services.ContentService; var rootNode = contentService.GetRootContent().OrderBy(x => x.SortOrder).First(x => x.ContentType.Alias == "Community"); var antiSpamPageName = "AntiSpam"; if (rootNode.Children().Any(x => x.Name == antiSpamPageName) == false) { var content = contentService.CreateContent(antiSpamPageName, rootNode.Id, "Textpage"); content.SetValue("bodyText", string.Format("<?UMBRACO_MACRO macroAlias=\"{0}\" />", macroAlias)); contentService.SaveAndPublishWithStatus(content); } string[] lines = { "" }; File.WriteAllLines(path, lines); } catch (Exception ex) { LogHelper.Error <MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex); } }
private void CommunityHome() { var migrationName = MethodBase.GetCurrentMethod().Name; try { var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt"); if (File.Exists(path)) { return; } var macroService = UmbracoContext.Current.Application.Services.MacroService; var macroAlias = "CommunityHome"; if (macroService.GetByAlias(macroAlias) == null) { // Run migration var macro = new Macro { Name = "[Community] Home", Alias = macroAlias, ScriptingFile = "~/Views/MacroPartials/Community/Home.cshtml", UseInEditor = true }; macro.Save(); } string[] lines = { "" }; File.WriteAllLines(path, lines); } catch (Exception ex) { LogHelper.Error <MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex); } }
protected void Page_Load(object sender, System.EventArgs e) { pane_edit.Text = ui.Text("general", "edit",this.getUser()) + " " + ui.Text("general", "macro",this.getUser()); pane_insert.Text = ui.Text("general", "insert",this.getUser()) + " " + ui.Text("general", "macro",this.getUser()); if (Request["macroID"] != null || Request["macroAlias"] != null) { // Put user code to initialize the page here cms.businesslogic.macro.Macro m; if (helper.Request("macroID") != "") m = new umbraco.cms.businesslogic.macro.Macro(int.Parse(helper.Request("macroID"))); else m = cms.businesslogic.macro.Macro.GetByAlias(helper.Request("macroAlias")); String macroAssembly = ""; String macroType = ""; foreach (cms.businesslogic.macro.MacroProperty mp in m.Properties) { macroAssembly = mp.Type.Assembly; macroType = mp.Type.Type; try { Assembly assembly = Assembly.LoadFrom( IOHelper.MapPath(SystemDirectories.Bin + "/" + macroAssembly + ".dll")); Type type = assembly.GetType(macroAssembly+"."+macroType); interfaces.IMacroGuiRendering typeInstance = Activator.CreateInstance(type) as interfaces.IMacroGuiRendering; if (typeInstance != null) { Control control = Activator.CreateInstance(type) as Control; control.ID = mp.Alias; if (Request[mp.Alias] != null) { if (Request[mp.Alias] != "") { type.GetProperty("Value").SetValue(control, Convert.ChangeType(Request[mp.Alias], type.GetProperty("Value").PropertyType), null); } } // register alias umbraco.uicontrols.PropertyPanel pp = new umbraco.uicontrols.PropertyPanel(); pp.Text = mp.Name; pp.Controls.Add(control); macroProperties.Controls.Add(pp); /* macroProperties.Controls.Add(new LiteralControl("<script>\nregisterAlias('" + control.ID + "');\n</script>")); macroProperties.Controls.Add(new LiteralControl("<tr><td class=\"propertyHeader\">" + mp.Name + "</td><td class=\"propertyContent\">")); macroProperties.Controls.Add(control); macroProperties.Controls.Add(new LiteralControl("</td></tr>")); */ } else { Trace.Warn("umbEditContent", "Type doesn't exist or is not umbraco.interfaces.DataFieldI ('" + macroAssembly + "." + macroType + "')"); } } catch (Exception fieldException) { Trace.Warn("umbEditContent", "Error creating type '" + macroAssembly + "." + macroType + "'", fieldException); } } } else { IRecordsReader macroRenderings; if (helper.Request("editor") != "") macroRenderings = SqlHelper.ExecuteReader("select macroAlias, macroName from cmsMacro where macroUseInEditor = 1 order by macroName"); else macroRenderings = SqlHelper.ExecuteReader("select macroAlias, macroName from cmsMacro order by macroName"); macroAlias.DataSource = macroRenderings; macroAlias.DataValueField = "macroAlias"; macroAlias.DataTextField = "macroName"; macroAlias.DataBind(); macroRenderings.Close(); } }
private void SpamOverview() { var migrationName = MethodBase.GetCurrentMethod().Name; try { var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt"); if (File.Exists(path)) return; var macroService = UmbracoContext.Current.Application.Services.MacroService; var macroAlias = "AntiSpam"; if (macroService.GetByAlias(macroAlias) == null) { // Run migration var macro = new Macro { Name = "[Spam] Overview", Alias = macroAlias, ScriptingFile = "~/Views/MacroPartials/Spam/Overview.cshtml", UseInEditor = true }; macro.Save(); } var contentService = UmbracoContext.Current.Application.Services.ContentService; var rootNode = contentService.GetRootContent().OrderBy(x => x.SortOrder).First(x => x.ContentType.Alias == "Community"); var antiSpamPageName = "AntiSpam"; if(rootNode.Children().Any(x => x.Name == antiSpamPageName) == false) { var content = contentService.CreateContent(antiSpamPageName, rootNode.Id, "Textpage"); content.SetValue("bodyText", string.Format("<?UMBRACO_MACRO macroAlias=\"{0}\" />", macroAlias)); contentService.SaveAndPublishWithStatus(content); } string[] lines = { "" }; File.WriteAllLines(path, lines); } catch (Exception ex) { LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex); } }
/// <summary> /// Flush macro from cache /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void MacroAfterSave(Macro sender, SaveEventArgs e) { DistributedCache.Instance.RefreshMacroCache(sender); }
protected void Page_Load(object sender, System.EventArgs e) { pane_edit.Text = ui.Text("general", "edit", this.getUser()) + " " + ui.Text("general", "macro", this.getUser()); pane_insert.Text = ui.Text("general", "insert", this.getUser()) + " " + ui.Text("general", "macro", this.getUser()); if (Request["macroID"] != null || Request["macroAlias"] != null) { // Put user code to initialize the page here cms.businesslogic.macro.Macro m; if (helper.Request("macroID") != "") { m = new umbraco.cms.businesslogic.macro.Macro(int.Parse(helper.Request("macroID"))); } else { m = cms.businesslogic.macro.Macro.GetByAlias(helper.Request("macroAlias")); } String macroAssembly = ""; String macroType = ""; foreach (cms.businesslogic.macro.MacroProperty mp in m.Properties) { macroAssembly = mp.Type.Assembly; macroType = mp.Type.Type; try { Assembly assembly = Assembly.LoadFrom(IOHelper.MapPath(SystemDirectories.Bin + "/" + macroAssembly + ".dll")); Type type = assembly.GetType(macroAssembly + "." + macroType); interfaces.IMacroGuiRendering typeInstance = Activator.CreateInstance(type) as interfaces.IMacroGuiRendering; if (typeInstance != null) { Control control = Activator.CreateInstance(type) as Control; control.ID = mp.Alias; if (Request[mp.Alias] != null) { if (Request[mp.Alias] != "") { type.GetProperty("Value").SetValue(control, Convert.ChangeType(Request[mp.Alias], type.GetProperty("Value").PropertyType), null); } } // register alias umbraco.uicontrols.PropertyPanel pp = new umbraco.uicontrols.PropertyPanel(); pp.Text = mp.Name; pp.Controls.Add(control); macroProperties.Controls.Add(pp); /* * macroProperties.Controls.Add(new LiteralControl("<script>\nregisterAlias('" + control.ID + "');\n</script>")); * macroProperties.Controls.Add(new LiteralControl("<tr><td class=\"propertyHeader\">" + mp.Name + "</td><td class=\"propertyContent\">")); * macroProperties.Controls.Add(control); * macroProperties.Controls.Add(new LiteralControl("</td></tr>")); */ } else { Trace.Warn("umbEditContent", "Type doesn't exist or is not umbraco.interfaces.DataFieldI ('" + macroAssembly + "." + macroType + "')"); } } catch (Exception fieldException) { Trace.Warn("umbEditContent", "Error creating type '" + macroAssembly + "." + macroType + "'", fieldException); } } } else { IRecordsReader macroRenderings; if (helper.Request("editor") != "") { macroRenderings = SqlHelper.ExecuteReader("select macroAlias, macroName from cmsMacro where macroUseInEditor = 1 order by macroName"); } else { macroRenderings = SqlHelper.ExecuteReader("select macroAlias, macroName from cmsMacro order by macroName"); } macroAlias.DataSource = macroRenderings; macroAlias.DataValueField = "macroAlias"; macroAlias.DataTextField = "macroName"; macroAlias.DataBind(); macroRenderings.Close(); } }
private void MemberActivationMigration() { var migrationName = MethodBase.GetCurrentMethod().Name; try { var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt"); if (File.Exists(path)) return; var macroService = UmbracoContext.Current.Application.Services.MacroService; var macroAlias = "MembersActivate"; if (macroService.GetByAlias(macroAlias) == null) { // Run migration var macro = new Macro { Name = "[Members] Activate", Alias = macroAlias, ScriptingFile = "~/Views/MacroPartials/Members/Activate.cshtml", UseInEditor = true }; macro.Save(); } var contentService = UmbracoContext.Current.Application.Services.ContentService; var rootNode = contentService.GetRootContent().OrderBy(x => x.SortOrder).First(x => x.ContentType.Alias == "Community"); var memberNode = rootNode.Children().FirstOrDefault(x => x.Name == "Member"); var pendingActivationPageName = "Pending activation"; if (memberNode != null && memberNode.Children().Any(x => x.Name == pendingActivationPageName) == false) { var pendingActivationPage = contentService.CreateContent(pendingActivationPageName, memberNode.Id, "Textpage"); pendingActivationPage.SetValue("bodyText", "<p>Thanks for signing up! <br />We\'ve sent you an email containing an activation link.</p><p>To be able to continue you need to click the link in that email. If you didn\'t get any mail from us, make sure to check your spam/junkmail folder for mail from [email protected].</p>"); contentService.SaveAndPublishWithStatus(pendingActivationPage); } var activatePageName = "Activate"; if (memberNode != null && memberNode.Children().Any(x => x.Name == activatePageName) == false) { var activatePage = contentService.CreateContent(activatePageName, memberNode.Id, "Textpage"); activatePage.SetValue("bodyText", string.Format("<?UMBRACO_MACRO macroAlias=\"{0}\" />", macroAlias)); contentService.SaveAndPublishWithStatus(activatePage); } string[] lines = {""}; File.WriteAllLines(path, lines); } catch (Exception ex) { LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex); } }
/// <summary> /// Flush macro from cache /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void MacroAfterDelete(Macro sender, DeleteEventArgs e) { DistributedCache.Instance.RemoveMacroCache(sender); }
/// <summary> /// Flush macro from cache /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void MacroAfterDelete(Macro sender, DeleteEventArgs e) { DistributedCache.Instance.RemoveMacroCache(sender); }
protected void confirmUnInstall(object sender, EventArgs e) { var refreshCache = false; //Uninstall Stylesheets foreach (ListItem li in stylesheets.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var s = new StyleSheet(nId); s.delete(); _pack.Data.Stylesheets.Remove(nId.ToString()); } } } //Uninstall templates foreach (ListItem li in templates.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var s = new Template(nId); s.RemoveAllReferences(); s.delete(); _pack.Data.Templates.Remove(nId.ToString()); } } } //Uninstall macros foreach (ListItem li in macros.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var s = new Macro(nId); if (!string.IsNullOrEmpty(s.Name)) { s.Delete(); } _pack.Data.Macros.Remove(nId.ToString()); } } } //Remove Document Types var contentTypes = new List <IContentType>(); var contentTypeService = ApplicationContext.Current.Services.ContentTypeService; foreach (ListItem li in documentTypes.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var contentType = contentTypeService.GetContentType(nId); if (contentType != null) { contentTypes.Add(contentType); _pack.Data.Documenttypes.Remove(nId.ToString(CultureInfo.InvariantCulture)); // refresh content cache when document types are removed refreshCache = true; } } } } //Order the DocumentTypes before removing them if (contentTypes.Any()) { var orderedTypes = (from contentType in contentTypes orderby contentType.ParentId descending, contentType.Id descending select contentType); foreach (var contentType in orderedTypes) { contentTypeService.Delete(contentType); } } //Remove Dictionary items foreach (ListItem li in dictionaryItems.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var di = new cms.businesslogic.Dictionary.DictionaryItem(nId); di.delete(); _pack.Data.DictionaryItems.Remove(nId.ToString()); } } } //Remove Data types foreach (ListItem li in dataTypes.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var dtd = new cms.businesslogic.datatype.DataTypeDefinition(nId); dtd.delete(); _pack.Data.DataTypes.Remove(nId.ToString()); } } } _pack.Save(); if (!IsManifestEmpty()) { Response.Redirect(Request.RawUrl); } else { // uninstall actions try { var actionsXml = new XmlDocument(); actionsXml.LoadXml("<Actions>" + _pack.Data.Actions + "</Actions>"); LogHelper.Debug <installedPackage>("executing undo actions: {0}", () => actionsXml.OuterXml); foreach (XmlNode n in actionsXml.DocumentElement.SelectNodes("//Action")) { try { cms.businesslogic.packager.PackageAction.UndoPackageAction(_pack.Data.Name, n.Attributes["alias"].Value, n); } catch (Exception ex) { LogHelper.Error <installedPackage>("An error occurred running undo actions", ex); } } } catch (Exception ex) { LogHelper.Error <installedPackage>("An error occurred running undo actions", ex); } //moved remove of files here so custom package actions can still undo //Remove files foreach (ListItem li in files.Items) { if (li.Selected) { //here we need to try to find the file in question as most packages does not support the tilde char var file = IOHelper.FindFile(li.Value); var filePath = IOHelper.MapPath(file); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); _pack.Data.Files.Remove(li.Value); } } } _pack.Save(); _pack.Delete(); packageUninstalled.Visible = true; installedPackagePanel.Visible = false; } // refresh cache if (refreshCache) { library.RefreshContent(); } //ensure that all tree's are refreshed after uninstall ClientTools.ClearClientTreeCache() .RefreshTree(); TreeDefinitionCollection.Instance.ReRegisterTrees(); BizLogicAction.ReRegisterActionsAndHandlers(); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { _pack = cms.businesslogic.packager.InstalledPackage.GetById(int.Parse(Request.QueryString["id"])); lt_packagename.Text = _pack.Data.Name; lt_packageVersion.Text = _pack.Data.Version; lt_packageAuthor.Text = _pack.Data.Author; lt_readme.Text = library.ReplaceLineBreaks(_pack.Data.Readme); bt_confirmUninstall.Attributes.Add("onClick", "jQuery('#buttons').hide(); jQuery('#loadingbar').show();; return true;"); if (!Page.IsPostBack) { //temp list to contain failing items... var tempList = new List <string>(); foreach (var str in _pack.Data.Documenttypes) { var tId = 0; if (int.TryParse(str, out tId)) { try { var dc = new DocumentType(tId); var li = new ListItem(dc.Text, dc.Id.ToString()); li.Selected = true; documentTypes.Items.Add(li); } catch { tempList.Add(str); } } } //removing failing documentTypes items from the uninstall manifest SyncLists(_pack.Data.Documenttypes, tempList); foreach (var str in _pack.Data.Templates) { var tId = 0; if (int.TryParse(str, out tId)) { try { var t = new Template(tId); var li = new ListItem(t.Text, t.Id.ToString()); li.Selected = true; templates.Items.Add(li); } catch { tempList.Add(str); } } } //removing failing template items from the uninstall manifest SyncLists(_pack.Data.Templates, tempList); foreach (string str in _pack.Data.Stylesheets) { int tId = 0; if (int.TryParse(str, out tId)) { try { var s = new StyleSheet(tId); ListItem li = new ListItem(s.Text, s.Id.ToString()); li.Selected = true; stylesheets.Items.Add(li); } catch { tempList.Add(str); } } } //removing failing stylesheet items from the uninstall manifest SyncLists(_pack.Data.Stylesheets, tempList); foreach (var str in _pack.Data.Macros) { var tId = 0; if (int.TryParse(str, out tId)) { try { var m = new Macro(tId); if (!string.IsNullOrEmpty(m.Name)) { //Macros need an extra check to see if they actually exists. For some reason the macro does not return null, if the id is not found... var li = new ListItem(m.Name, m.Id.ToString()); li.Selected = true; macros.Items.Add(li); } else { tempList.Add(str); } } catch { tempList.Add(str); } } } //removing failing macros items from the uninstall manifest SyncLists(_pack.Data.Macros, tempList); foreach (var str in _pack.Data.Files) { try { if (!string.IsNullOrEmpty(str) && System.IO.File.Exists(IOHelper.MapPath(str))) { var li = new ListItem(str, str); li.Selected = true; files.Items.Add(li); } else { tempList.Add(str); } } catch { tempList.Add(str); } } //removing failing files from the uninstall manifest SyncLists(_pack.Data.Files, tempList); foreach (string str in _pack.Data.DictionaryItems) { var tId = 0; if (int.TryParse(str, out tId)) { try { var di = new cms.businesslogic.Dictionary.DictionaryItem(tId); var li = new ListItem(di.key, di.id.ToString()); li.Selected = true; dictionaryItems.Items.Add(li); } catch { tempList.Add(str); } } } //removing failing files from the uninstall manifest SyncLists(_pack.Data.DictionaryItems, tempList); foreach (var str in _pack.Data.DataTypes) { var tId = 0; if (int.TryParse(str, out tId)) { try { var dtd = new cms.businesslogic.datatype.DataTypeDefinition(tId); if (dtd != null) { var li = new ListItem(dtd.Text, dtd.Id.ToString()); li.Selected = true; dataTypes.Items.Add(li); } else { tempList.Add(str); } } catch { tempList.Add(str); } } } //removing failing files from the uninstall manifest SyncLists(_pack.Data.DataTypes, tempList); //save the install manifest, so even tho the user doesn't uninstall, it stays uptodate. _pack.Save(); //Look for updates on packages. if (!string.IsNullOrEmpty(_pack.Data.RepositoryGuid) && !string.IsNullOrEmpty(_pack.Data.PackageGuid)) { try { _repo = cms.businesslogic.packager.repositories.Repository.getByGuid(_pack.Data.RepositoryGuid); if (_repo != null) { hl_packageRepo.Text = _repo.Name; hl_packageRepo.NavigateUrl = "BrowseRepository.aspx?repoGuid=" + _repo.Guid; pp_repository.Visible = true; } var repoPackage = _repo.Webservice.PackageByGuid(_pack.Data.PackageGuid); if (repoPackage != null) { if (repoPackage.HasUpgrade && repoPackage.UpgradeVersion != _pack.Data.Version) { bt_update.Visible = true; bt_update.Text = "Update available: version: " + repoPackage.UpgradeVersion; lt_upgradeReadme.Text = repoPackage.UpgradeReadMe; bt_gotoUpgrade.OnClientClick = "window.location.href = 'browseRepository.aspx?url=" + repoPackage.Url + "'; return true;"; lt_noUpdate.Visible = false; } else { bt_update.Visible = false; lt_noUpdate.Visible = true; } if (!string.IsNullOrEmpty(repoPackage.Demo)) { lb_demoLink.OnClientClick = "openDemo(this, '" + _pack.Data.PackageGuid + "'); return false;"; pp_documentation.Visible = true; } if (!string.IsNullOrEmpty(repoPackage.Documentation)) { hl_docLink.NavigateUrl = repoPackage.Documentation; hl_docLink.Target = "_blank"; pp_documentation.Visible = true; } } } catch { bt_update.Visible = false; lt_noUpdate.Visible = true; } } var deletePackage = true; //sync the UI to match what is in the package if (macros.Items.Count == 0) { pp_macros.Visible = false; } else { deletePackage = false; } if (documentTypes.Items.Count == 0) { pp_docTypes.Visible = false; } else { deletePackage = false; } if (files.Items.Count == 0) { pp_files.Visible = false; } else { deletePackage = false; } if (templates.Items.Count == 0) { pp_templates.Visible = false; } else { deletePackage = false; } if (stylesheets.Items.Count == 0) { pp_css.Visible = false; } else { deletePackage = false; } if (dictionaryItems.Items.Count == 0) { pp_di.Visible = false; } else { deletePackage = false; } if (dataTypes.Items.Count == 0) { pp_dt.Visible = false; } else { deletePackage = false; } if (deletePackage) { pane_noItems.Visible = true; bt_uninstall.Visible = false; pane_uninstall.Visible = false; } // List the package version history [LK 2013-067-10] Version v; var packageVersionHistory = cms.businesslogic.packager.InstalledPackage.GetAllInstalledPackages() .Where(x => x.Data.Id != _pack.Data.Id && string.Equals(x.Data.Name, _pack.Data.Name, StringComparison.OrdinalIgnoreCase)) .OrderBy(x => Version.TryParse(x.Data.Version, out v) ? v : new Version()); if (packageVersionHistory != null && packageVersionHistory.Count() > 0) { rptr_versions.DataSource = packageVersionHistory; rptr_versions.DataBind(); pane_versions.Visible = true; } } } }
protected void confirmUnInstall(object sender, EventArgs e) { var refreshCache = false; //Uninstall Stylesheets foreach (ListItem li in stylesheets.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var s = new StyleSheet(nId); s.delete(); _pack.Data.Stylesheets.Remove(nId.ToString()); } } } //Uninstall templates foreach (ListItem li in templates.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var s = new Template(nId); s.RemoveAllReferences(); s.delete(); _pack.Data.Templates.Remove(nId.ToString()); } } } //Uninstall macros foreach (ListItem li in macros.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var s = new Macro(nId); if (!string.IsNullOrEmpty(s.Name)) { // remove from cache runtimeMacro.GetMacro(s.Id).removeFromCache(); s.Delete(); } _pack.Data.Macros.Remove(nId.ToString()); } } } //Remove Document Types var contentTypes = new List<IContentType>(); var contentTypeService = ApplicationContext.Current.Services.ContentTypeService; foreach (ListItem li in documentTypes.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var contentType = contentTypeService.GetContentType(nId); if (contentType != null) { contentTypes.Add(contentType); _pack.Data.Documenttypes.Remove(nId.ToString(CultureInfo.InvariantCulture)); // refresh content cache when document types are removed refreshCache = true; } } } } //Order the DocumentTypes before removing them if (contentTypes.Any()) { var orderedTypes = (from contentType in contentTypes orderby contentType.ParentId descending, contentType.Id descending select contentType); foreach (var contentType in orderedTypes) { contentTypeService.Delete(contentType); } } //Remove Dictionary items foreach (ListItem li in dictionaryItems.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var di = new cms.businesslogic.Dictionary.DictionaryItem(nId); di.delete(); _pack.Data.DictionaryItems.Remove(nId.ToString()); } } } //Remove Data types foreach (ListItem li in dataTypes.Items) { if (li.Selected) { int nId; if (int.TryParse(li.Value, out nId)) { var dtd = new cms.businesslogic.datatype.DataTypeDefinition(nId); dtd.delete(); _pack.Data.DataTypes.Remove(nId.ToString()); } } } _pack.Save(); if (!IsManifestEmpty()) { Response.Redirect(Request.RawUrl); } else { // uninstall actions try { var actionsXml = new XmlDocument(); actionsXml.LoadXml("<Actions>" + _pack.Data.Actions + "</Actions>"); LogHelper.Debug<installedPackage>("executing undo actions: {0}", () => actionsXml.OuterXml); foreach (XmlNode n in actionsXml.DocumentElement.SelectNodes("//Action")) { try { cms.businesslogic.packager.PackageAction.UndoPackageAction(_pack.Data.Name, n.Attributes["alias"].Value, n); } catch (Exception ex) { LogHelper.Error<installedPackage>("An error occurred running undo actions", ex); } } } catch (Exception ex) { LogHelper.Error<installedPackage>("An error occurred running undo actions", ex); } //moved remove of files here so custom package actions can still undo //Remove files foreach (ListItem li in files.Items) { if (li.Selected) { //here we need to try to find the file in question as most packages does not support the tilde char var file = IOHelper.FindFile(li.Value); var filePath = IOHelper.MapPath(file); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); _pack.Data.Files.Remove(li.Value); } } } _pack.Save(); _pack.Delete(); packageUninstalled.Visible = true; installedPackagePanel.Visible = false; } // refresh cache if (refreshCache) { library.RefreshContent(); } //ensure that all tree's are refreshed after uninstall ClientTools.ClearClientTreeCache() .RefreshTree(); TreeDefinitionCollection.Instance.ReRegisterTrees(); BizLogicAction.ReRegisterActionsAndHandlers(); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { _pack = cms.businesslogic.packager.InstalledPackage.GetById(int.Parse(Request.QueryString["id"])); lt_packagename.Text = _pack.Data.Name; lt_packageVersion.Text = _pack.Data.Version; lt_packageAuthor.Text = _pack.Data.Author; lt_readme.Text = library.ReplaceLineBreaks( _pack.Data.Readme ); bt_confirmUninstall.Attributes.Add("onClick", "jQuery('#buttons').hide(); jQuery('#loadingbar').show();; return true;"); if (!Page.IsPostBack) { //temp list to contain failing items... var tempList = new List<string>(); foreach (var str in _pack.Data.Documenttypes) { var tId = 0; if (int.TryParse(str, out tId)) { try { var dc = new DocumentType(tId); var li = new ListItem(dc.Text, dc.Id.ToString()); li.Selected = true; documentTypes.Items.Add(li); } catch { tempList.Add(str); } } } //removing failing documentTypes items from the uninstall manifest SyncLists(_pack.Data.Documenttypes, tempList); foreach (var str in _pack.Data.Templates) { var tId = 0; if (int.TryParse(str, out tId)) { try { var t = new Template(tId); var li = new ListItem(t.Text, t.Id.ToString()); li.Selected = true; templates.Items.Add(li); } catch { tempList.Add(str); } } } //removing failing template items from the uninstall manifest SyncLists(_pack.Data.Templates, tempList); foreach (string str in _pack.Data.Stylesheets) { int tId = 0; if (int.TryParse(str, out tId)) { try { var s = new StyleSheet(tId); ListItem li = new ListItem(s.Text, s.Id.ToString()); li.Selected = true; stylesheets.Items.Add(li); } catch { tempList.Add(str); } } } //removing failing stylesheet items from the uninstall manifest SyncLists(_pack.Data.Stylesheets, tempList); foreach (var str in _pack.Data.Macros) { var tId = 0; if (int.TryParse(str, out tId)) { try { var m = new Macro(tId); if (!string.IsNullOrEmpty(m.Name)) { //Macros need an extra check to see if they actually exists. For some reason the macro does not return null, if the id is not found... var li = new ListItem(m.Name, m.Id.ToString()); li.Selected = true; macros.Items.Add(li); } else { tempList.Add(str); } } catch { tempList.Add(str); } } } //removing failing macros items from the uninstall manifest SyncLists(_pack.Data.Macros, tempList); foreach (var str in _pack.Data.Files) { try { if (!string.IsNullOrEmpty(str) && System.IO.File.Exists(IOHelper.MapPath(str) )) { var li = new ListItem(str, str); li.Selected = true; files.Items.Add(li); } else { tempList.Add(str); } } catch { tempList.Add(str); } } //removing failing files from the uninstall manifest SyncLists(_pack.Data.Files, tempList); foreach (string str in _pack.Data.DictionaryItems) { var tId = 0; if (int.TryParse(str, out tId)) { try { var di = new cms.businesslogic.Dictionary.DictionaryItem(tId); var li = new ListItem(di.key, di.id.ToString()); li.Selected = true; dictionaryItems.Items.Add(li); } catch { tempList.Add(str); } } } //removing failing files from the uninstall manifest SyncLists(_pack.Data.DictionaryItems, tempList); foreach (var str in _pack.Data.DataTypes) { var tId = 0; if (int.TryParse(str, out tId)) { try { var dtd = new cms.businesslogic.datatype.DataTypeDefinition(tId); if (dtd != null) { var li = new ListItem(dtd.Text, dtd.Id.ToString()); li.Selected = true; dataTypes.Items.Add(li); } else { tempList.Add(str); } } catch { tempList.Add(str); } } } //removing failing files from the uninstall manifest SyncLists(_pack.Data.DataTypes, tempList); //save the install manifest, so even tho the user doesn't uninstall, it stays uptodate. _pack.Save(); //Look for updates on packages. if (!string.IsNullOrEmpty(_pack.Data.RepositoryGuid) && !string.IsNullOrEmpty(_pack.Data.PackageGuid)) { try { _repo = cms.businesslogic.packager.repositories.Repository.getByGuid(_pack.Data.RepositoryGuid); if (_repo != null) { hl_packageRepo.Text = _repo.Name; hl_packageRepo.NavigateUrl = "BrowseRepository.aspx?repoGuid=" + _repo.Guid; pp_repository.Visible = true; } var repoPackage = _repo.Webservice.PackageByGuid(_pack.Data.PackageGuid); if (repoPackage != null) { if (repoPackage.HasUpgrade && repoPackage.UpgradeVersion != _pack.Data.Version) { bt_update.Visible = true; bt_update.Text = "Update available: version: " + repoPackage.UpgradeVersion; lt_upgradeReadme.Text = repoPackage.UpgradeReadMe; bt_gotoUpgrade.OnClientClick = "window.location.href = 'browseRepository.aspx?url=" + repoPackage.Url + "'; return true;"; lt_noUpdate.Visible = false; } else { bt_update.Visible = false; lt_noUpdate.Visible = true; } if (!string.IsNullOrEmpty(repoPackage.Demo)) { lb_demoLink.OnClientClick = "openDemo(this, '" + _pack.Data.PackageGuid + "'); return false;"; pp_documentation.Visible = true; } if (!string.IsNullOrEmpty(repoPackage.Documentation)) { hl_docLink.NavigateUrl = repoPackage.Documentation; hl_docLink.Target = "_blank"; pp_documentation.Visible = true; } } } catch { bt_update.Visible = false; lt_noUpdate.Visible = true; } } var deletePackage = true; //sync the UI to match what is in the package if (macros.Items.Count == 0) pp_macros.Visible = false; else deletePackage = false; if (documentTypes.Items.Count == 0) pp_docTypes.Visible = false; else deletePackage = false; if (files.Items.Count == 0) pp_files.Visible = false; else deletePackage = false; if (templates.Items.Count == 0) pp_templates.Visible = false; else deletePackage = false; if (stylesheets.Items.Count == 0) pp_css.Visible = false; else deletePackage = false; if (dictionaryItems.Items.Count == 0) pp_di.Visible = false; else deletePackage = false; if (dataTypes.Items.Count == 0) pp_dt.Visible = false; else deletePackage = false; if (deletePackage) { pane_noItems.Visible = true; bt_uninstall.Visible = false; pane_uninstall.Visible = false; } } } }
/// <summary> /// Flush macro from cache /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void MacroAfterSave(Macro sender, SaveEventArgs e) { DistributedCache.Instance.RefreshMacroCache(sender); }
private void AddReleaseCompareFeature() { var migrationName = MethodBase.GetCurrentMethod().Name; try { var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt"); if (File.Exists(path)) { return; } var contentTypeService = ApplicationContext.Current.Services.ContentTypeService; var releaseCompareAlias = "ReleaseCompare"; var compareContentType = contentTypeService.GetContentType(releaseCompareAlias); if (compareContentType == null) { var contentType = new ContentType(-1) { Name = "Release Compare", Alias = releaseCompareAlias }; contentTypeService.Save(contentType); } compareContentType = contentTypeService.GetContentType(releaseCompareAlias); var releaseLandingContentType = contentTypeService.GetContentType("ReleaseLanding"); var allowedContentTypes = new List <ContentTypeSort> { new ContentTypeSort(compareContentType.Id, 0) }; releaseLandingContentType.AllowedContentTypes = allowedContentTypes; contentTypeService.Save(releaseLandingContentType); var templatePathRelative = "~/masterpages/ReleaseCompare.master"; var templatePath = HostingEnvironment.MapPath(templatePathRelative); var templateContent = File.ReadAllText(templatePath); var releaseCompareTemplate = new Template("Release Compare", releaseCompareAlias) { MasterTemplateAlias = "Master", Content = templateContent }; var fileService = ApplicationContext.Current.Services.FileService; var masterTemplate = fileService.GetTemplate("Master"); releaseCompareTemplate.SetMasterTemplate(masterTemplate); fileService.SaveTemplate(releaseCompareTemplate); contentTypeService.Save(compareContentType); compareContentType.AllowedTemplates = new List <ITemplate> { releaseCompareTemplate }; compareContentType.SetDefaultTemplate(releaseCompareTemplate); contentTypeService.Save(compareContentType); var contentService = ApplicationContext.Current.Services.ContentService; var rootNode = contentService.GetRootContent().OrderBy(x => x.SortOrder).First(x => x.ContentType.Alias == "Community"); if (rootNode == null) { return; } var contributeNode = rootNode.Children().FirstOrDefault(x => x.Name == "Contribute"); if (contributeNode == null) { return; } var releasesNode = contributeNode.Children().FirstOrDefault(x => x.Name == "Releases"); if (releasesNode == null) { return; } var compareContent = contentService.CreateContent("Compare", releasesNode.Id, "ReleaseCompare"); compareContent.Template = releaseCompareTemplate; contentService.SaveAndPublishWithStatus(compareContent); var macroService = ApplicationContext.Current.Services.MacroService; const string macroAlias = "ReleasesDropdown"; if (macroService.GetByAlias(macroAlias) == null) { var macro = new Macro { Name = "ReleasesDropdown", Alias = macroAlias, ScriptingFile = "~/Views/MacroPartials/Releases/ReleasesDropdown.cshtml", UseInEditor = true }; macro.Save(); } string[] lines = { "" }; File.WriteAllLines(path, lines); } catch (Exception ex) { LogHelper.Error <MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex); } }