internal State(SourceLocation location, string name, IEnumerable<LocalsItemDescription> earlyLocals, int numberOfEarlyLocals)
 {
     this.location = location;
     this.name = name;
     this.earlyLocals = earlyLocals;
     this.numberOfEarlyLocals = (earlyLocals == null) ? 0 : numberOfEarlyLocals;
 }
Esempio n. 2
0
 private void SetLocation(object instance, SourceLocation location)
 {
     if (location != null)
     {
         XamlDebuggerXmlReader.SetFileName(instance, location.FileName);
         XamlDebuggerXmlReader.SetStartLine(instance, location.StartLine);
         XamlDebuggerXmlReader.SetStartColumn(instance, location.StartColumn);
         XamlDebuggerXmlReader.SetEndLine(instance, location.EndLine);
         XamlDebuggerXmlReader.SetEndColumn(instance, location.EndColumn);
     }
 }
        internal void UpdateMap(object key, SourceLocation sourceLocation)
        {
            if (this.deserializedObjectToSourceLocationMapping.ContainsKey(key))
            {
                this.deserializedObjectToSourceLocationMapping.Remove(key);
            }

            this.deserializedObjectToSourceLocationMapping.Add(key, new SourceLocation(/* fileName = */ null,
                sourceLocation.StartLine, sourceLocation.StartColumn,
                sourceLocation.EndLine, sourceLocation.EndColumn));
        }
        internal static bool Contains(this SourceLocation outer, SourceLocation inner)
        {
            Fx.Assert(inner != null && outer != null, "Argument should not be null");

            if ((inner.StartLine > outer.StartLine || (inner.StartLine == outer.StartLine && inner.StartColumn >= outer.StartColumn))
             && (inner.EndLine < outer.EndLine || (inner.EndLine == outer.EndLine && inner.EndColumn <= outer.EndColumn)))
            {
                return true;
            }

            return false;
        }
