Skip to content

Commit

Permalink
Initial revision
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjaoxygen committed Nov 8, 2017
0 parents commit b120a36
Show file tree
Hide file tree
Showing 13 changed files with 1,556 additions and 0 deletions.
181 changes: 181 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/

# Roslyn cache directories
*.ide/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

#NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding addin-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment out the next line if you want to keep your passwords hidden
*.pubxml

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# If using the old MSBuild-Integrated Package Restore, uncomment this:
#!**/packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/
142 changes: 142 additions & 0 deletions AVSP.ConsoleSupport/ConsoleHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#region License

/*
* File: ConsoleHelper.cs
*
* The MIT License
*
* Copyright © 2017 AVSP Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#endregion License

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;

namespace AVSP.ConsoleSupport
{
/// <summary>
/// Console support library for banner, copyright, version, command line arguments
/// </summary>
internal static class ConsoleHelper
{
public delegate int RunFunction(SimpleArguments arguments);

public static SimpleArguments Arguments { get; private set; }

/// <summary>
/// Runs a console app with parsed options, sensible exit codes, exception handler
///
/// Example:
/// private static int Main(string[] args)
/// {
/// return ConsoleHelper.RunProgram(args, Run);
/// }
/// </summary>
/// <param name="args">arguments from Main()</param>
/// <param name="run">delegate to run app</param>
/// <returns>program exit code</returns>
public static int RunProgram(IList<string> args, RunFunction run)
{
try
{
ConsoleHelper.Startup(args);
ConsoleHelper.WriteBanner();

int returnValue = run(ConsoleHelper.Arguments);

return (Environment.ExitCode == 0) ? returnValue : Environment.ExitCode;
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
Trace.TraceError(e.ToString());

return Environment.ExitCode != 0
? Environment.ExitCode : 100;
}
}

public static void Startup(IList<string> args)
{
Arguments = new SimpleArguments(args);

// enable trace with v parameter
if (Arguments.GetFlag("v"))
{
Trace.Listeners.Add(new ConsoleTraceListener(true));
}
}

public static string GetProductVersion()
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}

public static string GetProductName()
{
return Assembly.GetExecutingAssembly().GetName().Name;
}

public static string GetDescription()
{
//Type of attribute that is desired
Type type = typeof(AssemblyDescriptionAttribute);

//Is there an attribute of this type already defined?
if (AssemblyDescriptionAttribute.IsDefined(Assembly.GetExecutingAssembly(), type))
{
//if there is, get attribute of desired type
AssemblyDescriptionAttribute assemblyDescriptionAttribute = (AssemblyDescriptionAttribute)AssemblyDescriptionAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), type);

return assemblyDescriptionAttribute.Description;
}

return null;
}

public static string GetCopyright()
{
//Type of attribute that is desired
Type type = typeof(AssemblyCopyrightAttribute);

//Is there an attribute of this type already defined?
if (AssemblyCopyrightAttribute.IsDefined(Assembly.GetExecutingAssembly(), type))
{
//if there is, get attribute of desired type
AssemblyCopyrightAttribute assemblyCopyrightAttribute = (AssemblyCopyrightAttribute)AssemblyCopyrightAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), type);

return assemblyCopyrightAttribute.Copyright;
}

return null;
}

public static void WriteBanner()
{
Console.WriteLine(GetProductName() + " v" + GetProductVersion());
Console.WriteLine(GetCopyright());
Console.WriteLine();
}
}
}
Loading

0 comments on commit b120a36

Please sign in to comment.