forked from paolosalvatori/ServiceBusExplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
147 lines (141 loc) · 6.35 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#region Copyright
//=======================================================================================
// Microsoft Azure Customer Advisory Team
//
// This sample is supplemental to the technical guidance published on my personal
// blog at http://blogs.msdn.com/b/paolos/.
//
// Author: Paolo Salvatori
//=======================================================================================
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// LICENSED UNDER THE APACHE LICENSE, VERSION 2.0 (THE "LICENSE"); YOU MAY NOT USE THESE
// FILES EXCEPT IN COMPLIANCE WITH THE LICENSE. YOU MAY OBTAIN A COPY OF THE LICENSE AT
// http://www.apache.org/licenses/LICENSE-2.0
// UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, SOFTWARE DISTRIBUTED UNDER THE
// LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
// PERMISSIONS AND LIMITATIONS UNDER THE LICENSE.
//=======================================================================================
#endregion
#region Using Directives
using System;
using System.Threading;
using System.Globalization;
using System.Windows.Forms;
#endregion
namespace Microsoft.WindowsAzure.CAT.ServiceBusExplorer
{
static class Program
{
#region Private Constants
//***************************
// Formats
//***************************
private const string ExceptionFormat = "Exception: {0}";
private const string InnerExceptionFormat = "InnerException: {0}";
#endregion
#region Static Main Method
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
try
{
string argument = null;
string value = null;
if (args != null && args.Length >= 2)
{
for (var i = 0; i < args.Length; i++)
{
if ((string.Compare(args[i], "/n", StringComparison.InvariantCultureIgnoreCase) == 0 ||
string.Compare(args[i], "-n", StringComparison.InvariantCultureIgnoreCase) == 0) &&
args.Length > i + 1 &&
!string.IsNullOrWhiteSpace(args[i + 1]))
{
argument = args[i];
value = args[i + 1];
}
if ((string.Compare(args[i], "/c", StringComparison.InvariantCultureIgnoreCase) == 0 ||
string.Compare(args[i], "-c", StringComparison.InvariantCultureIgnoreCase) == 0) &&
args.Length > i + 1 &&
!string.IsNullOrWhiteSpace(args[i + 1]))
{
argument = args[i];
value = args[i + 1];
}
if ((string.Compare(args[i], "/q", StringComparison.InvariantCultureIgnoreCase) == 0 ||
string.Compare(args[i], "-q", StringComparison.InvariantCultureIgnoreCase) == 0) &&
args.Length > i + 1 &&
!string.IsNullOrWhiteSpace(args[i + 1]))
{
FilterExpressionHelper.QueueFilterExpression = args[i + 1];
}
if ((string.Compare(args[i], "/t", StringComparison.InvariantCultureIgnoreCase) == 0 ||
string.Compare(args[i], "-t", StringComparison.InvariantCultureIgnoreCase) == 0) &&
args.Length > i + 1 &&
!string.IsNullOrWhiteSpace(args[i + 1]))
{
FilterExpressionHelper.TopicFilterExpression = args[i + 1];
}
if ((string.Compare(args[i], "/s", StringComparison.InvariantCultureIgnoreCase) == 0 ||
string.Compare(args[i], "-s", StringComparison.InvariantCultureIgnoreCase) == 0) &&
args.Length > i + 1 &&
!string.IsNullOrWhiteSpace(args[i + 1]))
{
FilterExpressionHelper.SubscriptionFilterExpression = args[i + 1];
}
}
}
if (!string.IsNullOrWhiteSpace(argument) &&
!string.IsNullOrWhiteSpace(value))
{
Application.Run(new MainForm(argument, value));
}
else
{
Application.Run(new MainForm());
}
}
// ReSharper disable EmptyGeneralCatchClause
catch (Exception)
// ReSharper restore EmptyGeneralCatchClause
{
}
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
if (e != null &&
e.Exception != null)
{
HandleException(e.Exception);
}
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e != null &&
e.ExceptionObject != null)
{
HandleException(e.ExceptionObject as Exception);
}
}
static void HandleException(Exception ex)
{
if (ex != null && !string.IsNullOrWhiteSpace(ex.Message))
{
MainForm.StaticWriteToLog(string.Format(CultureInfo.CurrentCulture, ExceptionFormat, ex.Message));
if (ex.InnerException != null && !string.IsNullOrWhiteSpace(ex.InnerException.Message))
{
MainForm.StaticWriteToLog(string.Format(CultureInfo.CurrentCulture, InnerExceptionFormat, ex.InnerException.Message));
}
}
}
#endregion
}
}