Esempio n. 5
0
        internal State(SourceLocation location, string name, IEnumerable<LocalsItemDescription> earlyLocals, int numberOfEarlyLocals)
        {
            // If we are running in Partial Trust, validate the name string. We only do this in partial trust for backward compatability.
            // We are doing the validation because we want to prevent anything passed to us by non-critical code from affecting the generation
            // of the code to the dynamic assembly we are creating.
            if (!PartialTrustHelpers.AppDomainFullyTrusted)
            {
                this.name = ValidateIdentifierString(name);
                this.location = ValidateSourceLocation(location);
            }
            else
            {
                this.location = location;
                this.name = name;
            }

            this.earlyLocals = earlyLocals;
            Fx.Assert(earlyLocals != null || numberOfEarlyLocals == 0,
                "If earlyLocals is null then numberOfEarlyLocals should be 0");
            // Ignore the passed numberOfEarlyLocals if earlyLocal is null.
            this.numberOfEarlyLocals = (earlyLocals == null) ? 0 : numberOfEarlyLocals;
        }
 internal State DefineState(SourceLocation location, string name, LocalsItemDescription[] earlyLocals, int numberOfEarlyLocals)
 {
     return this.dynamicModuleManager.DefineState(location, name, earlyLocals, numberOfEarlyLocals);
 }
        private static ModelItem FindModelItemInMap(SourceLocation sourceLocation, IDictionary<SourceLocation, ModelItem> map)
        {
            SourceLocation exactSourceLocation = GetExactLocation(sourceLocation, map);
            if (exactSourceLocation == null)
            {
                return null;
            }

            return map[exactSourceLocation];
        }
 /// <summary>
 /// Initializes a new instance of the SourceLocationUpdatedEventArgs class.
 /// </summary>
 /// <param name="objectReference">The Guid of the ObjectReference that changed.</param>
 /// <param name="updatedSourceLocation">The updated SourceLocation.</param>
 public SourceLocationUpdatedEventArgs(Guid objectReference, SourceLocation updatedSourceLocation)
 {
     this.ObjectReference = objectReference;
     this.UpdatedSourceLocation = updatedSourceLocation;
 }
 // Update the appearance of a given breakpoint to show the given type.
 public void UpdateBreakpoint(SourceLocation sourceLocation, BreakpointTypes newBreakpointType)
 {
     ModelItem modelItem = this.GetModelItemFromSourceLocation(sourceLocation);
     if (modelItem != null)
     {
         SetBreakpointType(modelItem, newBreakpointType);
     }
     else
     {
         BreakpointTypes oldBreakpointType;
         if (this.unmappedBreakpoints.TryGetValue(sourceLocation, out oldBreakpointType))
         {
             if (newBreakpointType == BreakpointTypes.None)
             {
                 this.unmappedBreakpoints.Remove(sourceLocation);
             }
             else
             {
                 this.unmappedBreakpoints[sourceLocation] = newBreakpointType;
             }
         }
         else if (newBreakpointType != BreakpointTypes.None)
         {
             this.unmappedBreakpoints.Add(sourceLocation, newBreakpointType);
         }
     }
 }
 // Inserting a new breakpoint of a given type.
 public void InsertBreakpoint(SourceLocation sourceLocation, BreakpointTypes breakpointType)
 {
     this.UpdateBreakpoint(sourceLocation, breakpointType);
 }
        internal static SourceLocation FindClosestSourceLocation(SourceLocation approximateLocation, IEnumerable<SourceLocation> availableSourceLocations)
        {
            Fx.Assert(approximateLocation != null && availableSourceLocations != null, "Argument should not be null");

            SourceLocation exactLocation = null;
            SourceLocation innerMostOuterSourceLocation =
                FindInnerMostContainer(approximateLocation, availableSourceLocations);

            if (innerMostOuterSourceLocation != null)
            {
                exactLocation = innerMostOuterSourceLocation;
            }
            else
            {
                // Find the next line of the approximateLocation.
                int minimumDistance = int.MaxValue;
                foreach (SourceLocation sourceLocation in availableSourceLocations)
                {
                    int lineDistance = sourceLocation.StartLine - approximateLocation.StartLine;
                    if ((lineDistance > 0) &&
                        ((lineDistance < minimumDistance) ||
                         ((lineDistance == minimumDistance) && (sourceLocation.StartColumn < exactLocation.StartColumn))))  // if same distance, then compare the start column
                    {
                        exactLocation = sourceLocation;
                        minimumDistance = lineDistance;
                    }
                }
            }

            return exactLocation;
        }
        // This method tries to find the inner most outer source location from a list
        // The outer source locations of a source location is ones that contains it
        // The inner most outer source location is the one nested most deeply, right outside of the source location being contained.
        private static SourceLocation FindInnerMostContainer(SourceLocation approximateLocation, IEnumerable<SourceLocation> availableSourceLocations)
        {
            Fx.Assert(approximateLocation != null && availableSourceLocations != null, "Argument should not be null");

            SourceLocation innerMostOuterSourceLocation = null;

            foreach (SourceLocation sourceLocation in availableSourceLocations)
            {
                if (sourceLocation.Contains(approximateLocation))
                {
                    if (innerMostOuterSourceLocation == null)
                    {
                        innerMostOuterSourceLocation = sourceLocation;
                    }
                    else
                    {
                        if (innerMostOuterSourceLocation.Contains(sourceLocation))
                        {
                            innerMostOuterSourceLocation = sourceLocation;
                        }
                    }
                }
            }

            return innerMostOuterSourceLocation;
        }
Esempio n. 13
0
 // Declare a new state associated with the given source location.
 // States should have disjoint source locations.
 // location is Source location associated with this state.
 // This returns a state object, which can be passed to EnterState.
 internal State DefineState(SourceLocation location)
 {
     return(DefineState(location, string.Empty, null, 0));
 }
Esempio n. 14
0
 internal State DefineStateWithDebugInfo(SourceLocation location, string name)
 {
     return(DefineState(location, name, debugInfoDescriptions, debugInfoDescriptions.Length));
 }
Esempio n. 15
0
 internal State DefineState(SourceLocation location, string name, LocalsItemDescription[] earlyLocals, int numberOfEarlyLocals)
 {
     return(this.dynamicModuleManager.DefineState(location, name, earlyLocals, numberOfEarlyLocals));
 }
Esempio n. 16
0
 public State DefineState(SourceLocation location, string name, LocalsItemDescription[] earlyLocals, int numberOfEarlyLocals)
 {
     State state;
     lock (this)
     {
         if (!this.stateMap.TryGetValue(location, out state))
         {
             lock (this)
             {
                 state = new State(location, name, earlyLocals, numberOfEarlyLocals);
                 this.stateMap.Add(location, state);
                 this.states.Add(state);
             }
         }
     }
     return state;
 }
Esempio n. 17
0
 internal State DefineState(SourceLocation location, string name)
 {
     return(DefineState(location, name, null, 0));
 }
 // Delete a breakpoint.
 public void DeleteBreakpoint(SourceLocation sourceLocation)
 {
     UpdateBreakpoint(sourceLocation, BreakpointTypes.None);
 }
