private EntityBase FindNewEquivalent(EntityBase newTopEntity, EntityBase oldTopEntity, EntityBase oldEntity) { if (oldEntity == null) { return(null); } if (oldEntity == oldTopEntity) { return(newTopEntity); } var findFunc = EntityUtil.CreateFindEquivalentEntityFunc(oldTopEntity, oldEntity, false); return(findFunc == null ? null : findFunc(newTopEntity)); }
protected override bool PerformExecute(Model model) { // Figure out which entity to select when done Func <EntityBase, EntityBase> selectAncestorFunc = null; if (_sourceEntities.Count != 0 && _sourceEntities[0].DataElement.Document != null) { var srcEntity = _sourceEntities[0]; selectAncestorFunc = EntityUtil.CreateFindEquivalentEntityFunc(model.session.Entity, srcEntity, true); } // if nodes are not specified, use all if (_sourceEntities.Count == 0) { _sourceEntities.AddRange(model.session.Entity.GetChildEntities()); } // Since we don't know the order that each of the source entities will be in (i.e. document order) // we delete each one separately List <string> runsNotDeletedErrors = new List <string>(); foreach (var srcEntity in _sourceEntities) { var errors = DeleteRuns(srcEntity); if (errors.Count != 0) { runsNotDeletedErrors.AddRange(errors); continue; } //// delete empty engines //var emptyengines = srcEntity // .DescendantsAndSelf<PluginEngineEntity>() // .Where(p => p.DataElement.Document != null && !p.DescendantRunsAndSelf().Any()) // ; //foreach (var pluginEntity in emptyengines) // pluginEntity.Delete(); // delete nodes that are still in document and have no runs if (!_runsonly) { if (srcEntity.DataElement.Document != null && !srcEntity.DescendantRunsAndSelf().Any()) { srcEntity.Delete(); } } } foreach (var delRunErr in runsNotDeletedErrors) { SetError(delRunErr); } // bail out if interactive, and we couldn't delete all nodes if (!Successful() && interactive) { return(true); } if (Successful() && _resetcounter) { model.session.Entity.RuntimeState.ResetTaskCounter(); model.tasksController.DeleteAllTaskFolders(); } // Select the parent node of the first entity that was deleted if (selectAncestorFunc != null) { var entityToSelect = selectAncestorFunc(model.session.Entity); if (entityToSelect != null) { model.selection.Update(null, entityToSelect); } } return(Successful()); // if we were not successful we will try again }
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); }