Exemplo n.º 1
0
        /// <summary>
        /// Parses the given DTE expression into a dictionary recursively.
        /// </summary>
        /// <param name="expression">DTE expression</param>
        /// <param name="recursiveLevel">Current recursive level</param>
        /// <returns>Dictionary containing part of the object</returns>
        private Dictionary <string, object> ParseDTEExpression(EnvDTE.Expression expression, int recursiveLevel)
        {
            if (expression == null || recursiveLevel >= 5)
            {
                return(null);
            }

            var typeStr = expression.Type;

            if (typeStr == null || typeStr == "Null")
            {
                return(null);
            }

            System.Diagnostics.Debug.Write("\nMPH Type: " + typeStr);

            var parsedObject = new Dictionary <string, object>();

            if (expression.DataMembers == null || expression.DataMembers.Count == 0 || IsTypescriptPrimitive(typeStr))
            {
                (parsedObject as IDictionary <string, object>)?.Add(expression.Name, expression.Value);
            }
            else
            {
                foreach (EnvDTE.Expression item in expression.DataMembers)
                {
                    var parsedField = ParseDTEExpression(item, recursiveLevel + 1);
                    if (parsedField != null)
                    {
                        (parsedObject as IDictionary <string, object>)?.Add(item.Name, parsedField);
                    }
                }
            }
            return(parsedObject);
        }
