PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms 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. //===================================================================================
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Windows.Automation;
  22. using System.Diagnostics;
  23. using System.IO;
  24. using System.Threading;
  25. using AcceptanceTestLibrary.ApplicationHelper;
  26. using AcceptanceTestLibrary.Common;
  27. using AcceptanceTestLibrary.ApplicationObserver;
  28. namespace AcceptanceTestLibrary.Common.Silverlight
  29. {
  30. public class SilverlightAppLauncher : AppLauncherBase, IStateObserver
  31. {
  32. /// <summary>
  33. /// This method launches silverlight application
  34. /// </summary>
  35. /// <param name="applicationPath">Silverlight Application path</param>
  36. /// <param name="browserTitle">Browser Title</param>
  37. /// <returns></returns>
  38. public override List<AutomationElement> LaunchApp(string applicationPath, string browserTitle)
  39. {
  40. this.ApplicationTitle = browserTitle;
  41. StateDiagnosis.Instance.StartDiagnosis(this);
  42. try
  43. {
  44. List<AutomationElement> aeList = BrowserSupportHandler.LaunchBrowser(applicationPath, this.ApplicationTitle);
  45. StateDiagnosis.Instance.StopDiagnosis(this);
  46. return aeList;
  47. }
  48. catch (Exception)
  49. {
  50. StateDiagnosis.Instance.StopDiagnosis(this);
  51. return null;
  52. }
  53. }
  54. public override void UnloadApp(Process p)
  55. {
  56. if (p!= null && !p.HasExited)
  57. {
  58. p.Kill();
  59. }
  60. p.Dispose();
  61. }
  62. public override void UnloadApp()
  63. {
  64. }
  65. public static void UnloadBrowser(string applicationTitle)
  66. {
  67. BrowserSupportHandler.UnloadBrowser(applicationTitle);
  68. }
  69. public string ApplicationTitle
  70. {
  71. get;
  72. set;
  73. }
  74. #region IStateObserver Members
  75. public void Notify()
  76. {
  77. UnloadBrowser(this.ApplicationTitle);
  78. }
  79. #endregion
  80. }
  81. }