Inheritance: TreeGridNode
        public FieldRow(FieldRow parent, RowTypes type)
        {
            RowType = type;

            if (parent == null)
                return;

            ParentField = parent;
            Instances = parent.Instances;
        }
Exemple #2
0
        private void SyncRows(List <IFieldModel> modelNodes, TreeGridNodeCollection viewNodes)
        {
            foreach (var model in modelNodes)
            {
                var row = viewNodes.OfType <FieldRow>().FirstOrDefault(r => r.Model == model);

                if (row == null)
                {
                    row = new FieldRow(model);
                    viewNodes.Add(row);

                    //XRay.LogMessage("Row added");
                    ModelRowMap[model.ID] = row;

                    if (model.PossibleSubNodes)
                    {
                        row.Nodes.Add("Loading...");
                    }
                }

                row.SyncCells();
            }
        }
        private void SyncRows(List<IFieldModel> modelNodes, TreeGridNodeCollection viewNodes)
        {
            foreach (var model in modelNodes)
            {
                var row = viewNodes.OfType<FieldRow>().FirstOrDefault(r => r.Model == model);

                if (row == null)
                {
                    row = new FieldRow(model);
                    viewNodes.Add(row);

                    XRay.LogMessage("Row added");
                    ModelRowMap[model.ID] = row;

                    if (model.PossibleSubNodes)
                        row.Nodes.Add("Loading...");
                }

                row.SyncCells();
            }
        }
        public object GetFieldValue(object rootInstanceValue)
        {
            object current = rootInstanceValue;
            object found = null;

            // dont need to traverse type chain for static types
            FieldRow[] chain = TypeChain;
            if (TypeInfo != null && TypeInfo.IsStatic)
                chain = new FieldRow[] { this };

            foreach (var link in chain)
            {
                // if has index value, get that
                if (link.RowType == RowTypes.Element)
                {
                    int i = 0;
                    var e = (current as ICollection).GetEnumerator();

                    while (e.MoveNext())
                    {
                        if (i == link.ElementIndex)
                        {
                            current = e.Current;
                            break;
                        }

                        i++;
                    }
                }
                else if (link.RowType == RowTypes.Field)
                {
                    if (!link.TypeInfo.IsStatic && current == null)
                        return ""; // "<not static>";

                    current = link.TypeInfo.GetValue(current);

                    // current can be null for first lookup (static, but after that needs a value)
                    if (current == null)
                    {
                        found = current;
                        break;
                    }
                }

                // check if at end of chain
                if (link == this ||
                    (RowType == RowTypes.Enumerate && ParentField == link))
                {
                    found = current;
                    break;
                }
            }

            //return debugChain;
            return found;
        }
 public void AddRow(FieldRow row)
 {
     Nodes.Add(row);
     row.Init();
 }
 public FieldRow(FieldRow parent, RowTypes rowType, FieldInfo info)
     : this(parent, rowType, info.FieldType)
 {
     TypeInfo = info;
 }
 public FieldRow(FieldRow parent, RowTypes rowType, Type type, int elementIndex)
     : this(parent, rowType, type)
 {
     ElementIndex = elementIndex;
 }
 public FieldRow(FieldRow parent, RowTypes rowType, Type type)
     : this(parent, rowType)
 {
     FieldType = type;
 }
        void RefreshTree(bool clear)
        {
            if (!Visible)
                return;

            CurrentDisplay = SelectedNode;

            if (clear)
            {
                FieldGrid.Nodes.Clear();
                FieldGrid.Columns.Clear();

                // type col
                FieldGrid.Columns.Add(new TreeGridColumn() { HeaderText = "Type" });
                FieldGrid.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "Name" });

                GenericMap = new Dictionary<string, Tuple<Type, List<ActiveRecord>>>();
            }

            if (SelectedNode == null)
                return;

            var nodeTypeName = SelectedNode.XNode.UnformattedName;
            var record = SelectedNode.XNode.Record;

            if (record == null)
            {
                if(SelectedNode.XNode.External)
                    DetailsLabel.Text = "Not XRayed";
                else
                    DetailsLabel.Text = "No record of being created";
                return;
            }
            DetailsLabel.Text = String.Format("Active: {0}, Created: {1}, Deleted: {2}", record.Active.Count, record.Created, record.Deleted );

            // rebuild each list cause instances may be added or removed
            foreach (var recordList in GenericMap.Values)
                recordList.Item2.Clear();

            if (record != null && record.Active.Count > 0)
            {
                lock (record.Active)
                {
                    // traverse up the record's base types until we match the type for the class node selected in the UI
                    // (cant show a debug matrix for types with different properties)
                    // for example we click on the TreeView class, but the record type is of BuddyTreeView
                    for (int i = 0; i < record.Active.Count && i < MaxCols; i++)
                    {
                        var instance = record.Active[i];

                        if (!instance.IsStatic && instance.Ref.Target == null)
                            continue;

                        Type recordType = instance.InstanceType;
                        string recordTypeName = "";

                        while (recordType != null)
                        {
                            recordTypeName = recordType.ToString();

                            if (recordTypeName.Contains(nodeTypeName))
                                break;

                            recordType = recordType.BaseType;
                        }

                        if (recordType == null)
                            throw new Exception(string.Format("record type not found for node type {0} and instance type {1}", nodeTypeName, recordType.ToString()));

                        // if we're looking at a template class, then each root node is a diff type of template List<int>, List<string> etc..

                        recordTypeName = recordType.ToString();
                        string genericName = SelectedNode.Name;

                        if (recordTypeName.Contains('`'))
                            genericName = recordTypeName.Substring(recordTypeName.IndexOf('`'));

                        if (!GenericMap.ContainsKey(genericName))
                            GenericMap[genericName] = new Tuple<Type, List<ActiveRecord>>(recordType, new List<ActiveRecord>());

                        List<ActiveRecord> recordList = GenericMap[genericName].Item2;
                        if( !recordList.Contains(instance) )
                            recordList.Add(instance);
                    }
                }
            }

            // auto size type/name columns
            FieldGrid.AutoResizeColumn(0);
            FieldGrid.AutoResizeColumn(1);

            // add columns for each intance
            int mostInstances = 0;
            if(GenericMap.Count > 0)
                mostInstances = GenericMap.Values.Max(v => v.Item2.Count);

            var newColumns = new List<DataGridViewColumn>();

            for (int i = 0; i < mostInstances; i++)
                if (FieldGrid.ColumnCount <= 2 + i)
                {
                    var col = new DataGridViewTextBoxColumn() { HeaderText = "Instance " + i.ToString() };
                    newColumns.Add(col);
                    FieldGrid.Columns.Add(col);
                }

            foreach (var recordInstance in GenericMap)
            {
                FieldRow row = FieldGrid.Nodes.OfType<FieldRow>().FirstOrDefault(r => r.GenericName == recordInstance.Key);

                if (row != null)
                {
                    row.RefreshField();
                    continue;
                }

                row = new FieldRow(null, RowTypes.Root);
                row.GenericName = recordInstance.Key;
                row.FieldType = recordInstance.Value.Item1; // instance type that matches selected node
                row.Instances = recordInstance.Value.Item2; // list of instances

                if (row.Instances.Count > 0 && row.Instances[0].IsStatic)
                    FieldGrid.Columns[2].HeaderText = "Static";

                FieldGrid.Nodes.Add(row);
                row.Init();
                row.ExpandField(FieldFilter);
            }

            foreach (FieldRow generic in FieldGrid.Nodes.OfType<FieldRow>())
                generic.Expand();

            foreach (var col in newColumns)
                FieldGrid.AutoResizeColumn(col.Index);
                //AutoSizeColumn(col);
        }
        internal void ExpandField(string fieldFilter=null)
        {
            if (Expanded)
                return;

            Expanded = true;

            Nodes.Clear();

            if (FieldType != null)
            {
                if (RowType == RowTypes.Root && fieldFilter == null)
                {
                    AddRow(new FieldRow(this, RowTypes.Declared));
                    AddRow(new FieldRow(this, RowTypes.Selected, FieldType));
                    AddRow(new FieldRow(this, RowTypes.Number));
                    AddRow(new FieldRow(this, RowTypes.Age));
                }

                if (fieldFilter == null)
                    AddFieldMembers();
                else
                {
                    var field = FieldType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).FirstOrDefault(f => f.Name == fieldFilter);
                    if (field != null)
                    {
                        XRay.LogError("Field " + fieldFilter + " found on " + FieldType.ToString());

                        var row = new FieldRow(this, RowTypes.Field, field);
                        AddRow(row);
                        row.ExpandField();
                    }
                    else
                        XRay.LogError("Field " + fieldFilter + " not found on " + FieldType.ToString());
                }
            }

            RefreshField();
        }