public static IEnumerable <IGraphElementModel> DeleteElements(this IGraphModel self, IReadOnlyCollection <IGraphElementModel> graphElementModels) { var stickyNoteModels = new HashSet <IStickyNoteModel>(); var placematModels = new HashSet <IPlacematModel>(); var variableDeclarationsModels = new HashSet <IVariableDeclarationModel>(); var edgeModels = new HashSet <IEdgeModel>(); var nodeModels = new HashSet <INodeModel>(); foreach (var element in graphElementModels) { switch (element) { case IStickyNoteModel stickyNoteModel: stickyNoteModels.Add(stickyNoteModel); break; case IPlacematModel placematModel: placematModels.Add(placematModel); break; case IVariableDeclarationModel variableDeclarationModel: variableDeclarationsModels.Add(variableDeclarationModel); break; case IEdgeModel edgeModel: edgeModels.Add(edgeModel); break; case INodeModel nodeModel: nodeModels.Add(nodeModel); break; } } // Add nodes that would be backed by declaration models. nodeModels.AddRangeInternal(variableDeclarationsModels.SelectMany(d => self.FindReferencesInGraph <IHasDeclarationModel>(d).OfType <INodeModel>())); // Add edges connected to the deleted nodes. foreach (var portModel in nodeModels.OfType <IPortNodeModel>().SelectMany(n => n.Ports)) { edgeModels.AddRangeInternal(self.EdgeModels.Where(e => e.ToPort == portModel || e.FromPort == portModel)); } return(self.DeleteStickyNotes(stickyNoteModels) .Concat(self.DeletePlacemats(placematModels)) .Concat(self.DeleteEdges(edgeModels)) .Concat(self.DeleteVariableDeclarations(variableDeclarationsModels, deleteUsages: false)) .Concat(self.DeleteNodes(nodeModels, deleteConnections: false)).ToList()); }
public static IReadOnlyCollection <IGraphElementModel> DeleteStickyNote(this IGraphModel self, IStickyNoteModel stickyNoteToDelete) { return(self.DeleteStickyNotes(new[] { stickyNoteToDelete })); }