Back To: DotNetNuke Silverlight IWebXAML

// 
//  DotNetNuke? - http://www.dotnetnuke.com
//  Copyright (c) 2002-2007
//  by DotNetNuke Corporation
// 
//  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
//  documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
//  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
//  to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// 
//  The above copyright notice and this permission notice shall be included in all copies or substantial portions 
//  of the Software.
// 
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
//  TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
//  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
//  DEALINGS IN THE SOFTWARE.
// 
 
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Security.Roles;
using DotNetNuke.Security.Membership;
using System.Collections.Generic;
using DotNetNuke.Entities.Portals;
 
using System.Data;
using System.Configuration;
using System;
using System.EnterpriseServices;
using System.Drawing;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Web;
using System.Xml;
using System.Web.Services;
using System.Web.Mobile;
using System.IdentityModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNetNuke.Services.Exceptions;
 
namespace DotNetNuke.Modules.IWebXAML_C
{
    public partial class View : Entities.Modules.PortalModuleBase
    {
        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                //  Determine if AJAX is installed
                if (DotNetNuke.Framework.AJAX.IsInstalled())
                {
                    DotNetNuke.Framework.AJAX.RegisterScriptManager();
                    //  Create a reference to the Script Manager
                    ScriptManager objScriptManager = ScriptManager.GetCurrent(this.Page);
                    //  Add a reference to the web service
                    ServiceReference objServiceReference = new ServiceReference();
                    objServiceReference.Path = "~/DesktopModules/IWebXAML_C/WebService.asmx";
                    objScriptManager.Services.Add(objServiceReference);
                    ScriptReference objScriptReference = new ScriptReference();
                    //  Pointing to the file that contains the JavaScript method that will call the methods
                    objScriptReference.Path = "~/DesktopModules/IWebXAML_C/js/CallWebServiceMethods.js";
                    objScriptManager.Scripts.Add(objScriptReference);
 
                    // Silverlight scripts
                    Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "Silverlight", (this.TemplateSourceDirectory + "/js/Silverlight.js"));
                    Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "main", (this.TemplateSourceDirectory + "/js/main.js"));
 
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "DNN_Silverlight", DNN_Silverlight());
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), string.Format("createSilverlight{0}", Convert.ToString(ModuleId)), CreateSilverlight());
 
                    Literal1.Text = string.Format("createSilverlight{0}()", Convert.ToString(ModuleId));
 
                    if ((!(Settings["Silverlight_width"] == null)) & (!(Settings["Silverlight_height"] == null)))
                    {
                        SilverlightControlHost.Width = Convert.ToInt32(Settings["Silverlight_width"]);
                        SilverlightControlHost.Height = Convert.ToInt32(Settings["Silverlight_height"]);
                    }
                }
 
            }
            catch (Exception exc)
            { // Module failed to load
 
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
 
        private string DNN_Silverlight()
        {
            //  This method creates a JavaScript object that exposes the current user information
            //  for use by JavaScript methods
            DotNetNuke.Entities.Users.UserInfo objUser;
            objUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
 
            int intPortalID = objUser.PortalID;
            int intUserID = objUser.UserID;
            string strPassword = DotNetNuke.Modules.IWebXAML.IWebXAMLSupport.SetXAMLCall(objUser, ModuleId, 1);
 
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
 
            sb.Append("<script type='text/javascript'> ");
            sb.Append("if (!window.DNN_Silverlight) ");
            sb.Append("window.DNN_Silverlight = {}; ");
            sb.Append("DNN_Silverlight.Module = function() ");
            sb.Append("{ ");
            sb.Append(string.Format("this.PortalId = '{0}'; ", Convert.ToString(intPortalID)));
            sb.Append(string.Format("this.ModuleId = '{0}'; ", Convert.ToString(ModuleId)));
            sb.Append(string.Format("this.UserId = '{0}'; ", Convert.ToString(intUserID)));
            sb.Append(string.Format("this.Password = '{0}'; ", strPassword));
            sb.Append("} ");
            sb.Append("</script> ");
 
            return sb.ToString();
        }
 
        private string CreateSilverlight()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
 
            sb.Append("<script type='text/javascript'> ");
            sb.Append(string.Format("function createSilverlight{0}() ", Convert.ToString(ModuleId)));
            sb.Append("{ ");
            sb.Append("var scene = new DNN_SilverlightApplication.Scene(); ");
            sb.Append("Silverlight.createObjectEx(");
            sb.Append("{ ");
            sb.Append(string.Format("source: '{0}', ", (this.TemplateSourceDirectory + "/xaml/Scene.xaml")));
            sb.Append(string.Format("parentElement: document.getElementById('dnn_ctr{0}_View_SilverlightControlHost'), ", Convert.ToString(ModuleId)));
            sb.Append(string.Format("id: '{0}', ", Convert.ToString(ModuleId)));
            sb.Append("properties: { ");
            sb.Append("width:'100%', ");
            sb.Append("height:'100%', ");
            sb.Append("inplaceInstallPrompt:false, ");
            sb.Append("background:'#00000000', ");
            sb.Append("isWindowless:'true', ");
            sb.Append("version: '1.0' ");
            sb.Append("}, ");
            sb.Append("events: { ");
            sb.Append("onError: null,");
            sb.Append("onLoad: Silverlight.createDelegate(scene, scene.handleLoad) ");
            sb.Append("}, ");
            sb.Append("context: null ");
            sb.Append("});} ");
 
            sb.Append("if (!window.Silverlight) ");
            sb.Append("window.Silverlight = {}; ");
            sb.Append("Silverlight.createDelegate = function(instance, method) { ");
            sb.Append("return function() { ");
            sb.Append("return method.apply(instance, arguments); ");
            sb.Append("} ");
            sb.Append("} ");
 
            sb.Append("</script> ");
            return sb.ToString();
 
        }
 
    }
 
}