/// <summary> /// Tries to load the source test container. /// If successful, this entity is replaced with the loaded test container. /// Otherwise, the LoadError property is set, indicating the reason. /// </summary> /// <returns></returns> public bool TryLoad(bool loadDescendentIncludes = true, bool registerWithSession = true) { // 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 (LoadError != null) { LoadError.DataElement.Remove(); } var loader = new TestContainerLoader(this) { LoadRecursiveIncludes = loadDescendentIncludes, RegisterWithSession = registerWithSession, }; if (loader.Load()) { TestContainerUtil.MergeInSettingsFromInclude(loader.TestContainer.DataElement, DataElement); this.ReplaceWithEntity(loader.TestContainer); return(true); } else { this.AddEntity <ErrorEntity>(loader.LoadError); return(false); } }
private static TestGroupingEntity LoadTestContainer(string containerPath) { TestContainerLoader loader = new TestContainerLoader(containerPath) { Model = Model.Instance }; if (!loader.Load()) { throw new Exception(loader.LoadError.Message); } // TODO: If the loader failed, then the TestContainer will be an error entity, not a test group return((TestGroupingEntity)loader.TestContainer); }
protected override bool PerformExecute(Model model) { if (!_entity.GetSessionProperty_DetectChanges()) { return(true); } // First, ask if we should refresh first if (interactive && _confirmWithUser) { string msg = String.Format(@"The source file ""{0}"" has changed. Would you like to refresh it?", _hsf.SourceFilePath); string caption = "Source File Changed"; if (MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) != DialogResult.Yes) { return(true); } // In case it got changed while waiting on the user if (!_entity.GetSessionProperty_DetectChanges()) { return(true); } } try { var loader = new TestContainerLoader(_hsf.SourceFilePath) { Model = model, LoadRecursiveIncludes = true, RegisterWithSession = false, }; if (!loader.Load()) { SetError("Error: failed to refresh test container.\n" + loader.LoadError.Message); return(true); // true indicates no followups } var newEntity = loader.TestContainer; if (newEntity.DataElement.Name != _entity.DataElement.Name) { throw new ArgumentException("The new data element has a different XName than the original entity."); } // Figure out which entity to select when done Func <EntityBase, EntityBase> selectAncestorFunc = null; var prevSelectedEntity = model.selection.current.SelectedEntity; if (prevSelectedEntity != null && _entity.Contains(prevSelectedEntity)) { selectAncestorFunc = EntityUtil.CreateFindEquivalentEntityFunc(model.session.Entity, prevSelectedEntity, true); model.selection.Update(null, _entity.Parent); } // Create a temporary xml element for while merging because we don't want to raise entity changed // events for every run added, just one at the very end. var ph = PlaceholderEntity.CreatePlaceholder(model, "Loading tests container..."); _entity.DataElement.ReplaceWith(ph.DataElement); MergeSessionState(newEntity, _entity); // Need to make a copy so we aren't bound anymore ph.DataElement.ReplaceWith(newEntity.DataElement); _entity.SetSessionProperty_DetectChanges(false); // Turn this off here to prevent trying to update it again // Select the old selected node within the new sub-tree if (selectAncestorFunc != null) { var entityToSelect = selectAncestorFunc(model.session.Entity); if (entityToSelect != null) { //model.controller.AddFollowupCommand(new SelectEntityCommand(this, entityToSelect)); model.selection.Update(this, entityToSelect); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex, "RefreshCommand.Execute threw exception"); SetError("Failed to refresh:\n" + ex.Message); } return(true); }