Esempio n. 19
0
        SourceLocation ValidateSourceLocation(SourceLocation input)
        {
            bool returnNewLocation = false;
            string newFileName = input.FileName;

            if (string.IsNullOrWhiteSpace(newFileName))
            {
                this.DebuggingEnabled = false;
                Trace.WriteLine(SR.DebugInstrumentationFailed(SR.InvalidFileName(this.name)));
                return input;
            }

            // There was some validation of the column and line number already done in the SourceLocation constructor.
            // We are going to limit line and column numbers to Int16.MaxValue
            if ((input.StartLine > Int16.MaxValue) || (input.EndLine > Int16.MaxValue))
            {
                this.DebuggingEnabled = false;
                Trace.WriteLine(SR.DebugInstrumentationFailed(SR.LineNumberTooLarge(this.name)));
                return input;
            }

            if ((input.StartColumn > Int16.MaxValue) || (input.EndColumn > Int16.MaxValue))
            {
                this.DebuggingEnabled = false;
                Trace.WriteLine(SR.DebugInstrumentationFailed(SR.ColumnNumberTooLarge(this.name)));
                return input;
            }

            // Truncate at 255 characters.
            if (newFileName.Length > 255)
            {
                newFileName = newFileName.Substring(0, 255);
                returnNewLocation = true;
            }

            if (ReplaceInvalidCharactersWithUnderscore(ref newFileName, Path.GetInvalidPathChars()))
            {
                returnNewLocation = true;
            }

            string fileNameOnly = Path.GetFileName(newFileName);
            if (ReplaceInvalidCharactersWithUnderscore(ref fileNameOnly, Path.GetInvalidFileNameChars()))
            {
                // The filename portion has been munged. We need to make a new full name.
                string path = Path.GetDirectoryName(newFileName);
                newFileName = path + "\\" + fileNameOnly;
                returnNewLocation = true;
            }

            if (returnNewLocation)
            {
                return new SourceLocation(newFileName, input.StartLine, input.StartColumn, input.EndLine, input.EndColumn);
            }

            return input;
        }
 private static bool IsUnresolved(SourceLocation sourceLocation)
 {
     return !string.IsNullOrEmpty(sourceLocation.FileName) && sourceLocation.FileName.StartsWith(unresolvedPrefix, StringComparison.OrdinalIgnoreCase);
 }
        // This method reads a ViewStateData node from the xaml nodestream. It outputs the Id property into viewStateId
        // and the attached viewstate related properties in viewStateNodes. The input reader is positioned on a 
        // ViewStateData node within ViewStateManager.
        static void ReadViewState(XamlType viewStateType, XamlReader xamlReader, out string viewStateId, out XamlNodeList viewStateNodes, out SourceLocation sourceLocation)
        {
            int globalMemberLevel = 0;
            bool skippingUnexpectedAttachedProperty = false;
            int skippingUnexpectedAttachedPropertyLevel = 0;
            viewStateId = null;
            viewStateNodes = new XamlNodeList(viewStateType.SchemaContext);
            sourceLocation = null;

            Stack<Frame> objectNodes = new Stack<Frame>();
            XamlMember idMember = new XamlMember(typeof(ViewStateData).GetProperty("Id"), xamlReader.SchemaContext);
            int[] viewStateDataSourceLocation = new int[4];
            int sourceLocationIndex = -1;

            IXamlLineInfo lineInfo = xamlReader as IXamlLineInfo;
            IXamlLineInfoConsumer lineInfoComsumer = viewStateNodes.Writer as IXamlLineInfoConsumer;
            bool shouldPassLineInfo = lineInfo != null && lineInfo.HasLineInfo && lineInfoComsumer != null && lineInfoComsumer.ShouldProvideLineInfo;

            while (xamlReader.Read())
            {
                bool skipWritingToNodeList = false;
                switch (xamlReader.NodeType)
                {
                    case XamlNodeType.StartObject:
                        if (xamlReader.Type.Equals(viewStateType))
                        {
                            skipWritingToNodeList = true;
                        }
                        objectNodes.Push(new Frame { Type = xamlReader.Type });
                        break;

                    case XamlNodeType.GetObject:
                        objectNodes.Push(new Frame { Type = null });
                        break;

                    case XamlNodeType.StartMember:
                        globalMemberLevel++;
                        if (xamlReader.Member.Equals(idMember))
                        {
                            XamlReader idNode = xamlReader.ReadSubtree();
                            while (idNode.Read())
                            {
                                if (idNode.NodeType == XamlNodeType.Value)
                                {
                                    viewStateId = idNode.Value as string;
                                }
                            }
                        } 
                        else if (globalMemberLevel == 1 && !IsAttachablePropertyForConvert(xamlReader)) 
                        {
                            skippingUnexpectedAttachedProperty = true;
                        }
                        if (skippingUnexpectedAttachedProperty)
                        {
                            skippingUnexpectedAttachedPropertyLevel++;
                        }

                        sourceLocationIndex = GetViewStateDataSourceLocationIndexFromCurrentReader(xamlReader);
                        break;

                    case XamlNodeType.EndMember:
                        globalMemberLevel--;
                        if (skippingUnexpectedAttachedProperty)
                        {
                            skippingUnexpectedAttachedPropertyLevel--;
                        }
                        break;
                    case XamlNodeType.Value:
                        if (xamlReader.Value is int
                            && sourceLocationIndex >= 0 
                            && sourceLocationIndex < viewStateDataSourceLocation.Length)
                        {
                            viewStateDataSourceLocation[sourceLocationIndex] = (int)xamlReader.Value;
                        }

                        break;
                    case XamlNodeType.EndObject:
                        Frame objectNode = objectNodes.Pop();
                        if (objectNode.Type != null && objectNode.Type.Equals(viewStateType))
                        {
                            skipWritingToNodeList = true;
                            // The ViewStateData's source location should be valid, because
                            // before each EndObject, its SourceLocation is injected.
                            // If not, an exception will be thrown from constructor 
                            // of SourceLocation.
                            sourceLocation = new SourceLocation(null,
                                viewStateDataSourceLocation[0],
                                viewStateDataSourceLocation[1],
                                viewStateDataSourceLocation[2],
                                viewStateDataSourceLocation[3]
                                );
                        }

                        Array.Clear(viewStateDataSourceLocation, 0, viewStateDataSourceLocation.Length);
                        break;
                };

                if (!skipWritingToNodeList && !skippingUnexpectedAttachedProperty)
                {
                    if (shouldPassLineInfo)
                    {
                        lineInfoComsumer.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition);
                    }

                    viewStateNodes.Writer.WriteNode(xamlReader);
                }

                if (skippingUnexpectedAttachedPropertyLevel == 0)
                {
                    skippingUnexpectedAttachedProperty = false;
                }
            }
            viewStateNodes.Writer.Close();
        }
        private void EnsureSourceLocationUpdated()
        {
            Fx.Assert(this.modelSearchService != null, "ModelSearchService should be available and is ensured in WorkflowDesigner constructor");
            if (this.requiresUpdateSourceLocation)
            {
                Dictionary<object, SourceLocation> updatedSourceLocations = new Dictionary<object, SourceLocation>();
                foreach (ModelItem key in this.modelSearchService.GetObjectsWithSourceLocation())
                {
                    // disallow expressions
                    if (AllowBreakpointAttribute.IsBreakpointAllowed(key.ItemType) && !typeof(IValueSerializableExpression).IsAssignableFrom(key.ItemType))
                    {
                        SourceLocation sourceLocationWithoutFileName = this.modelSearchService.FindSourceLocation(key);

                        // Appending the fileName
                        SourceLocation sourceLocationWithFileName = new SourceLocation(this.fileName,
                            sourceLocationWithoutFileName.StartLine,
                            sourceLocationWithoutFileName.StartColumn,
                            sourceLocationWithoutFileName.EndLine,
                            sourceLocationWithoutFileName.EndColumn);
                        updatedSourceLocations.Add(key.GetCurrentValue(), sourceLocationWithFileName);
                    }
                }

                this.UpdateSourceLocations(updatedSourceLocations);
                this.requiresUpdateSourceLocation = false;
            }
        }
        // get the minimum source location which contains this source location and is in the mapping store.
        private static SourceLocation GetExactLocation(SourceLocation approximateLocation, IDictionary<SourceLocation, ModelItem> mapping)
        {
            SourceLocation candidate = null;
            foreach (SourceLocation srcLocation in mapping.Keys)
            {
                // in the scope?
                if (srcLocation.Contains(approximateLocation))
                {
                    if (candidate != null)
                    {
                        // More approximate?
                        if (candidate.Contains(srcLocation))
                        {
                            candidate = srcLocation;
                        }
                    }
                    else
                    {
                        candidate = srcLocation;
                    }
                }
            }

            return candidate;
        }
 private ModelItem GetModelItemFromSourceLocation(SourceLocation sourceLocation)
 {
     return GetModelItemFromSourceLocation(sourceLocation, /* forceCreate = */ false);
 }
 // find a modelitem whose SourceLocation contains the srcLocation passed in.
 internal ModelItem FindModelItem(SourceLocation srcLocation)
 {
     this.EnsureUpdated();
     return FindModelItemInMap(srcLocation, this.sourceLocationToModelItemMapping);
 }
        private ModelItem GetModelItemFromSourceLocation(SourceLocation sourceLocation, bool forceCreate)
        {
            ModelItem modelItem = null;
            if (sourceLocation != null)
            {
                if (!this.sourceLocationToModelItem.TryGetValue(sourceLocation, out modelItem))
                {
                    if (forceCreate)
                    {
                        object foundElement = null;
                        foreach (KeyValuePair<object, SourceLocation> kvp in this.instanceToSourceLocationMapping)
                        {
                            if (kvp.Value.Equals(sourceLocation))
                            {
                                foundElement = kvp.Key;
                                break;
                            }
                        }

                        if (foundElement != null)
                        {
                            modelItem = Validation.ValidationService.FindModelItem(this.modelTreeManager, foundElement);
                            
                            if (modelItem != null)
                            {
                                this.modelItemToSourceLocation.Add(modelItem, sourceLocation);
                                this.sourceLocationToModelItem.Add(sourceLocation, modelItem);
                            }
                        }
                    }
                }
            }

            return modelItem;
        }
