Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. namespace SBTech.CmsAutomation.ConsoleHost
  2. {
  3. using AutoMapper;
  4. using Microsoft.Practices.Unity;
  5. using OpenQA.Selenium;
  6. using OpenQA.Selenium.Support.UI;
  7. using SBTech.CmsAutomation.Configurator;
  8. using SBTech.CmsAutomation.Contracts;
  9. using SBTech.CmsAutomation.Contracts.Timer;
  10. using SBTech.CmsAutomation.Contracts.XmlTools;
  11. using SBTech.CmsAutomation.Models.Models.Automation.Xml;
  12. using System;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading;
  17. using System.Xml.Serialization;
  18.  
  19. class Program
  20. {
  21. private static IUnityContainer unityContainer;
  22.  
  23. static Program()
  24. {
  25. // unityContainer = Configurator.RegisterDependenciesForConsole();
  26. }
  27.  
  28. static void Main(string[] args)
  29. {
  30. unityContainer = Configurator.RegisterDependenciesForConsole(args[1]);
  31. //TODO: Needs to be improved.
  32. using (var webDriver = unityContainer.Resolve<IWebDriver>())
  33. {
  34. System.AppDomain.CurrentDomain.UnhandledException += CatchUnhandledException;
  35. var loggingUtility = unityContainer.Resolve<ILoggingUtility>();
  36.  
  37. if (args.Length == 0)
  38. {
  39. throw new ArgumentOutOfRangeException($"First argument should be a path to an .xml file");
  40. }
  41.  
  42. var map = unityContainer.Resolve<IMapper>();
  43. var deserializer = unityContainer.Resolve<IDeserializer>();
  44. var stopwatch = unityContainer.Resolve<IStopWatch>();
  45.  
  46. string pathToXml = args[0];
  47. Procedure procedure = deserializer.Deserialize<Procedure>(pathToXml);
  48. var mappedProcedure = map.Map<SBTech.CmsAutomation.Models.Models.Automation.Xml.Procedure, SBTech.CmsAutomation.Models.Models.Automation.MappedElements.Procedure>(procedure);
  49.  
  50. var stepList = mappedProcedure?.TaskList?.SelectMany(x => x.StepList);
  51. var actionList = stepList?.SelectMany(x => x.ActionList);
  52. if (actionList != null)
  53. {
  54. //timer
  55. stopwatch.Start();
  56.  
  57. loggingUtility.LogStartProcess();
  58. foreach (var action in actionList)
  59. {
  60. try
  61. {
  62. action.Element.DoWork();
  63. string logMessage = action.GetLog();
  64. string beautifiedMessage = action.GetBeautifiedLog();
  65. loggingUtility.LogInfo(logMessage);
  66. loggingUtility.LogInfo(beautifiedMessage);
  67.  
  68. Console.WriteLine(beautifiedMessage);
  69. //Console.WriteLine(logMessage); //hiding the old version from the console
  70. }
  71. catch (Exception e)
  72. {
  73. string logMessage = action.GetLog();
  74. string beautifiedMessage = action.GetBeautifiedLog();
  75.  
  76. loggingUtility.LogInfo(logMessage);
  77. loggingUtility.LogInfo(beautifiedMessage);
  78.  
  79. var exceptionMessage = loggingUtility.LogException(e);
  80.  
  81. Console.WriteLine(beautifiedMessage);
  82. //Console.WriteLine(logMessage); //hiding the old version from the console
  83. Console.WriteLine(exceptionMessage);
  84.  
  85. break;
  86. }
  87. }
  88.  
  89. stopwatch.Stop();
  90. loggingUtility.LogTime(stopwatch.FormatElapsed());
  91. Console.WriteLine(stopwatch.FormatElapsed());
  92. loggingUtility.LogEndProcess();
  93. Console.ReadKey();
  94. }
  95. }
  96. }
  97.  
  98. static void CatchUnhandledException(object sender, UnhandledExceptionEventArgs e)
  99. {
  100. var loggingUtility = unityContainer.Resolve<ILoggingUtility>();
  101. loggingUtility.LogError(e.ExceptionObject.ToString());
  102. loggingUtility.LogEndProcess();
  103. Console.WriteLine(e.ExceptionObject.ToString());
  104. }
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement