コード例 #1
0
        /// <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());
        }
コード例 #2
0
 public static SqlCreatePartitionFunction Create(PartitionFunction partitionFunction)
 {
     ArgumentValidator.EnsureArgumentNotNull(partitionFunction, "partitionFunction");
     return(new SqlCreatePartitionFunction(partitionFunction));
 }
コード例 #3
0
 public static SqlCreateSchema Create(Schema schema)
 {
     ArgumentValidator.EnsureArgumentNotNull(schema, "schema");
     return(new SqlCreateSchema(schema));
 }
コード例 #4
0
 public static SqlCreateIndex Create(Index index)
 {
     ArgumentValidator.EnsureArgumentNotNull(index, "index");
     return(new SqlCreateIndex(index));
 }
コード例 #5
0
 public static SqlDropConstraint DropConstraint(Constraint constraint, bool cascade)
 {
     ArgumentValidator.EnsureArgumentNotNull(constraint, "constraint");
     return(new SqlDropConstraint(constraint, cascade));
 }
コード例 #6
0
 public static SqlAlterPartitionScheme Alter(PartitionSchema partitionSchema, string filegroup)
 {
     ArgumentValidator.EnsureArgumentNotNull(partitionSchema, "partitionSchema");
     return(new SqlAlterPartitionScheme(partitionSchema, filegroup));
 }
コード例 #7
0
 public static SqlAddColumn AddColumn(TableColumn column)
 {
     ArgumentValidator.EnsureArgumentNotNull(column, "column");
     return(new SqlAddColumn(column));
 }
コード例 #8
0
 public static SqlDropDomain Drop(Domain domain, bool cascade)
 {
     ArgumentValidator.EnsureArgumentNotNull(domain, "domain");
     return(new SqlDropDomain(domain, cascade));
 }
コード例 #9
0
 public static SqlDropSchema Drop(Schema schema, bool cascade)
 {
     ArgumentValidator.EnsureArgumentNotNull(schema, "schema");
     return(new SqlDropSchema(schema, cascade));
 }
コード例 #10
0
 public static SqlDropIndex Drop(Index index)
 {
     ArgumentValidator.EnsureArgumentNotNull(index, "index");
     return(new SqlDropIndex(index));
 }
コード例 #11
0
 public static SqlCreateAssertion Create(Assertion assertion)
 {
     ArgumentValidator.EnsureArgumentNotNull(assertion, "assertion");
     return(new SqlCreateAssertion(assertion));
 }
コード例 #12
0
 public static SqlDropCollation Drop(Collation collation)
 {
     ArgumentValidator.EnsureArgumentNotNull(collation, "collation");
     return(new SqlDropCollation(collation));
 }
コード例 #13
0
 internal ComplexTerm(IOperator source, IOperand operandsSequenceRoot)
     : base(SearchConditionNodeType.ComplexTerm, source)
 {
     ArgumentValidator.EnsureArgumentNotNull(operandsSequenceRoot, "operandsSequenceRoot");
     RootOperand = operandsSequenceRoot;
 }
コード例 #14
0
        /// <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;
                }
            }
        }
コード例 #15
0
 public static SqlCreateDomain Create(Domain domain)
 {
     ArgumentValidator.EnsureArgumentNotNull(domain, "domain");
     return(new SqlCreateDomain(domain));
 }
コード例 #16
0
 public static SqlDropSequence Drop(Sequence sequence, bool cascade)
 {
     ArgumentValidator.EnsureArgumentNotNull(sequence, "sequence");
     return(new SqlDropSequence(sequence, cascade));
 }
コード例 #17
0
 public static SqlAlterPartitionScheme Alter(PartitionSchema partitionSchema)
 {
     ArgumentValidator.EnsureArgumentNotNull(partitionSchema, "partitionSchema");
     return(new SqlAlterPartitionScheme(partitionSchema, null));
 }
コード例 #18
0
 public static SqlDropTable Drop(Table table, bool cascade)
 {
     ArgumentValidator.EnsureArgumentNotNull(table, "table");
     return(new SqlDropTable(table, cascade));
 }
コード例 #19
0
 public static SqlAlterIdentityInfo Alter(TableColumn column, SequenceDescriptor descriptor)
 {
     ArgumentValidator.EnsureArgumentNotNull(column, "column");
     ArgumentValidator.EnsureArgumentNotNull(descriptor, "info");
     return(new SqlAlterIdentityInfo(column, descriptor, SqlAlterIdentityInfoOptions.All));
 }
コード例 #20
0
 public static SqlDropTranslation Drop(Translation translation)
 {
     ArgumentValidator.EnsureArgumentNotNull(translation, "translation");
     return(new SqlDropTranslation(translation));
 }
コード例 #21
0
 public static SqlAddConstraint AddConstraint(Constraint constraint)
 {
     ArgumentValidator.EnsureArgumentNotNull(constraint, "constraint");
     return(new SqlAddConstraint(constraint));
 }
コード例 #22
0
 public static SqlCreateCharacterSet Create(CharacterSet characterSet)
 {
     ArgumentValidator.EnsureArgumentNotNull(characterSet, "characterSet");
     return(new SqlCreateCharacterSet(characterSet));
 }
コード例 #23
0
 public static SqlDropColumn DropColumn(TableColumn column, bool cascade)
 {
     ArgumentValidator.EnsureArgumentNotNull(column, "column");
     return(new SqlDropColumn(column, cascade));
 }
コード例 #24
0
 public static SqlDropView Drop(View view, bool cascade)
 {
     ArgumentValidator.EnsureArgumentNotNull(view, "view");
     return(new SqlDropView(view, cascade));
 }
コード例 #25
0
 public static SqlSetDefault SetDefault(SqlExpression defaulValue, TableColumn column)
 {
     ArgumentValidator.EnsureArgumentNotNull(defaulValue, "defaulValue");
     return(new SqlSetDefault(defaulValue, column));
 }
コード例 #26
0
 public static SqlCreateCollation Create(Collation collation)
 {
     ArgumentValidator.EnsureArgumentNotNull(collation, "collation");
     return(new SqlCreateCollation(collation));
 }
コード例 #27
0
 public static SqlCreatePartitionScheme Create(PartitionSchema partitionSchema)
 {
     ArgumentValidator.EnsureArgumentNotNull(partitionSchema, "partitionSchema");
     return(new SqlCreatePartitionScheme(partitionSchema));
 }
コード例 #28
0
 public static SqlAlterSequence Alter(Sequence sequence, SequenceDescriptor descriptor)
 {
     ArgumentValidator.EnsureArgumentNotNull(sequence, "sequence");
     ArgumentValidator.EnsureArgumentNotNull(descriptor, "info");
     return(new SqlAlterSequence(sequence, descriptor, SqlAlterIdentityInfoOptions.All));
 }
コード例 #29
0
 public static SqlCreateSequence Create(Sequence sequence)
 {
     ArgumentValidator.EnsureArgumentNotNull(sequence, "sequence");
     return(new SqlCreateSequence(sequence));
 }
コード例 #30
0
 /// <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;
 }