PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/V4/AcceptanceTestLibrary/AcceptanceTestLibrary/Common/Launcher/Silverlight/SilverlightAppLauncher.cs

#
C# | 91 lines | 59 code | 10 blank | 22 comment | 2 complexity | 78d7facfb815604e36e015fb9ce2cd1a MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Text;
21using System.Windows.Automation;
22using System.Diagnostics;
23using System.IO;
24using System.Threading;
25using AcceptanceTestLibrary.ApplicationHelper;
26using AcceptanceTestLibrary.Common;
27using AcceptanceTestLibrary.ApplicationObserver;
28
29namespace AcceptanceTestLibrary.Common.Silverlight
30{
31    public class SilverlightAppLauncher : AppLauncherBase, IStateObserver
32    {
33        /// <summary>
34        /// This method launches silverlight application
35        /// </summary>
36        /// <param name="applicationPath">Silverlight Application path</param>
37        /// <param name="browserTitle">Browser Title</param>
38        /// <returns></returns>
39        public override List<AutomationElement> LaunchApp(string applicationPath, string browserTitle)
40        {
41            this.ApplicationTitle = browserTitle;
42            StateDiagnosis.Instance.StartDiagnosis(this);
43            try
44            {
45                List<AutomationElement> aeList = BrowserSupportHandler.LaunchBrowser(applicationPath, this.ApplicationTitle);
46                StateDiagnosis.Instance.StopDiagnosis(this);
47
48                return aeList;
49            }
50
51            catch (Exception)
52            {
53                StateDiagnosis.Instance.StopDiagnosis(this);
54                return null;
55            }
56            
57        }
58
59        public override void UnloadApp(Process p)
60        {
61            if (p!= null && !p.HasExited)
62            {
63                p.Kill();
64            }
65            p.Dispose();
66        }
67
68        public override void UnloadApp()
69        {
70        }
71        public static void UnloadBrowser(string applicationTitle)
72        {
73            BrowserSupportHandler.UnloadBrowser(applicationTitle);
74        }
75
76        public string ApplicationTitle
77        {
78            get;
79            set;
80        }
81
82        #region IStateObserver Members
83
84        public void Notify()
85        {
86            UnloadBrowser(this.ApplicationTitle);
87        }
88
89        #endregion
90    }
91}