public override void Read(XamlDebuggerXmlReader reader)
            {
                if (!base.UnderlyingReaderRead(reader))
                {
                    reader.current = null;
                }
                else
                {
                    reader.current = reader.underlyingReader.Current;
                    if (XamlDebuggerXmlReader.DebuggableNode(reader.current))
                    {
                        switch (reader.Current.NodeType)
                        {
                        case XamlNodeType.StartObject:
                            reader.records.Push(reader.Current);
                            return;

                        case XamlNodeType.GetObject:
                            return;

                        case XamlNodeType.EndObject:
                            reader.PrepareLineInfo();
                            reader.state = XamlDebuggerXmlReader.InAttachingLineInfoState.Instance;
                            return;
                        }
                    }
                }
            }
 public override void Read(XamlDebuggerXmlReader reader)
 {
     if (reader.lineInfoStateStack.Count == 0)
     {
         reader.state = XamlDebuggerXmlReader.InReaderState.Instance;
     }
 }
Beispiel #3
0
        private void CollectSubRoot(Activity activity)
        {
            string fileName = XamlDebuggerXmlReader.GetFileName(activity) as string;

            if (!string.IsNullOrEmpty(fileName))
            {
                this.uninstrumentedSubRoots.Add(activity, fileName);
            }
        }
Beispiel #4
0
        internal static object Deserialize(byte[] buffer, Assembly localAssembly)
        {
            using var memoryStream                  = new MemoryStream(buffer);
            using TextReader streamReader           = new StreamReader(memoryStream);
            using var xamlDebuggerReader            = new XamlDebuggerXmlReader(streamReader, new XamlSchemaContext(), localAssembly);
            xamlDebuggerReader.SourceLocationFound += XamlDebuggerXmlReader.SetSourceLocation;

            using var activityBuilderReader = ActivityXamlServices.CreateBuilderReader(xamlDebuggerReader);
            return(XamlServices.Load(activityBuilderReader));
        }
        // Collect subroot as uninstrumented activity.
        void CollectSubRoot(Activity activity)
        {
            string wfSymbol = DebugSymbol.GetSymbol(activity) as string;

            if (!string.IsNullOrEmpty(wfSymbol))
            {
                this.uninstrumentedSubRoots.Add(activity, wfSymbol);
            }
            else
            {
                string sourcePath = XamlDebuggerXmlReader.GetFileName(activity) as string;
                if (!string.IsNullOrEmpty(sourcePath))
                {
                    this.uninstrumentedSubRoots.Add(activity, sourcePath);
                }
            }
        }
Beispiel #6
0
        private static object Deserialize(byte[] buffer, Assembly localAssembly)
        {
            object obj2;

            using (XmlReader reader = XmlReader.Create(new MemoryStream(buffer)))
            {
                XamlXmlReaderSettings settings = new XamlXmlReaderSettings {
                    LocalAssembly   = localAssembly,
                    ProvideLineInfo = true
                };
                using (XamlXmlReader reader2 = new XamlXmlReader(reader, settings))
                {
                    using (XamlDebuggerXmlReader reader3 = new XamlDebuggerXmlReader(reader2, new StreamReader(new MemoryStream(buffer))))
                    {
                        using (XamlReader reader4 = ActivityXamlServices.CreateBuilderReader(reader3))
                        {
                            obj2 = XamlServices.Load(reader4);
                        }
                    }
                }
            }
            return(obj2);
        }
Beispiel #7
0
        internal static void SetSourceLocation(object sender, SourceLocationFoundEventArgs args)
        {
            object target                    = args.Target;
            Type   targetType                = target.GetType();
            XamlDebuggerXmlReader reader     = (XamlDebuggerXmlReader)sender;
            bool shouldStoreAttachedProperty = false;

            if (reader.CollectNonActivitySourceLocation)
            {
                shouldStoreAttachedProperty = !targetType.Equals(typeof(string));
            }
            else
            {
                if (typeof(Activity).IsAssignableFrom(targetType))
                {
                    if (!typeof(IExpressionContainer).IsAssignableFrom(targetType))
                    {
                        if (!typeof(IValueSerializableExpression).IsAssignableFrom(targetType))
                        {
                            shouldStoreAttachedProperty = true;
                        }
                    }
                }
            }

            shouldStoreAttachedProperty = shouldStoreAttachedProperty && !args.IsValueNode;

            if (shouldStoreAttachedProperty)
            {
                SourceLocation sourceLocation = args.SourceLocation;
                XamlDebuggerXmlReader.SetStartLine(target, sourceLocation.StartLine);
                XamlDebuggerXmlReader.SetStartColumn(target, sourceLocation.StartColumn);
                XamlDebuggerXmlReader.SetEndLine(target, sourceLocation.EndLine);
                XamlDebuggerXmlReader.SetEndColumn(target, sourceLocation.EndColumn);
            }
        }
Beispiel #8
0
 internal XamlSourceLocationCollector(XamlDebuggerXmlReader parent)
 {
     this.parent = parent;
     objRgnToInitValueRgnMapping = new Dictionary <DocumentRange, DocumentRange>();
 }
 protected bool UnderlyingReaderRead(XamlDebuggerXmlReader reader)
 {
     return(reader.underlyingReader.Read());
 }
 public abstract void Read(XamlDebuggerXmlReader reader);
 public abstract System.Activities.Debugger.XamlNode GetCurrent(XamlDebuggerXmlReader reader);
        internal static object Deserialize(byte[] buffer, Assembly localAssembly)
        {
            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                using (TextReader streamReader = new StreamReader(memoryStream))
                {
                    using (XamlDebuggerXmlReader xamlDebuggerReader = new XamlDebuggerXmlReader(streamReader, new XamlSchemaContext(), localAssembly))
                    {
                        xamlDebuggerReader.SourceLocationFound += XamlDebuggerXmlReader.SetSourceLocation;

                        using (XamlReader activityBuilderReader = ActivityXamlServices.CreateBuilderReader(xamlDebuggerReader))
                        {
                            return XamlServices.Load(activityBuilderReader);
                        }
                    }
                }
            }
        }
