forked from nippe/Prowlin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got console app up and running. Added Args from NuGet and used that l…
…ibrary for parsing command line arguments
- Loading branch information
Showing
16 changed files
with
485 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("" ); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Args" version="1.0.3" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.