Click here to Skip to main content
15,894,343 members
Articles / Programming Languages / C# 4.0

Dynamically Loading Silverlight Video Players using MEF

,
Rate me:
Please Sign up or sign in to vote.
4.97/5 (10 votes)
24 Aug 2010Ms-PL8 min read 55.4K   2.7K   16  
An example using MEF to dynamically load Silverlight Video Players
  • completeprojectwithallsamplevideoplayers.zip
    • PhilMiddlemissTheme
    • SkinableVideoPlayer.sln
    • SkinableVideoPlayer.Web
    • SkinableVideoPlayer
      • App.xaml
      • App.xaml.cs
      • Bin
        • Debug
          • AppManifest.xaml
          • ar
            • System.Windows.Controls.resources.dll
          • bg
            • System.Windows.Controls.resources.dll
          • ca
            • System.Windows.Controls.resources.dll
          • cs
            • System.Windows.Controls.resources.dll
          • da
            • System.Windows.Controls.resources.dll
          • de
            • System.ComponentModel.Composition.Initialization.resources.dll
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • el
            • System.Windows.Controls.resources.dll
          • es
            • System.ComponentModel.Composition.Initialization.resources.dll
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • et
            • System.Windows.Controls.resources.dll
          • eu
            • System.Windows.Controls.resources.dll
          • fi
            • System.Windows.Controls.resources.dll
          • fr
            • System.ComponentModel.Composition.Initialization.resources.dll
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • he
            • System.Windows.Controls.resources.dll
          • hr
            • System.Windows.Controls.resources.dll
          • hu
            • System.Windows.Controls.resources.dll
          • id
            • System.Windows.Controls.resources.dll
          • it
            • System.ComponentModel.Composition.Initialization.resources.dll
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • ja
            • System.ComponentModel.Composition.Initialization.resources.dll
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • ko
            • System.ComponentModel.Composition.Initialization.resources.dll
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • lt
            • System.Windows.Controls.resources.dll
          • lv
            • System.Windows.Controls.resources.dll
          • Microsoft.Expression.Interactions.dll
          • Microsoft.Expression.Interactions.xml
          • ms
            • System.Windows.Controls.resources.dll
          • nl
            • System.Windows.Controls.resources.dll
          • no
            • System.Windows.Controls.resources.dll
          • pl
            • System.Windows.Controls.resources.dll
          • pt
            • System.Windows.Controls.resources.dll
          • pt-BR
            • System.Windows.Controls.resources.dll
          • ro
            • System.Windows.Controls.resources.dll
          • ru
            • System.ComponentModel.Composition.Initialization.resources.dll
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • sk
            • System.Windows.Controls.resources.dll
          • SkinableVideoPlayer.dll
          • SkinableVideoPlayer.xap
          • SkinableVideoPlayerTestPage.html
          • SkinableVideoPlayerViewModel.dll
          • sl
            • System.Windows.Controls.resources.dll
          • sr-Cyrl-CS
            • System.Windows.Controls.resources.dll
          • sr-Latn-CS
            • System.Windows.Controls.resources.dll
          • sv
            • System.Windows.Controls.resources.dll
          • System.ComponentModel.Composition.dll
          • System.ComponentModel.Composition.Initialization.dll
          • System.ComponentModel.Composition.Initialization.xml
          • System.ComponentModel.Composition.xml
          • System.CoreEx.dll
          • System.Observable.dll
          • System.Reactive.dll
          • System.Windows.Controls.dll
          • System.Windows.Controls.Toolkit.dll
          • System.Windows.Controls.Toolkit.Internals.dll
          • System.Windows.Controls.Toolkit.xml
          • System.Windows.Controls.xml
          • System.Windows.Interactivity.dll
          • System.Windows.Interactivity.xml
          • th
            • System.Windows.Controls.resources.dll
          • tr
            • System.Windows.Controls.resources.dll
          • uk
            • System.Windows.Controls.resources.dll
          • vi
            • System.Windows.Controls.resources.dll
          • zh-Hans
            • System.ComponentModel.Composition.Initialization.resources.dll
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • zh-Hant
            • System.ComponentModel.Composition.Initialization.resources.dll
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
        • Release
      • classes
      • Models
      • Properties
      • Service References
        • wsSkinableVideoPlayer
          • configuration.svcinfo
          • configuration91.svcinfo
          • Reference.cs
          • Reference.svcmap
          • SkinableVideoPlayer.wsSkinableVideoPlayer.GetVideosResponse.datasource
          • SkinableVideoPlayer.wsSkinableVideoPlayer.GetXapsResponse.datasource
          • WebService.disco
          • WebService.wsdl
      • ServiceReferences.ClientConfig
      • SkinableVideoPlayer.csproj
      • SkinableVideoPlayer.csproj.user
      • ViewModels
      • Views
    • SkinableVideoPlayer_View
    • SkinableVideoPlayerViewModel
      • Bin
        • Debug
          • ar
          • bg
          • ca
          • cs
          • da
          • de
          • el
          • es
          • et
          • eu
          • fi
          • fr
          • he
          • hr
          • hu
          • id
          • it
          • ja
          • ko
          • lt
          • lv
          • ms
          • nl
          • no
          • pl
          • pt
          • pt-BR
          • ro
          • ru
          • sk
          • SkinableVideoPlayerViewModel.dll
          • sl
          • sr-Cyrl-CS
          • sr-Latn-CS
          • sv
          • th
          • tr
          • uk
          • vi
          • zh-Hans
          • zh-Hant
        • Release
      • ClassDiagram1.cd
      • classes
      • Model
      • Properties
      • Service References
        • wsSkinableVideoPlayer
          • configuration.svcinfo
          • configuration91.svcinfo
          • Reference.cs
          • Reference.svcmap
          • SkinableVideoPlayerViewModel.wsSkinableVideoPlayer.GetVideosResponse.datasource
          • SkinableVideoPlayerViewModel.wsSkinableVideoPlayer.GetXapsResponse.datasource
          • WebService.disco
          • WebService.wsdl
      • ServiceReferences.ClientConfig
      • SkinableVideoPlayerViewModel.csproj
      • SkinableVideoPlayerViewModel.csproj.user
      • ViewModel
  • versionone.zip
    • SkinableVideoPlayer.sln
    • WebService.cs
    • SkinableVideoPlayer.xap
    • VersionOne.xap
    • Default.aspx
    • Silverlight.js
    • desktop.ini
    • niceday.wmv
    • Thumbs.db
    • web.config
    • WebService.asmx
    • App.xaml
    • App.xaml.cs
    • AppManifest.xaml
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • Microsoft.Expression.Interactions.dll
    • Microsoft.Expression.Interactions.xml
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • SkinableVideoPlayer.dll
    • SkinableVideoPlayer.xap
    • SkinableVideoPlayerTestPage.html
    • SkinableVideoPlayerViewModel.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.dll
    • System.ComponentModel.Composition.Initialization.dll
    • System.ComponentModel.Composition.Initialization.xml
    • System.ComponentModel.Composition.xml
    • System.Windows.Controls.dll
    • System.Windows.Controls.Toolkit.dll
    • System.Windows.Controls.Toolkit.Internals.dll
    • System.Windows.Controls.Toolkit.xml
    • System.Windows.Controls.xml
    • System.Windows.Interactivity.dll
    • System.Windows.Interactivity.xml
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • DelegateCommand.cs
    • DeploymentCatalogService.cs
    • Extensions.cs
    • SilverlightXaps.cs
    • AppManifest.xml
    • AssemblyInfo.cs
    • configuration.svcinfo
    • configuration91.svcinfo
    • Reference.cs
    • Reference.svcmap
    • SkinableVideoPlayer.wsSkinableVideoPlayer.GetVideosResponse.datasource
    • SkinableVideoPlayer.wsSkinableVideoPlayer.GetXapsResponse.datasource
    • WebService.disco
    • WebService.wsdl
    • ServiceReferences.ClientConfig
    • SkinableVideoPlayer.csproj
    • SkinableVideoPlayer.csproj.user
    • MainPageModel.cs
    • MainPage.xaml
    • MainPage.xaml.cs
    • SkinableVideoPlayerViewModel.dll
    • SkinableVideoPlayerViewModel.pdb
    • DelegateCommand.cs
    • SilverlightVideos.cs
    • obj
    • VersionOne
      • App.xaml
      • App.xaml.cs
      • Bin
        • Debug
          • AppManifest.xaml
          • ar
            • System.Windows.Controls.resources.dll
          • bg
            • System.Windows.Controls.resources.dll
          • ca
            • System.Windows.Controls.resources.dll
          • cs
            • System.Windows.Controls.resources.dll
          • da
            • System.Windows.Controls.resources.dll
          • de
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • el
            • System.Windows.Controls.resources.dll
          • es
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • et
            • System.Windows.Controls.resources.dll
          • eu
            • System.Windows.Controls.resources.dll
          • fi
            • System.Windows.Controls.resources.dll
          • fr
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • he
            • System.Windows.Controls.resources.dll
          • hr
            • System.Windows.Controls.resources.dll
          • hu
            • System.Windows.Controls.resources.dll
          • id
            • System.Windows.Controls.resources.dll
          • it
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • ja
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • ko
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • lt
            • System.Windows.Controls.resources.dll
          • lv
            • System.Windows.Controls.resources.dll
          • ms
            • System.Windows.Controls.resources.dll
          • nl
            • System.Windows.Controls.resources.dll
          • no
            • System.Windows.Controls.resources.dll
          • pl
            • System.Windows.Controls.resources.dll
          • pt
            • System.Windows.Controls.resources.dll
          • pt-BR
            • System.Windows.Controls.resources.dll
          • ro
            • System.Windows.Controls.resources.dll
          • ru
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • sk
            • System.Windows.Controls.resources.dll
          • sl
            • System.Windows.Controls.resources.dll
          • sr-Cyrl-CS
            • System.Windows.Controls.resources.dll
          • sr-Latn-CS
            • System.Windows.Controls.resources.dll
          • sv
            • System.Windows.Controls.resources.dll
          • System.ComponentModel.Composition.dll
          • System.ComponentModel.Composition.xml
          • System.Windows.Controls.dll
          • System.Windows.Controls.Toolkit.dll
          • System.Windows.Controls.Toolkit.Internals.dll
          • System.Windows.Controls.Toolkit.pdb
          • System.Windows.Controls.Toolkit.xml
          • System.Windows.Controls.xml
          • System.Windows.Interactivity.dll
          • System.Windows.Interactivity.xml
          • th
            • System.Windows.Controls.resources.dll
          • tr
            • System.Windows.Controls.resources.dll
          • uk
            • System.Windows.Controls.resources.dll
          • VersionOne.dll
          • VersionOne.pdb
          • VersionOne.xap
          • VersionOneTestPage.html
          • vi
            • System.Windows.Controls.resources.dll
          • zh-Hans
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
          • zh-Hant
            • System.ComponentModel.Composition.resources.dll
            • System.Windows.Controls.resources.dll
        • Release
      • obj
      • Properties
      • VersionOne.csproj
      • VersionOne.csproj.user
      • Views
  • base.zip
    • SkinableVideoPlayer.sln
    • WebService.cs
    • SkinableVideoPlayer.xap
    • Default.aspx
    • Silverlight.js
    • desktop.ini
    • niceday.wmv
    • Thumbs.db
    • web.config
    • WebService.asmx
    • App.xaml
    • App.xaml.cs
    • AppManifest.xaml
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • Microsoft.Expression.Interactions.dll
    • Microsoft.Expression.Interactions.xml
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • SkinableVideoPlayer.dll
    • SkinableVideoPlayer.xap
    • SkinableVideoPlayerTestPage.html
    • SkinableVideoPlayerViewModel.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.dll
    • System.ComponentModel.Composition.Initialization.dll
    • System.ComponentModel.Composition.Initialization.xml
    • System.ComponentModel.Composition.xml
    • System.Windows.Controls.dll
    • System.Windows.Controls.Toolkit.dll
    • System.Windows.Controls.Toolkit.Internals.dll
    • System.Windows.Controls.Toolkit.xml
    • System.Windows.Controls.xml
    • System.Windows.Interactivity.dll
    • System.Windows.Interactivity.xml
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • System.ComponentModel.Composition.Initialization.resources.dll
    • System.ComponentModel.Composition.resources.dll
    • System.Windows.Controls.resources.dll
    • DelegateCommand.cs
    • DeploymentCatalogService.cs
    • Extensions.cs
    • SilverlightXaps.cs
    • AppManifest.xml
    • AssemblyInfo.cs
    • configuration.svcinfo
    • configuration91.svcinfo
    • Reference.cs
    • Reference.svcmap
    • SkinableVideoPlayer.wsSkinableVideoPlayer.GetVideosResponse.datasource
    • SkinableVideoPlayer.wsSkinableVideoPlayer.GetXapsResponse.datasource
    • WebService.disco
    • WebService.wsdl
    • ServiceReferences.ClientConfig
    • SkinableVideoPlayer.csproj
    • SkinableVideoPlayer.csproj.user
    • MainPageModel.cs
    • MainPage.xaml
    • MainPage.xaml.cs
    • SkinableVideoPlayerViewModel.dll
    • DelegateCommand.cs
    • SilverlightVideos.cs
    • AssemblyInfo.cs
    • configuration.svcinfo
    • configuration91.svcinfo
    • Reference.cs
    • Reference.svcmap
    • SkinableVideoPlayerViewModel.wsSkinableVideoPlayer.GetVideosResponse.datasource
    • SkinableVideoPlayerViewModel.wsSkinableVideoPlayer.GetXapsResponse.datasource
    • WebService.disco
    • WebService.wsdl
    • ServiceReferences.ClientConfig
    • SkinableVideoPlayerViewModel.csproj
    • SkinableVideoPlayerViewModel.csproj.user
    • MainViewModel.cs