Beispiel #13
0
        internal static Dictionary <object, SourceLocation> GetSourceLocations(Activity rootActivity, out string sourcePath, out bool isTemporaryFile)
        {
            sourcePath      = XamlDebuggerXmlReader.GetFileName(rootActivity) as string;
            isTemporaryFile = false;
            Assembly localAssembly = rootActivity.GetType().Assembly;

            if (rootActivity.Parent != null)
            {
                localAssembly = rootActivity.Parent.GetType().Assembly;
            }
            if ((rootActivity.Children != null) && (rootActivity.Children.Count > 0))
            {
                Activity instance = rootActivity.Children[0];
                string   fileName = XamlDebuggerXmlReader.GetFileName(instance) as string;
                if (!string.IsNullOrEmpty(fileName))
                {
                    rootActivity = instance;
                    sourcePath   = fileName;
                }
            }
            if (!string.IsNullOrEmpty(sourcePath))
            {
                SourceLocation location;
                Activity       workflowRoot;
                if (TryGetSourceLocation(rootActivity, sourcePath, out location))
                {
                    workflowRoot = rootActivity;
                }
                else
                {
                    FileInfo info   = new FileInfo(sourcePath);
                    byte[]   buffer = new byte[info.Length];
                    using (FileStream stream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
                    {
                        stream.Read(buffer, 0, buffer.Length);
                    }
                    object obj2 = Deserialize(buffer, localAssembly);
                    IDebuggableWorkflowTree tree = obj2 as IDebuggableWorkflowTree;
                    if (tree != null)
                    {
                        workflowRoot = tree.GetWorkflowRoot();
                    }
                    else
                    {
                        workflowRoot = obj2 as Activity;
                    }
                }
                Dictionary <object, SourceLocation> mapping = new Dictionary <object, SourceLocation>();
                if (workflowRoot != null)
                {
                    CollectMapping(rootActivity, workflowRoot, mapping, sourcePath);
                }
                return(mapping);
            }
            string tempFileName = Path.GetTempFileName();

            sourcePath = Path.ChangeExtension(tempFileName, ".xaml");
            File.Move(tempFileName, sourcePath);
            isTemporaryFile = true;
            return(PublishAndCollectMapping(rootActivity, sourcePath));
        }
 public override System.Activities.Debugger.XamlNode GetCurrent(XamlDebuggerXmlReader reader)
 {
     return(reader.lineInfoStateStack.Pop());
 }
 internal ValueNodeXamlMemberInvoker(XamlDebuggerXmlReader parent, XamlMemberInvoker wrapped, DocumentRange attributeValueRange)
 {
     this.parent = parent;
     this.wrapped = wrapped;
     this.attributeValueRange = attributeValueRange;
 }
 internal XamlSourceLocationCollector(XamlDebuggerXmlReader parent)
 {
     this.parent = parent;
     objRgnToInitValueRgnMapping = new Dictionary<DocumentRange, DocumentRange>();
 }
 private static object Deserialize(byte[] buffer, Assembly localAssembly)
 {
     object obj2;
     using (XmlReader reader = XmlReader.Create(new MemoryStream(buffer)))
     {
         XamlXmlReaderSettings settings = new XamlXmlReaderSettings {
             LocalAssembly = localAssembly,
             ProvideLineInfo = true
         };
         using (XamlXmlReader reader2 = new XamlXmlReader(reader, settings))
         {
             using (XamlDebuggerXmlReader reader3 = new XamlDebuggerXmlReader(reader2, new StreamReader(new MemoryStream(buffer))))
             {
                 using (XamlReader reader4 = ActivityXamlServices.CreateBuilderReader(reader3))
                 {
                     obj2 = XamlServices.Load(reader4);
                 }
             }
         }
     }
     return obj2;
 }
Beispiel #18
0
 internal ValueNodeXamlMemberInvoker(XamlDebuggerXmlReader parent, XamlMemberInvoker wrapped, DocumentRange attributeValueRange)
 {
     this.parent              = parent;
     this.wrapped             = wrapped;
     this.attributeValueRange = attributeValueRange;
 }
Beispiel #19
0
        static internal Dictionary <object, SourceLocation> GetSourceLocations(Activity rootActivity, out string sourcePath, out bool isTemporaryFile, out byte[] checksum)
        {
            isTemporaryFile = false;
            checksum        = null;
            string symbolString = DebugSymbol.GetSymbol(rootActivity) as String;

            if (string.IsNullOrEmpty(symbolString) && rootActivity.Children != null && rootActivity.Children.Count > 0)
            { // In case of actual root is wrapped either in x:Class activity or CorrelationScope
                Activity body             = rootActivity.Children[0];
                string   bodySymbolString = DebugSymbol.GetSymbol(body) as String;
                if (!string.IsNullOrEmpty(bodySymbolString))
                {
                    rootActivity = body;
                    symbolString = bodySymbolString;
                }
            }

            if (!string.IsNullOrEmpty(symbolString))
            {
                try
                {
                    WorkflowSymbol wfSymbol = WorkflowSymbol.Decode(symbolString);
                    if (wfSymbol != null)
                    {
                        sourcePath = wfSymbol.FileName;
                        checksum   = wfSymbol.GetChecksum();
                        // rootActivity is the activity with the attached symbol string.
                        // rootActivity.RootActivity is the workflow root activity.
                        // if they are not the same, then it must be compiled XAML, because loose XAML (i.e. XAMLX) always have the symbol attached at the root.
                        if (rootActivity.RootActivity != rootActivity)
                        {
                            Fx.Assert(rootActivity.Parent != null, "Compiled XAML implementation always have a parent.");
                            rootActivity = rootActivity.Parent;
                        }
                        return(GetSourceLocations(rootActivity, wfSymbol, translateInternalActivityToOrigin: false));
                    }
                }
                catch (SerializationException)
                {
                    // Ignore invalid symbol.
                }
            }

            sourcePath = XamlDebuggerXmlReader.GetFileName(rootActivity) as string;
            Dictionary <object, SourceLocation> mapping;
            Assembly localAssembly;

            //bool permissionRevertNeeded = false;

            // This may not be the local assembly since it may not be the real root for x:Class
            localAssembly = rootActivity.GetType().Assembly;

            if (rootActivity.Parent != null)
            {
                localAssembly = rootActivity.Parent.GetType().Assembly;
            }

            if (rootActivity.Children != null && rootActivity.Children.Count > 0)
            { // In case of actual root is wrapped either in x:Class activity or CorrelationScope
                Activity body           = rootActivity.Children[0];
                string   bodySourcePath = XamlDebuggerXmlReader.GetFileName(body) as string;
                if (!string.IsNullOrEmpty(bodySourcePath))
                {
                    rootActivity = body;
                    sourcePath   = bodySourcePath;
                }
            }

            try
            {
                Fx.Assert(!string.IsNullOrEmpty(sourcePath), "If sourcePath is null, it should have been short-circuited before reaching here.");

                SourceLocation tempSourceLocation;
                Activity       tempRootActivity;

                checksum = SymbolHelper.CalculateChecksum(sourcePath);

                if (TryGetSourceLocation(rootActivity, sourcePath, checksum, out tempSourceLocation)) // already has source location.
                {
                    tempRootActivity = rootActivity;
                }
                else
                {
                    byte[] buffer;

#if NET45
                    // Need to store the file in memory temporary so don't have to re-read the file twice
                    // for XamlDebugXmlReader's BracketLocator.
                    // If there is a debugger attached, Assert FileIOPermission for Read access to the specific file.
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        permissionRevertNeeded = true;
                        FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Read, sourcePath);
                        permission.Assert();
                    }
#endif

                    try
                    {
                        FileInfo fi = new FileInfo(sourcePath);
                        buffer = new byte[fi.Length];

                        using (FileStream fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
                        {
                            fs.Read(buffer, 0, buffer.Length);
                        }
                    }
                    finally
                    {
#if NET45
                        // If we Asserted FileIOPermission, revert it.
                        if (permissionRevertNeeded)
                        {
                            CodeAccessPermission.RevertAssert();
                            permissionRevertNeeded = false;
                        }
#endif
                    }

                    object deserializedObject = Deserialize(buffer, localAssembly);
                    IDebuggableWorkflowTree debuggableWorkflowTree = deserializedObject as IDebuggableWorkflowTree;
                    if (debuggableWorkflowTree != null)
                    { // Declarative Service and x:Class case
                        tempRootActivity = debuggableWorkflowTree.GetWorkflowRoot();
                    }
                    else
                    { // Loose XAML case.
                        tempRootActivity = deserializedObject as Activity;
                    }

                    Fx.Assert(tempRootActivity != null, "Unexpected workflow xaml file");
                }

                mapping = new Dictionary <object, SourceLocation>();
                if (tempRootActivity != null)
                {
                    CollectMapping(rootActivity, tempRootActivity, mapping, sourcePath, checksum);
                }
            }
            catch (Exception)
            {
                //// Only eat the exception if we were running in partial trust.
                //if (!PartialTrustHelpers.AppDomainFullyTrusted)
                //{
                //    // Eat the exception and return an empty dictionary.
                //    return new Dictionary<object, SourceLocation>();
                //}
                //else
                //{
                throw;
                //}
            }

            return(mapping);
        }
 public override System.Activities.Debugger.XamlNode GetCurrent(XamlDebuggerXmlReader reader)
 {
     return(reader.underlyingReader.Current);
 }