Esempio n. 27
0
 void Instrument(Activity activity, SourceLocation sourceLocation, string name)
 {
     Fx.Assert(activity != null, "activity can't be null");
     Fx.Assert(sourceLocation != null, "sourceLocation can't be null");
     if (this.states.ContainsKey(activity))
     {
         Trace.WriteLine(SR.DuplicateInstrumentation(activity.DisplayName));
     }
     else
     {
         State activityState = this.stateManager.DefineStateWithDebugInfo(sourceLocation, name);
         this.states.Add(activity, activityState);
     }
 }
        void ShowDebug(SourceLocation srcLoc)
        {
            this.Dispatcher.Invoke(DispatcherPriority.Render
                , (Action)(() =>
            {
                this.WorkflowDesigner.DebugManagerView.CurrentLocation = srcLoc;

            }));
        }
Esempio n. 29
0
 internal State DefineState(SourceLocation location, string name)
 {
     return DefineState(location, name, null, 0);
 }
 public ModelItem FindModelItemOfViewState(int startLine, int startColumn, int endLine, int endColumn)
 {
     SourceLocation sourceLocation = new SourceLocation(/* fileName = */ null, startLine, startColumn, endLine, endColumn);
     return designer.ObjectToSourceLocationMapping.FindModelItemOfViewState(sourceLocation);
 }