// Copyright (c) 2010
// by OpenLight Group
// http://openlightgroup.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 
//
// 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.Generic;
using System.Linq;
using System.ServiceModel;
using System.Collections.ObjectModel;
using SkinableVideoPlayer.wsSkinableVideoPlayer;
using Microsoft.VisualBasic;

namespace SkinableVideoPlayer
{
    public class SilverlightXaps
    {
        #region GetXaps
        public static void GetXaps(EventHandler<GetXapsCompletedEventArgs> eh)
        {
            // Set up web service call
            WebServiceSoapClient objWebServiceSoapClient =
              new WebServiceSoapClient();

            // Format the base address of the website that launched the Silverlight Application
            string BaseWebAddress = string.Format(@"{0}/{1}", GetBaseAddress(), @"WebService/WebService.asmx");
            EndpointAddress MyEndpointAddress = new
                EndpointAddress(BaseWebAddress);       

            // Set that address
            objWebServiceSoapClient.Endpoint.Address = MyEndpointAddress;

            objWebServiceSoapClient.GetXapsCompleted += eh;
            objWebServiceSoapClient.GetXapsAsync();
        }      
        #endregion

        #region GetBaseAddress
        private static string GetBaseAddress()
        {
            // Get the web address of the .xap that launched this application
            string strBaseWebAddress = App.Current.Host.Source.AbsoluteUri;
            // Find the position of the ClientBin directory
            int PositionOfClientBin =
                App.Current.Host.Source.AbsoluteUri.ToLower().IndexOf(@"/clientbin");
            // Strip off everything after the ClientBin directory
            strBaseWebAddress = Strings.Left(strBaseWebAddress, PositionOfClientBin);
            // Return the base address
            return strBaseWebAddress;
        }
        #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 Microsoft Public License (Ms-PL)


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:

Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions