-
Notifications
You must be signed in to change notification settings - Fork 0
Events
azrellie edited this page Dec 26, 2024
·
11 revisions
Events in this API allow you to listen for newly issued data right as its available. Setting up these events is straightforward.
Before we start listening for events, you must call this method:
events.enableEvents(); // tell the class to listen for eventsThis tells the class to begin listening for events.
You can also disable events by calling this method:
events.disableEvents(); // stop listening for eventsThis will make the class no longer listen for events until events.enableEvents() is called again.
Just like with enabling/disabling events, this part is pretty simple.
static StormPredictionCenter spc = new();
static void Main(string[] args)
{
spc.events.enableEvents();
spc.events.watchIssued += Events_watchIssued;
}
static void Events_watchIssued(object sender, StormPredictionCenterWatch[] watches, StormPredictionCenterWatchBox[] watchBoxes)
{
for (int i = 0; i < watches.Length; i++) // or you can use a foreach loop, but this works just as well
{
StormPredictionCenterWatch w = watches[i];
Console.WriteLine(w.ToString());
}
}As of 1.1.0, only one event exists, with that being spc.events.watchIssued. More events will be added in future versions.
static StormPredictionCenter spc = new();
static void Main(string[] args)
{
spc.events.enableEvents();
spc.events.watchIssued += Events_watchIssued;
string? cmd = Console.ReadLine();
if (cmd == "exit")
Environment.Exit(0);
}
static void Events_watchIssued(object sender, StormPredictionCenterWatch watch, StormPredictionCenterWatchBox watchBox)
{
Console.WriteLine($"{watch.watchType} {watch.watchNumber} watch has just been issued\n\ndetails:");
Console.WriteLine(watch.headline);
Console.WriteLine(watch.description);
Console.WriteLine("\ncounties affected:");
foreach (var county in watch.counties)
Console.WriteLine(county.name + ", " + county.state);
}