//
// 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.
//
// Original code
// (C) 2007 Jeff Paries
// http://designwithsilverlight.com
//
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Web.UI.WebControls;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Security;
using DotNetNuke.Security.Roles;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
namespace DotNetNuke.Modules.SilverlightAlbum
{
public partial class View : PortalModuleBase, DotNetNuke.Entities.Modules.IActionable
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (DotNetNuke.Framework.AJAX.IsInstalled())
{
DotNetNuke.Framework.AJAX.RegisterScriptManager();
}
// Silverlight scripts
Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "Silverlight", (this.TemplateSourceDirectory + "/js/Silverlight.js"));
Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "SilverlightAlbum_main", (this.TemplateSourceDirectory + "/js/main.js"));
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), string.Format("Silverlight_Gallery{0}", Convert.ToString(ModuleId)), Silverlight_Gallery());
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), string.Format("createSilverlight{0}", Convert.ToString(ModuleId)), CreateSilverlight());
lrlSilverlight.Text = string.Format("createSilverlight{0}()", Convert.ToString(ModuleId));
}
catch (Exception exc)
{ // Module failed to load
Exceptions.ProcessModuleLoadException(this, exc);
}
}
#region Silverlight_Gallery
private string Silverlight_Gallery()
{
List<PicturesInfo> colPicturesInfo = Edit_DAL.GetPictures(ModuleId);
string strPictureURl = "";
string strBaseDirectory = String.Format(@"http://{0}/{1}/", Request.Url.Host, this.TemplateSourceDirectory);
StringBuilder sb = new System.Text.StringBuilder();
int i = 0;
sb.Append("<script type='text/javascript'> ");
sb.Append("");
sb.Append(string.Format("var photoArray{0} = new Array({1}); ", Convert.ToString(ModuleId), Edit_DAL.CountPictures(ModuleId)));
foreach (PicturesInfo objPicturesInfo in colPicturesInfo)
{
strPictureURl = strBaseDirectory + objPicturesInfo.Picture;
sb.Append(string.Format("photoArray{0}[{1}]='{2}';", Convert.ToString(ModuleId), i, strPictureURl));
i++;
}
sb.Append("</script> ");
return sb.ToString();
}
#endregion
#region CreateSilverlight
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 photoGallery.Page(); ");
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();
}
#endregion
#region IActionable Members
public DotNetNuke.Entities.Modules.Actions.ModuleActionCollection ModuleActions
{
get
{
DotNetNuke.Entities.Modules.Actions.ModuleActionCollection Actions = new DotNetNuke.Entities.Modules.Actions.ModuleActionCollection();
Actions.Add(GetNextActionID(), "Edit Pictures", DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl(), false, SecurityAccessLevel.Edit, true, false);
return Actions;
}
}
#endregion
}
}