Exemplo n.º 2
0
        protected override List <Replicate> GetClassProperties(string variableName)
        {
            var properties = new List <Replicate>();

            string variableType = Debugger.GetExpression(String.Concat(variableName, ".GetType().FullName")).Value.Replace("\"", String.Empty).Replace("+", ".");

            EnvDTE.Expression expression = Debugger.GetExpression(String.Concat("(", variableType, ")", variableName)); //Need to cast it when list contains abstract type

            foreach (EnvDTE.Expression dataMember in expression.DataMembers)
            {
                if (IsPropertyInitializable(variableName, dataMember.Name))
                {
                    var property = CreateReplicate(String.Concat(variableName, ".", dataMember.Name));

                    if (property != null)
                    {
                        properties.Add(property);
                    }
                }
            }

            if (properties.Count == 0)
            {
                properties = null;
            }

            return(properties);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the adornment with the variable information
        /// </summary>
        /// <param name="sender">event source</param>
        /// <param name="e">event arguments</param>
        public void UpdateAdornment(Object sender, MouseHoverEventArgs e)
        {
            if (debugger.CurrentMode != dbgDebugMode.dbgBreakMode || "TypeScript" != dte?.ActiveDocument?.Language)
            {
                return;
            }
            if (root.IsMouseOver)
            {
                return;
            }
            var variable = DebuggerVariable.FindUnderMousePointer(debugger, e);

            if (variable != null)
            {
                var position = GetVariablePosition(variable);
                if (position != null)
                {
                    MoveAdornment(position.Item1, position.Item2);

                    var newTreeView = TreeViewBuilder.GetTreeView(variable.Expression);
                    currentExpression = variable.Expression;
                    root.ResultTreeView.Items.Clear();
                    foreach (var item in newTreeView.Items)
                    {
                        root.ResultTreeView.Items.Add(item);
                    }
                }
            }
            else
            {
                MoveAdornment(9999, 9999);
            }
        }
Exemplo n.º 4
0
        public Replicate CreateReplicate(string variableName)
        {
            _level++;

            Replicate replicate = null;

            if (_level > 20) //break infinite loop
            {
                replicate = CreateNullReplicate();
            }
            else
            {
                replicate = GetReplicate(variableName);
            }

            EnvDTE.Expression expression = Debugger.GetExpression(variableName);

            replicate.Name  = expression.Name.Substring(expression.Name.LastIndexOf(".") + 1);
            replicate.Type  = Debugger.GetExpression(String.Concat(variableName, ".GetType().FullName")).Value.Replace("\"", String.Empty).Replace("+", ".").Replace("[]", "()");
            replicate.Value = expression.Value.Replace("\"", String.Empty);

            _level--;

            return(replicate);
        }
Exemplo n.º 5
0
 public int GetDataTipText(TextSpan[] pSpan, out string pbstrText)
 {
     if (_debugger.CurrentMode != dbgDebugMode.dbgBreakMode)
     {
         pbstrText = null;
         return(VSConstants.S_FALSE);
     }
     try
     {
         TextSpan span = pSpan[0];
         if (TextView.GetWordExtent(span.iStartLine, span.iStartIndex, (uint)WORDEXTFLAGS.WORDEXT_CURRENT, pSpan) == VSConstants.S_OK)
         {
             span = pSpan[0];
             string key;
             if (TextView.GetTextStream(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex, out key) == VSConstants.S_OK)
             {
                 EnvDTE.Expression exp = _debugger.GetExpression("$" + key, false, 500);
                 if (exp != null && exp.IsValidValue)
                 {
                     int result = _vsdebugger.GetDataTipValue(_vsTextLines, pSpan, exp.Name, out pbstrText);
                     pbstrText = exp.Name;
                     return(result);
                 }
             }
         }
     }
     catch (Exception)
     {
         //TODO do some warning -david
     }
     pbstrText = null;
     return(VSConstants.S_FALSE);
 }
Exemplo n.º 6
0
        async Task <bool> AddGeometry(string text)
        {
            Logger.Log(this, string.Format("AddGeometry: {0}", text));

            // first call to method
            if (this.dte == null)
            {
                Logger.Log(this, string.Format("First call to AddGeometry."));
                this.dte = FirstToolWindowPackage.WindowToolPackage.GetService();
                Logger.Log(this, string.Format("Created DTE object."));

                if (cb_UpdateOnContextChange.IsChecked.Value)
                {
                    dte.Events.DebuggerEvents.OnContextChanged += DebuggerEvents_OnContextChanged;
                    Logger.Log(this, string.Format("Added DebuggerEvents_OnContextChanged event."));
                }
            }

            // Ensure that debugger is running
            if (dte.Debugger.CurrentStackFrame == null)
            {
                MessageBox.Show("You need to have the Debugger running");
                return(false);
            }

            EnvDTE.Expression local = dte.Debugger.GetExpression(text, true, 1);

            if (local == null)
            {
                Logger.Log(this, string.Format("dte.Debugger.GetExpression for variable \"{0}\" return null", local.Name));
                return(false);
            }

            Logger.Log(this, string.Format("name: {0}, val: {1}, type: {2}", local.Name, local.Value, local.Type));

            // since there is a check for ennumerable that creates a new variable,
            // we don't want to update the viz for that
            dte.Events.DebuggerEvents.OnContextChanged -= DebuggerEvents_OnContextChanged;



            if (ReaderUtils.TryAddObject(local, hv, _dict))
            {
                Logger.Log(this, string.Format("All good"));
            }
            else
            {
                Logger.Log(this, string.Format("No good"));
            }

            // we reattach the OnContextChanged
            if (cb_UpdateOnContextChange.IsChecked.Value)
            {
                dte.Events.DebuggerEvents.OnContextChanged += DebuggerEvents_OnContextChanged;
            }


            return(true);
        }
Exemplo n.º 7
0
 public ExpressionNf(EnvDTE.Expression expression)
 {
     Name         = expression.Name;
     Type         = expression.Type;
     Value        = expression.Value;
     IsValidValue = expression.IsValidValue;
     Members      = new List <ExpressionNf>();
 }
Exemplo n.º 8
0
        private LoadResults LoadArray(Expression expression, bool ignoreArraySize)
        {
            _lastLoadException = null;
            _data = null;
            try
            {
                if (expression.Value != "null")
                {
                    object[] values = null;

                    foreach (ITypeParser parser in _parsers.Where(P => P.IsExpressionTypeSupported(expression)))
                    {
                        _dimensions = parser.GetDimensions(expression);
                        int count = parser.GetMembersCount(expression);
                        if (ignoreArraySize || count <= 2000)
                        {
                            values = parser.GetValues(expression);
                        }
                        else
                        {
                            return(LoadResults.LargeArray);
                        }

                        break;
                    }

                    switch (_dimensions.Length)
                    {
                    case 1:
                        _data = values.ToArray(_dimensions[0]);
                        break;

                    case 2:
                        _data = values.ToArray(_dimensions[0], _dimensions[1]);
                        break;

                    case 3:
                        _data = values.ToArray(_dimensions[0], _dimensions[1], _dimensions[2]);
                        break;

                    case 4:
                        _data = values.ToArray(_dimensions[0], _dimensions[1], _dimensions[2], _dimensions[3]);
                        break;

                    default:
                        return(LoadResults.NotSupported);
                    }
                }
            }
            catch (Exception ex)
            {
                _lastLoadException = ex;
                return(LoadResults.Exception);
            }
            return(LoadResults.Success);
        }
Exemplo n.º 9
0
            public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger debugger,
                                                            string name, string type,
                                                            LoadCallback callback)
            {
                // NOTE: If the image is not created at the point of debugging, so the variable is
                // uninitialized, the size may be out of bounds of int32 range. In this case the
                // exception is thrown here and this is ok. However if there is some garbage in
                // memory random size could be loaded here. Then also the memory probably points
                // to some random place in memory (maybe protected?) so the result will probably
                // be another exception which is fine or an image containing noise from memory.
                ulong dataStart = ExpressionParser.GetPointer(debugger, name + ".DataStart");
                ulong dataEnd   = ExpressionParser.GetPointer(debugger, name + ".DataEnd");
                ulong length    = dataEnd - dataStart;
                int   cols      = ExpressionParser.LoadSize(debugger, name + ".Cols");
                int   rows      = ExpressionParser.LoadSize(debugger, name + ".Rows");

                EnvDTE.Expression exp = debugger.GetExpression("(int)(" + name + ".Type())");

                MatType mType = MatType.CV_8UC1;

                if (exp.IsValidValue)
                {
                    mType = (MatType)int.Parse(exp.Value);
                }

                byte[] memory   = new byte[length];
                bool   isLoaded = false;

                if (mreader != null)
                {
                    ulong address = ExpressionParser.GetValueAddress(debugger, name + ".DataPointer[0]");
                    if (address == 0)
                    {
                        return(null);
                    }

                    isLoaded = mreader.ReadBytes(address, memory);
                }

                var    pixelFormat = MatTypeToPixelFormat(mType);
                Bitmap bmp         = new Bitmap(
                    cols,
                    rows,
                    pixelFormat);

                BitmapData data = bmp.LockBits(
                    new Rectangle(System.Drawing.Point.Empty, bmp.Size),
                    ImageLockMode.WriteOnly,
                    pixelFormat);

                Marshal.Copy(memory, 0, data.Scan0, (int)length);

                bmp.UnlockBits(data);

                return(new ExpressionDrawer.Image(bmp));
            }
