Пример #1
0
        private bool ProcessLeftMouseDown(TreeNode node)
        {
            var          predicate = null;
            var          func2     = null;
            RelationNode rNode     = node as RelationNode;

            if (rNode != null)
            {
                TreeNode parent = rNode.Parent.Parent;
                if (!(parent is DynamicSchemaNode))
                {
                    parent = parent.Parent;
                }
                if (predicate == null)
                {
                    predicate = < > h__TransparentIdentifier50 => (< > h__TransparentIdentifier50.relationNode != rNode) && (< > h__TransparentIdentifier50.relationNode.Relation == rNode.Relation);
                }
                TreeNode node3 = (from <> h__TransparentIdentifier50 in (from tableNode in parent.Nodes.Cast <TreeNode>()
                                                                         from relationNode in tableNode.Nodes.OfType <RelationNode>()
                                                                         select new { tableNode = tableNode, relationNode = relationNode }).Where(predicate) select <> h__TransparentIdentifier50.tableNode).FirstOrDefault <TreeNode>();
                if (node3 == null)
                {
                    if (func2 == null)
                    {
                        func2 = < > h__TransparentIdentifier52 => (< > h__TransparentIdentifier52.relationNode != rNode) && (< > h__TransparentIdentifier52.relationNode.Relation == rNode.Relation);
                    }
                    node3 = (from <> h__TransparentIdentifier52 in (from schemaNode in parent.Nodes.Cast <TreeNode>()
                                                                    from tableNode in schemaNode.Nodes.Cast <TreeNode>()
                                                                    from relationNode in tableNode.Nodes.OfType <RelationNode>()
                                                                    select new { < > h__TransparentIdentifier51 = < > h__TransparentIdentifier51, relationNode = relationNode }).Where(func2) select <> h__TransparentIdentifier52.< > h__TransparentIdentifier51.tableNode).FirstOrDefault <TreeNode>();
Пример #2
0
        private IEnumerator LoadBundle(RelationNode node, LayerLoadParam param)
        {
            if (node.Nodes.Count() > 0)
            {
                LayerLoadParam layerParam = new LayerLoadParam();
                layerParam.layer = param.layer + 1;
                layerParam.num   = 0;

                for (int i = 0, count = node.Nodes.Count; i < count; i++)
                {
                    CoroutineHelper.CreateCoroutineHelper(LoadBundle(node.Nodes[i], layerParam));
                }

                while (layerParam.num >= 0 && layerParam.num < node.Nodes.Count)
                {
                    yield return(null);
                }

                if (layerParam.num < 0)
                {
                    UnLoad();
                    param.num = -100000;
                    yield break;
                }
            }

            ResLoader.LoadByName(node.File, EndLoadBundle, new LoadInfo()
            {
                name = node.File, param = param
            }, true);
        }
Пример #3
0
        public void TestRemoveBidirectionalRelation()
        {
            TableNode  tn;
            ColumnNode cn;

            // Returns the Orders table node
            PrepareEmployeeOrder(out tn, out cn);

            Assertion.Assert(!cn.Column.IsMapped);
            Assertion.Assert(!cn.Column.IsMapped);

            NDOTreeNode treeNode = (NDOTreeNode)FindNode(tn.Nodes, "EmployeeID");

            Assertion.AssertNotNull(treeNode);
            Assertion.Assert("Wrong type #1", treeNode is RelationNode);
            RelationNode rn    = (RelationNode)treeNode;
            TableNode    relTn = rn.RelatedTableNode;

            // tn is Orders, relTn is Employees
            treeNode = (NDOTreeNode)FindNode(relTn.Nodes, "EmployeeID", typeof(RelationNode));
            Assertion.AssertNotNull(treeNode);
            RelationNode rn2 = (RelationNode)treeNode;

            Assertion.Assert(rn2.Relation is ForeignFkRelation);
            rn.DeleteFkRelation(null, EventArgs.Empty);

            treeNode = (NDOTreeNode)FindNode(tn.Nodes, "EmployeeID", typeof(RelationNode));
            Assertion.AssertNull(treeNode);
            treeNode = (NDOTreeNode)FindNode(relTn.Nodes, "EmployeeID", typeof(RelationNode));
            Assertion.AssertNull(treeNode);
        }
Пример #4
0
 public void UnmapIntermediateClass(TableNode tn)
 {
     foreach (NDOTreeNode trn in tn.Nodes)
     {
         RelationNode rn = trn as RelationNode;
         if (rn == null)
         {
             continue;
         }
         rn.Remove();
         FkRelation fkRelation = rn.Relation as FkRelation;
         if (fkRelation != null)
         {
             if (fkRelation.RelationDirection != RelationDirection.DirectedFromMe)
             {
                 TableNode    relTn        = databaseNode.FindTableNode(fkRelation.RelatedTable, true);
                 RelationNode nodeToRemove = relTn.FindRelationNode(rn.Text, tn.Text);
                 if (nodeToRemove != null)
                 {
                     nodeToRemove.Remove();
                 }
             }
         }
     }
 }
Пример #5
0
        public void TestIntermediateClassRemove2()
        {
            TableNode tn;

            PrepareOrderDetails(out tn);

            TreeNodeCollection nodes = ApplicationController.Instance.DatabaseNode.Nodes;

            TableNode tnOrders   = (TableNode)FindNode(nodes, "Orders");
            TableNode tnProducts = (TableNode)FindNode(nodes, "Products");

            tnProducts.UnmapClass(null, EventArgs.Empty);

            Assertion.Assert("Mapping type wrong #1", tn.Table.MappingType == TableMappingType.NotMapped);

            RelationNode rn = tn.FindRelationNode("OrderID", "Orders");

            Assertion.AssertNull("Relation to Orders should be removed", rn);
            rn = tn.FindRelationNode("ProductID", "Products");
            Assertion.AssertNull("Relation to Products should be removed", rn);

            rn = tnOrders.FindRelationNode("OrderID", "Order Details");
            Assertion.AssertNull("Relation should be removed", rn);
//			ApplicationController.Instance.GenerateAssembly();
        }
Пример #6
0
        public static FuncDescriptor GetDescriptor(RelationIdentity relation, MetadataIdentity source)
        {
            FuncKey key = new FuncKey(relation, source);

            return(cache.GetOrAdd(key, _ =>
            {
                ListBuilder listBuilder = new ListBuilder(relation, source);
                RelationNode relationNode = listBuilder.Build();
                FuncBuilder funcBuilder = new FuncBuilder(relationNode);

                return funcBuilder.Build();
            }));
        }
Пример #7
0
        public void TestIntermediateClass()
        {
            TableNode tn;

            PrepareOrderDetails(out tn);
            Assertion.Assert("Mapping type wrong #1", tn.Table.MappingType == TableMappingType.MappedAsIntermediateClass);
            TreeNodeCollection nodes = ApplicationController.Instance.DatabaseNode.Nodes;
            object             o     = FindNode(nodes, tn.Text);

            Assertion.AssertNotNull("Intermediate Class '" + tn.Text + "' not found", o);
            Assertion.AssertSame("Node should be the same table node", tn, o);
            RelationNode rn = tn.FindRelationNode("OrderID", "Orders");

            Assertion.AssertNotNull("Relation to Orders should be there", rn);
            Assertion.Assert("Wrong relation type", rn.Relation is FkRelation);
            rn = tn.FindRelationNode("ProductID", "Products");
            Assertion.AssertNotNull("Relation to Products should be there", rn);
            Assertion.Assert("Wrong relation type", rn.Relation is FkRelation);

            TableNode tnOrders = (TableNode)FindNode(nodes, "Orders");

            rn = tnOrders.FindRelationNode("OrderID", "Order Details");
            Assertion.AssertNotNull("OrderID relation not found", rn);
            TableNode tnProducts = (TableNode)FindNode(nodes, "Products");

//			foreach(NDOTreeNode trn in tnProducts.Nodes)
//			{
//				RelationNode rn2 = trn as RelationNode;
//				if (rn2 != null)
//				{
//					Debug.WriteLine(rn2.Text + " " + rn2.Relation.GetType().Name);
//					ForeignFkRelation fkr = rn2.Relation as ForeignFkRelation;
//					if (fkr != null)
//						Debug.WriteLine(fkr.RelatedTable);
//				}
//			}
            rn = tnProducts.FindRelationNode("ProductID", "Order Details");
            Assertion.AssertNull("Relation is directed", rn);
            tn.UnmapIntermediateClass(null, EventArgs.Empty);

            Assertion.Assert("Mapping type wrong #1", tn.Table.MappingType == TableMappingType.NotMapped);

            rn = tn.FindRelationNode("OrderID", "Orders");
            Assertion.AssertNull("Relation to Orders should be removed", rn);
            rn = tn.FindRelationNode("ProductID", "Products");
            Assertion.AssertNull("Relation to Products should be removed", rn);

            rn = tnOrders.FindRelationNode("OrderID", "Order Details");
            Assertion.AssertNull("Relation should be removed", rn);
        }
Пример #8
0
        public void AddRelSymbol(RelationNode relationNode)
        {
            if (symbols.ContainsKey(relationNode.RelationName))
            {
                throw new QueryException($"Symbol {relationNode.RelationName} already present.");
            }

            Symbol symbol = new RelationSymbol(relationNode);

            if (!symbols.ContainsKey(relationNode.RelationName))
            {
                symbols.Add(relationNode.RelationName, symbol);
            }
        }
Пример #9
0
        void RemoveRelationNodeFromTable(string tableName, string nodeName)
        {
            TableNode tn = (TableNode)databaseNode.FindNode(tableName);

            if (tn != null)
            {
                RelationNode relNode = (RelationNode)tn.FindNode(nodeName, typeof(RelationNode));
                if (relNode != null)
                {
                    relNode.Remove();
                }
                //tn.Nodes. Remove(relNode);
            }
        }
Пример #10
0
        /// <summary>
        /// Builds a normalized relation graph of the anime directly/indirectly realted to the specified anime ID.
        /// </summary>
        /// <param name="rootAnimeId">The ID of the anime we're building the graph from.</param>
        /// <param name="nodes">Returns the graph nodes (Keyed by anime ID).</param>
        /// <param name="edges">Returns the graph edges.</param>
        /// <returns><c>true</c> if a graph was built; otherwise, <c>false</c>
        /// (e.g. if the specified anime has no relations).</returns>
        private bool BuildGroupGraph(int rootAnimeId, out Dictionary <int, RelationNode> nodes,
                                     out HashSet <RelationEdge> edges)
        {
            var  toVisit = new Queue <int>();
            bool first   = true;

            edges = null;
            nodes = null;

            toVisit.Enqueue(rootAnimeId);

            // Traverse the relation graph to build node and edge sets
            while (toVisit.Count > 0)
            {
                int animeId = toVisit.Dequeue();

                foreach (AnimeRelation relation in _relationMap[animeId].Where(ShouldConsiderAnimeRelation))
                {
                    // For the very first relationship we encounter we need to add a relation node for
                    // the anime it is from (i.e. the "anchor" anime we're using as our starting point for graph traversal)
                    if (first)
                    {
                        var startNode = new RelationNode(relation.FromId, relation.FromType, relation.FromAirDate);

                        edges = new HashSet <RelationEdge>();
                        nodes = new Dictionary <int, RelationNode>
                        {
                            [relation.FromId] = startNode
                        };
                        first = false;
                    }

                    var relEdge = new RelationEdge(relation.RelationType, relation.FromId, relation.ToId);

                    edges.Add(relEdge);

                    if (nodes.ContainsKey(relation.ToId))
                    {
                        continue; // We've already visited this anime
                    }

                    var node = new RelationNode(relation.ToId, relation.ToType, relation.ToAirDate);
                    nodes.Add(node.AnimeId, node);
                    toVisit.Enqueue(node.AnimeId);
                }
            }

            return(nodes != null);
        }
Пример #11
0
 public RelationNode FindRelationNode(string text, string relatedTableName)
 {
     foreach (NDOTreeNode tn in Nodes)
     {
         RelationNode rn = tn as RelationNode;
         if (rn == null)
         {
             continue;
         }
         if (rn.Text == text && rn.RelatedTableNode.Text == relatedTableName)
         {
             return(rn);
         }
     }
     return(null);
 }
Пример #12
0
        public void DeleteRelation(RelationNode relationNode)
        {
            FkRelation fkRelation = relationNode.Relation as FkRelation;
            TableNode  parentNode = null;

            if (fkRelation == null)
            {
                ForeignFkRelation ffkrel = relationNode.Relation as ForeignFkRelation;
                if (ffkrel == null)
                {
                    return;
                }
                parentNode   = (TableNode)this.databaseNode.FindNode(ffkrel.RelatedTable, typeof(TableNode));
                relationNode = parentNode.FindRelationNode(relationNode.Text, relationNode.Parent.Text);                //(RelationNode) parentNode.FindNode(relationNode.Text, typeof(RelationNode));
                fkRelation   = (FkRelation)relationNode.Relation;
                if (parentNode.Table.MappingType == TableMappingType.MappedAsIntermediateClass)
                {
                    parentNode.UnmapIntermediateClass(null, EventArgs.Empty);
                    return;
                }
            }
            else
            {
                parentNode = (TableNode)relationNode.Parent;
            }

            //parentNode.Nodes. Remove(relationNode);
            relationNode.Remove();
            parentNode.Nodes.Add(relationNode.OriginalColumnNode);

            Debug.Assert(fkRelation != null);
            if (fkRelation != null)
            {
                if (fkRelation.RelationDirection != RelationDirection.DirectedFromMe)
                {
                    TableNode    tn           = databaseNode.FindTableNode(fkRelation.RelatedTable, true);
                    RelationNode nodeToRemove = tn.FindRelationNode(relationNode.Text, parentNode.Text);
                    if (nodeToRemove != null)
                    {
                        nodeToRemove.Remove();
                    }
                }
            }
        }
Пример #13
0
        public void MakeForeignKey(ColumnNode columnNode, ForeignKeyWizModel model)
        {
            FkRelation   fkRelation   = null;
            RelationNode relationNode = null;

            if (model == null)
            {
                fkRelation   = new FkRelation(columnNode.Name);
                relationNode = new RelationNode(fkRelation, columnNode.Parent);
            }
            else
            {
                fkRelation   = (FkRelation)model.RelationNode.Relation;
                relationNode = model.RelationNode;
            }
            fkRelation.OwningTable = ((TableNode)relationNode.Parent).Table.Name;
            fkRelation.OwningType  = ((TableNode)relationNode.Parent).Table.ClassName;
            IList tableNodes = new ArrayList();

            if (model == null)
            {
                foreach (TableNode tnode in ((DatabaseNode)columnNode.Parent.Parent).TableNodes)
                {
                    if (tnode.Table.MappingType == TableMappingType.MappedAsClass)
                    {
                        tableNodes.Add(tnode);
                    }
                }
                model = new ForeignKeyWizModel(relationNode, tableNodes);
                IWizardController controller = ApplicationController.wizardControllerFactory.Create
                                                   ("ForeignKeyWizController", "ForeignKeyWiz", "Foreign Key Wizard");
                //controller.FrameSize = new Size( 544, 408 );
                DialogResult r = controller.Run(model);
                if (r == DialogResult.OK)
                {
                    MakeForeignKeyRelation(relationNode, columnNode, model);
                }
            }
            else
            {
                MakeForeignKeyRelation(relationNode, columnNode, model);
            }
        }
Пример #14
0
        public void TestIntermediateTable()
        {
            TableNode tn;

            PrepareEmployeeTerritories(out tn);

            DatabaseNode dbn = (DatabaseNode)tn.Parent;

            IntermediateTableNode itn = (IntermediateTableNode)FindNode(dbn.Nodes, "EmployeeTerritories", typeof(IntermediateTableNode));

            Assertion.AssertNotNull("IntermediateTableNode not found", itn);
            Assertion.AssertEquals("Wrong original table", tn, itn.OriginalTableNode);
            Assertion.AssertEquals("Wrong image", itn.SelectedImageIndex, 13);

            tn = (TableNode)FindNode(dbn.Nodes, "Employees");
            RelationNode rn = (RelationNode)FindNode(tn.Nodes, "EmployeeID", typeof(RelationNode));

            Assertion.AssertNotNull("Relation node should exist #1", rn);

            tn = (TableNode)FindNode(dbn.Nodes, "Territories");
            rn = (RelationNode)FindNode(tn.Nodes, "TerritoryID", typeof(RelationNode));
            Assertion.AssertNotNull("Relation node should exist #2", rn);

            // Now unmap and test
            itn.UnmapIntermediateTable(null, EventArgs.Empty);

            itn = (IntermediateTableNode)FindNode(dbn.Nodes, "EmployeeTerritories", typeof(IntermediateTableNode));
            Assertion.AssertNull("itn should be null", itn);
            tn = (TableNode)FindNode(dbn.Nodes, "EmployeeTerritories", typeof(TableNode));
            Assertion.AssertNotNull("Table node should be back", tn);

            tn = (TableNode)FindNode(dbn.Nodes, "Employees");
            rn = (RelationNode)FindNode(tn.Nodes, "EmployeeID", typeof(RelationNode));
            Assertion.AssertNull("Relation node shouldn't be there", rn);

            tn = (TableNode)FindNode(dbn.Nodes, "Territories");
            rn = (RelationNode)FindNode(tn.Nodes, "TerritoryID", typeof(RelationNode));
            Assertion.AssertNull("Relation node shouldn't be there #2", rn);
        }
Пример #15
0
        private void MakeForeignKeyRelation(RelationNode relationNode, ColumnNode columnNode, ForeignKeyWizModel model)
        {
            FkRelation fkRelation = (FkRelation)relationNode.Relation;

            fkRelation.RelatedTable = relationNode.RelatedTableNode.Table.Name;
            fkRelation.RelatedType  = relationNode.RelatedTableNode.Table.ClassName;
            TableNode tn = (TableNode)columnNode.Parent;

            //tn.Nodes. Remove(columnNode);
            columnNode.Remove();
            tn.Nodes.Add(relationNode);
            relationNode.OriginalColumnNode = columnNode;
            this.assemblyNode.Refresh();
            if (fkRelation.RelationDirection == RelationDirection.DirectedToMe ||
                fkRelation.RelationDirection == RelationDirection.Bidirectional)
            {
                tn = databaseNode.FindTableNode(fkRelation.RelatedTable, true);
                RelationNode rn = new RelationNode(fkRelation.ForeignRelation, tn);
                rn.RelatedTableNode = (TableNode)columnNode.Parent;
                tn.Nodes.Add(rn);
            }
        }
Пример #16
0
        public void MapIntermediateTable(TableNode tn)
        {
            IntermediateTable     it  = new IntermediateTable(tn.Text);
            IntermediateTableNode itn = new IntermediateTableNode(it, tn);

            IList tableNodes = databaseNode.TableNodes;

            tableNodes.Remove(tn);

            IntermediateTableWizardModel model = new IntermediateTableWizardModel(itn, tableNodes);

            IWizardController controller = ApplicationController.wizardControllerFactory.Create
                                               ("IntermediateTableWizController", "IntTblWiz", "Intermediate Table Wizard");
            //controller.FrameSize = new Size(544, 416);
            DialogResult r = controller.Run(model);

            if (r == DialogResult.OK)
            {
                DatabaseNode parent = (DatabaseNode)tn.Parent;
                //tn.Parent.Nodes. Remove(tn);
                int index = parent.Nodes.IndexOf(tn);
                tn.Remove();
                tn.Parent.Nodes.Insert(index, itn);
                itn.TreeView.SelectedNode = itn;
                itn.Nodes.Add(tn);                  // This ensures persisting the column nodes with file/save.
                RelatedTableInfo rti0     = it[0];
                RelatedTableInfo rti1     = it[1];
                TableNode        relTn0   = null;
                TableNode        relTn1   = null;
                RelationNode     relNode0 = null;
                RelationNode     relNode1 = null;
                foreach (TableNode loopTn in tableNodes)
                {
                    if (loopTn.Text == rti0.Table)
                    {
                        relTn0 = loopTn;
                        if (rti0.RelationDirection != RelationDirection.DirectedToMe)
                        {
                            ForeignIntermediateTableRelation fitr = new ForeignIntermediateTableRelation(rti0, tn.Text);
                            relNode0 = new RelationNode(fitr, relTn0);
                            relTn0.Nodes.Add(relNode0);
                        }
                    }
                    if (loopTn.Text == rti1.Table)
                    {
                        relTn1 = loopTn;
                        if (rti1.RelationDirection != RelationDirection.DirectedToMe)
                        {
                            ForeignIntermediateTableRelation fitr = new ForeignIntermediateTableRelation(rti1, tn.Text);
                            relNode1 = new RelationNode(fitr, relTn1);
                            relTn1.Nodes.Add(relNode1);
                        }
                    }
                }
                if (relNode0 != null)
                {
                    relNode0.RelatedTableNode = relTn1;
                }
                if (relNode1 != null)
                {
                    relNode1.RelatedTableNode = relTn0;
                }
            }
        }
 /// <summary>
 /// Initializes static members of the <see cref="RelationBuilder"/> class.
 /// </summary>
 static RelationBuilder()
 {
     _dataflowToDsd = new RelationNode(RelationType.Descendant, SdmxStructureEnumType.Dataflow, SdmxStructureEnumType.Dsd);
     _categorisationToDataflow = new RelationNode(RelationType.Descendant, SdmxStructureEnumType.Categorisation, SdmxStructureEnumType.Dataflow);
     _categorySchemeToCategorisation = new RelationNode(RelationType.Parent, SdmxStructureEnumType.CategoryScheme, SdmxStructureEnumType.Categorisation);
     _dataflowToCategorisation = new RelationNode(RelationType.Parent, SdmxStructureEnumType.Dataflow, SdmxStructureEnumType.Categorisation);
     _dsdToDataflow = new RelationNode(RelationType.Parent, SdmxStructureEnumType.Dsd, SdmxStructureEnumType.Dataflow);
     _codeListToDsd = new RelationNode(RelationType.Parent, SdmxStructureEnumType.CodeList, SdmxStructureEnumType.Dsd);
     _conceptSchemeToDsd = new RelationNode(RelationType.Parent, SdmxStructureEnumType.ConceptScheme, SdmxStructureEnumType.Dsd);
 }
Пример #18
0
 public FuncBuilder(RelationNode relationNode)
 {
     this.relationNode = relationNode;
     this.args         = new FuncArguments(relationNode.Items.Count);
 }
Пример #19
0
 public PropertyGenerator(RelationNode rn)
 {
     this.relationNode = rn;
     this.relation     = rn.Relation;
 }
Пример #20
0
        public void RelationNodeTest_TypeCoercion()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);
            Expression operandA = Expression.Constant(43L);
            Expression operandB = Expression.Constant(3.4D);

            RelationNode sut = new RelationNode(RelationNode.Operator.EQ,
                                                new SimpleValueTestNode(operandA, FieldValueType.INTEGER),
                                                new SimpleValueTestNode(operandB, FieldValueType.FLOAT),
                                                expectedLocation);

            Assert.AreEqual(TNode.RELATION, sut.NodeType);
            Assert.AreEqual(expectedLocation, sut.Location);
            Assert.IsTrue(sut.Description.Contains("RELATION"));
            Assert.IsInstanceOfType(sut.SubExpression, typeof(BinaryExpression));
            Assert.AreEqual(ExpressionType.Equal, sut.SubExpression.NodeType);
            Assert.AreEqual(typeof(bool), sut.SubExpression.Type);
            Assert.IsInstanceOfType(((BinaryExpression)sut.SubExpression).Left, typeof(UnaryExpression));
            UnaryExpression cast = (UnaryExpression)((BinaryExpression)sut.SubExpression).Left;
            Assert.AreEqual(ExpressionType.Convert, cast.NodeType);
            Assert.AreEqual(operandA, cast.Operand);
            Assert.AreEqual(operandB, ((BinaryExpression)sut.SubExpression).Right);
        }
Пример #21
0
 public RelationSymbol GetRelationSymbol(RelationNode node)
 {
     return((RelationSymbol)symbols[node.RelationName]);
 }
Пример #22
0
        public void RelationNodeTest_TypeMismatch()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);
            Expression operandA = Expression.Constant(43L);
            Expression operandB = Expression.Constant("34");

            RelationNode sut = new RelationNode(RelationNode.Operator.EQ,
                                                new SimpleValueTestNode(operandA, FieldValueType.INTEGER),
                                                new SimpleValueTestNode(operandB, FieldValueType.TEXT),
                                                expectedLocation);
        }
