Ejemplo n.º 1
0
        private static void ConvertNamespaces(object root, EditingContext context)
        {
            VisualBasicSettings       settings = VisualBasic.GetSettings(root);
            IList <AssemblyReference> references;
            IList <string>            importedNamespaces = NamespaceHelper.GetTextExpressionNamespaces(root, out references);
            FrameworkName             targetFramework    = WorkflowDesigner.GetTargetFramework(context);

            if (targetFramework.IsLessThan45())
            {
                if (settings == null)
                {
                    if ((importedNamespaces != null) && (importedNamespaces.Count > 0))
                    {
                        NamespaceHelper.ConvertToVBSettings(
                            importedNamespaces,
                            references,
                            context,
                            out settings);
                    }
                    else
                    {
                        settings = new VisualBasicSettings();
                    }

                    NamespaceHelper.SetVisualBasicSettings(root, settings);
                    NamespaceHelper.SetTextExpressionNamespaces(root, null, null);
                }

                IDebuggableWorkflowTree debuggableWorkflowTree = root as IDebuggableWorkflowTree;
                if (debuggableWorkflowTree != null)
                {
                    Activity rootActivity = debuggableWorkflowTree.GetWorkflowRoot();
                    if (rootActivity != null)
                    {
                        NamespaceHelper.SetVisualBasicSettings(rootActivity, settings);
                        NamespaceHelper.SetTextExpressionNamespaces(rootActivity, null, null);
                    }
                }
            }
            else
            {
                if ((importedNamespaces == null) || (importedNamespaces.Count == 0))
                {
                    if (settings != null)
                    {
                        NamespaceHelper.ConvertToTextExpressionImports(settings, out importedNamespaces, out references);
                        NamespaceHelper.SetTextExpressionNamespaces(root, importedNamespaces, references);
                        NamespaceHelper.SetVisualBasicSettings(root, null);
                    }
                    else
                    {
                        NamespaceHelper.SetTextExpressionNamespaces(root, new Collection <string>(), new Collection <AssemblyReference>());
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static Activity GetRootWorkflowElement(object rootModelObject)
        {
            Activity rootWorkflowElement;
            IDebuggableWorkflowTree debuggableWorkflowTree = rootModelObject as IDebuggableWorkflowTree;

            if (debuggableWorkflowTree != null)
            {
                rootWorkflowElement = debuggableWorkflowTree.GetWorkflowRoot();
            }
            else // Loose xaml case.
            {
                rootWorkflowElement = rootModelObject as Activity;
            }
            return(rootWorkflowElement);
        }
        // Get root WorkflowElement.  Currently only handle when the object is ActivitySchemaType or WorkflowElement.
        // May return null if it does not know how to get the root activity.
        Activity GetRootWorkflowElement(object rootModelObject)
        {
            System.Diagnostics.Debug.Assert(rootModelObject != null, "Cannot pass null as rootModelObject");

            Activity rootWorkflowElement;
            IDebuggableWorkflowTree debuggableWorkflowTree = rootModelObject as IDebuggableWorkflowTree;

            if (debuggableWorkflowTree != null)
            {
                rootWorkflowElement = debuggableWorkflowTree.GetWorkflowRoot();
            }
            else // Loose xaml case.
            {
                rootWorkflowElement = rootModelObject as Activity;
            }
            return(rootWorkflowElement);
        }
        // Get root Activity. Currently only handle when the object is ActivityBuilder or Activity.
        // May return null if it does not know how to get the root activity.
        internal static Activity GetRootWorkflowElement(object rootModelObject)
        {
            SharedFx.Assert(rootModelObject != null, "Cannot pass null as rootModelObject");
            Activity rootWorkflowElement;
            IDebuggableWorkflowTree debuggableWorkflowTree = rootModelObject as IDebuggableWorkflowTree;

            if (debuggableWorkflowTree != null)
            {
                rootWorkflowElement = debuggableWorkflowTree.GetWorkflowRoot();
            }
            else
            {
                // Loose xaml case.
                rootWorkflowElement = rootModelObject as Activity;
            }

            return(rootWorkflowElement);
        }
        private Activity GetRootWorkflowElement(object rootModelObject)
        {
            // Get root WorkflowElement.  Currently only handle when the object is ActivitySchemaType or WorkflowElement.
            // May return null if it does not know how to get the root activity.
            Debug.Assert(rootModelObject != null, "Cannot pass null as rootModelObject");

            Activity rootWorkflowElement;
            IDebuggableWorkflowTree debuggableWorkflowTree = rootModelObject as IDebuggableWorkflowTree;

            if (debuggableWorkflowTree != null)
            {
                rootWorkflowElement = debuggableWorkflowTree.GetWorkflowRoot();
            }
            else
            {
                // Loose xaml case.
                rootWorkflowElement = rootModelObject as Activity;
            }

            return(rootWorkflowElement);
        }
Ejemplo n.º 6
0
        static void OnRootPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            ModelItem rootModel = sender as ModelItem;

            Fx.Assert(rootModel != null, "sender item could not be null");
            ModelProperty changedProperty = rootModel.Properties[e.PropertyName];

            if (changedProperty == null)
            {
                return;
            }

            object changedPropertyValue = changedProperty.ComputedValue;

            if (changedPropertyValue == null)
            {
                return;
            }

            Fx.Assert(rootModel.GetCurrentValue().GetType() == WorkflowServiceType, "This handler should only be attached when the root is WorkflowService");
            IDebuggableWorkflowTree root = rootModel.GetCurrentValue() as IDebuggableWorkflowTree;
            Activity rootActivity        = root.GetWorkflowRoot();

            if (rootActivity == changedPropertyValue)
            {
                if (WorkflowDesigner.GetTargetFramework(rootModel.GetEditingContext()).IsLessThan45())
                {
                    VisualBasicSettings settings = VisualBasic.GetSettings(root);
                    NamespaceHelper.SetVisualBasicSettings(changedPropertyValue, settings);
                }
                else
                {
                    IList <AssemblyReference> referencedAssemblies;
                    IList <string>            namespaces = NamespaceHelper.GetTextExpressionNamespaces(root, out referencedAssemblies);
                    NamespaceHelper.SetTextExpressionNamespaces(rootActivity, namespaces, referencedAssemblies);
                }
            }
        }
Ejemplo n.º 7
0
        // Get root WorkflowElement.  Currently only handle when the object is ActivitySchemaType or WorkflowElement.
        // May return null if it does not know how to get the root activity.
        Activity GetRootWorkflowElement(object rootModelObject)
        {
            Activity rootWorkflowElement = null;

            try
            {
                System.Diagnostics.Debug.Assert(rootModelObject != null, "Cannot pass null as rootModelObject");
                IDebuggableWorkflowTree debuggableWorkflowTree = rootModelObject as IDebuggableWorkflowTree;
                if (debuggableWorkflowTree != null)
                {
                    rootWorkflowElement = debuggableWorkflowTree.GetWorkflowRoot();
                }
                else // Loose xaml case.
                {
                    rootWorkflowElement = rootModelObject as Activity;
                }
            }
            catch (Exception ex)
            {
                Log.Logger.LogData(ex.Message, LogLevel.Error);
            }

            return(rootWorkflowElement);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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));
        }