public static bool Delete(string themeId, string identifier, ScriptletType scriptletType, bool isCustom) { Scriptlet s = Load(themeId, identifier, scriptletType, (isCustom ? BitFieldState.True : BitFieldState.False), false); if (s != null) { return(s.Delete()); } return(false); }
private string GetMergedTemplate() { Scriptlet layout = ScriptletDataSource.Load(this.Page.Theme, this.Layout, ScriptletType.Layout, true); //IF THE DESIRED LAYOUT IS NOT FOUND, RETURN DEFAULT THREE COLUMN LAYOUT if (layout == null) { return("<table width=100%><tr><td colspan=3>[[layout:header]]</td></tr><tr><td></td><td>[[layout:leftsidebar]]</td><td>[[layout:content]]</td><td>[[layout:rightsidebar]]</td></tr><tr><td colspan=3>[[layout:footer]]</td></tr></table>"); } //CHECK FOR HEADER OPTIONS if (!string.IsNullOrEmpty(layout.HeaderData)) { this.Page.Header.Controls.Add(new LiteralControl(layout.HeaderData)); } string mergedTemplate = layout.ScriptletData; MatchCollection nestedScriptlets = Regex.Matches(mergedTemplate, "\\[\\[(header|footer|sidebar|sidebar2|leftsidebar|rightsidebar|content):([^\\]]+)\\]\\]", RegexOptions.IgnoreCase); if (nestedScriptlets.Count > 0) { StringBuilder mergedTemplateBuilder = new StringBuilder(); int currentIndex = 0; foreach (Match match in nestedScriptlets) { //output the literal content up to the match index if (currentIndex < match.Index) { mergedTemplateBuilder.Append(mergedTemplate.Substring(currentIndex, (match.Index - currentIndex))); currentIndex = match.Index; } //include the nested scriptlet ScriptletType nestedType = (ScriptletType)Enum.Parse(typeof(ScriptletType), match.Groups[1].Value); string nestedIdentifier = match.Groups[2].Value.Trim(); Scriptlet nestedScriptlet = ScriptletDataSource.Load(this.Page.Theme, nestedIdentifier, nestedType, true); if (nestedScriptlet != null) { if (!string.IsNullOrEmpty(nestedScriptlet.HeaderData)) { this.Page.Header.Controls.Add(new LiteralControl(nestedScriptlet.HeaderData)); } mergedTemplateBuilder.Append(nestedScriptlet.ScriptletData); } //advance the current index currentIndex += match.Length; } //output any remaining literal content if (currentIndex < mergedTemplate.Length) { mergedTemplateBuilder.Append(mergedTemplate.Substring(currentIndex)); } mergedTemplate = mergedTemplateBuilder.ToString(); } return(mergedTemplate); }
/// <summary> /// Creates a copy of the given scriptlet /// </summary> /// <param name="themeId">Name/Identifier of the theme</param> /// <param name="identifier">Identifier of scriptlet to create copy of</param> /// <param name="scriptletType">Type of scriptlet to create copy of</param> /// <returns>Copy of the given scriptlet</returns> public static Scriptlet Copy(string themeId, string identifier, ScriptletType scriptletType) { Scriptlet copy = ScriptletDataSource.Load(themeId, identifier, scriptletType, false); if (copy != null) { copy.Identifier = "Copy of " + copy.Identifier; copy.IsCustom = true; copy.ClearLoadedState(); return(copy); } return(null); }
/// <summary> /// Gets the index of the specified scriptlet in this collection /// </summary> /// <param name="identifier">Identifier of the scriptlet to find index of</param> /// <param name="scriptletType">Type of the scriptlet to find index of</param> /// <param name="isCustom">Indicates whether this a custom scriptlet or default scriptlet or any of the two</param> /// <returns>Index of the specified scriptlet in this collection</returns> public int IndexOf(string identifier, ScriptletType scriptletType, BitFieldState isCustom) { bool custom = (isCustom == BitFieldState.True); for (int i = 0; i < this.Count; i++) { Scriptlet s = this[i]; if ((identifier == s.Identifier) && (scriptletType == s.ScriptletType)) { if ((isCustom == BitFieldState.Any) || (custom == s.IsCustom)) { return(i); } } } return(-1); }
/// <summary> /// Loads a collection of Scriptlet Objects for the given theme and given type from the cache /// </summary> /// <param name="scriptletType">Type of scriptlets to load</param> /// <param name="sortExpression">The sort expression to use for sorting the loaded objects.</param> /// <param name="themeId">Theme for which to load the scriptlets</param> /// <returns>A collection of Scriptlet objects</returns> public static ScriptletCollection CacheLoad(string themeId, ScriptletType scriptletType, string sortExpression) { ScriptletCollection scriptlets = GetCachedScriptlets(themeId); ScriptletCollection subset = new ScriptletCollection(); foreach (Scriptlet item in scriptlets) { if ((scriptletType == ScriptletType.Unspecified) || (item.ScriptletType == scriptletType)) { subset.Add(item); } } if (sortExpression != string.Empty) { subset.Sort(sortExpression); } return(subset); }
/// <summary> /// Gets the file path for given scriptlet details /// </summary> /// <param name="themeId">Name/Identifier of the theme</param> /// <param name="identifier">The scriptlet identifier</param> /// <param name="scriptletType">The scriptlet type</param> /// <param name="custom">Whether the scriptlet is a custom scriptlet</param> /// <returns>The file path of the scriptlet</returns> private static string GetFilePath(string themeId, string identifier, ScriptletType scriptletType, bool custom) { if (string.IsNullOrEmpty(themeId)) { return("App_Data\\Scriptlets" + (custom ? "\\Custom\\" : "\\Default\\") + scriptletType.ToString() + "\\" + identifier + ".htm"); } else { string pathPart = "App_Themes\\" + themeId + "\\Scriptlets"; if (Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pathPart))) { return("App_Themes\\" + themeId + "\\Scriptlets" + (custom ? "\\Custom\\" : "\\Default\\") + scriptletType.ToString() + "\\" + identifier + ".htm"); } else { return("App_Data\\Scriptlets" + (custom ? "\\Custom\\" : "\\Default\\") + scriptletType.ToString() + "\\" + identifier + ".htm"); } } }
/// <summary> /// Loads a Scriptlet object with given identifier and type from the database /// </summary> /// <param name="themeId">Name/Identifier of the theme</param> /// <param name="identifier">Identifier of Scriptlet to load</param> /// <param name="scriptletType">Type of of Scriptlet to load</param> /// <param name="custom">Is the Scriptlet to be loaded a custom scriptlet?</param> /// <param name="useCache">If <b>true</b> tries to load the object from cache first</param> /// <returns>The Scriptlet object loaded</returns> public static Scriptlet Load(string themeId, string identifier, ScriptletType scriptletType, BitFieldState custom, bool useCache) { if (useCache) { ScriptletCollection scriptlets = CacheLoad(themeId); int index = scriptlets.IndexOf(identifier, scriptletType, custom); if (index > -1) { return(scriptlets[index]); } return(null); } //(DO NOT USE CACHE, LOAD FOR THE NAME) Scriptlet s = new Scriptlet(); if (s.Load(themeId, identifier, scriptletType, custom)) { return(s); } return(null); }
private void HandleEdit(DropDownList choices, ScriptletType scriptletType) { Control c = RecursiveFindControl(this.Page, "EditScriptlet"); if (c != null) { Scriptlet s = ScriptletDataSource.Load(this.Page.Theme, choices.SelectedValue, scriptletType); if (s != null) { System.Reflection.PropertyInfo i = c.GetType().GetProperty("Identifier"); i.SetValue(c, s.Identifier, null); System.Reflection.PropertyInfo t = c.GetType().GetProperty("ScriptletType"); t.SetValue(c, s.ScriptletType, null); //we do not want the edit-mode section to disappear when user clicked on //the edit icon without selecting any valid scriptlet in the dropdown c = RecursiveFindControl(this.Page, "phEditor"); if (c != null) { c.Visible = false; } } } }
/// <summary> /// Creates a copy of the given scriptlet /// </summary> /// <param name="identifier">Identifier of scriptlet to create copy of</param> /// <param name="scriptletType">Type of scriptlet to create copy of</param> /// <returns>Copy of the given scriptlet</returns> public static Scriptlet Copy(string identifier, ScriptletType scriptletType) { return(Copy(string.Empty, identifier, scriptletType)); }
internal void ClearLoadedState() { _LoadedIdentifier = string.Empty; _LoadedIsCustom = false; _LoadedScriptletType = ScriptletType.Unspecified; }
/// <summary> /// Loads this scriptlet object for given scriptlet identifier and scriptlet type /// </summary> /// <param name="themeId">Name/Identifier of the theme</param> /// <param name="identifier">criptlet identifier</param> /// <param name="scriptletType">The scriptlet type</param> /// <param name="custom">Is it a custom scriptlet, default script or any of the two</param> /// <returns></returns> public bool Load(string themeId, string identifier, ScriptletType scriptletType, BitFieldState custom) { //VALIDATE INPUT PARAMETERS if (string.IsNullOrEmpty(identifier)) { throw new ArgumentNullException("Identifier must be specified.", "identifier"); } identifier = identifierRegex.Replace(identifier, string.Empty); if (scriptletType == ScriptletType.Unspecified) { throw new ArgumentOutOfRangeException("Scriptlet type must be specified.", "scriptletType"); } //DETERMINE THE FILE PATH TO LOAD string baseDir = _BaseDir; string filePath; bool isCustom = false; switch (custom) { case BitFieldState.Any: filePath = GetFilePath(themeId, identifier, scriptletType, true); if (File.Exists(Path.Combine(baseDir, filePath))) { isCustom = true; } else { filePath = GetFilePath(identifier, scriptletType, false); } break; case BitFieldState.True: filePath = GetFilePath(themeId, identifier, scriptletType, true); isCustom = true; break; default: filePath = GetFilePath(themeId, identifier, scriptletType, false); break; } //LOAD THE FILE FileInfo fi = new FileInfo(Path.Combine(baseDir, filePath)); if (fi.Exists) { this.ThemeId = themeId; this.Identifier = identifier; _LoadedIdentifier = identifier; this.ScriptletType = scriptletType; _LoadedScriptletType = scriptletType; this.IsCustom = isCustom; _LoadedIsCustom = isCustom; try { bool parsed = this.ParseScriptletFile(File.ReadAllText(fi.FullName)); if (parsed) { this.IsDirty = false; return(true); } return(false); } catch (Exception ex) { Logger.Warn("Could not read scriptlet file '" + filePath + "'.", ex); } } return(false); }
/// <summary> /// Loads this scriptlet object for given scriptlet identifier and scriptlet type /// </summary> /// <param name="themeId">Name/Identifier of the theme</param> /// <param name="identifier">criptlet identifier</param> /// <param name="scriptletType">The scriptlet type</param> /// <returns></returns> public bool Load(string themeId, string identifier, ScriptletType scriptletType) { return(Load(themeId, identifier, scriptletType, BitFieldState.Any)); }
/// <summary> /// Gets the file path for given scriptlet details /// </summary> /// <param name="identifier">The scriptlet identifier</param> /// <param name="scriptletType">The scriptlet type</param> /// <param name="custom">Whether the scriptlet is a custom scriptlet</param> /// <returns>The file path of the scriptlet</returns> private static string GetFilePath(string identifier, ScriptletType scriptletType, bool custom) { return(GetFilePath(string.Empty, identifier, scriptletType, custom)); }
/// <summary> /// Loads a Scriptlet object with given identifier and type from the database /// </summary> /// <param name="themeId">Name/Identifier of the theme</param> /// <param name="identifier">Identifier of Scriptlet to load</param> /// <param name="scriptletType">Type of of Scriptlet to load</param> /// <param name="useCache">If <b>true</b> tries to load the object from cache first</param> /// <returns>The Scriptlet object loaded</returns> public static Scriptlet Load(string themeId, string identifier, ScriptletType scriptletType, bool useCache) { return(Load(themeId, identifier, scriptletType, BitFieldState.Any, useCache)); }
/// <summary> /// Gets the index of the specified scriptlet in this collection /// </summary> /// <param name="identifier">Identifier of the scriptlet to find index of</param> /// <param name="scriptletType">Type of the scriptlet to find index of</param> /// <returns>Index of the specified scriptlet in this collection</returns> public int IndexOf(string identifier, ScriptletType scriptletType) { return(IndexOf(identifier, scriptletType, BitFieldState.Any)); }