Click here to Skip to main content
15,891,431 members
Articles / Web Development / XHTML

Introducing SilverlightDesktop.net

Rate me:
Please Sign up or sign in to vote.
4.11/5 (4 votes)
19 Oct 2008BSD5 min read 38.6K   266   49  
SilverlightDesktop.net is a Open-Source ASP.NET framework that allows you to dynamically load Silverlight modules into resizable draggable windows.
// SilverlightDesktop.Net - http://www.SilverlightDesktop.net
// Copyright (c) 2008
// by SilverlightDesktop.Net
//
// 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.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SilverlightDesktopCore.DAL;

public partial class _Default : System.Web.UI.Page
{
    string strCurrentVersion = "01.70.00";
    bool boolSetup = false;

    protected void Page_Load(object sender, EventArgs e)
    {
        boolSetup = DatabaseReady();

        if (boolSetup)
        {
            lnkLogin.Visible = !User.Identity.IsAuthenticated;
            lnkLogOut.Visible = User.Identity.IsAuthenticated;

            ShowSilverlightDesktopLink();

            // Possibly show Administration link
            if (User.Identity.IsAuthenticated && (User.Identity.AuthenticationType == "Forms"))
            {
                FormsIdentity id = (FormsIdentity)User.Identity;
                FormsAuthenticationTicket ticket = id.Ticket;
                lnkAdministration.Visible = (ticket.UserData.ToString() == "Administrators");
            }

            ShowDesktops();
        }
        else
        {
            lnkSetup.Visible = true;
        }
    }

    #region ShowSilverlightDesktopLink
    private void ShowSilverlightDesktopLink()
    {
        GeneralSettings GeneralSettings = new GeneralSettings();
        if (GeneralSettings.AnonymousLogin)
        {
            lnkSilverlightDesktop.Visible = true;
        }
        else
        {
            lnkSilverlightDesktop.Visible = User.Identity.IsAuthenticated;
        }
    }
    #endregion

    #region DatabaseReady
    private bool DatabaseReady()
    {
        // This method returns true if the databse exists and the table is created
        bool CanConnect = true;

        try
        {
            SilverlightDesktopDAL SilverlightDesktopDAL = new SilverlightDesktopDAL();
            var result = from VersionNumber in SilverlightDesktopDAL.Versions
                         select VersionNumber;
            CanConnect = (result.FirstOrDefault().VersionNumber == strCurrentVersion) ? true : false;
        }
        catch (Exception e)
        {
            string strError = e.Message;
            CanConnect = false;
        }

        return CanConnect;
    }
    #endregion

    #region ShowDesktops
    private void ShowDesktops()
    {
        SilverlightDesktopDAL SilverlightDesktopDAL = new SilverlightDesktopDAL();
        var result = from DesktopInstances in SilverlightDesktopDAL.SilverlightDesktopInstances
                     select DesktopInstances;

        GridView1.DataSource = result.ToList();
        GridView1.DataBind();

        GridView1.Visible = (result.Count() > 0) ? true : false;
    }
    #endregion

    #region LogOut
    protected void lnkLogOut_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Response.Redirect("Default.aspx");
    }
    #endregion
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Software Developer (Senior) http://ADefWebserver.com
United States United States
Michael Washington is a Microsoft MVP. He is a ASP.NET and
C# programmer.
He is the founder of
AiHelpWebsite.com,
LightSwitchHelpWebsite.com, and
HoloLensHelpWebsite.com.

He has a son, Zachary and resides in Los Angeles with his wife Valerie.

He is the Author of:

Comments and Discussions