Skip to content

Commit 36c0a9e

Browse files
committed
Updated procedures and structure
1 parent 137c76e commit 36c0a9e

File tree

11 files changed

+824
-381
lines changed

11 files changed

+824
-381
lines changed

VB/My Project/Settings.Designer.vb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VB/My Project/Settings.settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<Value Profile="(Default)">OperatingSystem</Value>
3434
</Setting>
3535
<Setting Name="Rdg_LdapPath" Type="System.String" Scope="User">
36-
<Value Profile="(Default)">LDAP://OU=Servers,</Value>
36+
<Value Profile="(Default)">LDAP://OU=Servers,OU=FT,DC=federationtraining,DC=edu,DC=au</Value>
3737
</Setting>
3838
<Setting Name="Rdg_LdapQry" Type="System.String" Scope="User">
3939
<Value Profile="(Default)">SELECT whenCreated, whenChanged, distinguishedName, OperatingSystem, OperatingSystemVersion, dNSHostname, Name, CN FROM '[Rdg.LdapPath]' WHERE objectClass = 'computer'</Value>

VB/Ribbon.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
id="btnPing"
3737
label="Ping"
3838
size="large"
39-
onAction="addPingColumn"
39+
onAction="OnAction"
4040
getImage="GetButtonImage"
4141
screentip="This will ping the visible servers in the selected data table."
4242
/>
@@ -47,7 +47,7 @@
4747
id="cboServerName"
4848
label="Server: "
4949
onChange="OnChange"
50-
getText="GetText"
50+
getText="GetLabelText"
5151
getItemCount="GetItemCount"
5252
getItemLabel="GetItemLabel"
5353
sizeString= "XXXXXXXXXXXXXXXXXXXX"
@@ -57,7 +57,7 @@
5757
id="cboPingName"
5858
label="Ping: "
5959
onChange="OnChange"
60-
getText="GetText"
60+
getText="GetLabelText"
6161
getItemCount="GetItemCount"
6262
getItemLabel="GetItemLabel"
6363
sizeString= "XXXXXXXXXXXXXXXXXXXX"
@@ -73,7 +73,7 @@
7373
id="btnCreateRdgFile"
7474
label="Create File"
7575
size="large"
76-
onAction="CreateRdgFile"
76+
onAction="OnAction"
7777
getImage="GetButtonImage"
7878
screentip="Create A Remote Desktop Manager File"
7979
supertip="This creates a Remote Desktop Manager file from the active table list of servers."
@@ -85,7 +85,7 @@
8585
id="cboRdgServer"
8686
label="Server: "
8787
onChange="OnChange"
88-
getText="GetText"
88+
getText="GetLabelText"
8989
getItemCount="GetItemCount"
9090
getItemLabel="GetItemLabel"
9191
sizeString= "XXXXXXXXXXXXXXXXXXXX"
@@ -95,7 +95,7 @@
9595
id="cboRdgDescription"
9696
label="Description: "
9797
onChange="OnChange"
98-
getText="GetText"
98+
getText="GetLabelText"
9999
getItemCount="GetItemCount"
100100
getItemLabel="GetItemLabel"
101101
sizeString= "XXXXXXXXXXXXXXXXXXXX"
@@ -105,7 +105,7 @@
105105
id="cboRdgComment"
106106
label="Comment: "
107107
onChange="OnChange"
108-
getText="GetText"
108+
getText="GetLabelText"
109109
getItemCount="GetItemCount"
110110
getItemLabel="GetItemLabel"
111111
sizeString= "XXXXXXXXXXXXXXXXXXXX"
@@ -118,7 +118,7 @@
118118
id="cboRdgGroup"
119119
label="Group: "
120120
onChange="OnChange"
121-
getText="GetText"
121+
getText="GetLabelText"
122122
getItemCount="GetItemCount"
123123
getItemLabel="GetItemLabel"
124124
sizeString= "XXXXXXXXXXXXXXXXXXXX"
@@ -128,7 +128,7 @@
128128
id="txtFileName"
129129
label="File Name: "
130130
onChange="OnChange"
131-
getText="GetText"
131+
getText="GetLabelText"
132132
sizeString= "XXXXXXXXXXXXXXXXXXXXXX"
133133
screentip="This is the file path for the Remote Desktop Manager file."
134134
/>
Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,20 @@ Imports System.Reflection
99

1010
Namespace Scripts
1111

12-
Module Form
12+
Public Class AssemblyInfo
1313

14-
''' <summary>
15-
''' Set form icon
16-
''' </summary>
17-
''' <param name="currentForm">the current form object</param>
18-
''' <param name="bmp">the icon referenced for the form</param>
1914
Public Sub SetIcon(ByRef currentForm As System.Windows.Forms.Form, ByRef bmp As Bitmap)
2015
Try
2116
currentForm.Icon = Icon.FromHandle(bmp.GetHicon)
2217

2318
Catch ex As Exception
24-
Call DisplayMessage(ex)
19+
Call ErrorHandler.DisplayMessage(ex)
2520
Exit Try
2621

2722
End Try
2823

2924
End Sub
3025

31-
''' <summary>
32-
''' set the icon in add/remove programs
33-
''' </summary>
34-
''' <param name="iconName">The referenced icon name for the application.</param>
35-
''' <remarks>
36-
''' only run if deployed
37-
''' </remarks>
3826
Public Sub SetAddRemoveProgramsIcon(iconName As String)
3927
If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed AndAlso ApplicationDeployment.CurrentDeployment.IsFirstRun Then
4028
Try
@@ -66,12 +54,12 @@ Namespace Scripts
6654
End If
6755
Next
6856
Catch ex As Exception
69-
Call DisplayMessage(ex)
57+
Call ErrorHandler.DisplayMessage(ex)
7058
End Try
7159
End If
7260
End Sub
7361

74-
End Module
62+
End Class
7563

7664

7765
End Namespace

VB/Scripts/ErrorHandler.vb

Lines changed: 179 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,192 @@ Option Explicit On
33

44
Imports System.Environment
55
Imports System.Windows.Forms
6+
Imports log4net
7+
'Imports log4net.Config 'needed if you want to change the path of the log file at runtime
8+
9+
<Assembly: log4net.Config.XmlConfigurator(Watch:=True)>
610

711
Namespace Scripts
812

9-
Module ErrorHandler
13+
Public Class ErrorHandler
14+
15+
Private Shared ReadOnly log As ILog = LogManager.GetLogger(GetType(ErrorHandler))
16+
17+
Public Shared Sub CreateLogRecord()
18+
Try
19+
Dim sf As New System.Diagnostics.StackFrame(1)
20+
Dim caller As System.Reflection.MethodBase = sf.GetMethod()
21+
Dim currentProcedure As String = (caller.Name).Trim()
22+
log.Info((Convert.ToString("[PROCEDURE]=|") & currentProcedure) + "|[USER NAME]=|" + Environment.UserName + "|[MACHINE NAME]=|" + Environment.MachineName)
23+
24+
Catch ex As Exception
25+
ErrorHandler.DisplayMessage(ex)
26+
End Try
1027

11-
''' <summary>
12-
''' Global error message for all procedures
13-
''' </summary>
14-
''' <param name="ex">the handled exception</param>
15-
Public Sub DisplayMessage(ByRef ex As Exception)
16-
Dim caption As String = "Unexpected Error"
28+
End Sub
29+
30+
Public Shared Sub DisplayMessage(ex As Exception, Optional isSilent As [Boolean] = False)
1731
Dim sf As New System.Diagnostics.StackFrame(1)
1832
Dim caller As System.Reflection.MethodBase = sf.GetMethod()
19-
Dim procedure As String = (caller.Name).Trim
20-
Dim msg As String = "Contact your system administrator."
21-
msg += NewLine & "Procedure: " & procedure
22-
msg += NewLine & "Description: " & ex.ToString
23-
'Console.WriteLine(msg)
24-
MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.Error)
33+
Dim currentProcedure As String = (caller.Name).Trim()
34+
Dim currentFileName As String = "" 'AssemblyInfo.GetCurrentFileName()
35+
Dim errorMessageDescription As String = ex.ToString()
36+
errorMessageDescription = System.Text.RegularExpressions.Regex.Replace(errorMessageDescription, "\r\n+", " ")
37+
'the carriage returns were messing up my log file
38+
Dim msg As String = "Contact your system administrator. A record has been created in the log file." + Environment.NewLine
39+
msg += (Convert.ToString("Procedure: ") & currentProcedure) + Environment.NewLine
40+
msg += "Description: " + ex.ToString() + Environment.NewLine
41+
log.[Error](Convert.ToString((Convert.ToString((Convert.ToString("[PROCEDURE]=|") & currentProcedure) + "|[USER NAME]=|" + Environment.UserName + "|[MACHINE NAME]=|" + Environment.MachineName + "|[FILE NAME]=|") & currentFileName) + "|[DESCRIPTION]=|") & errorMessageDescription)
42+
If isSilent = False Then
43+
MessageBox.Show(msg, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
44+
End If
2545

2646
End Sub
2747

28-
End Module
48+
Public Shared Function IsActiveDocument(Optional showMsg As Boolean = False) As Boolean
49+
Try
50+
If Globals.ThisAddIn.Application.ActiveWorkbook Is Nothing Then
51+
If showMsg = True Then
52+
MessageBox.Show("The command could not be completed. Please open a document and select a range.", My.Application.Info.Description, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
53+
End If
54+
Return False
55+
Else
56+
Return True
57+
End If
58+
59+
Catch ex As Exception
60+
ErrorHandler.DisplayMessage(ex)
61+
Return False
62+
End Try
63+
64+
End Function
65+
66+
Public Shared Function IsActiveSelection(Optional showMsg As Boolean = False) As Boolean
67+
Dim checkRange As Excel.Range = Nothing
68+
Try
69+
checkRange = TryCast(Globals.ThisAddIn.Application.Selection, Excel.Range)
70+
'must cast the selection as range or errors
71+
If checkRange Is Nothing Then
72+
If showMsg = True Then
73+
MessageBox.Show("The command could not be completed by using the range specified. Select a single cell within the range and try the command again. [Range]", My.Application.Info.Description, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
74+
End If
75+
Return False
76+
Else
77+
Return True
78+
End If
79+
80+
Catch ex As Exception
81+
ErrorHandler.DisplayMessage(ex)
82+
Return False
83+
84+
Finally
85+
If checkRange IsNot Nothing Then
86+
'Marshal.ReleaseComObject(checkRange)
87+
End If
88+
End Try
89+
90+
End Function
91+
92+
Public Shared Function IsValidListObject(Optional showMsg As Boolean = False) As Boolean
93+
Dim tbl As Excel.ListObject = Nothing
94+
Try
95+
tbl = Globals.ThisAddIn.Application.ActiveCell.ListObject
96+
' directly after the table is created this is not true
97+
If (tbl Is Nothing) Then
98+
If showMsg = True Then
99+
MessageBox.Show("The command could not be completed by using the range specified. Select a single cell within the range and try the command again. [ListObject]", My.Application.Info.Description, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
100+
End If
101+
Return False
102+
Else
103+
Return True
104+
End If
105+
106+
Catch generatedExceptionName As Exception
107+
Return False
108+
109+
Finally
110+
If tbl IsNot Nothing Then
111+
'Marshal.ReleaseComObject(tbl)
112+
End If
113+
End Try
114+
115+
End Function
116+
117+
Private Shared Function IsInCellEditingMode(Optional showMsg As Boolean = False) As Boolean
118+
Dim flag As Boolean = False
119+
Try
120+
'This will throw an Exception if Excel is in Cell Editing Mode
121+
Globals.ThisAddIn.Application.DisplayAlerts = False
122+
123+
Catch generatedExceptionName As Exception
124+
If showMsg = True Then
125+
MessageBox.Show("The procedure can not run while you are editing a cell.", "No action taken.", MessageBoxButtons.OK, MessageBoxIcon.Information)
126+
End If
127+
flag = True
128+
End Try
129+
Return flag
130+
131+
End Function
132+
133+
Public Shared Function IsEnabled(Optional showMsg As Boolean = False) As Boolean
134+
Try
135+
If IsActiveDocument(showMsg) = False Then
136+
Return False
137+
Else
138+
If IsActiveSelection(showMsg) = False Then
139+
Return False
140+
Else
141+
If IsInCellEditingMode(showMsg) = True Then
142+
Return False
143+
Else
144+
Return True
145+
End If
146+
End If
147+
End If
148+
149+
Catch ex As Exception
150+
ErrorHandler.DisplayMessage(ex)
151+
Return False
152+
End Try
153+
154+
End Function
155+
156+
Public Shared Function IsAvailable(Optional showMsg As Boolean = False) As Boolean
157+
Try
158+
If IsEnabled(showMsg) = False Then
159+
Return False
160+
Else
161+
If IsValidListObject(showMsg) = False Then
162+
Return False
163+
Else
164+
Return True
165+
End If
166+
End If
167+
168+
Catch ex As Exception
169+
ErrorHandler.DisplayMessage(ex)
170+
Return False
171+
End Try
172+
173+
End Function
174+
175+
Public Shared Function IsDate(expression As Object) As Boolean
176+
If expression IsNot Nothing Then
177+
If TypeOf expression Is DateTime Then
178+
Return True
179+
End If
180+
181+
If TypeOf expression Is String Then
182+
Dim time1 As DateTime
183+
Return DateTime.TryParse(DirectCast(expression, String), time1)
184+
End If
185+
186+
End If
187+
188+
Return False
189+
190+
End Function
191+
192+
End Class
29193

30-
End Namespace
194+
End Namespace

0 commit comments

Comments
 (0)