PK
¸DsAkTûµl l KSharpDemo.aspx<%@ Page Language="C#" AutoEventWireup="true" Inherits="CMSAdminControls_UI_Macros_KSharpDemo"
Title="Untitled Page" ValidateRequest="false" Theme="default" MasterPageFile="~/CMSMasterPages/UI/SimplePage.master"
CodeFile="KSharpDemo.aspx.cs" %>
<%@ Register Src="~/CMSAdminControls/UI/Trees/MacroTree.ascx" TagName="MacroTree" TagPrefix="cms" %>
<%@ Register Src="~/CMSAdminControls/UI/Macros/MacroSelector.ascx" TagPrefix="cc1"
TagName="MacroSelector" %>
<%@ Register Src="~/CMSAdminControls/UI/Macros/MacroEditor.ascx" TagName="MacroEditor"
TagPrefix="cms" %>
PK
õDsAŽ
ð¼ ¼ KSharpDemo.aspx.csusing System;
using System.Web.UI.WebControls;
using CMS.GlobalHelper;
using CMS.UIControls;
using CMS.ExtendedControls;
using CMS.CMSHelper;
using CMS.DocumentEngine;
using CMS.WorkflowEngine;
using CMS.SiteProvider;
using System.Collections;
[Title(Text = "K# Demo Page")]
public partial class CMSAdminControls_UI_Macros_KSharpDemo : SiteManagerPage
{
#region "Variables"
private static ContextResolver mWebpartResolver = null;
private static CMS.DocumentEngine.TreeNode mCurrentDocument = null;
private static TreeProvider mProvider = null;
private static string mCurrentCulture = null;
private int mNodeID = 0;
private string mAliasPath = null;
private string mCulture = null;
#endregion
#region "Properties"
///
/// Default webpart resolver.
///
public ContextResolver WebpartResolver
{
get
{
if (mWebpartResolver == null)
{
// Init resolver
mWebpartResolver = new ContextResolver();
}
if ((mWebpartResolver != null) && (CurrentDocument != null))
{
// Add document as resolver object
mWebpartResolver.SetNamedSourceData("CurrentDocument", CurrentDocument);
}
return mWebpartResolver;
}
}
///
/// Node ID as specified in the URL.
///
private static int NodeID
{
get
{
return QueryHelper.GetInteger("nodeid", 0);
}
}
///
/// Node alias path as specified in the URL.
///
private static string AliasPath
{
get
{
return QueryHelper.GetString("aliaspath", "");
}
}
///
/// Culture code as specified in the URL.
///
private static string Culture
{
get
{
return QueryHelper.GetString("culture", "");
}
}
///
/// Hashtable storing old document NodeID, NodeAliasPath and DocumentCulture.
///
private Hashtable OldDocumentInfo
{
get
{
return (SessionHelper.GetValue("OldDocumentInfo") as Hashtable);
}
set
{
SessionHelper.SetValue("OldDocumentInfo", value);
}
}
///
/// Currently selected content culture.
///
private static string CurrentCulture
{
get
{
// Default culture (either default visitor culture OR default website culture)
string defCulture = !string.IsNullOrEmpty(CMSContext.CurrentSite.DefaultVisitorCulture) ? CMSContext.CurrentSite.DefaultVisitorCulture : CultureHelper.GetDefaultCulture(CMSContext.CurrentSiteName);
// Use culture code coming in the URL or default content culture set for current website
return (Culture != "") ? Culture : defCulture;
}
}
///
/// Tree provider.
///
private static TreeProvider Provider
{
get
{
if (mProvider == null)
{
mProvider = new TreeProvider(CMSContext.CurrentUser);
}
return mProvider;
}
}
///
/// Current document initialized from query string.
///
private CMS.DocumentEngine.TreeNode CurrentDocument
{
get
{
if ((mCurrentDocument == null) || ((mCurrentDocument != null) && DocumentHasChanged))
{
if (Provider != null)
{
if (NodeID > 0)
{
mCurrentDocument = DocumentHelper.GetDocument(NodeID, CurrentCulture, Provider);
}
else
{
if (AliasPath != null)
{
mCurrentDocument = DocumentHelper.GetDocument(CMSContext.CurrentSiteName, AliasPath, CurrentCulture, false, TreeProvider.ALL_CLASSNAMES, null, null, -1, false, null, Provider);
}
}
if (mCurrentDocument != null)
{
if (OldDocumentInfo == null)
{
OldDocumentInfo = new Hashtable();
}
// Store document info in ViewState for validation purposes
OldDocumentInfo["NodeID"] = mCurrentDocument.NodeID;
OldDocumentInfo["NodeAliasPath"] = mCurrentDocument.NodeAliasPath;
OldDocumentInfo["DocumentCulture"] = mCurrentDocument.DocumentCulture;
}
}
}
return mCurrentDocument;
}
}
///
/// Indicates whether the current document should be reloaded.
///
private bool DocumentHasChanged
{
get
{
if (OldDocumentInfo != null)
{
// Get old document info
int oldNodeId = ValidationHelper.GetInteger(OldDocumentInfo["NodeID"], 0);
string oldAliasPath = ValidationHelper.GetString(OldDocumentInfo["NodeAliasPath"], null);
string oldCulture = ValidationHelper.GetString(OldDocumentInfo["DocumentCulture"], null);
// Compare to info coming in the URL
return ((NodeID > 0) && (oldNodeId != NodeID)) || ((AliasPath != "") && (oldAliasPath.ToLower() != AliasPath.ToLower())) || ((Culture != "") && (oldCulture.ToLower() != Culture.ToLower()));
}
return true;
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
SetupControls();
}
private void SetupControls()
{
// Initialize UI
CurrentMaster.Title.TitleText = "K# and Macro Engine - Testing Page";
CurrentMaster.Title.TitleImage = GetImageUrl("Design/Controls/EditingFormControl/title.png");
// Initialize macro editor control
macroEditor.TopOffset = 35;
macroEditor.MixedMode = true;
macroEditor.Editor.Language = LanguageEnum.HTMLMixed;
macroEditor.Editor.Width = new Unit("97%");
macroEditor.Editor.Height = new Unit("255px");
macroSelector.Resolver = WebpartResolver;
macroSelector.ExtendedTextAreaElem = macroEditor.Editor.EditorID;
macroSelector.TextAreaID = macroEditor.Editor.ClientID;
string macroText = this.macroEditor.Text;
// If multiple macro expressions defined in the editor hide tree (it doesn't support complex scenarios
if (macroText.IndexOf("%}") != macroText.LastIndexOf("%}"))
{
this.treeElem.Visible = false;
this.lblTreeInfo.Visible = true;
this.lblTreeInfo.Text = "Macro tree does not support multiple expressions and is temporarily disabled.";
}
else
{
this.lblTreeInfo.Visible = false;
// Initialize macro tree element
treeElem.ContextResolver.CheckIntegrity = false;
treeElem.TreeControl.NodeWrap = true;
treeElem.MacroExpression = macroText.Replace("{%", "").Replace("%}", "");
treeElem.ContextResolver = WebpartResolver;
}
this.treeElem.Visible = !string.IsNullOrEmpty(this.macroEditor.Text);
// Resolve macro and output result in the text area
this.txtOutput.Text = macroSelector.Resolver.ResolveMacros(this.macroEditor.Text);
}
protected void btnRefresh_Click(object sender, EventArgs e)
{
// Empty event defined just to invoke PostBacks
}
}
PK
¸DsAkTûµl l $ KSharpDemo.aspx
ÌŒW5tÆÍYÀƺsÆÍYÀƺsÆÍPK
õDsAŽ
ð¼ ¼ $ ™ KSharpDemo.aspx.cs
Œ|xtÆÍXnȺsÆÍXnȺsÆÍPK Å …)