Esempio n. 31
0
 internal State DefineStateWithDebugInfo(SourceLocation location, string name)
 {
     return DefineState(location, name, debugInfoDescriptions, debugInfoDescriptions.Length);
 }
        private void OnValueNodeDeserialized(object value, DocumentRange attributeValueLocation)
        {
            int startLine = attributeValueLocation.Start.LineNumber.Value;
            int startColumn = attributeValueLocation.Start.LinePosition.Value;
            int endLine = attributeValueLocation.End.LineNumber.Value;
            int endColumn = attributeValueLocation.End.LinePosition.Value;
            // XamlDebuggerXmlReader has no idea what the filename is (it only knew a stream of data)
            // So we set FileName = null.

            // To enhance visual selection, endColumn + 1
            SourceLocation valueLocation = new SourceLocation(null, startLine, startColumn, endLine, endColumn + 1);
            this.NotifySourceLocationFound(value, valueLocation, isValueNode: true);
        }
Esempio n. 33
0
 // Declare a new state associated with the given source location.
 // States should have disjoint source locations. 
 // location is Source location associated with this state.
 // This returns a state object, which can be passed to EnterState.
 internal State DefineState(SourceLocation location)
 {
     return DefineState(location, string.Empty, null, 0);
 }
        private void NotifySourceLocationFound(object instance, SourceLocation currentLocation, bool isValueNode)
        {
            Argument argumentInstance = instance as Argument;

            // For Argument containing an IValueSerializable expression serializing as a ValueNode.
            // We associate the SourceLocation to the expression instead of the Argument.
            // For example, when we have <WriteLine Text="[abc]" />, Then the SourceLocation found for the InArgument object 
            // is associated with the VisualBasicValue object instead.
            if (argumentInstance != null && argumentInstance.Expression is IValueSerializableExpression && isValueNode)
            {
                instance = argumentInstance.Expression;
            }
            if (this._sourceLocationFound != null)
            {
                this._sourceLocationFound(this, new SourceLocationFoundEventArgs(instance, currentLocation, isValueNode));
            }
        }