Пример #23
0
        public bool MapIntermediateClass(TableNode tn)
        {
//			IntermediateClass ic = new IntermediateClass();
//			IntermediateClassNode icn = new IntermediateClassNode(ic, tn);

            IList tableNodes = new ArrayList();

            foreach (TableNode tnode in databaseNode.TableNodes)
            {
                if (tn.Text == tnode.Text)
                {
                    continue;
                }
                if (tnode.Table.MappingType == TableMappingType.MappedAsClass)
                {
                    tableNodes.Add(tnode);
                }
            }

            IntermediateClassWizardModel model = new IntermediateClassWizardModel(tn, tableNodes);

            IWizardController controller = ApplicationController.wizardControllerFactory.Create
                                               ("IntermediateClassWizController", "IntClassWiz", "Intermediate Class Wizard");

            //controller.FrameSize = new Size(544, 500);
            model[0].RelationDirection = RelationDirection.Bidirectional;
            model[1].RelationDirection = RelationDirection.Bidirectional;
            DialogResult r = controller.Run(model);

            if (r == DialogResult.OK)
            {
                DatabaseNode parent = (DatabaseNode)tn.Parent;
                // Nothing to remove, because we use the original table node
                //				tn.Remove();
                //				tn.Parent.Nodes.Add(icn);
                for (int i = 0; i < 2; i++)
                {
                    ColumnNode            columnNode   = (ColumnNode)tn.FindNode(model[i].ForeignKeyColumnName, typeof(ColumnNode));
                    FkRelation            fkr          = new FkRelation(columnNode.Text);
                    IntermediateClassInfo intermClInfo = model[i];
                    fkr.FieldName          = intermClInfo.OwnFieldName;
                    fkr.ForeignCodingStyle = intermClInfo.CodingStyle;
                    fkr.ForeignFieldName   = intermClInfo.ForeignFieldName;
                    fkr.ForeignIsComposite = false;
                    fkr.IsComposite        = false;
                    fkr.OwningTable        = tn.Text;
                    fkr.OwningType         = tn.Table.ClassName;
                    fkr.RelatedTable       = intermClInfo.Table;
                    fkr.RelatedType        = intermClInfo.Type;
                    fkr.RelationDirection  = intermClInfo.RelationDirection;
                    fkr.RelationName       = string.Empty;
                    //ForeignFkRelation ffkr = fkr.ForeignRelation;
                    RelationNode relationNode = new RelationNode(fkr, tn);
                    relationNode.RelatedTableNode = (TableNode)databaseNode.FindNode(intermClInfo.Table);
                    ForeignKeyWizModel fkwizModel = new ForeignKeyWizModel(relationNode, new ArrayList());

                    tn.DualKeyRelations[i] = intermClInfo.OwnFieldName;

                    MakeForeignKeyRelation(relationNode, columnNode, fkwizModel);
                }
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Returns the method that retrieves the 
        /// </summary>
        /// <param name="crossReferenceManager">
        /// The cross reference manager.
        /// </param>
        /// <param name="returnStub">
        /// The return stub.
        /// </param>
        /// <param name="allowedDataflows">
        /// The allowed dataflows.
        /// </param>
        /// <param name="relationNode">
        /// The relation node.
        /// </param>
        /// <returns>
        /// The function that returns 
        /// </returns>
        private static Func<IMaintainableMutableObject, IList<IMaintainableMutableObject>> GetFunc(
            IAuthCrossReferenceMutableRetrievalManager crossReferenceManager, 
            bool returnStub, 
            IList<IMaintainableRefObject> allowedDataflows, 
            RelationNode relationNode)
        {
            Func<IMaintainableMutableObject, IList<IMaintainableMutableObject>> func = x => new IMaintainableMutableObject[0];
            var destinationType = SdmxStructureType.GetFromEnum(relationNode.DestType);
            switch (relationNode.RelationType)
            {
                case RelationType.Parent:
                    func = x => crossReferenceManager.GetCrossReferencingStructures(x, returnStub, allowedDataflows, destinationType);
                    break;
                case RelationType.Descendant:
                    func = x => crossReferenceManager.GetCrossReferencedStructures(x, returnStub, allowedDataflows, destinationType);
                    break;
            }

            return func;
        }
Пример #25
0
        public void RelationNodeTest_NE()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);
            Expression operandA = Expression.Constant(43L);
            Expression operandB = Expression.Constant(34L);

            RelationNode sut = new RelationNode(RelationNode.Operator.NE,
                                                new SimpleValueTestNode(operandA, FieldValueType.INTEGER),
                                                new SimpleValueTestNode(operandB, FieldValueType.INTEGER),
                                                expectedLocation);

            Assert.AreEqual(TNode.RELATION, sut.NodeType);
            Assert.AreEqual(expectedLocation, sut.Location);
            Assert.IsTrue(sut.Description.Contains("RELATION"));
            Assert.IsInstanceOfType(sut.SubExpression, typeof(BinaryExpression));
            Assert.AreEqual(ExpressionType.NotEqual, sut.SubExpression.NodeType);
            Assert.AreEqual(typeof(bool), sut.SubExpression.Type);
            Assert.AreEqual(operandA, ((BinaryExpression)sut.SubExpression).Left);
            Assert.AreEqual(operandB, ((BinaryExpression)sut.SubExpression).Right);
        }
        /// <summary>
        /// Processes the node.
        /// </summary>
        /// <param name="crossReferenceManager">The cross reference manager.</param>
        /// <param name="maintainable">The maintainable.</param>
        /// <param name="specificStructureType">Type of the specific structure.</param>
        /// <param name="returnStub">if set to <c>true</c> [return stub].</param>
        /// <param name="allowedDataflows">The allowed dataflows.</param>
        /// <param name="rootNode">The root node.</param>
        /// <param name="specificObjects">The specific objects.</param>
        /// <param name="stack">The stack.</param>
        private static void ProcessNode(
            IAuthCrossReferenceMutableRetrievalManager crossReferenceManager, 
            IMaintainableMutableObject maintainable, 
            BaseConstantType<SdmxStructureEnumType> specificStructureType, 
            bool returnStub, 
            IList<IMaintainableRefObject> allowedDataflows, 
            RelationNode rootNode, 
            ICollection<IMaintainableMutableObject> specificObjects, 
            Stack<IMaintainableMutableObject> stack)
        {
            var isTarget = rootNode.DestType == specificStructureType.EnumType;
            bool getStub;
            Action<IMaintainableMutableObject> action;
            if (isTarget)
            {
                getStub = returnStub;
                action = specificObjects.Add;
            }
            else
            {
                getStub = rootNode.DestType != SdmxStructureEnumType.Categorisation;
                action = stack.Push;
            }

            var rootFunc = GetFunc(crossReferenceManager, getStub, allowedDataflows, rootNode);
            
            foreach (var maintainableMutableObject in rootFunc(maintainable))
            {
                action(maintainableMutableObject);
            }
        }
