/// <summary> /// Sorts the specified oriented graph of the nodes in their topological order /// (following the outgoing connections). /// </summary> /// <param name="nodes">The nodes.</param> /// <param name="removedEdges">Edges removed to make graph non-cyclic.</param> /// <param name="removeWholeNode">If <see langword="true"/> removes whole node in the case of loop, otherwise removes only one edge.</param> /// <returns>Sorting result.</returns> public static List <TNodeItem> Sort <TNodeItem, TConnectionItem>(IEnumerable <Node <TNodeItem, TConnectionItem> > nodes, out List <NodeConnection <TNodeItem, TConnectionItem> > removedEdges, bool removeWholeNode) { ArgumentValidator.EnsureArgumentNotNull(nodes, "nodes"); var head = new Queue <TNodeItem>(); var tail = new Queue <TNodeItem>(); removedEdges = new List <NodeConnection <TNodeItem, TConnectionItem> >(); var nodeList = nodes.ToList(); var nodesToRemove = new List <Node <TNodeItem, TConnectionItem> >(); while (nodeList.Count > 0) { nodesToRemove.Clear(); Node <TNodeItem, TConnectionItem> nodeToBreakLoop = null; NodeConnection <TNodeItem, TConnectionItem> edgeToBreakLoop = null; foreach (var node in nodeList) { if (node.IncomingConnectionCount == 0) { // Add to head head.Enqueue(node.Item); nodesToRemove.Add(node); var connections = node.OutgoingConnections.ToArray(); foreach (var connection in connections) { connection.UnbindFromNodes(); } } else if (node.OutgoingConnectionCount == 0) { // Add to tail tail.Enqueue(node.Item); nodesToRemove.Add(node); var connections = node.IncomingConnections.ToArray(); foreach (var connection in connections) { connection.UnbindFromNodes(); } } else { if (removeWholeNode) { if (node.PermanentOutgoingConnectionCount == 0 && (nodeToBreakLoop == null || node.OutgoingConnectionCount > nodeToBreakLoop.OutgoingConnectionCount)) { nodeToBreakLoop = node; } } else { if (node.BreakableOutgoingConnectionCount > 0 && edgeToBreakLoop == null) { edgeToBreakLoop = node.OutgoingConnections.First(connection => connection.ConnectionType == ConnectionType.Breakable); } } } } if (nodesToRemove.Count == 0) { if (nodeToBreakLoop != null) { // Remove node var connections = nodeToBreakLoop.OutgoingConnections.ToArray(); foreach (var connection in connections) { connection.UnbindFromNodes(); } foreach (var connection in nodeToBreakLoop.IncomingConnections.ToArray()) { connection.UnbindFromNodes(); } removedEdges.AddRange(connections); tail.Enqueue(nodeToBreakLoop.Item); nodeList.Remove(nodeToBreakLoop); } else if (edgeToBreakLoop != null) { // remove edge removedEdges.Add(edgeToBreakLoop); edgeToBreakLoop.UnbindFromNodes(); } else { throw new InvalidOperationException(Strings.ExOnlyBreakableNodesSadSmile); } } foreach (var nodeToRemove in nodesToRemove) { nodeList.Remove(nodeToRemove); } } return(head.Concat(tail.Reverse()).ToList()); }
public static SqlCreatePartitionFunction Create(PartitionFunction partitionFunction) { ArgumentValidator.EnsureArgumentNotNull(partitionFunction, "partitionFunction"); return(new SqlCreatePartitionFunction(partitionFunction)); }
public static SqlCreateSchema Create(Schema schema) { ArgumentValidator.EnsureArgumentNotNull(schema, "schema"); return(new SqlCreateSchema(schema)); }
public static SqlCreateIndex Create(Index index) { ArgumentValidator.EnsureArgumentNotNull(index, "index"); return(new SqlCreateIndex(index)); }
public static SqlDropConstraint DropConstraint(Constraint constraint, bool cascade) { ArgumentValidator.EnsureArgumentNotNull(constraint, "constraint"); return(new SqlDropConstraint(constraint, cascade)); }
public static SqlAlterPartitionScheme Alter(PartitionSchema partitionSchema, string filegroup) { ArgumentValidator.EnsureArgumentNotNull(partitionSchema, "partitionSchema"); return(new SqlAlterPartitionScheme(partitionSchema, filegroup)); }
public static SqlAddColumn AddColumn(TableColumn column) { ArgumentValidator.EnsureArgumentNotNull(column, "column"); return(new SqlAddColumn(column)); }
public static SqlDropDomain Drop(Domain domain, bool cascade) { ArgumentValidator.EnsureArgumentNotNull(domain, "domain"); return(new SqlDropDomain(domain, cascade)); }
public static SqlDropSchema Drop(Schema schema, bool cascade) { ArgumentValidator.EnsureArgumentNotNull(schema, "schema"); return(new SqlDropSchema(schema, cascade)); }
public static SqlDropIndex Drop(Index index) { ArgumentValidator.EnsureArgumentNotNull(index, "index"); return(new SqlDropIndex(index)); }
public static SqlCreateAssertion Create(Assertion assertion) { ArgumentValidator.EnsureArgumentNotNull(assertion, "assertion"); return(new SqlCreateAssertion(assertion)); }
public static SqlDropCollation Drop(Collation collation) { ArgumentValidator.EnsureArgumentNotNull(collation, "collation"); return(new SqlDropCollation(collation)); }
internal ComplexTerm(IOperator source, IOperand operandsSequenceRoot) : base(SearchConditionNodeType.ComplexTerm, source) { ArgumentValidator.EnsureArgumentNotNull(operandsSequenceRoot, "operandsSequenceRoot"); RootOperand = operandsSequenceRoot; }
/// <inheritdoc/> /// <exception cref="ArgumentOutOfRangeException"><c>hints.SourceModel</c> or <c>hints.TargetModel</c> /// is out of range.</exception> /// <exception cref="InvalidOperationException">Upgrade sequence validation has failed.</exception> public ReadOnlyList <NodeAction> GetUpgradeSequence(Difference difference, HintSet hints, IComparer comparer) { ArgumentValidator.EnsureArgumentNotNull(hints, "hints"); ArgumentValidator.EnsureArgumentNotNull(comparer, "comparer"); if (difference == null) { return(new ReadOnlyList <NodeAction>(Enumerable.Empty <NodeAction>().ToList())); } TemporaryRenames = new Dictionary <string, Node>(StringComparer.OrdinalIgnoreCase); SourceModel = (IModel)difference.Source; TargetModel = (IModel)difference.Target; Hints = hints ?? new HintSet(SourceModel, TargetModel); Comparer = comparer; if (Hints.SourceModel != SourceModel) { throw new ArgumentOutOfRangeException("hints.SourceModel"); } if (Hints.TargetModel != TargetModel) { throw new ArgumentOutOfRangeException("hints.TargetModel"); } CurrentModel = (IModel)SourceModel.Clone(null, SourceModel.Name); Difference = difference; var previous = currentAsync.Value; currentAsync.Value = this; using (NullActionHandler.Instance.Activate()) { try { var actions = new GroupingNodeAction(); ProcessStage(UpgradeStage.CleanupData, actions); ProcessStage(UpgradeStage.Prepare, actions); ProcessStage(UpgradeStage.TemporaryRename, actions); ProcessStage(UpgradeStage.Upgrade, actions); ProcessStage(UpgradeStage.CopyData, actions); ProcessStage(UpgradeStage.PostCopyData, actions); ProcessStage(UpgradeStage.Cleanup, actions); var validationHints = new HintSet(CurrentModel, TargetModel); Hints.OfType <IgnoreHint>().ForEach(validationHints.Add); var diff = comparer.Compare(CurrentModel, TargetModel, validationHints); if (diff != null) { CoreLog.InfoRegion(Strings.LogAutomaticUpgradeSequenceValidation); CoreLog.Info(Strings.LogValidationFailed); CoreLog.Info(Strings.LogItemFormat, Strings.Difference); CoreLog.Info("{0}", diff); CoreLog.Info(Strings.LogItemFormat + "\r\n{1}", Strings.UpgradeSequence, new ActionSequence() { actions }); CoreLog.Info(Strings.LogItemFormat, Strings.ExpectedTargetModel); TargetModel.Dump(); CoreLog.Info(Strings.LogItemFormat, Strings.ActualTargetModel); CurrentModel.Dump(); throw new InvalidOperationException(Strings.ExUpgradeSequenceValidationFailure); } return(new ReadOnlyList <NodeAction>(actions.Actions, true)); } finally { currentAsync.Value = previous; } } }
public static SqlCreateDomain Create(Domain domain) { ArgumentValidator.EnsureArgumentNotNull(domain, "domain"); return(new SqlCreateDomain(domain)); }
public static SqlDropSequence Drop(Sequence sequence, bool cascade) { ArgumentValidator.EnsureArgumentNotNull(sequence, "sequence"); return(new SqlDropSequence(sequence, cascade)); }
public static SqlAlterPartitionScheme Alter(PartitionSchema partitionSchema) { ArgumentValidator.EnsureArgumentNotNull(partitionSchema, "partitionSchema"); return(new SqlAlterPartitionScheme(partitionSchema, null)); }
public static SqlDropTable Drop(Table table, bool cascade) { ArgumentValidator.EnsureArgumentNotNull(table, "table"); return(new SqlDropTable(table, cascade)); }
public static SqlAlterIdentityInfo Alter(TableColumn column, SequenceDescriptor descriptor) { ArgumentValidator.EnsureArgumentNotNull(column, "column"); ArgumentValidator.EnsureArgumentNotNull(descriptor, "info"); return(new SqlAlterIdentityInfo(column, descriptor, SqlAlterIdentityInfoOptions.All)); }
public static SqlDropTranslation Drop(Translation translation) { ArgumentValidator.EnsureArgumentNotNull(translation, "translation"); return(new SqlDropTranslation(translation)); }
public static SqlAddConstraint AddConstraint(Constraint constraint) { ArgumentValidator.EnsureArgumentNotNull(constraint, "constraint"); return(new SqlAddConstraint(constraint)); }
public static SqlCreateCharacterSet Create(CharacterSet characterSet) { ArgumentValidator.EnsureArgumentNotNull(characterSet, "characterSet"); return(new SqlCreateCharacterSet(characterSet)); }
public static SqlDropColumn DropColumn(TableColumn column, bool cascade) { ArgumentValidator.EnsureArgumentNotNull(column, "column"); return(new SqlDropColumn(column, cascade)); }
public static SqlDropView Drop(View view, bool cascade) { ArgumentValidator.EnsureArgumentNotNull(view, "view"); return(new SqlDropView(view, cascade)); }
public static SqlSetDefault SetDefault(SqlExpression defaulValue, TableColumn column) { ArgumentValidator.EnsureArgumentNotNull(defaulValue, "defaulValue"); return(new SqlSetDefault(defaulValue, column)); }
public static SqlCreateCollation Create(Collation collation) { ArgumentValidator.EnsureArgumentNotNull(collation, "collation"); return(new SqlCreateCollation(collation)); }
public static SqlCreatePartitionScheme Create(PartitionSchema partitionSchema) { ArgumentValidator.EnsureArgumentNotNull(partitionSchema, "partitionSchema"); return(new SqlCreatePartitionScheme(partitionSchema)); }
public static SqlAlterSequence Alter(Sequence sequence, SequenceDescriptor descriptor) { ArgumentValidator.EnsureArgumentNotNull(sequence, "sequence"); ArgumentValidator.EnsureArgumentNotNull(descriptor, "info"); return(new SqlAlterSequence(sequence, descriptor, SqlAlterIdentityInfoOptions.All)); }
public static SqlCreateSequence Create(Sequence sequence) { ArgumentValidator.EnsureArgumentNotNull(sequence, "sequence"); return(new SqlCreateSequence(sequence)); }
/// <summary> /// Initializes a new instance of the <see cref="DataTableNode"/> class. /// </summary> /// <param name="dataTable">The dataTable.</param> /// <param name="name">The name.</param> protected DataTableNode(DataTable dataTable, string name) : base(name) { ArgumentValidator.EnsureArgumentNotNull(dataTable, "dataTable"); DataTable = dataTable; }