1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation
8 using System.Activities.Debugger;
9 using System.Activities.Debugger.Symbol;
10 using System.Activities.Presentation.View;
11 using System.Activities.Presentation.Xaml;
12 using System.Activities.XamlIntegration;
13 using System.Collections.Generic;
14 using System.Diagnostics.CodeAnalysis;
17 using System.Runtime.Versioning;
20 using Microsoft.Activities.Presentation.Xaml;
22 public partial class WorkflowDesigner : IWorkflowDesignerXamlHelperExecutionContext
24 FrameworkName IWorkflowDesignerXamlHelperExecutionContext.FrameworkName
26 get { return WorkflowDesigner.GetTargetFramework(this.context); }
29 WorkflowDesignerXamlSchemaContext IWorkflowDesignerXamlHelperExecutionContext.XamlSchemaContext
31 get { return this.XamlSchemaContext; }
34 ViewStateIdManager IWorkflowDesignerXamlHelperExecutionContext.IdManager
36 get { return this.idManager; }
39 WorkflowSymbol IWorkflowDesignerXamlHelperExecutionContext.LastWorkflowSymbol
41 get { return this.lastWorkflowSymbol; }
42 set { this.lastWorkflowSymbol = value; }
45 void IWorkflowDesignerXamlHelperExecutionContext.OnSerializationCompleted(Dictionary<object, object> sourceLocationObjectToModelItemObjectMapping)
47 this.ObjectToSourceLocationMapping.SourceLocationObjectToModelItemObjectMapping = sourceLocationObjectToModelItemObjectMapping;
48 this.ObjectReferenceService.OnSaveCompleted();
51 void IWorkflowDesignerXamlHelperExecutionContext.OnBeforeDeserialize()
53 this.ObjectToSourceLocationMapping.Clear();
56 void IWorkflowDesignerXamlHelperExecutionContext.OnSourceLocationFound(object target, SourceLocation sourceLocationFound)
58 this.ObjectToSourceLocationMapping.UpdateMap(target, sourceLocationFound);
61 void IWorkflowDesignerXamlHelperExecutionContext.OnAfterDeserialize(Dictionary<string, SourceLocation> viewStateDataSourceLocationMapping)
63 this.ObjectToSourceLocationMapping.ViewStateDataSourceLocationMapping = viewStateDataSourceLocationMapping;
66 string IWorkflowDesignerXamlHelperExecutionContext.LocalAssemblyName
68 get { return this.GetLocalAssemblyName(); }
71 WorkflowDesignerXamlSchemaContext XamlSchemaContext
75 if (this.workflowDesignerXamlSchemaContext == null)
77 this.workflowDesignerXamlSchemaContext = new WorkflowDesignerXamlSchemaContext(this.GetLocalAssemblyName(), this.Context);
80 return this.workflowDesignerXamlSchemaContext;
84 internal object DeserializeString(string text)
86 return new WorkflowDesignerXamlHelper(this).DeserializeString(text);
89 internal object DeserializeString(string text, out IList<XamlLoadErrorInfo> loadErrors, out Dictionary<object, SourceLocation> sourceLocations)
91 return new WorkflowDesignerXamlHelper(this).DeserializeString(text, out loadErrors, out sourceLocations);
94 internal string SerializeToString(object obj, string fileName = null)
96 return new WorkflowDesignerXamlHelper(this).SerializeToString(obj, fileName);
99 [SuppressMessage(FxCop.Category.Design, FxCop.Rule.DoNotCatchGeneralExceptionTypes,
100 Justification = "Serializer might throw if it fails to serialize. Catching all exceptions to avoid VS Crash.")]
101 [SuppressMessage("Reliability", "Reliability108",
102 Justification = "Serializer might throw if it fails to serialize. Catching all exceptions to avoid VS crash.")]
103 void WriteModelToText(string fileName)
105 this.perfEventProvider.WorkflowDesignerSerializeStart();
106 object rootModelObject = this.modelTreeManager.Root.GetCurrentValue();
107 // if we are serializing a activity schema type, remove the namespace in the Name property.
108 ActivityBuilder activityBuilderType = rootModelObject as ActivityBuilder;
110 // now try to serialize
113 string newText = SerializeToString(rootModelObject, fileName);
114 if (string.IsNullOrEmpty(this.Text) ||
115 (this.isModelChanged && !string.Equals(newText, this.Text, StringComparison.Ordinal)))
118 if (this.TextChanged != null)
120 this.TextChanged.Invoke(this, null);
123 this.isModelChanged = false;
127 this.Context.Items.SetValue(new ErrorItem() { Message = e.Message, Details = e.ToString() });
129 this.perfEventProvider.WorkflowDesignerSerializeEnd();
132 void RaiseLoadError(Exception e)
134 if (this.xamlLoadErrorService != null)
136 XamlLoadErrorInfo errorInfo = null;
137 XamlException xamlEx = e as XamlException;
140 errorInfo = new XamlLoadErrorInfo(xamlEx.Message, xamlEx.LineNumber, xamlEx.LinePosition);
144 XmlException xmlEx = e as XmlException;
147 errorInfo = new XamlLoadErrorInfo(xmlEx.Message, xmlEx.LineNumber, xmlEx.LinePosition);
150 if (errorInfo != null)
152 var errors = new XamlLoadErrorInfo[] { errorInfo };
153 xamlLoadErrorService.ShowXamlLoadErrors(errors);
158 void RaiseLoadErrors(IList<XamlLoadErrorInfo> loadErrors)
160 if (this.xamlLoadErrorService != null)
162 this.xamlLoadErrorService.ShowXamlLoadErrors(loadErrors);