예제 #1
0
        // TODO: Remove from here as this class is WebReportGenerator - not viewer
        private bool RunClientApp(string json, string clientAppFolderPath, WebReportFilter openObject, bool shouldDisplayReport)
        {
            bool response = false;

            try
            {
                json = $"window.runsetData={json};";
                StringBuilder pageDataSb = new StringBuilder();
                pageDataSb.Append("file:///");
                pageDataSb.Append(clientAppFolderPath.Replace('\\', '/'));
                pageDataSb.Append("/");
                pageDataSb.Append("index.html");
                if (openObject != null)
                {
                    pageDataSb.Append("#/?Routed_Guid=");
                    pageDataSb.Append(openObject.Guid);
                }
                string taskCommand = $"\"{pageDataSb.ToString()}\"";
                System.IO.File.WriteAllText(Path.Combine(clientAppFolderPath, "assets", "Execution_Data", "executiondata.js"), json);
                if (shouldDisplayReport)
                {
                    System.Diagnostics.Process.Start(@browserPath, taskCommand);
                    System.Diagnostics.Process.Start(clientAppFolderPath);
                }
                response = true;
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, "Error in RunClientApp", ex);
            }
            return(response);
        }
예제 #2
0
        // TODO: Make this function to just generate the report folder !!!
        public LiteDbRunSet RunNewHtmlReport(string runSetGuid = null, WebReportFilter openObject = null, bool shouldDisplayReport = true)
        {
            LiteDbRunSet lightDbRunSet = new LiteDbRunSet();
            bool         response      = false;

            try
            {
                string clientAppFolderPath = Path.Combine(WorkSpace.Instance.LocalUserApplicationDataFolderPath, "Reports", "Ginger-Web-Client");
                if (!Directory.Exists(clientAppFolderPath))
                {
                    return(lightDbRunSet);
                }
                DeleteFoldersData(Path.Combine(clientAppFolderPath, "assets", "Execution_Data"));
                DeleteFoldersData(Path.Combine(clientAppFolderPath, "assets", "screenshots"));
                LiteDbManager dbManager = new LiteDbManager(new ExecutionLoggerHelper().GetLoggerDirectory(WorkSpace.Instance.Solution.LoggerConfigurations.CalculatedLoggerFolder));
                lightDbRunSet = dbManager.GetLatestExecutionRunsetData(runSetGuid);
                PopulateMissingFields(lightDbRunSet, clientAppFolderPath);
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(lightDbRunSet);
                response = RunClientApp(json, clientAppFolderPath, openObject, shouldDisplayReport);
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, "RunNewHtmlReport,error :" + ex.ToString());
            }
            return(lightDbRunSet);
        }
        // TODO: Remove from here as this class is WebReportGenerator - not viewer
        private bool RunClientApp(string json, string clientAppFolderPath, WebReportFilter openObject, bool shouldDisplayReport)
        {
            bool response = false;


            try
            {
                string backDir = System.IO.Directory.GetParent(clientAppFolderPath).FullName;
                string viewReportTemplatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reports", "HTMLTemplates", "viewreport.html");
                string strViewReport          = System.IO.File.ReadAllText(viewReportTemplatePath);
                strViewReport = strViewReport.Replace("<!--FULLREPORTPATH-->", Path.GetFileName(clientAppFolderPath));
                System.IO.File.WriteAllText(Path.Combine(backDir, "viewreport.html"), strViewReport);
                json = $"window.runsetData={json};";

#warning Report Fix MEN not stable approach
                StringBuilder pageDataSb = new StringBuilder();
                pageDataSb.Append("file:///");
                pageDataSb.Append(backDir.Replace('\\', '/'));
                pageDataSb.Append("/");
                pageDataSb.Append("viewreport.html");
                if (openObject != null)
                {
                    pageDataSb.Append("#/?Routed_Guid=");
                    pageDataSb.Append(openObject.Guid);
                }
                string taskCommand = $"\"{pageDataSb.ToString()}\"";
                System.IO.File.WriteAllText(Path.Combine(clientAppFolderPath, "assets", "Execution_Data", "executiondata.js"), json);

                if (shouldDisplayReport && !Assembly.GetEntryAssembly().FullName.ToUpper().Contains("CONSOLE"))
                {
                    System.Diagnostics.Process.Start(@browserPath, taskCommand);
                    System.Diagnostics.Process.Start(backDir);
                }
                response = true;
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, "Error in RunClientApp", ex);
            }

            return(response);
        }
        // TODO: Make this function to just generate the report folder !!!
        public LiteDbRunSet RunNewHtmlReport(string reportResultsFolderPath = "", string runSetGuid = null, WebReportFilter openObject = null, bool shouldDisplayReport = true)
        {
            //Copy folder to reportResultsFolderPath or Execution logger
            string reportsResultFolder = string.Empty;

            if (!string.IsNullOrEmpty(reportResultsFolderPath))
            {
                reportsResultFolder = reportResultsFolderPath;
            }
            else
            {
                HTMLReportsConfiguration currentConf = WorkSpace.Instance.Solution.HTMLReportsConfigurationSetList.Where(x => (x.IsSelected == true)).FirstOrDefault();
                reportsResultFolder = Path.Combine(ExtensionMethods.GetReportDirectory(currentConf.HTMLReportsFolder), "Reports", "Ginger-Web-Client");
            }
            string ReportrootPath = Path.Combine(reportsResultFolder, "WebReport");

            try
            {
                string clientAppFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reports", "Ginger-Web-Client");
                Reporter.ToLog(eLogLevel.INFO, "Copying web report folder from: " + clientAppFolderPath);

                Reporter.ToLog(eLogLevel.INFO, "Copying web report folder to: " + ReportrootPath);
                if (Directory.Exists(clientAppFolderPath))
                {
                    string rootFolder = Path.Combine(ReportrootPath);
                    if (Directory.Exists(rootFolder))
                    {
                        IoHandler.Instance.TryFolderDelete(rootFolder);
                    }
                    IoHandler.Instance.CopyFolderRec(clientAppFolderPath, ReportrootPath, true);
                }
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, "Check WebReportFolder Error: " + ex.Message, ex);
            }

            //get exeution data and replace
            LiteDbRunSet lightDbRunSet = new LiteDbRunSet();
            bool         response      = false;

            try
            {
                if (!Directory.Exists(ReportrootPath))
                {
                    return(lightDbRunSet);
                }
                IoHandler.Instance.DeleteFoldersData(Path.Combine(ReportrootPath, "assets", "Execution_Data"));
                IoHandler.Instance.DeleteFoldersData(Path.Combine(ReportrootPath, "assets", "screenshots"));
                LiteDbManager dbManager = new LiteDbManager(new ExecutionLoggerHelper().GetLoggerDirectory(WorkSpace.Instance.Solution.LoggerConfigurations.CalculatedLoggerFolder));
                lightDbRunSet = dbManager.GetLatestExecutionRunsetData(runSetGuid);
                PopulateMissingFields(lightDbRunSet, ReportrootPath);
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(lightDbRunSet);
                response = RunClientApp(json, ReportrootPath, openObject, shouldDisplayReport);
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, "RunNewHtmlReport,error :" + ex.ToString());
            }
            return(lightDbRunSet);
        }