de7ac273d96f60de82835029982b362166d2caf3
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / WorkflowDesigner.Debugger.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation
6 {
7     using System;
8     using System.Activities.Debugger.Symbol;
9     using System.Activities.Presentation.Debug;
10     using System.Activities.Presentation.Model;
11     using System.Activities.Presentation.Xaml;
12     using System.Runtime;
13     using System.Xaml;
14
15     public partial class WorkflowDesigner
16     {
17         public IDesignerDebugView DebugManagerView
18         {
19             get
20             {
21                 return this.DebuggerService;
22             }
23         }
24
25         DebuggerService DebuggerService
26         {
27             get
28             {
29                 if (this.debuggerService == null)
30                 {
31                     this.debuggerService = new DebuggerService(this.context);
32                     this.context.Services.Publish<IDesignerDebugView>(this.debuggerService);
33                 }
34                 return this.debuggerService;
35             }
36         }
37
38         ModelSearchServiceImpl ModelSearchService
39         {
40             get;
41             set;
42         }
43
44         internal ObjectToSourceLocationMapping ObjectToSourceLocationMapping
45         {
46             get
47             {
48                 if (this.objectToSourceLocationMapping == null)
49                 {
50                     this.objectToSourceLocationMapping = new ObjectToSourceLocationMapping(this.ModelSearchService);
51                 }
52                 return this.objectToSourceLocationMapping;
53             }
54         }
55
56         // Get the attached workflow symbol and remove it from the root.
57         WorkflowSymbol GetAttachedWorkflowSymbol()
58         {
59             object rootInstance = this.GetRootInstance();
60             WorkflowSymbol wfSymbol = null;
61
62             if (rootInstance != null)
63             {
64                 Activity documentRootElement = GetRootWorkflowElement(rootInstance);
65                 if (documentRootElement != null)
66                 {
67                     string symbolString;
68                     if (AttachablePropertyServices.TryGetProperty<string>(documentRootElement, DebugSymbol.SymbolName, out symbolString))
69                     {
70                         try
71                         {
72                             wfSymbol = WorkflowSymbol.Decode(symbolString);
73                             // Change the name to the currently loaded file.
74                             wfSymbol.FileName = this.Context.Items.GetValue<WorkflowFileItem>().LoadedFile;
75                         }
76                         catch (Exception ex)
77                         {
78                             if (Fx.IsFatal(ex))
79                             {
80                                 throw;
81                             }
82                         }
83                         finally
84                         {
85                             AttachablePropertyServices.RemoveProperty(documentRootElement, DebugSymbol.SymbolName);
86                         }
87                     }
88                 }
89             }
90             return wfSymbol;
91         }
92     }
93 }