private TestLogFull GetTestLog(TestSuiteParameters testSuiteParameters, SerializableTestingParameters parameters, TestController controller) { controller.UpdateTestLog(); TestLogFull testLog = new TestLogFull(); Data.TestLog log = ContextController.GetTestLog(); testLog.TestResults = log.TestResults; testLog.Features = log.Features; testLog.InitializationData = log.InitializationData; testLog.FeaturesDefinitionLog = log.FeaturesDefinitionLog; testLog.DeviceInformation = controller.DeviceInformation; if (log.TestExecutionTime != DateTime.MinValue) { testLog.TestExecutionTime = log.TestExecutionTime; } else { testLog.TestExecutionTime = DateTime.Now; } testLog.Application = new ApplicationInfo(); testLog.DeviceEnvironment = new DeviceEnvironment(); testLog.DeviceEnvironment.Credentials = new Credentials(); testLog.DeviceEnvironment.Credentials.UserName = testSuiteParameters.UserName; // password not used for REPORTS testLog.DeviceEnvironment.TestSettings = new TestSettings(); // only two values are user for log testLog.DeviceEnvironment.TestSettings.OperationDelay = testSuiteParameters.OperationDelay; testLog.DeviceEnvironment.TestSettings.RecoveryDelay = testSuiteParameters.RecoveryDelay; testLog.DeviceEnvironment.Timeouts.InterTests = testSuiteParameters.TimeBetweenTests; testLog.DeviceEnvironment.Timeouts.Message = testSuiteParameters.MessageTimeout; testLog.DeviceEnvironment.Timeouts.Reboot = testSuiteParameters.RebootTimeout; if (parameters.Device != null) { testLog.ProductName = parameters.Device.Model; } if (parameters.SessionInfo != null) { testLog.TesterInfo = parameters.SessionInfo.TesterInfo; testLog.OtherInformation = parameters.SessionInfo.OtherInformation; testLog.MemberInfo = parameters.SessionInfo.MemberInfo; } return(testLog); }
private SerializableTestingParameters LoadParameters() { SerializableTestingParameters userParameters = null; if (_options.ContainsKey(CommandLineArgs.PARAMETERSFILE)) { string parametersFile = _options[CommandLineArgs.PARAMETERSFILE]; if (!File.Exists(parametersFile)) { SaveErrorLog(string.Format("File not found: {0}", parametersFile)); return(null); } XmlSerializer serializer = new XmlSerializer(typeof(SerializableTestingParameters)); FileStream stream = null; try { stream = new FileStream(parametersFile, FileMode.Open); userParameters = (SerializableTestingParameters)serializer.Deserialize(stream); } catch (Exception exc) { SaveErrorLog(string.Format("Parameters loading failed: {0}", exc.Message)); return(null); } finally { if (stream != null) { stream.Close(); } } } return(userParameters); }
public void Run(string[] args) { if (args.Contains(CommandLineArgs.PARAMETERSFILE)) { LoadOptions(args); SerializableTestingParameters parameters = LoadParameters(); if (parameters == null) { return; } // get test suite parameters; // get operator's etc. data // get info about files where to save data; Controllers.TestController controller = new TestController(_view); _controller = controller; AutoResetEvent completed = new AutoResetEvent(false); bool completedOk = true; controller.TestSuiteCompleted += (normally) => { completedOk = normally; completed.Set(); }; controller.ConformanceInitializationCompleted += controller_ConformanceInitializationCompleted; controller.LoadTests(); TestSuiteParameters testSuiteParameters = parameters.GetTestSuiteParameters(); testSuiteParameters.AdvancedParameters = new Dictionary <string, object>(); if (parameters.Advanced != null) { List <object> advanced = AdvancedParametersUtils.Deserialize(parameters.Advanced, controller.AdvancedSettingsTypes); foreach (object p in advanced) { testSuiteParameters.AdvancedParameters.Add(p.GetType().GUID.ToString(), p); } } UpdateDeviceContext(testSuiteParameters); controller.RunConformanceSilent(testSuiteParameters); completed.WaitOne(); if (!completedOk) { return; } try { // Save documents Output output = parameters.Output; // Get directory string folder = string.Empty; if (output != null) { folder = output.Directory; } if (string.IsNullOrEmpty(folder)) { folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); folder = Path.Combine(folder, "ONVIF Device Test Tool"); } string path = folder; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } // Create nested folder if necessary if (output != null && output.CreateNestedFolder) { string name = DateTime.Now.ToString("yyyy-MM-dd hh-mm"); path = Path.Combine(folder, name); Directory.CreateDirectory(path); } TestLogFull log = GetTestLog(testSuiteParameters, parameters, controller); // Save Report string reportFileName = null; if (output != null) { reportFileName = output.Report; } if (string.IsNullOrEmpty(reportFileName)) { if (log.DeviceInformation != null) { reportFileName = string.Format("{0} - report.pdf", log.ProductName); } } if (string.IsNullOrEmpty(reportFileName)) { reportFileName = "report.pdf"; } reportFileName = Path.Combine(path, reportFileName); Utils.PdfReportGenerator reportGenerator = new PdfReportGenerator(); reportGenerator.CreateReport(reportFileName, log); // Save DoC string docFileName = null; if (output != null) { docFileName = output.DeclarationOfConformance; } if (string.IsNullOrEmpty(docFileName)) { if (log.DeviceInformation != null) { docFileName = string.Format("{0} - DoC.pdf", log.ProductName); } } if (string.IsNullOrEmpty(docFileName)) { docFileName = "DoC.pdf"; } docFileName = Path.Combine(path, docFileName); Utils.DoCGenerator docGenerator = new DoCGenerator(); docGenerator.CreateReport(docFileName, log); // Save log, if required if (output != null) { if (!string.IsNullOrEmpty(output.TestLog)) { string fileName = Path.Combine(path, output.TestLog); List <TestResult> results = new List <TestResult>(); foreach (TestTool.Tests.Definitions.Data.TestInfo ti in controller.TestInfos) { TestResult tr = controller.GetTestResult(ti); if (tr != null) { results.Add(tr); } } controller.Save(fileName, results); } if (!string.IsNullOrEmpty(output.FeatureDefinitionLog)) { string fileName = Path.Combine(path, output.FeatureDefinitionLog); TestResult tr = new TestResult(); tr.Log = _controller.GetFeaturesDefinitionLog().Log; tr.PlainTextLog = _controller.GetFeaturesDefinitionLog().PlainTextLog; controller.Save(fileName, tr); } } } catch (Exception exc) { SaveErrorLog(string.Format("Failed to create documents: {0}", exc.Message)); } } }