/// <summary> /// 将对象转换为其 XML 表示形式。 /// </summary> /// <param name="writer">对象要序列化为的 <see cref="T:System.Xml.XmlWriter" /> 流。</param> public override void WriteXml(XmlWriter writer) { if (!string.IsNullOrEmpty(ModuleId)) { writer.WriteAttributeString("moduleId", ModuleId); } writer.WriteAttributeString("type", Type); writer.WriteAttributeString("enumerator", ScopeIEnumerableInstance); if (BuildInstance) { writer.WriteAttributeString("isInstance", BuildInstance.ToString()); } writer.WriteAttributeString("target", Target.ToString()); writer.WriteStartElement("match"); Match.WriteXml(writer); writer.WriteEndElement(); writer.WriteStartElement("invoke"); writer.WriteAttributeString("type", typeof(ModuleBuildStepElement).GetNoVersionTypeName()); foreach (ModuleBuildStepElement step in Steps) { step.ObjectWriteXml(writer); } writer.WriteEndElement(); }
private static BuildInstance GetAddBuildInstance(PEUTEST002Entities dbc, int buildDefnId, string buildInstanceName, string dateStr) { var countBuildInstances = (from x in DatabaseInstance.BuildInstances where x.BuildDefinitionId == buildDefnId && x.BuildInstanceName == buildInstanceName select x).Count(); if (countBuildInstances <= 0) { dbc.BuildInstances.Add(new BuildInstance { BuildDefinitionId = buildDefnId, BuildInstanceName = buildInstanceName, DateId = dateStr }); dbc.SaveChanges(); BuildInstance bi = (from x in dbc.BuildInstances where x.BuildDefinitionId == buildDefnId && x.BuildInstanceName == buildInstanceName select x).ToList()[0]; Console.WriteLine($"Added Build Instance {bi.BuildDefinition.BuildDefinitionName} / {buildInstanceName}"); DatabaseInstance.BuildInstances.Add(bi); } return((from x in DatabaseInstance.BuildInstances where x.BuildDefinitionId == buildDefnId && x.BuildInstanceName == buildInstanceName select x).ToList()[0]); }
private static void ProcessBuildInstance(string build, PEUTEST002Entities dbc, BuildDefinition buildDefinition) { try { var dateStr = GetTestDateString(Directory.GetCreationTime(build)); TestDate dbDate = GetAddTestDate(dbc, dateStr); var buildInstanceName = Path.GetFileName(build); var buildDefnId = buildDefinition.BuildDefinitionId; BuildInstance buildInstance = GetAddBuildInstance(dbc, buildDefnId, buildInstanceName, dateStr); //var resultsDir = Path.Combine(buildDefinition.ResultsShare, buildDefinition.BuildDefinitionName, build, buildDefinition.ResultsPath); foreach (string resultsDir in Directory.GetDirectories(build, buildDefinition.ResultsPath, SearchOption.TopDirectoryOnly)) { foreach (string xmlFile in Directory.GetFiles(resultsDir, "TestResult_*.xml", SearchOption.AllDirectories)) { ProcessAssembly(dbc, xmlFile, buildInstance, resultsDir); } } //var resultsDir = Path.Combine(build, buildDefinition.ResultsPath); } catch (Exception ex1Exception) { WriteException(ex1Exception); //Environment.Exit(-1); } }
private void UpdateLastBuildStatusAsync(BuildInstance build) { var buildStatus = build.ProgressStatus == BuildProgressStatus.InProgress ? BuildResultStatus.InProgress : build.ResultStatus; if (ServiceStatus < buildStatus) { ServiceStatus = buildStatus; } }
private async Task RaiseBuildEventAsync(BuildDefinition definition, BuildInstance previousBuild = null, BuildInstance mostRecentBuild = null, Exception ex = null) { await RaiseEventAsync(BuildEvent, new BuildEventArgs() { Name = definition.Name, Code = ex == null ? BuildEventCode.StatusUpdate : BuildEventCode.Error, BuildDetails = new BuildDetails() { Definition = definition, CurrentBuild = mostRecentBuild, PreviousBuild = previousBuild }, Exception = ex }); }
private Color CalculateColour(BuildInstance instance) { Color colour = UnknownColour; if (instance == null) { colour = UnknownColour; } else if (instance.ProgressStatus != BuildProgressStatus.Completed) { colour = InProgressColour; } else { colour = CalculateColour(instance.ResultStatus); } return(colour); }
public override string ToString() { var message = string.Empty; BuildInstance instance = null; if (BuildDetails != null) { if (BuildDetails.CurrentBuild != null) { instance = BuildDetails.CurrentBuild; } else if (BuildDetails.PreviousBuild != null) { instance = BuildDetails.PreviousBuild; } } if (instance != null) { if (instance.ProgressStatus == BuildProgressStatus.Completed) { message = string.Format("Build '{0}' completed with a result status of '{1}'.", instance.Name, instance.ResultStatus.ToString().ToLower()); } else if (instance.ProgressStatus == BuildProgressStatus.InProgress) { message = string.Format("Build '{0}' is current in progress.", instance.Name); } else { message = string.Format("The execution status of the build instance '{0}' is unknown.", instance.Name); } } return(message); }
/// <summary> /// 将对象转换为其 XML 表示形式。 /// </summary> /// <param name="writer">对象要序列化为的 <see cref="T:System.Xml.XmlWriter" /> 流。</param> public override void WriteXml(XmlWriter writer) { if (!string.IsNullOrEmpty(moduleDef)) { writer.WriteAttributeString("moduleId", ModuleId); } if (!string.IsNullOrEmpty(Type)) { writer.WriteAttributeString("type", Type); } if (BuildInstance) { writer.WriteAttributeString("isInstance", BuildInstance.ToString()); } writer.WriteAttributeString("target", Target.ToString()); foreach (ModuleBuildStepElement step in _innerSteps) { step.ObjectWriteXml(writer); } }
private static void ProcessAssembly(PEUTEST002Entities dbc, string xmlFile, BuildInstance buildInstance, string resultsDir) { try { var share = buildInstance.BuildDefinition.ResultsShare; XmlDocument xdoc = new XmlDocument(); xdoc.Load(CopyLocal(share, xmlFile)); if (!CheckIfValidNUnitXml(xdoc)) { return; } Console.WriteLine($"Loaded file {xmlFile} {buildInstance.BuildInstanceName}"); //var asemblyname = GetAssemblyName(xdoc); var vmName = GetVmName(xdoc); string assemblyName = GetAssemblyName(xdoc); string xmlRelativePath = Path.GetDirectoryName(xmlFile).Replace($"{resultsDir}\\", string.Empty); //Assembly assembly = GetAddAssembly(dbc, assemblyName, xmlRelativePath); AddAssembly(assemblyName, xmlRelativePath); foreach (XmlNode testcaseNode in xdoc.GetElementsByTagName("test-case")) { try { XmlNode fixtureNode = GetFixtureNode(testcaseNode); var fixtureName = FormatChars(fixtureNode.Attributes["name"].Value); var fixtureFullName = GetFixtureFullNamespacePath(fixtureNode); var testcaseFullName = FormatChars(testcaseNode.Attributes["name"].Value).Trim('.'); var testcaseName = testcaseFullName.Replace($"{fixtureFullName}.", string.Empty); bool executed, success; int time; string message, stacktrace; GetValues(testcaseNode, out executed, out success, out time, out message, out stacktrace); if (testcaseName == testcaseFullName) { testcaseName = GetTestcaseNameFromFullName(testcaseFullName); } if (testcaseName == testcaseFullName) { throw new Exception($"Unable to find testcase correct name: TestcaseName:{testcaseFullName}"); } //testcaseFullName.Replace($"{fixtureFullName}.", string.Empty); if (!testcaseFullName.Contains(fixtureFullName)) { // Console.WriteLine($"#### Fixture <> Testcasename : Fixturename={fixtureFullName} / Testcasename={testcaseFullName}"); //fixtureFullName = testcaseFullName.Substring(0, testcaseFullName.LastIndexOf(".")); //throw new Exception($"Unable to find testcase/fixture correct name: Fixname:{fixtureNameFull}, TestcaseName:{testcaseFullName}"); } if (!fixtureFullName.Contains(fixtureName)) { //fixtureNameFull = testcaseFullName.Substring(0, testcaseFullName.LastIndexOf(".")); throw new Exception($"Unable to find fixture correct name: Fixname:{fixtureFullName} / FixtureName:{fixtureName} / TestcaseName:{testcaseFullName}"); } //Fixture fixture = GetAddFixture(dbc, fixtureFullName, fixtureName, assembly.AssemblyId); AddFixture(fixtureFullName, fixtureName); try { //var fixtureId = fixture.FixtureId; if (testcaseName == testcaseFullName) { throw new Exception($"Unable to find testcase/fixture correct name: Fixname:{fixtureFullName}, TestcaseName:{testcaseFullName}"); } //Testcase testcase = GetAddTestcase(dbc, testcaseName, testcaseFullName, fixtureId); AddTestcase(testcaseName, testcaseFullName); try { AddReport(buildInstance.BuildInstanceId, time, vmName, executed, success, message, stacktrace); } catch (Exception eeee) { WriteException(eeee); } } catch (Exception eee) { WriteException(eee); } } catch (Exception exception) { WriteException(exception); //Environment.Exit(-1); } } //foreach (XmlNode testcaseNode in xdoc.GetElementsByTagName("test-case")) //{ // ProcessFixture(dbc, testcaseNode, assembly); //} } catch (Exception ex2Exception) { WriteException(ex2Exception); //Environment.Exit(-1); } }