using System; using System.Text; using CMS.GlobalHelper; using CMS.UIControls; public partial class CMSAdminControls_Silverlight_SilverlightApplication : CMSUserControl { #region "Variables" private string mAlternateContent = null; private string mApplicationPath = ""; private string mMinimumVersion = ""; private string mParameters = ""; private string mContainerWidth = ""; private string mContainerHeight = ""; private string mContainerBackground = "#00FFFFFF"; private bool mIsWindowLess = false; #endregion #region "Public properties" /// /// HTML content which is displayed to user when Silverlight plugin is not installed. /// public string AlternateContent { get { // Try to load custom alternate content if (string.IsNullOrEmpty(mAlternateContent)) { mAlternateContent = "var altHtml = \"{3}\";" + "altHtml = altHtml.replace('{1}', 'http://go.microsoft.com/fwlink/?LinkID=124807');" + "altHtml = altHtml.replace('{2}', 'http://go.microsoft.com/fwlink/?LinkId=108181');" + "altHtml = altHtml.replace('{3}', 'Get Microsoft Silverlight');"; } else { mAlternateContent = "var altHtml = " + ScriptHelper.GetString(mAlternateContent) + ";"; } return mAlternateContent; } set { mAlternateContent = value; } } /// /// Gets or sets value indicating whether the silverlight application should be windowless or not. Default is false. /// public bool IsWindowless { get { return mIsWindowLess; } set { mIsWindowLess = value; } } /// /// Silverlight application path. /// public string ApplicationPath { get { return mApplicationPath; } set { mApplicationPath = value; } } /// /// Minimum version of the Microsoft Silverlight which is required by the current silverlight application. /// public string MinimumVersion { get { return mMinimumVersion; } set { mMinimumVersion = value; } } /// /// Silverlight application parameters. /// public string Parameters { get { return mParameters; } set { mParameters = value; } } /// /// Silverlight application container width. /// public string ContainerWidth { get { return mContainerWidth; } set { mContainerWidth = value; } } /// /// Silverlight application container height. /// public string ContainerHeight { get { return mContainerHeight; } set { mContainerHeight = value; } } /// /// Silverlight application container background. /// public string ContainerBackground { get { return mContainerBackground; } set { mContainerBackground = value; } } #endregion #region "Page Events" protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (!StopProcessing) { ReloadData(); } } #endregion #region "Private Methods" /// /// Initializes silverlight application container. /// private void ReloadData() { // Register silverlight support script ScriptHelper.RegisterSilverlight(Page); StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"
", ClientID); // Create script initiating silverlight application string slApp = string.Format(@"function createSilverlight(controlHost) {{ Silverlight.createObjectEx( {{ source: {0}, parentElement: controlHost, id: 'silverlightControl', properties: {{ autoUpgrade: 'true', width: '{1}', alt: altHtml, height: '{2}', version: '{3}', background: '{4}', initParams: '{5}', isWindowless: 'true', enableHtmlAccess: 'true', IsWindowless: '{7}' }}, events: {{}} }}); }} var hostElement = document.getElementById('Silverlight_{6}'); createSilverlight(hostElement);", ScriptHelper.GetString(URLHelper.ResolveUrl(ApplicationPath)), ContainerWidth, ContainerHeight, MinimumVersion, ContainerBackground, Parameters, ClientID, IsWindowless); sb.Append(ScriptHelper.GetScript(AlternateContent + slApp)); ltlSilverlight.Text = sb.ToString(); } #endregion }