public void RegisterResult (string configuration, UnitTest test, UnitTestResult result) { string aname = test.StoreRelativeName; TestRecord root = GetRootRecord (configuration, result.TestDate); if (root == null) { root = new TestRecord (); fileCache [GetRootFileName (configuration, result.TestDate)] = root; } root.Modified = true; TestRecord record = root; if (aname.Length > 0) { string[] path = test.StoreRelativeName.Split ('.'); foreach (string p in path) { TestRecord ctr = record.Tests != null ? record.Tests [p] : null; if (ctr == null) { ctr = new TestRecord (); ctr.Name = p; if (record.Tests == null) record.Tests = new TestRecordCollection (); record.Tests.Add (ctr); } record = ctr; } } if (record.Results == null) record.Results = new UnitTestResultCollection (); record.Results.Add (result); }
TestRecord GetRootRecord(string configuration, DateTime date) { string file = GetRootFileName(configuration, date); TestRecord res = (TestRecord)fileCache [file]; if (res != null) { return(res); } string filePath; try { filePath = Path.Combine(basePath, file); } catch (Exception) { return(null); } if (!File.Exists(filePath)) { return(null); } StreamReader s = new StreamReader(filePath); try { res = (TestRecord)serializer.Deserialize(s); } catch (Exception ex) { LoggingService.LogError(ex.ToString()); return(null); } finally { s.Close(); } fileCache [file] = res; return(res); }
public UnitTestResult GetNextResult(string configuration, UnitTest test, DateTime date) { DateTime currentDate = date; TestRecord root = GetRootRecord(configuration, currentDate); if (root == null) { root = GetNextRootRecord(configuration, ref currentDate); } while (root != null) { TestRecord tr = FindRecord(root, test.StoreRelativeName); if (tr != null && tr.Results != null) { foreach (UnitTestResult res in tr.Results) { if (res.TestDate > date) { return(res); } } } root = GetNextRootRecord(configuration, ref currentDate); } return(null); }
TestRecord FindRecord(TestRecord root, string aname) { if (aname.Length == 0) { return(root); } else { string[] path = aname.Split('.'); TestRecord tr = root; foreach (string p in path) { if (tr.Tests == null) { return(null); } tr = tr.Tests [p]; if (tr == null) { return(null); } } return(tr); } }
public void Save() { if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } foreach (DictionaryEntry entry in fileCache) { TestRecord record = (TestRecord)entry.Value; if (!record.Modified) { continue; } string file = Path.Combine(basePath, (string)entry.Key); StreamWriter writer = new StreamWriter(file); try { serializer.Serialize(writer, record); } finally { writer.Close(); } record.Modified = false; } cachedRootList.Clear(); }
public UnitTestResult GetPreviousResult(string configuration, UnitTest test, DateTime date) { DateTime currentDate = date; TestRecord root = GetRootRecord(configuration, currentDate); if (root == null) { root = GetPreviousRootRecord(configuration, ref currentDate); } while (root != null) { TestRecord tr = FindRecord(root, test.StoreRelativeName); if (tr != null && tr.Results != null) { for (int n = tr.Results.Count - 1; n >= 0; n--) { UnitTestResult res = (UnitTestResult)tr.Results [n]; if (res.TestDate < date) { return(res); } } } root = GetPreviousRootRecord(configuration, ref currentDate); } return(null); }
TestRecord GetRootRecord(string configuration, DateTime date) { string file = GetRootFileName(configuration, date); TestRecord res = (TestRecord)fileCache [file]; if (res != null) { return(res); } string filePath; try { filePath = Path.Combine(basePath, file); } catch (Exception) { return(null); } try { res = (TestRecord)serializer.Deserialize(filePath); } catch (Exception ex) { LoggingService.LogError(ex.ToString()); return(null); } if (res != null) { fileCache [file] = res; } return(res); }
public void Save() { if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } foreach (DictionaryEntry entry in fileCache) { TestRecord record = (TestRecord)entry.Value; if (!record.Modified) { continue; } string filePath = Path.Combine(basePath, (string)entry.Key); try { serializer.Serialize(filePath, record); record.Modified = false; } catch (Exception ex) { LoggingService.LogError(ex.ToString()); } } cachedRootList.Clear(); }
public void Serialize (string xmlFilePath, TestRecord testRecord) { // no need for xml serialization because next time it will be // deserialized from the binary format string binaryFilePath = GetBinaryFilePath (xmlFilePath); using (var stream = File.OpenWrite(binaryFilePath)) { fastSerializer.Serialize (stream, testRecord); } }
public void Serialize(string xmlFilePath, TestRecord testRecord) { // no need for xml serialization because next time it will be // deserialized from the binary format string binaryFilePath = GetBinaryFilePath(xmlFilePath); using (var stream = File.OpenWrite(binaryFilePath)) { fastSerializer.Serialize(stream, testRecord); } }
public void RegisterResult(string configuration, UnitTest test, UnitTestResult result) { string aname = test.StoreRelativeName; TestRecord root = GetRootRecord(configuration, result.TestDate); if (root == null) { root = new TestRecord(); fileCache [GetRootFileName(configuration, result.TestDate)] = root; } root.Modified = true; TestRecord record = root; if (aname.Length > 0) { string[] path = test.StoreRelativeName.Split('.'); foreach (string p in path) { TestRecord ctr = record.Tests != null ? record.Tests [p] : null; if (ctr == null) { ctr = new TestRecord(); ctr.Name = p; if (record.Tests == null) { record.Tests = new TestRecordCollection(); } record.Tests.Add(ctr); } record = ctr; } } if (record.Results == null) { record.Results = new UnitTestResultCollection(); } record.Results.Add(result); }
public UnitTestResult[] GetResults(string configuration, UnitTest test, DateTime startDate, DateTime endDate) { ArrayList list = new ArrayList(); DateTime firstDay = new DateTime(startDate.Year, startDate.Month, startDate.Day); DateTime[] dates = GetStoreDates(configuration); foreach (DateTime date in dates) { if (date < firstDay) { continue; } if (date > endDate) { break; } TestRecord root = GetRootRecord(configuration, date); if (root == null) { continue; } TestRecord tr = FindRecord(root, test.StoreRelativeName); if (tr != null && tr.Results != null) { foreach (UnitTestResult res in tr.Results) { if (res.TestDate >= startDate && res.TestDate <= endDate) { list.Add(res); } } } } return((UnitTestResult[])list.ToArray(typeof(UnitTestResult))); }
public UnitTestResult[] GetResultsToDate(string configuration, UnitTest test, DateTime endDate, int count) { ArrayList list = new ArrayList(); DateTime[] dates = GetStoreDates(configuration); for (int n = dates.Length - 1; n >= 0 && list.Count < count; n--) { if (dates [n] > endDate) { continue; } TestRecord root = GetRootRecord(configuration, dates [n]); if (root == null) { continue; } TestRecord tr = FindRecord(root, test.StoreRelativeName); if (tr != null && tr.Results != null) { for (int m = tr.Results.Count - 1; m >= 0 && list.Count < count; m--) { UnitTestResult res = (UnitTestResult)tr.Results [m]; if (res.TestDate <= endDate) { list.Add(res); } } } } UnitTestResult[] array = (UnitTestResult[])list.ToArray(typeof(UnitTestResult)); Array.Reverse(array); return(array); }
public void Add (TestRecord test) { ((IList)this).Add (test); }
TestRecord FindRecord (TestRecord root, string aname) { if (aname.Length == 0) return root; else { string[] path = aname.Split ('.'); TestRecord tr = root; foreach (string p in path) { if (tr.Tests == null) return null; tr = tr.Tests [p]; if (tr == null) return null; } return tr; } }
public void Add(TestRecord test) { ((IList)this).Add(test); }