Back To: DotNetNuke Silverlight Video

//
// 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 System;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Security;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Users;
using System.Data.Common;
using System.Data;
using System.Web.UI;
using System.IO;
 
namespace DotNetNuke.Modules
{
    public partial class SilverLightVideo : DotNetNuke.Entities.Modules.PortalModuleBase, DotNetNuke.Entities.Modules.IActionable
    {
 
        protected void Page_Load(object sender, EventArgs e)
        {
            Literal1.Text = String.Format("createSilverlight{0}() ", Convert.ToString(ModuleId));
            try
            {
                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(), String.Format("createSilverlight{0}", 
                  Convert.ToString(ModuleId)), CreateSilverlight());
            }
            catch (Exception exc)
            {
                // Module failed to load
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
 
        string CreateSilverlight()
        {
 
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
 
            string path = MapPath(@"~/DesktopModules/silverlightvideo/");
            path += Convert.ToString(ModuleId) + "_silverlightvideo.wmv";
            if (!File.Exists(path))
            {
                sb.Append("<script type='text/javascript'> ");
                sb.Append(String.Format("function createSilverlight{0}() ", Convert.ToString(ModuleId)));
                sb.Append("{ ");
                sb.Append("} ");
                sb.Append("</script> ");
 
                return sb.ToString();
            }
 
            string strVideoSource = String.Format(@"http://{0}/{1}/{2}", Request.Url.Host, this.TemplateSourceDirectory, 
             Convert.ToString(ModuleId) + "_silverlightvideo.wmv");
 
            sb.Append("<script type='text/javascript'> ");
            sb.Append(String.Format("function createSilverlight{0}() ", Convert.ToString(ModuleId)));
            sb.Append("{ ");
            sb.Append("Silverlight.createObject( ");
            sb.Append(String.Format("'{0}', ", this.TemplateSourceDirectory + @"/xaml/Scene.xaml"));
            sb.Append(String.Format("document.getElementById('dnn_ctr{0}_SilverLightVideo_SilverlightControlHost'), ",
             Convert.ToString(ModuleId)));
            sb.Append(String.Format("'{0}', ", strVideoSource));
            sb.Append(" { ");
            sb.Append("width:'100%', ");
            sb.Append("height:'100%', ");
            sb.Append("inplaceInstallPrompt:false, ");
            sb.Append("background:'black', ");
            sb.Append("isWindowless:'false', ");
            sb.Append("framerate:'24', ");
            sb.Append("version: '1.0' ");
            sb.Append("}, ");
            sb.Append("{ ");
            sb.Append("onError:null,");
            sb.Append("onLoad:null ");
            sb.Append("}, ");
            sb.Append("null) ");
            sb.Append("} ");
            sb.Append("</script> ");
 
            return sb.ToString();
        }
 
        public DotNetNuke.Entities.Modules.Actions.ModuleActionCollection ModuleActions
        {
            get
            {
                DotNetNuke.Entities.Modules.Actions.ModuleActionCollection Actions = 
                 new DotNetNuke.Entities.Modules.Actions.ModuleActionCollection();
                Actions.Add(GetNextActionID(), "Configure", DotNetNuke.Entities.Modules.Actions.ModuleActionType.EditContent, "", "", 
                EditUrl(), false, SecurityAccessLevel.Edit, true, false);
                return Actions;
            }
        }
    }
}