Пример #27
0
 public ForeignKeyWizModel(RelationNode relationNode, IList tableNodes)
 {
     this.relationNode = relationNode;
     this.tableNodes   = tableNodes;
 }
Пример #28
0
        public void RelationNodeTest_IN_Range_Inclusive()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);
            Expression operandA = Expression.Constant(43L, typeof(long?));
            SimpleValueNode rangeLow = new NumberNode("34", new StreamLocation());
            SimpleValueNode rangeHigh = new NumberNode("68", new StreamLocation());

            RelationNode sut = new RelationNode(RelationNode.Operator.IN,
                                                new SimpleValueTestNode(operandA, FieldValueType.INTEGER),
                                                new RangeNode(rangeLow, true, rangeHigh, true, new StreamLocation()),
                                                expectedLocation);

            Assert.AreEqual(TNode.RELATION, sut.NodeType);
            Assert.AreEqual(expectedLocation, sut.Location);
            Assert.IsTrue(sut.Description.Contains("RELATION"));
            Assert.IsInstanceOfType(sut.SubExpression, typeof(BinaryExpression));
            Assert.AreEqual(ExpressionType.And, sut.SubExpression.NodeType);
            Assert.AreEqual(typeof(bool), sut.SubExpression.Type);
            {
                Expression left = ((BinaryExpression)sut.SubExpression).Left;
                Assert.IsInstanceOfType(left, typeof(BinaryExpression));
                Assert.AreEqual(ExpressionType.GreaterThanOrEqual, left.NodeType);
                Assert.AreEqual(operandA, ((BinaryExpression)left).Left);
                Assert.AreEqual(rangeLow.SubExpression, ((BinaryExpression)left).Right);
            }
            {
                Expression right = ((BinaryExpression)sut.SubExpression).Right;
                Assert.IsInstanceOfType(right, typeof(BinaryExpression));
                Assert.AreEqual(ExpressionType.LessThanOrEqual, right.NodeType);
                Assert.AreEqual(operandA, ((BinaryExpression)right).Left);
                Assert.AreEqual(rangeHigh.SubExpression, ((BinaryExpression)right).Right);
            }
        }
