Skip to content

Commit

Permalink
Got console app up and running. Added Args from NuGet and used that l…
Browse files Browse the repository at this point in the history
…ibrary for parsing command line arguments
  • Loading branch information
nippe committed May 19, 2011
1 parent b8ad0ff commit 0f6c570
Show file tree
Hide file tree
Showing 16 changed files with 485 additions and 36 deletions.
105 changes: 87 additions & 18 deletions Prowlin.Console/Program.cs
@@ -1,32 +1,101 @@
using System;
using Prowlin;
using Args;


namespace Prowlin.Console
{
class Program
[ArgsModel(SwitchDelimiter = "-")]
public class ArgumentsObject
{
static void Main(string[] args) {
public string Application = string.Empty;
public string Description = string.Empty;
public string Event = string.Empty;
public string Key = string.Empty;
public string Priority = string.Empty;
public string Url = string.Empty;
public bool Help = false;
}

Program p = new Program();
internal class Program
{
private static void Main(string[] args) {
var p = new Program();
p.Run(args);

}

private void Run(string[] args) {
INotification notification = new Prowlin.Notification()
{
Application = "Prowlin.Console",
Description = "Testing",
Event = "Some Event",
Priority = NotificationPriority.High,
Url = "http://www.nnihlen.com/blog"
};
notification.AddApiKey("<your-apikey(s)-goes here>");

ProwlClient prowlClient = new ProwlClient();
ArgumentsObject arguments = Configuration.Configure<ArgumentsObject>().CreateAndBind(args);

if(arguments.Help) {
ShowHelp();
return;
}

if (string.IsNullOrEmpty(arguments.Key)) {
System.Console.WriteLine("ApiKey requried");
return;
}

if (string.IsNullOrEmpty(arguments.Event)) {
System.Console.WriteLine("Event is required");
return;
}

if (string.IsNullOrEmpty(arguments.Application)) {
System.Console.WriteLine("Application is required");
return;
}

var notification = new Notification
{
Application = arguments.Application,
Description = arguments.Description,
Event = arguments.Event,
Url = arguments.Url
};


switch (arguments.Priority.ToLower()) {
case "verylow":
notification.Priority = NotificationPriority.VeryLow;
break;
case "moderate":
notification.Priority = NotificationPriority.Moderate;
break;
case "high":
notification.Priority = NotificationPriority.High;
break;
case "emergency":
notification.Priority = NotificationPriority.Emergency;
break;
default:
notification.Priority = NotificationPriority.Normal;
break;
}


foreach (string s in arguments.Key.Split(new[] {',', ';'})) {
notification.AddApiKey(s);
}


var prowlClient = new ProwlClient();
int remaingMessages = prowlClient.SendNotification(notification);

System.Console.WriteLine("Remaing number of messages: {0}", remaingMessages.ToString());
System.Console.WriteLine("Remaing number of messages: {0}", remaingMessages);
}

private void ShowHelp() {
System.Console.WriteLine("Prowlin version {0}", "0.8.0.0" );
System.Console.WriteLine("" );
System.Console.WriteLine("USAGE:" );
System.Console.WriteLine("\t\t> Prowlin -k one_apikey -e \"event X\" -a \"Application Y\"" );
System.Console.WriteLine("\t\t> Prowlin -k apikey_one,apikey_two,... -e \"event X\" -a \"Application Y\"" );
System.Console.WriteLine("\tOptions:" );
System.Console.WriteLine("\t-k, -key\tAPIKEY(s)" );
System.Console.WriteLine("" );
System.Console.WriteLine("" );
System.Console.WriteLine("" );
}
}
}
}
10 changes: 5 additions & 5 deletions Prowlin.Console/Properties/AssemblyInfo.cs
Expand Up @@ -5,12 +5,12 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Prowlin.Console")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("Prowlin Console")]
[assembly: AssemblyDescription("Prowlin by Niklas Nihlén")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Prowlin.Console")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Prowlin Console")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
10 changes: 7 additions & 3 deletions Prowlin.Console/Prowlin.Console.csproj
Expand Up @@ -35,6 +35,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Args">
<HintPath>..\packages\Args.1.0.3\lib\Net40\Args.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -45,15 +48,16 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Prowlin\Prowlin.csproj">
<Project>{297034F7-4E9C-4F7D-AFBF-E7852A60A1A6}</Project>
<Name>Prowlin</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 4 additions & 0 deletions Prowlin.Console/packages.config
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Args" version="1.0.3" />
</packages>
3 changes: 2 additions & 1 deletion Prowlin.UnitTests/Fakes/FakeHttpInterface.cs
Expand Up @@ -17,7 +17,8 @@ public class FakeHttpInterface : IHttpInterface
}

public int SendNotification(INotification notification) {
throw new NotImplementedException();
_sendNotificationsCalled = true;
return 900;
}

public void SendVerification() {
Expand Down
6 changes: 3 additions & 3 deletions Prowlin.UnitTests/Properties/AssemblyInfo.cs
Expand Up @@ -8,9 +8,9 @@
[assembly: AssemblyTitle("Prowlin.UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Prowlin.UnitTests")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Prowlin by Niklas Nihlén")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
2 changes: 1 addition & 1 deletion Prowlin.sln
Expand Up @@ -9,7 +9,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prowlin.UnitTests", "Prowli
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0C6B74CA-EA5D-4A53-8391-96E8EBD52532}"
ProjectSection(SolutionItems) = preProject
README.txt = README.txt
README.markdown = README.markdown
EndProjectSection
EndProject
Global
Expand Down
2 changes: 1 addition & 1 deletion Prowlin/HttpInterface.cs
Expand Up @@ -113,7 +113,7 @@ public class HttpInterface : IHttpInterface
}
sb.Append(method);

if(parameters != null) {
if(parameters != null && parameters.Count > 0) {
sb.Append("?");
sb.Append(this.BuildParameterString(parameters));
}
Expand Down
2 changes: 1 addition & 1 deletion Prowlin/Notification.cs
Expand Up @@ -36,7 +36,7 @@ public string Keys
[StringLength(1024)]
public string Event { get; set; }

[Required]
[Required(AllowEmptyStrings = true)]
[StringLength(10000)]
public string Description { get; set; }
}
Expand Down
6 changes: 3 additions & 3 deletions Prowlin/Properties/AssemblyInfo.cs
Expand Up @@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Prowlin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Prowlin by Niklas Nihlén")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Prowlin")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
Binary file added packages/Args.1.0.3/Args.1.0.3.nupkg
Binary file not shown.
Binary file added packages/Args.1.0.3/lib/Net35/Args.dll
Binary file not shown.

0 comments on commit 0f6c570

Please sign in to comment.