Exemplo n.º 10
0
        protected override void ReadExpression(Expression exp)
        {
            EnvDTE.Expression x = FindChildren(X_Name);
            this.x = double.Parse(x.Value);

            EnvDTE.Expression y = FindChildren(Y_Name);
            this.y = double.Parse(y.Value);

            EnvDTE.Expression z = FindChildren(Z_Name);
            this.z = double.Parse(z.Value);
        }
Exemplo n.º 11
0
 public ExpressionNf(EnvDTE.Expression expression, int depth) : this(expression)
 {
     if (depth > 0 && expression.DataMembers.Count > 0)
     {
         //Recursively call this constructor until depth of 0
         foreach (EnvDTE.Expression dataMember in expression.DataMembers)
         {
             ExpressionNf convertedDataMember = new ExpressionNf(dataMember, this, depth - 1);
             Members.Add(convertedDataMember);
         }
     }
 }
Exemplo n.º 12
0
        static EnvDTE.Expression GetDataMember(EnvDTE.Expression exp, string name)
        {
            foreach (EnvDTE.Expression exp1 in exp.DataMembers)
            {
                if (exp1.Name == name)
                {
                    return(exp1);
                }
            }

            return(null);
        }
Exemplo n.º 13
0
        private string GetSelectedVariable()
        {
            var dteInstance      = (DTE)GetService(typeof(SDTE));
            var textDocument     = (EnvDTE.TextDocument)dteInstance.ActiveDocument.Object(String.Empty);
            var selectedVariable = textDocument.Selection.Text;

            EnvDTE.Expression expression = dteInstance.Debugger.GetExpression(selectedVariable);

            if (!expression.IsValidValue)
            {
                throw new InvalidExpressionException(selectedVariable);
            }

            return(selectedVariable);
        }
Exemplo n.º 14
0
        static IEnumerable <EnvDTE.Expression> ReadEnumerable(EnvDTE.Expression exp)
        {
            Logger.Log(exp, string.Format("Reading IENumerable. Name: {0}, val: {1}, type: {2}", exp.Name, exp.Value, exp.Type));

            //if (!enums.Any(e => exp.Type.Contains(e)))
            //    yield return null;

            foreach (EnvDTE.Expression exp1 in exp.DataMembers)
            {
                Logger.Log(exp, string.Format(exp1.Name));

                if (exp1.Name.Contains("["))
                {
                    yield return(exp1);
                }
            }
        }
Exemplo n.º 15
0
        static bool IsEnumerable(EnvDTE.Expression exp)
        {
            string varName = "_" + Guid.NewGuid().ToString("N");

            exp.DTE.Debugger.ExecuteStatement(string.Format("System.Collections.IEnumerable {0} = (System.Collections.IEnumerable) {1};", varName, exp.Name));

            EnvDTE.Expression tempVar = exp.DTE.Debugger.GetExpression(varName);

            if (!tempVar.IsValidValue ||
                tempVar.Value == "null")
            {
                return(false);
            }

            exp.DTE.Debugger.ExecuteStatement(string.Format("{0} = null;", varName /*, exp.Name*/));

            return(true);
        }
