SampleEmbeddedUI.cs :  » Installers-Generators » WiX » Microsoft » Deployment » Samples » EmbeddedUI » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Installers Generators » WiX 
WiX » Microsoft » Deployment » Samples » EmbeddedUI » SampleEmbeddedUI.cs
//---------------------------------------------------------------------
// <copyright file="SampleEmbeddedUI.cs" company="Microsoft">
//    Copyright (c) Microsoft Corporation.  All rights reserved.
//    
//    The use and distribution terms for this software are covered by the
//    Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
//    which can be found in the file CPL.TXT at the root of this distribution.
//    By using this software in any fashion, you are agreeing to be bound by
//    the terms of this license.
//    
//    You must not remove this notice, or any other, from this software.
// </copyright>
// <summary>
// Sample embedded UI for the Deployment Tools Foundation project.
// </summary>
//---------------------------------------------------------------------

namespace Microsoft.Deployment.Samples.EmbeddedUI{
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Threading;
    using System.Windows;
    using System.Windows.Forms;
    using System.Windows.Threading;
    using Microsoft.Deployment.WindowsInstaller;
    using Application = System.Windows.Application;

    public class SampleEmbeddedUI : IEmbeddedUI
    {
        private Thread appThread;
        private Application app;
        private SetupWizard setupWizard;
        private ManualResetEvent installStartEvent;
        private ManualResetEvent installExitEvent;

        /// <summary>
        /// Initializes the embedded UI.
        /// </summary>
        /// <param name="session">Handle to the installer which can be used to get and set properties.
        /// The handle is only valid for the duration of this method call.</param>
        /// <param name="resourcePath">Path to the directory that contains all the files from the MsiEmbeddedUI table.</param>
        /// <param name="internalUILevel">On entry, contains the current UI level for the installation. After this
        /// method returns, the installer resets the UI level to the returned value of this parameter.</param>
        /// <returns>True if the embedded UI was successfully initialized; false if the installation
        /// should continue without the embedded UI.</returns>
        /// <exception cref="InstallCanceledException">The installation was canceled by the user.</exception>
        /// <exception cref="InstallerException">The embedded UI failed to initialize and
        /// causes the installation to fail.</exception>
        public bool Initialize(Session session, string resourcePath, ref InstallUIOptions internalUILevel)
        {
            if (session != null)
            {
                if ((internalUILevel & InstallUIOptions.Full) != InstallUIOptions.Full)
                {
                    // Don't show custom UI when the UI level is set to basic.
                    return false;

                    // An embedded UI could display an alternate dialog sequence for reduced or
                    // basic modes, but it's not implemented here. We'll just fall back to the
                    // built-in MSI basic UI.
                }

                if (String.Equals(session["REMOVE"], "All", StringComparison.OrdinalIgnoreCase))
                {
                    // Don't show custom UI when uninstalling.
                    return false;

                    // An embedded UI could display an uninstall wizard, it's just not imlemented here.
                }
            }

            // Start the setup wizard on a separate thread.
            this.installStartEvent = new ManualResetEvent(false);
            this.installExitEvent = new ManualResetEvent(false);
            this.appThread = new Thread(this.Run);
            this.appThread.SetApartmentState(ApartmentState.STA);
            this.appThread.Start();

            // Wait for the setup wizard to either kickoff the install or prematurely exit.
            int waitResult = WaitHandle.WaitAny(new WaitHandle[] { this.installStartEvent, this.installExitEvent });
            if (waitResult == 1)
            {
                // The setup wizard set the exit event instead of the start event. Cancel the installation.
                throw new InstallCanceledException();
            }
            else
            {
                // Start the installation with a silenced internal UI.
                // This "embedded external UI" will handle message types except for source resolution.
                internalUILevel = InstallUIOptions.NoChange | InstallUIOptions.SourceResolutionOnly;
                return true;
            }
        }

        /// <summary>
        /// Processes information and progress messages sent to the user interface.
        /// </summary>
        /// <param name="messageType">Message type.</param>
        /// <param name="messageRecord">Record that contains message data.</param>
        /// <param name="buttons">Message box buttons.</param>
        /// <param name="icon">Message box icon.</param>
        /// <param name="defaultButton">Message box default button.</param>
        /// <returns>Result of processing the message.</returns>
        public MessageResult ProcessMessage(InstallMessage messageType, Record messageRecord,
            MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
        {
            // Synchronously send the message to the setup wizard window on its thread.
            object result = this.setupWizard.Dispatcher.Invoke(DispatcherPriority.Send,
                new Func<MessageResult>(delegate()
                {
                    return this.setupWizard.ProcessMessage(messageType, messageRecord, buttons, icon, defaultButton);
                }));
            return (MessageResult) result;
        }

        /// <summary>
        /// Shuts down the embedded UI at the end of the installation.
        /// </summary>
        /// <remarks>
        /// If the installation was canceled during initialization, this method will not be called.
        /// If the installation was canceled or failed at any later point, this method will be called at the end.
        /// </remarks>
        public void Shutdown()
        {
            // Wait for the user to exit the setup wizard.
            this.setupWizard.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                new Action(delegate()
                {
                    this.setupWizard.EnableExit();
                }));
            this.appThread.Join();
        }

        /// <summary>
        /// Creates the setup wizard and runs the application thread.
        /// </summary>
        private void Run()
        {
            this.app = new Application();
            this.setupWizard = new SetupWizard(this.installStartEvent);
            this.setupWizard.InitializeComponent();
            this.app.Run(this.setupWizard);
            this.installExitEvent.Set();
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.