Пример #29
0
 public RelationGenerator(RelationNode relationNode, NamespaceWrapper namespaceWrapper)
 {
     this.relationNode     = relationNode;
     this.namespaceWrapper = namespaceWrapper;
 }
Пример #30
0
        public void MakeForeignKey(DataRelation dataRelation)
        {
            // The FkRelation is owned by the child table, because it holds
            // the foreign key.
            // Therefore the XPath has to be stored in the ForeignFkRelation.
            string xpath = (string)dataRelation.ExtendedProperties["xpath"];

            TableNode          ownTableNode     = this.databaseNode[dataRelation.ChildTable.TableName];
            TableNode          foreignTableNode = this.databaseNode[dataRelation.ParentTable.TableName];
            ColumnNode         cn           = ownTableNode[dataRelation.ChildColumns[0].ColumnName];
            FkRelation         fkRelation   = new FkRelation(cn.Text);
            RelationNode       relationNode = new RelationNode(fkRelation, cn.Parent);
            ForeignKeyWizModel model        = new ForeignKeyWizModel(relationNode, null);

            fkRelation.CodingStyle        = CodingStyle.ArrayList;
            fkRelation.FieldName          = MakeCamelCase(foreignTableNode.Text);
            fkRelation.RelationDirection  = RelationDirection.DirectedToMe;// Bidirectional;
            relationNode.RelatedTableNode = foreignTableNode;
            fkRelation.RelatedTable       = dataRelation.ParentTable.TableName;
            fkRelation.RelatedType        = relationNode.RelatedTableNode.Table.ClassName;
            fkRelation.IsComposite        = false;

            string singularFieldName = null;

            if (xpath != null)
            {
                singularFieldName = MakePascalCase(xpath.Substring(xpath.LastIndexOf('/') + 1));
            }
            else
            {
                singularFieldName = MakePascalCase(ownTableNode.Text);
            }

            singularFieldName = singularFieldName.Substring(singularFieldName.IndexOf(':') + 1);

            string foreignFieldName = MakeCamelCase(singularFieldName);

            if (foreignFieldName.EndsWith("y"))
            {
                char c = char.ToLower(foreignFieldName[foreignFieldName.Length - 2]);
                if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
                {
                    foreignFieldName += "s";
                }
                else
                {
                    foreignFieldName = foreignFieldName.Substring(0, foreignFieldName.Length - 1) + "ies";
                }
            }
            else if (foreignFieldName.EndsWith("s"))
            {
                foreignFieldName += "es";
            }
            else if (foreignFieldName.EndsWith("f"))
            {
                foreignFieldName = foreignFieldName.Substring(0, foreignFieldName.Length - 1) + "ves";
            }
            else
            {
                foreignFieldName += "s";
            }
            fkRelation.ForeignFieldName = foreignFieldName;

            fkRelation.ForeignIsComposite = true;
            fkRelation.ForeignCodingStyle = CodingStyle.ArrayList;
            fkRelation.RelationName       = string.Empty;
            MakeForeignKey(cn, model);
            fkRelation.ForeignRelation.SingularFieldName = MakePascalCase(singularFieldName);
            fkRelation.ForeignRelation.XPath             = xpath;
        }
