public List <ObjectReference> this[IDaxObject key]
 {
     get
     {
         return(InternalDictionary[key]);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Changes all references to object "obj", to reflect "newName"
 /// </summary>
 /// <param name="obj"></param>
 public static void DoFixup(IDaxObject obj)
 {
     foreach (var d in obj.ReferencedBy.ToList())
     {
         d.DependsOn.UpdateRef(obj);
     }
 }
Beispiel #3
0
 static public void AddDep(this IDaxDependantObject target, IDaxObject dependsOn, DAXProperty property, int fromChar, int toChar, bool fullyQualified)
 {
     target.DependsOn.Add(dependsOn, property, fromChar, toChar, fullyQualified);
     if (!dependsOn.ReferencedBy.Contains(target))
     {
         dependsOn.ReferencedBy.Add(target);
     }
 }
Beispiel #4
0
        private void InverseRecursiveAdd(IDaxObject obj, TreeNodeCollection nodes)
        {
            var img = UI.Tree.TabularIcon.GetIconIndex(obj);
            var n   = new TreeNode((obj as IDaxObject)?.DaxObjectFullName ?? obj.Name, img, img)
            {
                Tag = obj
            };

            if (obj is IExpressionObject)
            {
                n.ToolTipText = (obj as IExpressionObject).Expression;
            }

            nodes.Add(n);

            foreach (var d in obj.ReferencedBy.OrderBy(o => o.ObjectType))
            {
                if (d.DependsOn.ContainsKey(obj))
                {
                    var i = UI.Tree.TabularIcon.GetIconIndex(d);

                    currentDepth++;
                    if (d == _rootObject)
                    {
                        n.Nodes.Add(new TreeNode(d.GetName() + " (circular dependency)", i, i));
                    }
                    else if (currentDepth < MAX_LEVELS && d is IDaxObject)
                    {
                        InverseRecursiveAdd(d as IDaxObject, n.Nodes);
                    }
                    else if (currentDepth < MAX_LEVELS && d is TablePermission tp)
                    {
                        var newNode = new TreeNode(tp.Role.Name + " RLS on " + tp.Table.DaxObjectFullName, i, i);
                        newNode.Tag = tp;
                        n.Nodes.Add(newNode);
                    }
                    else if (currentDepth < MAX_LEVELS && d is CalculationItem ci)
                    {
                        var newNode = new TreeNode(d.GetName(), i, i);
                        newNode.Tag = ci;
                        n.Nodes.Add(newNode);
                    }
                    else
                    {
                        n.Nodes.Add("(Infinite recursion)");
                    }
                    currentDepth--;
                }
            }
            if (obj is Column c)
            {
                // Include columns that use the current object as a Sort-by column:
                foreach (var col in c.UsedInSortBy)
                {
                    InverseRecursiveAdd(col, n.Nodes);
                }
            }
        }
Beispiel #5
0
        public void RelationshipTest()
        {
            var builder = new TOMBuilder("dsstest.json");
            var model   = builder.Model;

            Assert.IsTrue(model.AllMeasures.Count() > 5);

            // get from and to tables from relationships
            var rels       = model.Relationships;
            var fromTables = rels.Select(r => r.FromTable).Distinct().ToList();
            var toTables   = rels.Select(r => r.ToTable).Distinct().ToList();

            // get tables from measure
            var pd2      = model.AllMeasures.Where(m => m.Name == "PD2").FirstOrDefault();
            var pd2table = pd2.Table;

            Assert.AreEqual("Test_Vint", pd2table.Name);
            var pd2ReferencedByList = pd2.ReferencedBy;
            var isSimpleMeasure     = pd2.IsSimpleMeasure;

            Assert.IsFalse(isSimpleMeasure);
            var dependsOn = pd2.DependsOn;

            Assert.AreEqual(2, dependsOn.Count);
            Assert.AreEqual(0, dependsOn.Columns.Count());
            var dependsOnKeys = dependsOn.Keys;

            Assert.AreEqual(2, dependsOnKeys.Count());
            var keyNames = dependsOnKeys.Select(k => k.DaxObjectName).ToList();

            Assert.AreEqual(2, keyNames.Count);
            // key1
            IDaxObject k1 = dependsOnKeys.Where(k => k.DaxObjectName == keyNames[0]).First();

            Assert.IsTrue(k1 is Measure);
            var m1 = k1 as Measure;

            Assert.IsNotNull(m1);
            Assert.AreEqual(1, m1.DependsOn.Columns.Count());
            var m1DepCol = m1.DependsOn.Columns.First();

            Assert.AreEqual("Default_Accounts", m1DepCol.Name);
            Assert.AreEqual("Test_Vint", m1DepCol.Table.Name);

            IDaxObject k2 = dependsOnKeys.Where(k => k.DaxObjectName == keyNames[1]).First();

            Assert.IsTrue(k2 is Measure);
            var m2 = k2 as Measure;

            Assert.IsNotNull(m2);
            Assert.AreEqual(1, m2.DependsOn.Columns.Count());
            var m2DepCol = m2.DependsOn.Columns.First();

            Assert.AreEqual("Booked_Accounts", m2DepCol.Name);
            Assert.AreEqual("Test_Orig", m2DepCol.Table.Name);
        }
 public void ShowDependencies(IDaxObject dependantObject)
 {
     if (DependencyForm.IsDisposed)
     {
         DependencyForm = new DependencyForm();
     }
     DependencyForm.Owner      = UI.FormMain;
     DependencyForm.RootObject = dependantObject;
     DependencyForm.Show();
 }
Beispiel #7
0
 /// <summary>
 /// Changes all references to object "obj", to reflect the new name of the object.
 /// </summary>
 /// <param name="obj"></param>
 public static void DoFixup(IDaxObject obj, bool rebuildImmediately = false)
 {
     foreach (var d in obj.ReferencedBy.ToList())
     {
         d.DependsOn.UpdateRef(obj);
         if (rebuildImmediately)
         {
             BuildDependencyTree(d, true);
         }
     }
 }
Beispiel #8
0
        internal void UpdateRef(IDaxObject renamedObj)
        {
            // This method is called on a DependsOnList, which belongs to a IDaxDependantObject. The argument is the IDaxObject which was typically renamed.
            // For example: The DependsOnList could be attached to a Measure [MyMeasure] with an expression such as: "COUNTROWS('MyTable')". If the name of
            // 'MyTable' was changed, this method would be called with 'MyTable' as the renamedObj and [MyMeasure] as Parent. It is then up to this method
            // to loop through all object references to 'MyTable' (see #1). As an IDaxDependantObject can have more than one DAX expression property, and an
            // object reference to 'MyTable' could exist in any of them, we must make sure to loop all the properties (#2)

            List <ObjectReference> depList;

            if (TryGetValue(renamedObj, out depList))   // #1 Get a list of object references for renamedObj
            {
                var orgDax = new string[DaxPropertyCount];
                var pos    = new int[DaxPropertyCount];
                var sbs    = new StringBuilder[DaxPropertyCount];

                foreach (var prop in Parent.GetDAXProperties())  // #2 Initialize a string buider and the original DAX for every DAX property on Parent
                {
                    var dax = Parent.GetDAX(prop);
                    if (dax != null)
                    {
                        sbs[(int)prop]    = new StringBuilder();
                        orgDax[(int)prop] = dax.Replace("\r", ""); // Carriage Returns are excluded when the dependency tree is built
                    }
                }

                // Loop through all dependencies:
                foreach (var dep in depList)
                {
                    var propIx = (int)dep.property;

                    var sb = sbs[propIx];

                    sb.Append(orgDax[propIx].Substring(pos[propIx], dep.from - pos[propIx]));
                    sb.Append(dep.fullyQualified ? renamedObj.DaxObjectFullName : renamedObj.DaxObjectName);
                    pos[propIx] = dep.to + 1;
                }

                // Finalize:
                foreach (var prop in Parent.GetDAXProperties())
                {
                    var propIx = (int)prop;

                    if (pos[propIx] > 0)
                    {
                        sbs[propIx].Append(orgDax[propIx].Substring(pos[propIx]));
                        Parent.SetDAX(prop, sbs[propIx].ToString());
                    }
                }
            }
        }
Beispiel #9
0
        internal void Add(IDaxObject dependsOn, DAXProperty property, int fromChar, int toChar, bool fullyQualified)
        {
            var dep = new ObjectReference {
                property = property, from = fromChar, to = toChar, fullyQualified = fullyQualified
            };
            List <ObjectReference> depList;

            if (!InternalDictionary.TryGetValue(dependsOn, out depList))
            {
                depList = new List <ObjectReference>();
                InternalDictionary.Add(dependsOn, depList);
                InternalList.Add(dependsOn);
            }
            depList.Add(dep);
        }
Beispiel #10
0
        private void InverseRecursiveAdd(IDaxObject obj, TreeNodeCollection nodes)
        {
            var img = UI.Tree.TabularIcon.GetIconIndex(obj);
            var n   = new TreeNode((obj as IDaxObject)?.DaxObjectFullName ?? obj.Name, img, img)
            {
                Tag = obj
            };

            if (obj is IExpressionObject)
            {
                n.ToolTipText = (obj as IExpressionObject).Expression;
            }

            nodes.Add(n);

            foreach (var d in obj.ReferencedBy.OrderBy(o => o.ObjectType))
            {
                if (d.DependsOn.ContainsKey(obj))
                {
                    var i = UI.Tree.TabularIcon.GetIconIndex(d);

                    currentDepth++;
                    if (d == _rootObject)
                    {
                        n.Nodes.Add(new TreeNode(d.GetName() + " (circular dependency)", i, i));
                    }
                    else if (currentDepth < MAX_LEVELS && d is IDaxObject)
                    {
                        InverseRecursiveAdd(d as IDaxObject, n.Nodes);
                    }
                    else if (currentDepth < MAX_LEVELS && d is RLSFilterExpression)
                    {
                        var newNode = new TreeNode(d.GetName(), i, i);
                        newNode.Tag = (d as RLSFilterExpression).Role;
                        n.Nodes.Add(newNode);
                    }
                    else
                    {
                        n.Nodes.Add("(Infinite recursion)");
                    }
                    currentDepth--;
                }
            }
        }
Beispiel #11
0
        public void RefreshTree()
        {
            if (RootObject.IsRemoved)
            {
                Close();
                _rootObject = null;
                return;
            }
            treeObjects.Nodes.Clear();

            currentDepth = 0;
            if (radioButton1.Checked)
            {
                RecursiveAdd(RootObject, treeObjects.Nodes);
                treeObjects.Nodes[0].Expand();
                chkShowInactive.Visible = false;
            }
            else if (radioButton2.Checked)
            {
                InverseRecursiveAdd(RootObject, treeObjects.Nodes);
                treeObjects.Nodes[0].Expand();
                chkShowInactive.Visible = false;
            }
            else
            {
                VisitedRelationships = new HashSet <ITabularObject>();

                var img = UI.Tree.TabularIcon.GetIconIndex(_rootObject);
                var n   = new TreeNode(((_rootObject as IDaxObject)?.DaxObjectFullName ?? _rootObject.Name), img, img)
                {
                    Tag = new ObjectRel {
                        Object = _rootObject as TabularNamedObject, Relationship = null
                    }
                };
                treeObjects.Nodes.Add(n);
                CreateRelationshipTree(RootObject, n);
                n.Expand();

                chkShowInactive.Visible = true;
            }
        }
Beispiel #12
0
        internal void UpdateRef(IDaxObject renamedObj)
        {
            List <ObjectReference> depList;

            if (TryGetValue(renamedObj, out depList))
            {
                var propertyCount = Enum.GetValues(typeof(DAXProperty)).Length;
                var pos           = new int[propertyCount];
                var sbs           = new StringBuilder[propertyCount];
                for (var i = 0; i < propertyCount; i++)
                {
                    sbs[i] = new StringBuilder();
                }

                // Loop through all dependencies:
                foreach (var dep in depList)
                {
                    var propIx = (int)dep.property;

                    var sb = sbs[propIx];

                    sb.Append(Parent.GetDAX(dep.property).Substring(pos[propIx], dep.from - pos[propIx]));
                    sb.Append(dep.fullyQualified ? renamedObj.DaxObjectFullName : renamedObj.DaxObjectName);
                    pos[propIx] = dep.to + 1;
                }

                // Finalize:
                for (var i = 0; i < propertyCount; i++)
                {
                    if (pos[i] > 0)
                    {
                        sbs[i].Append(Parent.GetDAX((DAXProperty)i).Substring(pos[i]));
                        Parent.SetDAX((DAXProperty)i, sbs[i].ToString());
                    }
                }
            }
        }
        private void FixUpTest(TabularModelHandler tmh, IDaxDependantObject obj, Utils.DAXProperty property, bool isFullyQualified, Table tableRef, IDaxObject objRef)
        {
            var baseExpression = obj.GetDAX(property);

            if (isFullyQualified)
            {
                Assert.AreEqual(2, obj.DependsOn.Count);

                Assert.AreSame(tableRef, obj.DependsOn[0]);
                var references = obj.DependsOn[tableRef];
                Assert.AreEqual(1, references.Count);
                Assert.AreEqual(property, references[0].property);
                Assert.IsTrue(references[0].fullyQualified);

                Assert.AreSame(objRef, obj.DependsOn[1]);
                references = obj.DependsOn[objRef];
                Assert.AreEqual(1, references.Count);
                Assert.AreEqual(property, references[0].property);
                Assert.IsTrue(references[0].fullyQualified);
            }
            else
            {
                Assert.AreEqual(1, obj.DependsOn.Count);

                Assert.AreSame(objRef, obj.DependsOn[0]);
                var references = obj.DependsOn[objRef];
                Assert.AreEqual(1, references.Count);
                Assert.AreEqual(property, references[0].property);
                Assert.IsFalse(references[0].fullyQualified);
            }

            var expression = baseExpression;

            var oldObjName = objRef.Name;

            objRef.Name = oldObjName + " Renamed";
            var expr1 = expression = expression.Replace(oldObjName, objRef.Name);

            Assert.AreEqual(expression, obj.GetDAX(property));

            var oldTableName = tableRef.Name;

            tableRef.Name = oldTableName + " Renamed";
            var expr2 = expression = expression.Replace(oldTableName, tableRef.Name);

            Assert.AreEqual(expression, obj.GetDAX(property));

            oldObjName  = objRef.Name;
            objRef.Name = "b b";
            var expr3 = expression = expression.Replace(oldObjName, objRef.Name);

            Assert.AreEqual(expression, obj.GetDAX(property));

            oldTableName  = tableRef.Name;
            tableRef.Name = "a a";
            var expr4 = expression = expression.Replace(oldTableName, tableRef.Name);

            Assert.AreEqual(expression, obj.GetDAX(property));

            tmh.UndoManager.Undo();
            Assert.AreEqual(expr3, obj.GetDAX(property));

            tmh.UndoManager.Undo();
            Assert.AreEqual(expr2, obj.GetDAX(property));

            tmh.UndoManager.Undo();
            Assert.AreEqual(expr1, obj.GetDAX(property));

            tmh.UndoManager.Undo();
            Assert.AreEqual(baseExpression, obj.GetDAX(property));
        }
Beispiel #14
0
 public bool TryGetValue(IDaxObject key, out List <ObjectReference> value)
 {
     return(InternalDictionary.TryGetValue(key, out value));
 }
Beispiel #15
0
 public bool ContainsKey(IDaxObject key)
 {
     return(InternalDictionary.ContainsKey(key));
 }
Beispiel #16
0
 public void Remove(IDaxObject key)
 {
     InternalDictionary.Remove(key);
     InternalList.Remove(key);
 }
 private void Dax_SingleRefAssert(IDaxDependantObject dependant, IDaxObject reference)
 {
     Assert.AreEqual(1, dependant.DependsOn.Count);
     Assert.AreSame(reference, dependant.DependsOn[0]);
     Assert.IsTrue(reference.ReferencedBy.Contains(dependant));
 }