From 9dfe873de01a7a7c31d2358b2bb5ecd719949943 Mon Sep 17 00:00:00 2001 From: hartvig Date: Mon, 6 Dec 2010 13:49:34 +0000 Subject: [PATCH] WIP IMacroEngine [TFS Changeset #81536] --- umbraco.MacroEngines/DLRScriptingEngine.cs | 56 +++++ .../Properties/AssemblyInfo.cs | 36 ++++ umbraco.MacroEngines/Scripting/MacroScript.cs | 65 ++++++ .../Scripting/ScriptEngine.cs | 199 ++++++++++++++++++ .../umbraco.MacroEngines.csproj | 89 ++++++++ .../umbraco.MacroEngines.csproj.vspscc | 10 + umbraco.sln | 11 +- .../cms/businesslogic/macro/IMacroEngine.cs | 27 +++ .../businesslogic/macro/MacroEngineFactory.cs | 112 ++++++++++ umbraco/cms/businesslogic/macro/MacroModel.cs | 66 ++++++ .../cms/businesslogic/skinning/Skinning.cs | 80 +++---- umbraco/cms/umbraco.cms.csproj | 3 + umbraco/interfaces/INode.cs | 43 ++++ umbraco/interfaces/umbraco.interfaces.csproj | 1 + umbraco/presentation/macro.cs | 133 +++--------- umbraco/presentation/requestHandler.cs | 2 +- .../presentation/umbraco.presentation.csproj | 8 - .../umbraco/create/DLRScripting.ascx.cs | 5 +- .../presentation/umbraco/nodeFactory/Page.cs | 21 +- .../umbraco/templateControls/Script.cs | 3 +- .../webservices/codeEditorSave.asmx.cs | 3 +- 21 files changed, 811 insertions(+), 162 deletions(-) create mode 100644 umbraco.MacroEngines/DLRScriptingEngine.cs create mode 100644 umbraco.MacroEngines/Properties/AssemblyInfo.cs create mode 100644 umbraco.MacroEngines/Scripting/MacroScript.cs create mode 100644 umbraco.MacroEngines/Scripting/ScriptEngine.cs create mode 100644 umbraco.MacroEngines/umbraco.MacroEngines.csproj create mode 100644 umbraco.MacroEngines/umbraco.MacroEngines.csproj.vspscc create mode 100644 umbraco/cms/businesslogic/macro/IMacroEngine.cs create mode 100644 umbraco/cms/businesslogic/macro/MacroEngineFactory.cs create mode 100644 umbraco/cms/businesslogic/macro/MacroModel.cs create mode 100644 umbraco/interfaces/INode.cs diff --git a/umbraco.MacroEngines/DLRScriptingEngine.cs b/umbraco.MacroEngines/DLRScriptingEngine.cs new file mode 100644 index 0000000000..f9a5e01e21 --- /dev/null +++ b/umbraco.MacroEngines/DLRScriptingEngine.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using umbraco.cms.businesslogic.macro; +using umbraco.interfaces; +using umbraco.IO; +using umbraco.MacroEngines.Scripting; + +namespace umbraco.MacroEngines +{ + public class DLRScriptingEngine : IMacroEngine + { + public string Name + { + get { return "Umbraco DLR Macro Engine"; } + } + + public List SupportedExtensions + { + get + { + var exts = new List {"py", "rb"}; + return exts; + } + } + + public Dictionary SupportedProperties + { + get { throw new NotImplementedException(); } + } + + + public bool Validate(string code, INode currentPage, out string errorMessage) + { + throw new NotImplementedException(); + } + + public string Execute(MacroModel macro, INode currentPage) + { + string fileEnding = macro.ScriptName.Substring(macro.ScriptName.LastIndexOf('.')).Trim('.'); + + MacroScriptEngine mse = MacroScriptEngine.LoadEngineByFileExtension(fileEnding); + + SortedDictionary vars = new SortedDictionary(); + vars.Add("currentPage", currentPage); + foreach (MacroPropertyModel prop in macro.Properties) + { + vars.Add(prop.Key, prop.Value); + } + mse.ScriptVariables = vars; + + return mse.ExecuteFile(IOHelper.MapPath(SystemDirectories.Python + "/" + macro.ScriptName)); + } + } +} diff --git a/umbraco.MacroEngines/Properties/AssemblyInfo.cs b/umbraco.MacroEngines/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..db6f1457c5 --- /dev/null +++ b/umbraco.MacroEngines/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("umbraco.MacroEngines")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("umbraco.MacroEngines")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fef82f07-246f-406a-8a80-db0163bf41dc")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/umbraco.MacroEngines/Scripting/MacroScript.cs b/umbraco.MacroEngines/Scripting/MacroScript.cs new file mode 100644 index 0000000000..973f949ce6 --- /dev/null +++ b/umbraco.MacroEngines/Scripting/MacroScript.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Scripting.Hosting; + +namespace umbraco.MacroEngines.Scripting +{ + public class MacroScript + { + public static string Execute(string script, string scriptType, Hashtable variables) + { + MacroScriptEngine mse = new MacroScriptEngine(scriptType); + mse.ScriptVariables = ConvertHashTable(variables); + mse.Script = script; + return mse.Execute(); + } + + public static string Evaluate(string script, string scriptType, Hashtable variables) + { + MacroScriptEngine mse = new MacroScriptEngine(scriptType); + mse.ScriptVariables = ConvertHashTable(variables); + mse.Script = script; + return mse.Evaluate(); + } + + public static string ExecuteFile(string path, Hashtable variables) + { + string fileEnding = path.Substring(path.LastIndexOf('.')).Trim('.'); + + MacroScriptEngine mse = MacroScriptEngine.LoadEngineByFileExtension(fileEnding); + mse.ScriptVariables = ConvertHashTable(variables); + + return mse.ExecuteFile(path); + } + + //friendly helpers.... + public static string ExecutePython(string script, Hashtable variables) + { + return Execute(script, "python", variables); + } + + public static string ExecuteRuby(string script, Hashtable variables) + { + return Execute(script, "ruby", variables); + } + + private static SortedDictionary ConvertHashTable(Hashtable ht) + { + SortedDictionary retval = new SortedDictionary(); + foreach (DictionaryEntry de in ht) + { + retval.Add(de.Key.ToString(), de.Value); + } + + return retval; + } + + public static List GetAvailableLanguages() + { + return ScriptRuntimeSetup.ReadConfiguration().LanguageSetups.ToList(); + } + } +} diff --git a/umbraco.MacroEngines/Scripting/ScriptEngine.cs b/umbraco.MacroEngines/Scripting/ScriptEngine.cs new file mode 100644 index 0000000000..bcec3b5ab8 --- /dev/null +++ b/umbraco.MacroEngines/Scripting/ScriptEngine.cs @@ -0,0 +1,199 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using Microsoft.Scripting; +using Microsoft.Scripting.Hosting; + +namespace umbraco.MacroEngines.Scripting +{ + internal class MacroScriptEngine + { + ScriptRuntime m_runTime; + ScriptEngine m_engine; + ExceptionOperations m_exceptionOperations; + SortedDictionary m_inputVariables; + SortedDictionary m_outputVariables; + string m_script; + MemoryStream m_output; + + internal MacroScriptEngine() { } + + internal MacroScriptEngine(string scriptType) + { + loadRunTime(); + m_engine = m_runTime.GetEngine(scriptType); + m_exceptionOperations = m_engine.GetService(); + } + + internal static MacroScriptEngine LoadEngineByFileExtension(string fileExtension) + { + MacroScriptEngine mse = new MacroScriptEngine(); + mse.loadRunTime(); + mse.m_engine = mse.m_runTime.GetEngineByFileExtension(fileExtension); + mse.m_exceptionOperations = mse.m_engine.GetService(); + return mse; + } + + internal static MacroScriptEngine GetEngineByType(string scriptType) + { + MacroScriptEngine mse = new MacroScriptEngine(); + mse.loadRunTime(); + mse.m_engine = mse.m_runTime.GetEngine(scriptType); + mse.m_exceptionOperations = mse.m_engine.GetService(); + return mse; + } + + private void loadRunTime() + { + m_output = new MemoryStream(); + m_runTime = ScriptRuntime.CreateFromConfiguration(); + + m_runTime.IO.SetOutput(m_output, new StreamWriter(m_output)); + m_runTime.IO.SetErrorOutput(m_output, new StreamWriter(m_output)); + + Assembly pluginsAssembly = Assembly.LoadFile(IO.IOHelper.MapPath(IO.SystemDirectories.Bin + "/umbraco.dll")); + m_runTime.LoadAssembly(pluginsAssembly); + + m_runTime.LoadAssembly(typeof(String).Assembly); + m_runTime.LoadAssembly(typeof(Uri).Assembly); + m_runTime.LoadAssembly(typeof(umbraco.presentation.nodeFactory.Node).Assembly); + } + + + internal SortedDictionary ScriptVariables + { + set { m_inputVariables = value; } + } + + internal SortedDictionary OutPutVariables + { + get { return m_outputVariables; } + } + + internal string Script + { + set { m_script = value; } + } + + internal ExceptionOperations ExceptionOperations + { + get { return m_exceptionOperations; } + } + + internal string Evaluate() + { + //Create structures + SourceCodeKind sc = SourceCodeKind.Expression; + ScriptSource source = m_engine.CreateScriptSourceFromString(m_script, sc); + ScriptScope scope = m_engine.CreateScope(); + + //Fill input variables + foreach (KeyValuePair variable in m_inputVariables) + { + scope.SetVariable(variable.Key, variable.Value); + } + + string result = ""; + + try + { + object r = source.Execute(scope); + + if (r != null) + result = r.ToString(); + } + catch (Exception e) + { + umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, e.ToString()); + result = m_exceptionOperations.FormatException(e); + } + + return result; + } + + internal string Execute() + { + SourceCodeKind sc = SourceCodeKind.Statements; + ScriptSource source = m_engine.CreateScriptSourceFromString(m_script, sc); + ScriptScope scope = m_engine.CreateScope(); + + //Fill input variables + foreach (KeyValuePair variable in m_inputVariables) + { + scope.SetVariable(variable.Key, variable.Value); + } + + source.Execute(scope); + + m_outputVariables = new SortedDictionary(); + foreach (string variable in scope.GetVariableNames()) + { + m_outputVariables.Add(variable, scope.GetVariable(variable)); + } + + return ReadFromStream(m_output); + } + + internal string ExecuteFile(string path) + { + string rbCode; + + // OpenText will strip the BOM and keep the Unicode intact + using (var rdr = File.OpenText(path)) + { + rbCode = rdr.ReadToEnd(); + } + + m_script = rbCode; + return Execute(); + } + + internal SortedDictionary _Execute() + { + //Create structures + SourceCodeKind sc = SourceCodeKind.Statements; + ScriptSource source = m_engine.CreateScriptSourceFromString(m_script, sc); + ScriptScope scope = m_engine.CreateScope(); + + //Fill input variables + foreach (KeyValuePair variable in m_inputVariables) + { + scope.SetVariable(variable.Key, variable.Value); + } + + SortedDictionary outputVariables = new SortedDictionary(); + //Execute the script + try + { + + source.Execute(scope); + //Recover variables + foreach (string variable in scope.GetVariableNames()) + { + outputVariables.Add(variable, scope.GetVariable(variable)); + } + } + catch (Exception e) + { + string error = m_exceptionOperations.FormatException(e); + //Do something with the pretty printed error + throw; + } + return outputVariables; + } + + private static string ReadFromStream(MemoryStream ms) + { + int length = (int)ms.Length; + Byte[] bytes = new Byte[length]; + + ms.Seek(0, SeekOrigin.Begin); + ms.Read(bytes, 0, (int)ms.Length); + + return Encoding.GetEncoding("utf-8").GetString(bytes, 0, (int)ms.Length); + } + } +} diff --git a/umbraco.MacroEngines/umbraco.MacroEngines.csproj b/umbraco.MacroEngines/umbraco.MacroEngines.csproj new file mode 100644 index 0000000000..76dd19286e --- /dev/null +++ b/umbraco.MacroEngines/umbraco.MacroEngines.csproj @@ -0,0 +1,89 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {6AE67079-2C00-476C-81DE-2800D1AC14BC} + Library + Properties + umbraco.MacroEngines + umbraco.MacroEngines + v3.5 + 512 + SAK + SAK + SAK + SAK + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\foreign dlls\DLR 2.0 SP1\Microsoft.Scripting.dll + + + False + ..\foreign dlls\DLR 2.0 SP1\Microsoft.Scripting.Core.dll + + + + + + + + + + + + + + + + + {E469A9CE-1BEC-423F-AC44-713CD72457EA} + umbraco.businesslogic + + + {CCD75EC3-63DB-4184-B49D-51C1DD337230} + umbraco.cms + + + {511F6D8D-7717-440A-9A57-A507E9A8B27F} + umbraco.interfaces + + + {651E1350-91B6-44B7-BD60-7207006D7003} + umbraco.presentation + + + + + xcopy "$(TargetPath)" "$(SolutionDir)\umbraco\presentation\bin" /Y + + + \ No newline at end of file diff --git a/umbraco.MacroEngines/umbraco.MacroEngines.csproj.vspscc b/umbraco.MacroEngines/umbraco.MacroEngines.csproj.vspscc new file mode 100644 index 0000000000..feffdecaa4 --- /dev/null +++ b/umbraco.MacroEngines/umbraco.MacroEngines.csproj.vspscc @@ -0,0 +1,10 @@ +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" +} diff --git a/umbraco.sln b/umbraco.sln index a83f8dc078..8c441a1420 100644 --- a/umbraco.sln +++ b/umbraco.sln @@ -105,9 +105,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{194009 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlCE4Umbraco", "components\SQLCE4Umbraco\SqlCE4Umbraco.csproj", "{5BA5425F-27A7-4677-865E-82246498AA2E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "umbraco.MacroEngines", "umbraco.MacroEngines\umbraco.MacroEngines.csproj", "{6AE67079-2C00-476C-81DE-2800D1AC14BC}" +EndProject Global GlobalSection(TeamFoundationVersionControl) = preSolution - SccNumberOfProjects = 15 + SccNumberOfProjects = 16 SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} SccTeamFoundationServer = https://tfs.codeplex.com/tfs/tfs01 SccLocalPath0 = . @@ -153,6 +155,9 @@ Global SccProjectUniqueName14 = components\\SQLCE4Umbraco\\SqlCE4Umbraco.csproj SccProjectName14 = components/SQLCE4Umbraco SccLocalPath14 = components\\SQLCE4Umbraco + SccProjectUniqueName15 = umbraco.MacroEngines\\umbraco.MacroEngines.csproj + SccProjectName15 = umbraco.MacroEngines + SccLocalPath15 = umbraco.MacroEngines EndGlobalSection GlobalSection(TestCaseManagementSettings) = postSolution CategoryFile = umbraco2.vsmdi @@ -215,6 +220,10 @@ Global {5BA5425F-27A7-4677-865E-82246498AA2E}.Debug|Any CPU.Build.0 = Debug|Any CPU {5BA5425F-27A7-4677-865E-82246498AA2E}.Release|Any CPU.ActiveCfg = Release|Any CPU {5BA5425F-27A7-4677-865E-82246498AA2E}.Release|Any CPU.Build.0 = Release|Any CPU + {6AE67079-2C00-476C-81DE-2800D1AC14BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6AE67079-2C00-476C-81DE-2800D1AC14BC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6AE67079-2C00-476C-81DE-2800D1AC14BC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6AE67079-2C00-476C-81DE-2800D1AC14BC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/umbraco/cms/businesslogic/macro/IMacroEngine.cs b/umbraco/cms/businesslogic/macro/IMacroEngine.cs new file mode 100644 index 0000000000..f23a9dfde6 --- /dev/null +++ b/umbraco/cms/businesslogic/macro/IMacroEngine.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using umbraco.interfaces; + +namespace umbraco.cms.businesslogic.macro +{ + public interface IMacroEngine + { + string Name + { + get; + } + List SupportedExtensions + { + get; + } + Dictionary SupportedProperties + { + get; + } + + bool Validate(string code, INode currentPage, out string errorMessage); + string Execute(MacroModel macro, INode currentPage); + } +} diff --git a/umbraco/cms/businesslogic/macro/MacroEngineFactory.cs b/umbraco/cms/businesslogic/macro/MacroEngineFactory.cs new file mode 100644 index 0000000000..9fb71c9b52 --- /dev/null +++ b/umbraco/cms/businesslogic/macro/MacroEngineFactory.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using umbraco.BusinessLogic.Utils; +using umbraco.interfaces; + +namespace umbraco.cms.businesslogic.macro +{ + public class MacroEngineFactory + { + private static readonly Dictionary m_engines = new Dictionary(); + private static readonly List m_allEngines = new List(); + public MacroEngineFactory() + { + Initialize(); + } + + protected static void Initialize() + { + List types = TypeFinder.FindClassesOfType(); + getEngines(types); + } + + private static void getEngines(List types) + { + foreach (Type t in types) + { + IMacroEngine typeInstance = null; + try + { + if (t.IsVisible) + { + typeInstance = Activator.CreateInstance(t) as IMacroEngine; + } + } + catch { } + if (typeInstance != null) + { + try + { + m_engines.Add(typeInstance.Name, t); + } + catch (Exception ee) + { + BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Error, -1, "Can't import MacroEngine '" + t.FullName + "': " + ee); + } + } + } + } + + public static List GetAll() + { + + if (m_allEngines.Count == 0) + { + Initialize(); + foreach (string name in m_engines.Keys) + { + m_allEngines.Add(GetEngine(name)); + } + } + + return m_allEngines; + } + + public static IMacroEngine GetEngine(string name) + { + if (m_engines.ContainsKey(name)) + { + var newObject = Activator.CreateInstance(m_engines[name]) as IMacroEngine; + return newObject; + } + + return null; + } + + public static IMacroEngine GetByFilename(string filename) + { + if (filename.Contains(".")) + { + string extension = filename.Substring(filename.LastIndexOf(".") + 1); + return GetByExtension(extension); + } + + throw new MacroEngineException(string.Format("No MacroEngine matches the file with extension '{0}'", filename)); + } + + public static IMacroEngine GetByExtension(string extension) + { + IMacroEngine engine = + GetAll().Find(t => t.SupportedExtensions.Contains(extension)); + if (engine != null) + { + return engine; + } + + throw new MacroEngineException(string.Format("No MacroEngine found for extension '{0}'", extension)); + } + } + + public class MacroEngineException : Exception + { + public MacroEngineException() : base() { } + + public MacroEngineException(string msg) + : base(msg) + { + + } + } +} diff --git a/umbraco/cms/businesslogic/macro/MacroModel.cs b/umbraco/cms/businesslogic/macro/MacroModel.cs new file mode 100644 index 0000000000..5a5d3cb47e --- /dev/null +++ b/umbraco/cms/businesslogic/macro/MacroModel.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace umbraco.cms.businesslogic.macro +{ + + [Serializable] + public class MacroModel + { + public string Name { get; set; } + public string Alias { get; set; } + + public string TypeAssembly { get; set; } + public string TypeName { get; set; } + public string Xslt { get; set; } + public string ScriptName { get; set; } + public string ScriptCode { get; set; } + + public int CacheDuration { get; set; } + public bool CacheByPage { get; set; } + public bool CacheByMember { get; set; } + + public List Properties { get; set; } + + public MacroModel() + { + Properties = new List(); + } + + public MacroModel(string name, string alias, string typeAssembly, string typeName, string xslt, string scriptName, int cacheDuration, bool cacheByPage, bool cacheByMember) + { + Name = name; + Alias = alias; + TypeAssembly = typeAssembly; + TypeName = typeName; + Xslt = xslt; + ScriptName = scriptName; + CacheDuration = cacheDuration; + CacheByPage = cacheByPage; + CacheByMember = cacheByMember; + + Properties = new List(); + } + } + + [Serializable] + public class MacroPropertyModel + { + public string Key { get; set; } + public string Value { get; set; } + + public MacroPropertyModel() + { + + } + + public MacroPropertyModel(string key, string value) + { + Key = key; + Value = value; + } + } +} diff --git a/umbraco/cms/businesslogic/skinning/Skinning.cs b/umbraco/cms/businesslogic/skinning/Skinning.cs index 4f17c7e2dd..d4924cff68 100644 --- a/umbraco/cms/businesslogic/skinning/Skinning.cs +++ b/umbraco/cms/businesslogic/skinning/Skinning.cs @@ -21,26 +21,27 @@ namespace umbraco.cms.businesslogic.skinning static private string _skinningXmlSource = IOHelper.MapPath(SystemFiles.SkinningXml, false); private const string CACHEKEY = "SkinnableTemplates"; - + private static void clearCheckPages() { _checkedPages.Clear(); } - + public static void RollbackSkin(int template) { string currentSkin = GetCurrentSkinAlias(template); Skin skin = Skin.CreateFromAlias(currentSkin); - if (skin != null) { - skin.RollbackDependencies(); + if (skin != null) + { + skin.RollbackDependencies(); - if (skin.OverridesTemplates()) - skin.RollbackTemplateFiles(); + if (skin.OverridesTemplates()) + skin.RollbackTemplateFiles(); - //else - // skin.RollbackDependencies(); + //else + // skin.RollbackDependencies(); } RemoveSkin(template); @@ -57,10 +58,11 @@ namespace umbraco.cms.businesslogic.skinning { //lookup template in skinning.config string currentSkin = GetCurrentSkinAlias(template); - + //if different from current, and the template is skinned - if(currentSkin != skinAlias){ - + if (currentSkin != skinAlias) + { + //this will restore the files to the standard runway, as they looked before the skin was applied if (currentSkin != string.Empty) { @@ -80,19 +82,19 @@ namespace umbraco.cms.businesslogic.skinning } } - - + + private static void save() { - System.IO.FileStream f = System.IO.File.Open(_skinningXmlSource, FileMode.Create); - SkinXml.Save(f); - f.Close(); + System.IO.FileStream f = System.IO.File.Open(_skinningXmlSource, FileMode.Create); + SkinXml.Save(f); + f.Close(); } public static string GetCurrentSkinAlias(int templateID) { XmlElement x = (XmlElement)getTemplate(templateID); - if(x != null && x.HasAttribute("alias") && !string.IsNullOrEmpty(x.Attributes["alias"].Value)) + if (x != null && x.HasAttribute("alias") && !string.IsNullOrEmpty(x.Attributes["alias"].Value)) return x.Attributes["alias"].Value; return string.Empty; @@ -146,8 +148,8 @@ namespace umbraco.cms.businesslogic.skinning } } return skins; - } - + } + private static XmlDocument SkinXml { @@ -254,13 +256,13 @@ namespace umbraco.cms.businesslogic.skinning public static bool IsStarterKitInstalled() { - foreach(packager.InstalledPackage p in packager.InstalledPackage.GetAllInstalledPackages()) - { - if (p.Data.EnableSkins) - return true; - - } - return false; + foreach (packager.InstalledPackage p in packager.InstalledPackage.GetAllInstalledPackages()) + { + if (p.Data.EnableSkins) + return true; + + } + return false; } public static Guid? StarterKitGuid() @@ -276,16 +278,20 @@ namespace umbraco.cms.businesslogic.skinning public static Guid? StarterKitGuid(int template) { + string packageFile = IO.IOHelper.MapPath(SystemDirectories.Packages) + "/installed/installedPackages.config"; XmlDocument installed = new XmlDocument(); - installed.Load(IO.IOHelper.MapPath(SystemDirectories.Packages) + "/installed/installedPackages.config"); + if (File.Exists(packageFile)) + { + installed.Load(packageFile); - XmlNode starterKit = installed.SelectSingleNode( - string.Format("//package [@enableSkins = 'True' and @packageGuid != '' and contains(./templates, '{0}')]", template)); - - if (starterKit != null) - return new Guid(starterKit.Attributes["packageGuid"].Value); - else - return null; + XmlNode starterKit = installed.SelectSingleNode( + string.Format("//package [@enableSkins = 'True' and @packageGuid != '' and contains(./templates, '{0}')]", template)); + + if (starterKit != null) + return new Guid(starterKit.Attributes["packageGuid"].Value); + } + + return null; } public static bool HasAvailableSkins(int template) @@ -300,8 +306,8 @@ namespace umbraco.cms.businesslogic.skinning { string url = umbraco.cms.businesslogic.packager.InstalledPackage.GetByGuid(g.ToString()).Data.SkinWebserviceUrl; umbraco.cms.businesslogic.packager.repositories.Repository repo = cms.businesslogic.packager.repositories.Repository.getByGuid("65194810-1f85-11dd-bd0b-0800200c9a66"); - - if(!string.IsNullOrEmpty(url)) + + if (!string.IsNullOrEmpty(url)) repo.WebserviceUrl = url; r = repo.Webservice.Skins(g.ToString()).Length > 0; @@ -313,7 +319,7 @@ namespace umbraco.cms.businesslogic.skinning public static bool IsSkinInstalled(Guid SkinGuid) { - + return IsPackageInstalled(SkinGuid); } diff --git a/umbraco/cms/umbraco.cms.csproj b/umbraco/cms/umbraco.cms.csproj index 081cce52c3..74fa1a1722 100644 --- a/umbraco/cms/umbraco.cms.csproj +++ b/umbraco/cms/umbraco.cms.csproj @@ -208,6 +208,9 @@ Code + + + True True diff --git a/umbraco/interfaces/INode.cs b/umbraco/interfaces/INode.cs new file mode 100644 index 0000000000..d3c9ca1bd8 --- /dev/null +++ b/umbraco/interfaces/INode.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; + +namespace umbraco.interfaces +{ + public interface INode + { + INode Parent { get; } + int Id { get; } + int template { get; } + int SortOrder { get; } + string Name { get; } + string Url { get; } + string UrlName { get; } + string NodeTypeAlias { get; } + string WriterName { get; } + string CreatorName { get; } + int WriterID { get; } + int CreatorID { get; } + string Path { get; } + DateTime CreateDate { get; } + DateTime UpdateDate { get; } + Guid Version { get; } + string NiceUrl { get; } + int Level { get; } + List PropertiesAsList { get; } + List ChildrenAsList { get; } + IProperty GetProperty(string Alias); + DataTable ChildrenAsTable(); + DataTable ChildrenAsTable(string nodeTypeAliasFilter); + } + + public interface IProperty + { + string Alias { get; } + string Value { get; } + Guid Version { get; } + string ToString(); + } +} diff --git a/umbraco/interfaces/umbraco.interfaces.csproj b/umbraco/interfaces/umbraco.interfaces.csproj index 1c2cb51727..5b7d914f2c 100644 --- a/umbraco/interfaces/umbraco.interfaces.csproj +++ b/umbraco/interfaces/umbraco.interfaces.csproj @@ -149,6 +149,7 @@ Code + Code diff --git a/umbraco/presentation/macro.cs b/umbraco/presentation/macro.cs index 23516756a7..fc99a5376c 100644 --- a/umbraco/presentation/macro.cs +++ b/umbraco/presentation/macro.cs @@ -15,11 +15,11 @@ using System.Web.UI.WebControls; using System.Xml; using System.Xml.Xsl; using umbraco.BusinessLogic; +using umbraco.cms.businesslogic.macro; using umbraco.cms.businesslogic.member; using umbraco.DataLayer; using umbraco.interfaces; using umbraco.IO; -using umbraco.Models; using umbraco.presentation.nodeFactory; using umbraco.presentation.templateControls; using umbraco.presentation.xslt.Exslt; @@ -443,18 +443,18 @@ namespace umbraco try { HttpContext.Current.Trace.Write("umbracoMacro", - "DLR Script script added (" + ScriptFile + ")"); - MacroModel model = new MacroModel(this, attributes); + "MacroEngine script added (" + ScriptFile + ")"); + MacroModel model = ConvertToMacroModel(attributes); macroControl = loadMacroDLR(model); break; } catch (Exception e) { HttpContext.Current.Trace.Warn("umbracoMacro", - "Error loading python script (file: " + ScriptFile + + "Error loading MacroEngine script (file: " + ScriptFile + ", Type: '" + scriptType + "'", e); - var result = new LiteralControl("Error loading DLR script (file: " + ScriptFile + ")"); + var result = new LiteralControl("Error loading MacroEngine script (file: " + ScriptFile + ")"); /* string args = "
    "; @@ -534,6 +534,29 @@ namespace umbraco } } + public MacroModel ConvertToMacroModel(Hashtable attributes) + { + MacroModel model = new MacroModel( + this.Name, + this.Alias, + this.ScriptAssembly, + this.ScriptType, + this.XsltFile, + this.ScriptFile, + this.RefreshRate, + this.CacheByPage, + this.CacheByPersonalization + ); + + foreach (string key in attributes.Keys) + { + model.Properties.Add(new MacroPropertyModel(key, attributes[key].ToString())); + } + + return model; + } + + public static XslCompiledTransform CreateXsltTransform(XmlTextReader xslReader, bool debugMode) { var macroXSLT = new XslCompiledTransform(debugMode); @@ -1097,7 +1120,8 @@ namespace umbraco var ret = new LiteralControl(); string path = IOHelper.MapPath(SystemDirectories.Python + "/" + macro.ScriptName); -// ret.Text = MacroScript.ExecuteFile(path, args); + IMacroEngine engine = MacroEngineFactory.GetByFilename(path); + ret.Text = engine.Execute(macro, Node.GetCurrent()); return ret; } @@ -1624,101 +1648,4 @@ namespace umbraco return Namespace; } } -} - -namespace umbraco.Models -{ - [Serializable] - public class MacroModel - { - public string Name { get; set; } - public string Alias { get; set; } - - public string TypeAssembly { get; set; } - public string TypeName { get; set; } - public string Xslt { get; set; } - public string ScriptName { get; set; } - public string ScriptCode { get; set; } - - public int CacheDuration { get; set; } - public bool CacheByPage { get; set; } - public bool CacheByMember { get; set; } - - public List Properties { get; set; } - - public MacroModel() - { - Properties = new List(); - } - - public MacroModel(string name, string alias, string typeAssembly, string typeName, string xslt, string scriptName, int cacheDuration, bool cacheByPage, bool cacheByMember) - { - Name = name; - Alias = alias; - TypeAssembly = typeAssembly; - TypeName = typeName; - Xslt = xslt; - ScriptName = scriptName; - CacheDuration = cacheDuration; - CacheByPage = cacheByPage; - CacheByMember = cacheByMember; - - Properties = new List(); - } - - public MacroModel(macro macro, Hashtable attributes) - { - Name = macro.Name; - Alias = macro.Alias; - TypeAssembly = macro.ScriptAssembly; - TypeName = macro.ScriptType; - Xslt = macro.XsltFile; - ScriptName = macro.ScriptFile; - CacheDuration = macro.RefreshRate; - CacheByPage = macro.CacheByPage; - CacheByMember = macro.CacheByPersonalization; - - Properties = new List(); - foreach (string key in attributes.Keys) - { - Properties.Add(new MacroPropertyModel(key, attributes[key].ToString())); - } - } - - } - - [Serializable] - public class MacroPropertyModel - { - public string Key { get; set; } - public string Value { get; set; } - - public MacroPropertyModel() - { - - } - - public MacroPropertyModel(string key, string value) - { - Key = key; - Value = value; - } - } -} - -namespace umbraco.interfaces { - public interface IMacroEngine - { - string Name - { - get; - } - List SupportedExtensions - { - get; - } - - string Execute(MacroModel macro, Node currentPage); - } - } \ No newline at end of file diff --git a/umbraco/presentation/requestHandler.cs b/umbraco/presentation/requestHandler.cs index 3481cce15c..f3a77816b9 100644 --- a/umbraco/presentation/requestHandler.cs +++ b/umbraco/presentation/requestHandler.cs @@ -103,7 +103,7 @@ namespace umbraco { if (checkDomain && Domain.Exists(HttpContext.Current.Request.ServerVariables["SERVER_NAME"])) { // we need to get the node based on domain - Node n = new Node(Domain.GetRootFromDomain(HttpContext.Current.Request.ServerVariables["SERVER_NAME"])); + INode n = new Node(Domain.GetRootFromDomain(HttpContext.Current.Request.ServerVariables["SERVER_NAME"])); domainUrl = n.UrlName; // we don't use niceUrlFetch as we need more control if (n.Parent != null) { diff --git a/umbraco/presentation/umbraco.presentation.csproj b/umbraco/presentation/umbraco.presentation.csproj index 36cc19a29b..de2ccd89eb 100644 --- a/umbraco/presentation/umbraco.presentation.csproj +++ b/umbraco/presentation/umbraco.presentation.csproj @@ -106,12 +106,6 @@ C:\Users\Shannon\Documents\Visual Studio 2008\Projects\Umbraco\Branch-4.1\foreign dlls\Lucene.Net.dll - - ..\..\foreign dlls\DLR 2.0 SP1\Microsoft.Scripting.dll - - - ..\..\foreign dlls\DLR 2.0 SP1\Microsoft.Scripting.Core.dll - ..\..\foreign dlls\Nibble.Umb.ZipUpload.dll @@ -711,8 +705,6 @@ MemberSearch.ascx - - QuickSearch.ascx diff --git a/umbraco/presentation/umbraco/create/DLRScripting.ascx.cs b/umbraco/presentation/umbraco/create/DLRScripting.ascx.cs index d604ae4cb9..0598ab3821 100644 --- a/umbraco/presentation/umbraco/create/DLRScripting.ascx.cs +++ b/umbraco/presentation/umbraco/create/DLRScripting.ascx.cs @@ -10,7 +10,6 @@ using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; -using Microsoft.Scripting.Hosting; using umbraco.scripting; using umbraco.BasePages; @@ -23,12 +22,12 @@ namespace umbraco.presentation.create protected void Page_Load(object sender, System.EventArgs e) { sbmt.Text = ui.Text("create"); - +/* foreach (LanguageSetup ls in MacroScript.GetAvailableLanguages()) { filetype.Items.Add( new ListItem( ls.DisplayName, ls.FileExtensions[0].Trim('.'))); } - +*/ if(!Page.IsPostBack) filetype.SelectedIndex = 0; diff --git a/umbraco/presentation/umbraco/nodeFactory/Page.cs b/umbraco/presentation/umbraco/nodeFactory/Page.cs index 08172f9755..bc3a62d493 100644 --- a/umbraco/presentation/umbraco/nodeFactory/Page.cs +++ b/umbraco/presentation/umbraco/nodeFactory/Page.cs @@ -8,16 +8,18 @@ using System.Xml.XPath; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.propertytype; using System.Collections.Generic; +using umbraco.interfaces; namespace umbraco.presentation.nodeFactory { + /// /// Summary description for Node. /// [Serializable] [XmlType(Namespace = "http://umbraco.org/webservices/")] - public class Node + public class Node : INode { private Hashtable _aliasToNames = new Hashtable(); @@ -52,7 +54,7 @@ namespace umbraco.presentation.nodeFactory } } - public Node Parent + public INode Parent { get { @@ -198,7 +200,7 @@ namespace umbraco.presentation.nodeFactory } } - internal string UrlName + public string UrlName { get { @@ -226,6 +228,11 @@ namespace umbraco.presentation.nodeFactory } } + public List PropertiesAsList + { + get { return Properties.Cast().ToList(); } + } + public Properties Properties { get @@ -298,7 +305,7 @@ namespace umbraco.presentation.nodeFactory initialize(); } - public Property GetProperty(string Alias) + public IProperty GetProperty(string Alias) { foreach (Property p in Properties) { @@ -319,9 +326,9 @@ namespace umbraco.presentation.nodeFactory } - public List ChildrenAsList + public List ChildrenAsList { - get { return Children.Cast().ToList(); } + get { return Children.Cast().ToList(); } } public DataTable ChildrenAsTable() @@ -571,7 +578,7 @@ namespace umbraco.presentation.nodeFactory [Serializable] [XmlType(Namespace = "http://umbraco.org/webservices/")] - public class Property + public class Property : IProperty { private Guid _version; private string _alias; diff --git a/umbraco/presentation/umbraco/templateControls/Script.cs b/umbraco/presentation/umbraco/templateControls/Script.cs index 51c5c661c4..3ced82332d 100644 --- a/umbraco/presentation/umbraco/templateControls/Script.cs +++ b/umbraco/presentation/umbraco/templateControls/Script.cs @@ -56,7 +56,8 @@ namespace umbraco.presentation.templateControls Hashtable attr = new Hashtable((Hashtable)Context.Items["pageElements"]); attr.Add("currentPage", nodeFactory.Node.GetCurrent()); - string result = MacroScript.Execute(this.Text, this.Language, attr); + // TODO: Hook the new MacroEngine + string result = ""; // MacroScript.Execute(this.Text, this.Language, attr); writer.Write(result); diff --git a/umbraco/presentation/umbraco/webservices/codeEditorSave.asmx.cs b/umbraco/presentation/umbraco/webservices/codeEditorSave.asmx.cs index 488890a069..6c72010fa8 100644 --- a/umbraco/presentation/umbraco/webservices/codeEditorSave.asmx.cs +++ b/umbraco/presentation/umbraco/webservices/codeEditorSave.asmx.cs @@ -251,7 +251,8 @@ namespace umbraco.presentation.webservices try { - MacroScript.ExecuteFile(tempFileName, args); + // TODO: Hook the new MacroEngine +// MacroScript.ExecuteFile(tempFileName, args); } catch (Exception err) {