Пример #31
0
        public void RelationNodeTest_IN_Set()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);
            Expression operandA = Expression.Constant(43L, typeof(long?));
            List<ConstantExpression> testExprs = new List<ConstantExpression>() { Expression.Constant(34L, typeof(long?)),
                                                                                  Expression.Constant(64L, typeof(long?)) };
            ISet<SimpleValueNode> testSet = new HashSet<SimpleValueNode>();
            foreach (ConstantExpression expr in testExprs)
            {
                testSet.Add(new SimpleValueTestNode(expr, FieldValueType.INTEGER));
            }

            RelationNode sut = new RelationNode(RelationNode.Operator.IN,
                                                new SimpleValueTestNode(operandA, FieldValueType.INTEGER),
                                                new SetNode(testSet, new StreamLocation()),
                                                expectedLocation);

            Assert.AreEqual(TNode.RELATION, sut.NodeType);
            Assert.AreEqual(expectedLocation, sut.Location);
            Assert.IsTrue(sut.Description.Contains("RELATION"));
            Assert.IsInstanceOfType(sut.SubExpression, typeof(BinaryExpression));
            Assert.AreEqual(ExpressionType.Or, sut.SubExpression.NodeType);
            Assert.AreEqual(typeof(bool), sut.SubExpression.Type);
            List<ConstantExpression> resultExprs = new List<ConstantExpression>();
            {
                Expression left = ((BinaryExpression)sut.SubExpression).Left;
                Assert.IsInstanceOfType(left, typeof(BinaryExpression));
                Assert.AreEqual(ExpressionType.Or, sut.SubExpression.NodeType);
                Assert.AreEqual(typeof(bool), sut.SubExpression.Type);
                {
                    Expression leftLeft = ((BinaryExpression)left).Left;
                    Assert.IsInstanceOfType(leftLeft, typeof(ConstantExpression));
                    Assert.AreEqual(ExpressionType.Constant, leftLeft.NodeType);
                    Assert.AreEqual(typeof(bool), leftLeft.Type);
                    Assert.AreEqual(false, ((ConstantExpression)leftLeft).Value);
                }
                {
                    Expression leftRight = ((BinaryExpression)left).Right;
                    Assert.IsInstanceOfType(leftRight, typeof(BinaryExpression));
                    Assert.AreEqual(ExpressionType.Equal, leftRight.NodeType);
                    Assert.AreEqual(operandA, ((BinaryExpression)leftRight).Left);
                    resultExprs.Add((ConstantExpression)((BinaryExpression)leftRight).Right);
                }
            }
            {
                Expression right = ((BinaryExpression)sut.SubExpression).Right;
                Assert.IsInstanceOfType(right, typeof(BinaryExpression));
                Assert.AreEqual(ExpressionType.Equal, right.NodeType);
                Assert.AreEqual(operandA, ((BinaryExpression)right).Left);
                resultExprs.Add((ConstantExpression)((BinaryExpression)right).Right);
            }
            CollectionAssert.AreEquivalent(testExprs, resultExprs);
        }
