protected TEntity AddEntity <TEntity>(XElement xentity) where TEntity : EntityBase { // Create the entity instance var entity = xentity.Annotation <TEntity>(); if (entity == null) { entity = (TEntity)Model.EntityBuilder.CreateEntityAndBindToElement(xentity); } // Make sure the entity doesn't have a parent if (entity.Parent != null) { throw new ArgumentException("The element's existing bound entity should not have a parent set when using this method.", "xentity"); } DataElement.Add(xentity); if (entity.Parent == null) // Because this may already get set during Session.EntityChanged event { Model.EntityBuilder.SetParentEntity(entity); } entity.LoadChildren(true); return(entity); }
//public override void CheckForResults() //{ // XElement xchessResults = TaskState.TaskHandle.GetXmlResults(); // if (xchessResults != null) // ProcessTaskResults(xchessResults); //} internal void ProcessTaskResults(XElement xtaskResults) { // TODO: Might need to add this element elsewhere once plugins are finished DataElement.Add(xtaskResults); // if this run was started by an engine, notify it now int?xengineid = (int?)DataElement.Element(XSessionNames.Engineid); if (xengineid.HasValue) { Engine engine = Model.engines[xengineid.Value]; engine.NewResults(this, xtaskResults); } }
public bool TryLoadProjectFile() { // Remove our previous error // It's not in the try-catch because any error is due to other code, not due to a loading failure. if (ProjectLoadError != null) { ProjectLoadError.DataElement.Remove(); } XElement xmsbProj = null; XElement xerror = null; try { xmsbProj = MSBuildProject.ParseProjectFileToXElement(SourceFilePath); if (xmsbProj == null) { xerror = XNames.CreateXError("Project file could not be found."); } // Replace existing element or add it // Note: The element isn't an entity if (_msbuildProj != null) { // We replace so the order of the child elements are preserved (i.e. if a TestAssembly el also exists) Debug.Assert(_msbuildProj.DataElement.Parent == this.DataElement); // move the previous runs to the new project element var prevRuns = _msbuildProj.DataElement.Elements(XSessionNames.BuildRun).ToArray(); foreach (var prevRun in prevRuns) { prevRun.Remove(); xmsbProj.Add(prevRun); } // _msbuildProj.DataElement.ReplaceWith(xmsbProj); } else { DataElement.Add(xmsbProj); } // create the new one _msbuildProj = new MSBuildProject(xmsbProj); } catch (Exception ex) { xerror = XNames.CreateXError("An error occurred trying to parse the project file.", ex); } if (xerror != null) { // Clear out the existing extra elements if they exist var elementsToRemove = DataElement.Elements(XSessionMSBuildNames.Project, XNames.TestAssembly, XNames.Include); foreach (var xel in elementsToRemove) { xel.Remove(); } // Add the error and then eject this.AddEntity <ErrorEntity>(xerror); return(false); } // Make sure we use the correct configuration name if (Configuration != null && !_msbuildProj.Configurations.Any(cfg => cfg.Configuration == Configuration)) { Configuration = null; // Reset to use the default configuration } else // Call the changed event manually so we get a new ProjectConfiguration obj that's part of the new MSBuildProject instance { OnConfigurationChanged(); } return(true); }