59
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
1 Imports System.Diagnostics
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
2 Imports System.Collections.ObjectModel
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
3 Imports System.ComponentModel
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
4
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
5 Public Class GlimpseService
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
6
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
7 #Region " Declarations "
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
8
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
9 Private Shared _instance As GlimpseService
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
10 Private _objGlimpseWindow As ChildWindow
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
11 Private _objHostExceptions As New ObservableCollection(Of ExceptionWrapper)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
12 Private _strHostApplicationName As String = String.Empty
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
13 Private WithEvents _objApp As Application
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
14 Private WithEvents _objRootVisual As FrameworkElement
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
15
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
16 #End Region
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
17
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
18 #Region " Properties "
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
19
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
20 Public Shared ReadOnly Property CreateInstance() As GlimpseService
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
21 Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
22
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
23 If _instance Is Nothing Then
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
24 _instance = New GlimpseService
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
25 End If
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
26
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
27 Return _instance
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
28 End Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
29 End Property
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
30
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
31 Friend Property App() As Application
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
32 Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
33 Return _objApp
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
34 End Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
35 Set(ByVal Value As Application)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
36 _objApp = Value
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
37 End Set
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
38 End Property
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
39
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
40 Friend Property GlimpseWindow() As ChildWindow
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
41 Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
42 Return _objGlimpseWindow
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
43 End Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
44
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
45 Private Set(ByVal Value As ChildWindow)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
46 _objGlimpseWindow = Value
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
47 End Set
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
48 End Property
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
49
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
50 Friend Property HostApplicationName() As String
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
51 Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
52 Return _strHostApplicationName
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
53 End Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
54 Set(ByVal Value As String)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
55 _strHostApplicationName = Value
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
56 End Set
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
57 End Property
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
58
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
59 Friend ReadOnly Property HostExceptions() As ObservableCollection(Of ExceptionWrapper)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
60 Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
61 Return _objHostExceptions
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
62 End Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
63 End Property
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
64
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
65 Friend Property RootVisual() As FrameworkElement
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
66 Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
67 Return _objRootVisual
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
68 End Get
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
69 Set(ByVal Value As FrameworkElement)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
70 _objRootVisual = Value
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
71 End Set
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
72 End Property
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
73
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
74 #End Region
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
75
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
76 #Region " Creation and Loading "
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
77
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
78 Public Sub DisplayLoadFailure(ByVal objApp As Application, ByVal ex As Exception, ByVal strHostApplicationName As String)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
79 Debug.WriteLine(String.Format("{0} had exception. {1}", Me.HostApplicationName, ex.ToString))
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
80 _objApp = objApp
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
81 _objApp.RootVisual = New LoadExceptionViewer(ex, strHostApplicationName)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
82 End Sub
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
83
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
84 Public Sub Load(ByVal objApp As Application, ByVal strHostApplicationName As String)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
85 Me.App = objApp
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
86 Me.RootVisual = TryCast(objApp.RootVisual, FrameworkElement)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
87 Me.HostApplicationName = strHostApplicationName
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
88
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
89 Dim fw As New ChildWindow
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
90 fw.Title = Me.HostApplicationName
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
91 fw.Content = New GlimpseViewer
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
92 fw.Show()
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
93
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
94 'If Double.IsNaN(Me.RootVisual.Width) Then
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
95 ' 'if the host control is autosized (consumes the browser window) then locate Glimpse in the top, left
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
96 ' fw.Show()
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
97 'Else
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
98 ' 'if the host is fixed size then attempt to locate the popup control in the upper right corner
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
99 ' Dim dblLeft As Double = Me.RootVisual.Width - 200
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
100
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
101 ' If dblLeft < 0 Then
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
102 ' dblLeft = 0
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
103 ' End If
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
104
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
105 ' fw.Show()
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
106 'End If
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
107
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
108 End Sub
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
109
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
110 Private Sub New()
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
111 End Sub
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
112
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
113 #End Region
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
114
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
115 #Region " Host Application Events "
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
116
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
117 Private Sub _objHostRootVisual_BindingValidationError(ByVal sender As Object, ByVal e As System.Windows.Controls.ValidationErrorEventArgs) Handles _objRootVisual.BindingValidationError
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
118
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
119 Dim strControlName As String = "(none)"
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
120 Dim objControl As Control = TryCast(e.OriginalSource, Control)
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
121
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
122 If objControl IsNot Nothing AndAlso Not String.IsNullOrEmpty(objControl.Name) Then
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
123 strControlName = objControl.Name
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
124 End If
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
125
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
126 Dim ex As Exception = e.Error.Exception
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
127
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
128 While ex IsNot Nothing
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
129 Me.HostExceptions.Add(New ExceptionWrapper(e.Action, strControlName, e.Error.Exception))
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
130 ex = ex.InnerException
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
131 End While
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
132
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
133 End Sub
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
134
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
135 Private Sub Application_UnhandledException(ByVal sender As Object, ByVal e As ApplicationUnhandledExceptionEventArgs) Handles _objApp.UnhandledException
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
136 Debug.WriteLine(String.Format("{0} had exception. {1}", Me.HostApplicationName, e.ExceptionObject.ToString))
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
137
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
138 Dim ex As Exception = e.ExceptionObject
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
139
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
140 While ex IsNot Nothing
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
141 Me.HostExceptions.Add(New ExceptionWrapper(ex))
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
142 ex = ex.InnerException
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
143 End While
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
144
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
145 e.Handled = True
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
146 End Sub
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
147
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
148 #End Region
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
149
|
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff
changeset
|
150 End Class
|