Пример #32
0
 // Constructor
 public TargetNode(RelationNode parent, bool isEnabled, BplClass targetClass) {
    Class = targetClass;
    IsEnabled = isEnabled;
    Name = targetClass.Name;
    Parent = parent;
 }
Пример #33
0
        public void RelationNodeTest_IN_EmptySet()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);
            Expression operandA = Expression.Constant(43L, typeof(long?));
            List<ConstantExpression> testExprs = new List<ConstantExpression>();
            ISet<SimpleValueNode> testSet = new HashSet<SimpleValueNode>();
            foreach (ConstantExpression expr in testExprs)
            {
                testSet.Add(new SimpleValueTestNode(expr, FieldValueType.INTEGER));
            }

            RelationNode sut = new RelationNode(RelationNode.Operator.IN,
                                                new SimpleValueTestNode(operandA, FieldValueType.INTEGER),
                                                new SetNode(testSet, new StreamLocation()),
                                                expectedLocation);

            Assert.AreEqual(TNode.RELATION, sut.NodeType);
            Assert.AreEqual(expectedLocation, sut.Location);
            Assert.IsTrue(sut.Description.Contains("RELATION"));
            Assert.IsInstanceOfType(sut.SubExpression, typeof(ConstantExpression));
            Assert.AreEqual(ExpressionType.Constant, sut.SubExpression.NodeType);
            Assert.AreEqual(typeof(bool), sut.SubExpression.Type);
            Assert.AreEqual(false, ((ConstantExpression)sut.SubExpression).Value);
        }