Exemplo n.º 16
0
        public void SetExpression(EnvDTE.Expression exp)
        {
            root_expression = exp;

            if (root_expression == null)
            {
                graph = null;
            }
            else
            {
                RebuildGraph();
                MakeVertexCaptions();
                MakeVertexTooltips();
            }

            if (graphUpdated != null)
            {
                graphUpdated(graph);
            }
        }
Exemplo n.º 17
0
        private static string IntegralCaptionBuilder(object captionData, string formatter)
        {
            Expression exp = captionData as Expression;
            string     text;

            if (exp == null)
            {
                text = (captionData ?? "").ToString();
            }
            else
            {
                text = (exp.Value ?? "");
            }

            if (long.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out var number))
            {
                text = number.ToString(formatter, CultureInfo.CurrentCulture);
            }
            return(text);
        }
Exemplo n.º 18
0
 private void ProcessAction(Action action)
 {
     if (curAction != null)
     {
         Expression variable = GetDebugVariable(curAction.Variable.VariableName);
         if (variable == null)
         {
             MessageBox.Show(string.Format("Unable to find variable '{0}'", curAction.Variable.VariableName));
         }
         else
         {
             try{
                 if (variable.Type == "float")
                 {
                     variable.Value = curAction.ValueToAssign.ToString() + "f";
                 }
                 if (variable.Type == "char")
                 {
                     variable.Value = string.Format("'{0}'", Convert.ToChar(Convert.ToInt16(curAction.ValueToAssign)).ToString());
                 }
                 else
                 {
                     variable.Value = curAction.ValueToAssign.ToString();
                 }
                 DisplayText += string.Format("Set value of variable '{0}' to '{1}' at line '{2}' {3}", curAction.Variable.VariableName, curAction.ValueToAssign, curAction.BreakPointLocation, Environment.NewLine);
             }
             catch (Exception e) {
                 MessageBox.Show("Unable to set debugger variable");
                 throw;
             }
         }
     }
     if (action != null)
     {
         SetBreakpointAtLine(action.BreakPointLocation);
     }
     curAction = action;
 }
Exemplo n.º 19
0
 public ExpressionNf(EnvDTE.Expression expression, ExpressionNf parent, int depth) : this(expression, depth)
 {
     Parent = parent;
 }
Exemplo n.º 20
0
        internal static bool TryAddObject(EnvDTE.Expression exp, HelixViewport3D hv, Map <string, ModelVisual3D> _dict)
        {
            if (!exp.IsValidValue)
            {
                return(false);
            }

            // get type
            string type = exp.Type;

            // create the 3d
            ModelVisual3D _mv3d;

            Logger.Log("", string.Format("Searching this type in dictionary: {0}", type));
            // try get object from dictionary
            MetaObject obj;

            if (dictType_.TryGetValue(type, out obj))
            {
                // let's create a brand new one
                obj = obj.InstantiateNew();

                obj.Run(exp);

                _mv3d = obj.To3DViz();

                obj.VisualizationProperties(_mv3d);
            }
            else if (IsEnumerable(exp))
            {
                // clean from enumerables' characters
                type = CleanFromEnumerables(type);

                if (!dictType_.TryGetValue(type, out obj))
                {
                    Logger.Log("", string.Format("Could not find this type in dictionary: {0}", type));
                    return(false);
                }


                // let's create a brand new one
                obj = obj.InstantiateNew();

                _mv3d = new ModelVisual3D();

                foreach (EnvDTE.Expression exp1 in ReaderUtils.ReadEnumerable(exp))
                {
                    obj.Run(exp1);

                    ModelVisual3D mv3d = obj.To3DViz();

                    obj.VisualizationProperties(mv3d);

                    _mv3d.Children.Add(mv3d);
                }
            }
            else
            {
                Logger.Log("", string.Format("Could not find this type in dictionary: {0}", type));
                return(false);
            }

            if (_mv3d.Children != null && _mv3d.Children.Count > 0)
            {
                for (int i = 0; i < _mv3d.Children.Count; i++)
                {
                    Visual3D mv3d = _mv3d.Children[i];

                    // new bindings
                    Binding myBinding = new Binding();
                    myBinding.Source = mv3d;
                    myBinding.Path   = new PropertyPath("MyProperties");
                    myBinding.Mode   = BindingMode.TwoWay;
                    myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

                    // set bindings
                    BindingOperations.SetBinding(mv3d, MyProperties.MyParentProperty, myBinding);

                    // set value
                    mv3d.SetValue(MyProperties.MyParentProperty, _mv3d);
                }
            }

            Logger.Log(exp, string.Format("Add3D"));

            _mv3d.SetName(exp.Name);

            // add to dict and viewport
            _dict.Add(exp.Name, _mv3d);
            hv.Items.Add(_mv3d);

            // exit
            Logger.Log(exp, string.Format("Add3D - Added to dict"));
            return(true);
        }