//<-----------------Gets data required for building a DLL-------------------------------> public String libraryCreation(String directoryPath, TestRequestData datasent, string path) { rply.to = ClientEnvironment.endPoint; rply.from = EnvironmentSet.address + ":" + (EnvironmentSet.port).ToString() + "/IMessagePassingComm"; bldse = new BuildServer(); List <String> tdrivertCase = new List <String>(10); try { String[] files = Directory.GetFiles(directoryPath, datasent.testDriver); foreach (String file in files) { tdrivertCase.Add(file); dllName = Path.GetFileNameWithoutExtension(file); } foreach (String file in datasent.testCode) { tdrivertCase.Add(file); } } catch (Exception e) { Console.WriteLine(e.Message); } String status = libraryCreationHelper(tdrivertCase, directoryPath, datasent, dllName, path); datasent.status = status; return(status); }
// <------------------parses request and returns in list form-------------------------> public List <TestRequestData> parseXMLRequest(String XmlRequest) { List <TestRequestData> testList_ = new List <TestRequestData>(); TextReader tr = new StringReader(XmlRequest); try { XDocument doc; testList_ = new List <TestRequestData>(); doc = XDocument.Load(tr); if (doc == null) { return(null); } string author = doc.Descendants("author").First().Value; TestRequestData test = null; XElement[] xtests = doc.Descendants("test").ToArray(); int numTests = xtests.Count(); for (int i = 0; i < numTests; ++i) { test = new TestRequestData(); test.testCode = new List <string>(); test.authorName = author; test.timeStamp = DateTime.Now; test.testName = xtests[i].Attribute("name").Value; test.toolChain = xtests[i].Element("toolChain").Value; test.testDriver = xtests[i].Element("testDriver").Value; IEnumerable <XElement> xtestCode = xtests[i].Elements("tested"); foreach (var xlibrary in xtestCode) { test.testCode.Add(xlibrary.Value); } test.showTestRequest(); testList_.Add(test); } return(testList_); } catch (Exception e) { Console.Write("\n Excetion Caught while parsing::" + e.Message); } finally { tr.Close(); } return(testList_); }
// ----------------------< Creation of Xml for creating BuildLog, TestLog and TestRequest >----------- public String XmlCreation(String destination, List <TestRequestData> data) { XDocument doc; if (data != null) { TestRequestData tdata1 = new TestRequestData(); tdata1 = data[0]; String authorName = data[0].authorName; doc = new XDocument(new XElement(destination, new XElement("author", authorName), from TestRequestData tdata in data select new XElement("test", new XAttribute("name", tdata.testName), new XElement("toolChain", tdata.toolChain), new XElement("testDriver", tdata.testDriver) ))); if (destination.Equals("BuildRequest")) { XElement[] xtests = doc.Descendants("test").ToArray(); int i = 0; foreach (XElement xtest in xtests) { foreach (String testcase in data[i].testCode) { xtest.Add( new XElement("tested", testcase)); } ++i; } } if (destination.Equals("BuildLog") || destination.Equals("TestLog")) { XElement[] xtests = doc.Descendants("test").ToArray(); int i = 0; foreach (XElement xtest in xtests) { xtest.Add( new XElement("status", data[i].status), new XElement("Message", data[i].logInfo)); ++i; } } return(doc.ToString()); } return(null); }
//------------------------------< start processing the building of test libraries >---------------- public string requestRepoForFilesBuildDll(List <TestRequestData> Data, String Destination, String path) { String buildStatus; ArrayList testNames = new ArrayList(); ArrayList testDlls = new ArrayList(); foreach (TestRequestData dataRequested in Data) { Console.Write("\n=================================================\nRequirement #7 ## Attempt to Build\n================================================="); Console.Write("\n\nInvoke Build Library to build DLL for : {0}", dataRequested.testName); buildStatus = blib.libraryCreation(Destination, dataRequested, path); if (buildStatus.Equals("Success")) { String driver = Path.GetFileNameWithoutExtension(dataRequested.testDriver); testNames.Add(dataRequested.testName); testDlls.Add(driver + ".dll"); Console.ForegroundColor = ConsoleColor.DarkGreen; } else { Console.ForegroundColor = ConsoleColor.DarkRed; } Console.Write("\n-----------------------------------------------\n Test Name '{0}' : Build Status '{1}' ", dataRequested.testName, buildStatus); Console.ResetColor(); } doc = xmlParse.XmlCreation("BuildLog", Data); testLog = new List <TestRequestData>(testNames.Count); if (testDlls.Count > 0) { for (int i = 0; i < testNames.Count; i++) { TestRequestData tem = new TestRequestData(); tem = Data[i]; tem.testName = (String)testNames[i]; tem.testDriver = (String)testDlls[i]; testLog.Add(tem); } testRequest = xmlParse.XmlCreation("TestRequest", testLog); createTestRequestMessage(testRequest); } toolChain = Data[0].toolChain; Data.Clear(); return(doc); }
//-------------------< To create a build request on files selected b the user >-------------- void testHelper() { TestRequestData td = new TestRequestData(); int count = testcase.SelectedItems.Count; StringBuilder f1 = new StringBuilder(count); f1.Append("TestName : Test"); int i = 0; string m1 = "Please select a Test Driver"; if (testDrivers.SelectedItems.Count <= 0) { System.Windows.MessageBox.Show(m1); } foreach (String tdriver in testDrivers.SelectedItems) { td.testDriver = tdriver; f1.Append("\n" + Path.GetFileName(tdriver)); } td.testCode = new List <String>(testcase.SelectedItems.Count); foreach (String l1 in testcase.SelectedItems) { td.testCode.Add(l1); i += 1; f1.Append("\n" + Path.GetFileName(l1)); } td.testName = "test"; td.authorName = "Harika"; td.toolChain = "C#"; Console.WriteLine("\n-----Test Added to Build Request\n"); td.showTestRequest(); tdList.Add(td); Dispatcher.Invoke( new Action <StringBuilder>(addAddedTests), System.Windows.Threading.DispatcherPriority.Background, new StringBuilder[] { f1 } ); }
// <------------------------------------Creates a DLL using Process--------------------> public String libraryCreationHelper(List <String> fileNames, String directory, TestRequestData datasent, String dllName, String path) { try { Process Process = new Process(); String commandNames = "", command; foreach (String name in fileNames) { commandNames = Path.GetFileName(name) + " " + commandNames; } if (datasent.toolChain.Equals("CPP")) { Console.WriteLine("\n========================\nBuildig DLL for CPP Tested Codes\n=======================\n"); command = @"/C cl /EHsc /nologo /D_USRDLL /D_WINDLL " + commandNames + "/link /DLL /OUT:" + dllName + ".dll "; } else { command = @"/C csc /nologo /target:library /out:" + dllName + ".dll /r:../../TestInterfaces/bin/debug/TestInterfaces.dll " + commandNames; } Process.StartInfo.FileName = "cmd.exe"; Process.StartInfo.Arguments = command; Process.StartInfo.WorkingDirectory = Path.GetFullPath(directory); Process.StartInfo.UseShellExecute = false; Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.RedirectStandardError = true; Process.StartInfo.CreateNoWindow = true; try { Process.Start(); } catch (Exception e) { Console.WriteLine(e.Message); } logInfo = Process.StandardError.ReadToEnd(); if (datasent.toolChain.Equals("C#")) { logInfo = logInfo + Process.StandardOutput.ReadToEnd(); } datasent.logInfo = logInfo; if (logInfo.Length <= 0) { buildStatus = "Success"; rply.body = datasent.testName + " " + buildStatus + " " + "Errors : 0 Warnings : 0"; datasent.logInfo = "Errors:0 Warnings: 0"; } else { buildStatus = "Failed"; rply.body = datasent.testName + " " + buildStatus; } Process.WaitForExit(); } catch (Exception e) { Console.WriteLine(e.Message); } return(buildStatus); }