We use log4net, please remove from the code if you do not use log4net
namespace Upac.Core.Packager.Actions { using System; using System.Collections.Generic; using System.Linq; using System.Xml;
using log4net;
using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.cms.businesslogic.datatype; using umbraco.cms.businesslogic.packager.standardPackageActions; using umbraco.interfaces;
public class AddMacroAliasToMacroPicker : IPackageAction { #region Fields
public string Alias() { return "AddMacroAliasToMacroPicker"; }
public bool Execute(string packageName, XmlNode xmlData) { log.Info("AddMacroAliasToMacroPicker action started"); string macroAlias = GetAttributeValueFromNode(xmlData, "macroAliasToAdd"); string dataTypeName = GetAttributeValueFromNode(xmlData, "dataTypeNameToUpdate"); if (!string.IsNullOrEmpty(macroAlias) && !string.IsNullOrEmpty(dataTypeName)) { log.InfoFormat("Add macro alias: {0} to data type with name: {1}", macroAlias, dataTypeName); DataTypeDefinition[] definitions = DataTypeDefinition.GetAll(); DataTypeDefinition datatypeToUpdate = definitions.SingleOrDefault(dt => dt.Text == dataTypeName);
if (datatypeToUpdate == null) { log.ErrorFormat("Data type with name '{0}' not found!", dataTypeName); return false; }
if (datatypeToUpdate.DataType.Id != macroPiackerDataTypeId) { log.ErrorFormat("Data type with name '{0}' has wrong data type id: {1} should be: {2}!", dataTypeName, datatypeToUpdate.DataType.Id, macroPiackerDataTypeId); return false; }
List<string> values = GetPreValues(datatypeToUpdate.Id); if (!values.Contains(macroAlias)) { log.InfoFormat("Adding macro alias: {0} to data type with name: {1}", macroAlias, dataTypeName); values.Add(macroAlias); string[] valuesAsArray = values.ToArray(); string newDataTypePrevalue = string.Join(",", valuesAsArray); SavePreValues(newDataTypePrevalue, datatypeToUpdate.Id); log.InfoFormat("Macro alias: {0} added to data type with name: {1}", macroAlias, dataTypeName); } } log.Info("AddMacroAliasToMacroPicker action ended"); return true; }
MacroPicker: Package action AddMacroAliasToMacroPicker in this tread
I love the MacroPicker!
We have created a package action wich can add a new MacroAlias to the "Allowed Macros" list.
Maybe you can use to?
Source code below
We use log4net, please remove from the code if you do not use log4net
is working on a reply...