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.
'
 
Imports DotNetNuke
Imports DotNetNuke.Common
Imports DotNetNuke.Security.Roles
Imports DotNetNuke.Security.Membership
Imports System.Collections.Generic
Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Security.PortalSecurity
 
Namespace DotNetNuke.Modules.IWebXAML
 
    Partial Class View
        Inherits DotNetNuke.Entities.Modules.PortalModuleBase
 
        Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
 
                ' Determine if AJAX is installed
                If DotNetNuke.Framework.AJAX.IsInstalled Then
                    DotNetNuke.Framework.AJAX.RegisterScriptManager()
                    ' Create a reference to the Script Manager
                    Dim objScriptManager As ScriptManager = ScriptManager.GetCurrent(Me.Page)
                    ' Add a reference to the web service
                    Dim objServiceReference As ServiceReference = New ServiceReference
                    objServiceReference.Path = "~/DesktopModules/IWebXAML/WebService.asmx"
                    objScriptManager.Services.Add(objServiceReference)
                    Dim objScriptReference As ScriptReference = New ScriptReference
                    ' Pointing to the file that contains the JavaScript method that will call the methods
                    objScriptReference.Path = "~/DesktopModules/IWebXAML/js/CallWebServiceMethods.js"
                    objScriptManager.Scripts.Add(objScriptReference)
 
                    'Silverlight scripts
                    Page.ClientScript.RegisterClientScriptInclude(Me.GetType, "Silverlight", (Me.TemplateSourceDirectory + "/js/Silverlight.js"))
                    Page.ClientScript.RegisterClientScriptInclude(Me.GetType, "main", (Me.TemplateSourceDirectory + "/js/main.js"))
 
                    Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "DNN_Silverlight", DNN_Silverlight)
                    Page.ClientScript.RegisterClientScriptBlock(Me.GetType, String.Format("createSilverlight{0}", Convert.ToString(ModuleId)), CreateSilverlight)
 
                    Literal1.Text = String.Format("createSilverlight{0}()", Convert.ToString(ModuleId))
 
                    If (Not Settings("Silverlight_width") Is Nothing) And (Not Settings("Silverlight_height") Is Nothing) Then
                        SilverlightControlHost.width = CType(Settings("Silverlight_width"), String)
                        SilverlightControlHost.height = CType(Settings("Silverlight_height"), String)
                    End If
                End If
 
            Catch exc As Exception        'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub
        Private Function DNN_Silverlight() As String
            ' This method creates a JavaScript object that exposes the current user information
            ' for use by JavaScript methods
            Dim objUser As Entities.Users.UserInfo
            objUser = Entities.Users.UserController.GetCurrentUserInfo
 
            Dim intPortalID As Integer = objUser.PortalID
            Dim intUserID As Integer = objUser.UserID
            Dim strPassword As String = DotNetNuke.Modules.IWebXAML.IWebXAMLSupport.SetXAMLCall(objUser, ModuleId, 1)
 
            Dim sb As System.Text.StringBuilder = 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
        End Function
 
        Private Function CreateSilverlight() As String
            Dim sb As System.Text.StringBuilder = 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}', ", (Me.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
 
        End Function
 
    End Class
 
End Namespace