Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace SBTech.CmsAutomation.ConsoleHost
- {
- using AutoMapper;
- using Microsoft.Practices.Unity;
- using OpenQA.Selenium;
- using OpenQA.Selenium.Support.UI;
- using SBTech.CmsAutomation.Configurator;
- using SBTech.CmsAutomation.Contracts;
- using SBTech.CmsAutomation.Contracts.Timer;
- using SBTech.CmsAutomation.Contracts.XmlTools;
- using SBTech.CmsAutomation.Models.Models.Automation.Xml;
- using System;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Xml.Serialization;
- class Program
- {
- private static IUnityContainer unityContainer;
- static Program()
- {
- // unityContainer = Configurator.RegisterDependenciesForConsole();
- }
- static void Main(string[] args)
- {
- unityContainer = Configurator.RegisterDependenciesForConsole(args[1]);
- //TODO: Needs to be improved.
- using (var webDriver = unityContainer.Resolve<IWebDriver>())
- {
- System.AppDomain.CurrentDomain.UnhandledException += CatchUnhandledException;
- var loggingUtility = unityContainer.Resolve<ILoggingUtility>();
- if (args.Length == 0)
- {
- throw new ArgumentOutOfRangeException($"First argument should be a path to an .xml file");
- }
- var map = unityContainer.Resolve<IMapper>();
- var deserializer = unityContainer.Resolve<IDeserializer>();
- var stopwatch = unityContainer.Resolve<IStopWatch>();
- string pathToXml = args[0];
- Procedure procedure = deserializer.Deserialize<Procedure>(pathToXml);
- var mappedProcedure = map.Map<SBTech.CmsAutomation.Models.Models.Automation.Xml.Procedure, SBTech.CmsAutomation.Models.Models.Automation.MappedElements.Procedure>(procedure);
- var stepList = mappedProcedure?.TaskList?.SelectMany(x => x.StepList);
- var actionList = stepList?.SelectMany(x => x.ActionList);
- if (actionList != null)
- {
- //timer
- stopwatch.Start();
- loggingUtility.LogStartProcess();
- foreach (var action in actionList)
- {
- try
- {
- action.Element.DoWork();
- string logMessage = action.GetLog();
- string beautifiedMessage = action.GetBeautifiedLog();
- loggingUtility.LogInfo(logMessage);
- loggingUtility.LogInfo(beautifiedMessage);
- Console.WriteLine(beautifiedMessage);
- //Console.WriteLine(logMessage); //hiding the old version from the console
- }
- catch (Exception e)
- {
- string logMessage = action.GetLog();
- string beautifiedMessage = action.GetBeautifiedLog();
- loggingUtility.LogInfo(logMessage);
- loggingUtility.LogInfo(beautifiedMessage);
- var exceptionMessage = loggingUtility.LogException(e);
- Console.WriteLine(beautifiedMessage);
- //Console.WriteLine(logMessage); //hiding the old version from the console
- Console.WriteLine(exceptionMessage);
- break;
- }
- }
- stopwatch.Stop();
- loggingUtility.LogTime(stopwatch.FormatElapsed());
- Console.WriteLine(stopwatch.FormatElapsed());
- loggingUtility.LogEndProcess();
- Console.ReadKey();
- }
- }
- }
- static void CatchUnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- var loggingUtility = unityContainer.Resolve<ILoggingUtility>();
- loggingUtility.LogError(e.ExceptionObject.ToString());
- loggingUtility.LogEndProcess();
- Console.WriteLine(e.ExceptionObject.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement