Skip to content

Commit b120a36

Browse files
committed
Initial revision
0 parents  commit b120a36

File tree

13 files changed

+1556
-0
lines changed

13 files changed

+1556
-0
lines changed

.gitignore

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
9+
# Build results
10+
[Dd]ebug/
11+
[Dd]ebugPublic/
12+
[Rr]elease/
13+
[Rr]eleases/
14+
x64/
15+
x86/
16+
build/
17+
bld/
18+
[Bb]in/
19+
[Oo]bj/
20+
21+
# Roslyn cache directories
22+
*.ide/
23+
24+
# MSTest test Results
25+
[Tt]est[Rr]esult*/
26+
[Bb]uild[Ll]og.*
27+
28+
#NUNIT
29+
*.VisualState.xml
30+
TestResult.xml
31+
32+
# Build Results of an ATL Project
33+
[Dd]ebugPS/
34+
[Rr]eleasePS/
35+
dlldata.c
36+
37+
*_i.c
38+
*_p.c
39+
*_i.h
40+
*.ilk
41+
*.meta
42+
*.obj
43+
*.pch
44+
*.pdb
45+
*.pgc
46+
*.pgd
47+
*.rsp
48+
*.sbr
49+
*.tlb
50+
*.tli
51+
*.tlh
52+
*.tmp
53+
*.tmp_proj
54+
*.log
55+
*.vspscc
56+
*.vssscc
57+
.builds
58+
*.pidb
59+
*.svclog
60+
*.scc
61+
62+
# Chutzpah Test files
63+
_Chutzpah*
64+
65+
# Visual C++ cache files
66+
ipch/
67+
*.aps
68+
*.ncb
69+
*.opensdf
70+
*.sdf
71+
*.cachefile
72+
73+
# Visual Studio profiler
74+
*.psess
75+
*.vsp
76+
*.vspx
77+
78+
# TFS 2012 Local Workspace
79+
$tf/
80+
81+
# Guidance Automation Toolkit
82+
*.gpState
83+
84+
# ReSharper is a .NET coding add-in
85+
_ReSharper*/
86+
*.[Rr]e[Ss]harper
87+
*.DotSettings.user
88+
89+
# JustCode is a .NET coding addin-in
90+
.JustCode
91+
92+
# TeamCity is a build add-in
93+
_TeamCity*
94+
95+
# DotCover is a Code Coverage Tool
96+
*.dotCover
97+
98+
# NCrunch
99+
_NCrunch_*
100+
.*crunch*.local.xml
101+
102+
# MightyMoose
103+
*.mm.*
104+
AutoTest.Net/
105+
106+
# Web workbench (sass)
107+
.sass-cache/
108+
109+
# Installshield output folder
110+
[Ee]xpress/
111+
112+
# DocProject is a documentation generator add-in
113+
DocProject/buildhelp/
114+
DocProject/Help/*.HxT
115+
DocProject/Help/*.HxC
116+
DocProject/Help/*.hhc
117+
DocProject/Help/*.hhk
118+
DocProject/Help/*.hhp
119+
DocProject/Help/Html2
120+
DocProject/Help/html
121+
122+
# Click-Once directory
123+
publish/
124+
125+
# Publish Web Output
126+
*.[Pp]ublish.xml
127+
*.azurePubxml
128+
# TODO: Comment out the next line if you want to keep your passwords hidden
129+
*.pubxml
130+
131+
# NuGet Packages
132+
*.nupkg
133+
# The packages folder can be ignored because of Package Restore
134+
**/packages/*
135+
# except build/, which is used as an MSBuild target.
136+
!**/packages/build/
137+
# If using the old MSBuild-Integrated Package Restore, uncomment this:
138+
#!**/packages/repositories.config
139+
140+
# Windows Azure Build Output
141+
csx/
142+
*.build.csdef
143+
144+
# Windows Store app package directory
145+
AppPackages/
146+
147+
# Others
148+
sql/
149+
*.Cache
150+
ClientBin/
151+
[Ss]tyle[Cc]op.*
152+
~$*
153+
*~
154+
*.dbmdl
155+
*.dbproj.schemaview
156+
*.pfx
157+
*.publishsettings
158+
node_modules/
159+
160+
# RIA/Silverlight projects
161+
Generated_Code/
162+
163+
# Backup & report files from converting an old project file
164+
# to a newer Visual Studio version. Backup files are not needed,
165+
# because we have git ;-)
166+
_UpgradeReport_Files/
167+
Backup*/
168+
UpgradeLog*.XML
169+
UpgradeLog*.htm
170+
171+
# SQL Server files
172+
*.mdf
173+
*.ldf
174+
175+
# Business Intelligence projects
176+
*.rdl.data
177+
*.bim.layout
178+
*.bim_*.settings
179+
180+
# Microsoft Fakes
181+
FakesAssemblies/
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#region License
2+
3+
/*
4+
* File: ConsoleHelper.cs
5+
*
6+
* The MIT License
7+
*
8+
* Copyright © 2017 AVSP Ltd
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in
18+
* all copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26+
* THE SOFTWARE.
27+
*/
28+
29+
#endregion License
30+
31+
using System;
32+
using System.Collections.Generic;
33+
using System.Diagnostics;
34+
using System.Reflection;
35+
36+
namespace AVSP.ConsoleSupport
37+
{
38+
/// <summary>
39+
/// Console support library for banner, copyright, version, command line arguments
40+
/// </summary>
41+
internal static class ConsoleHelper
42+
{
43+
public delegate int RunFunction(SimpleArguments arguments);
44+
45+
public static SimpleArguments Arguments { get; private set; }
46+
47+
/// <summary>
48+
/// Runs a console app with parsed options, sensible exit codes, exception handler
49+
///
50+
/// Example:
51+
/// private static int Main(string[] args)
52+
/// {
53+
/// return ConsoleHelper.RunProgram(args, Run);
54+
/// }
55+
/// </summary>
56+
/// <param name="args">arguments from Main()</param>
57+
/// <param name="run">delegate to run app</param>
58+
/// <returns>program exit code</returns>
59+
public static int RunProgram(IList<string> args, RunFunction run)
60+
{
61+
try
62+
{
63+
ConsoleHelper.Startup(args);
64+
ConsoleHelper.WriteBanner();
65+
66+
int returnValue = run(ConsoleHelper.Arguments);
67+
68+
return (Environment.ExitCode == 0) ? returnValue : Environment.ExitCode;
69+
}
70+
catch (Exception e)
71+
{
72+
Console.Error.WriteLine(e.Message);
73+
Trace.TraceError(e.ToString());
74+
75+
return Environment.ExitCode != 0
76+
? Environment.ExitCode : 100;
77+
}
78+
}
79+
80+
public static void Startup(IList<string> args)
81+
{
82+
Arguments = new SimpleArguments(args);
83+
84+
// enable trace with v parameter
85+
if (Arguments.GetFlag("v"))
86+
{
87+
Trace.Listeners.Add(new ConsoleTraceListener(true));
88+
}
89+
}
90+
91+
public static string GetProductVersion()
92+
{
93+
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
94+
}
95+
96+
public static string GetProductName()
97+
{
98+
return Assembly.GetExecutingAssembly().GetName().Name;
99+
}
100+
101+
public static string GetDescription()
102+
{
103+
//Type of attribute that is desired
104+
Type type = typeof(AssemblyDescriptionAttribute);
105+
106+
//Is there an attribute of this type already defined?
107+
if (AssemblyDescriptionAttribute.IsDefined(Assembly.GetExecutingAssembly(), type))
108+
{
109+
//if there is, get attribute of desired type
110+
AssemblyDescriptionAttribute assemblyDescriptionAttribute = (AssemblyDescriptionAttribute)AssemblyDescriptionAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), type);
111+
112+
return assemblyDescriptionAttribute.Description;
113+
}
114+
115+
return null;
116+
}
117+
118+
public static string GetCopyright()
119+
{
120+
//Type of attribute that is desired
121+
Type type = typeof(AssemblyCopyrightAttribute);
122+
123+
//Is there an attribute of this type already defined?
124+
if (AssemblyCopyrightAttribute.IsDefined(Assembly.GetExecutingAssembly(), type))
125+
{
126+
//if there is, get attribute of desired type
127+
AssemblyCopyrightAttribute assemblyCopyrightAttribute = (AssemblyCopyrightAttribute)AssemblyCopyrightAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), type);
128+
129+
return assemblyCopyrightAttribute.Copyright;
130+
}
131+
132+
return null;
133+
}
134+
135+
public static void WriteBanner()
136+
{
137+
Console.WriteLine(GetProductName() + " v" + GetProductVersion());
138+
Console.WriteLine(GetCopyright());
139+
Console.WriteLine();
140+
}
141+
}
142+
}

0 commit comments

Comments
 (0)