namespace MTA_Transit;
// using https://github.com/MobilityData/gtfs-realtime-bindings/ package
using ProtoBuf;
using TransitRealtime;
using System.Net.Http;
/// <summary>
/// Represents a parser for MTA GTFS-realtime data feeds for multiple subway lines.
/// </summary>
/// <remarks>
/// This class fetches and parses GTFS-realtime feed data from the MTA API for specific subway lines:
/// Orange, Blue, Yellow, and Red/Green.
/// It stores the feed URLs internally and provides asynchronous methods to fetch and process the data.
/// Parsing focuses on FeedEntities, such as TripUpdates, which can then be used for further processing or display.
/// </remarks>
public class ParseMtaData
{
private static readonly HttpClient Client = new HttpClient();
public async Task FindTrainStatus(string line,string lineDirection, string api)
{
try
{
using HttpResponseMessage response = await Client.GetAsync(api);
response.EnsureSuccessStatusCode();
await using var stream = await response.Content.ReadAsStreamAsync();
FeedMessage feed = Serializer.Deserialize<FeedMessage>(stream);
foreach (FeedEntity entity in feed.Entities) {
if (entity.Vehicle != null && ( entity.Vehicle.StopId.Contains(line) && entity.Vehicle.StopId.Contains(lineDirection)))
{
Console.WriteLine(entity.Vehicle.CurrentStatus);
}
}
}
catch (HttpRequestException e)
{
//redacted
}
}
}
namespace MTA_Transit;
// using https://github.com/MobilityData/gtfs-realtime-bindings/ package
using ProtoBuf;
using TransitRealtime;
using System.Net.Http;
/// <summary>
/// Represents a parser for MTA GTFS-realtime data feeds for multiple subway lines.
/// </summary>
/// <remarks>
/// This class fetches and parses GTFS-realtime feed data from the MTA API for specific subway lines:
/// Orange, Blue, Yellow, and Red/Green.
/// It stores the feed URLs internally and provides asynchronous methods to fetch and process the data.
/// Parsing focuses on FeedEntities, such as TripUpdates, which can then be used for further processing or display.
/// </remarks>
public class ParseMtaData
{
private static readonly HttpClient Client = new HttpClient();
public async Task FindTrainStatus(string line,string lineDirection, string api)
{
try
{
using HttpResponseMessage response = await Client.GetAsync(api);
response.EnsureSuccessStatusCode();
await using var stream = await response.Content.ReadAsStreamAsync();
FeedMessage feed = Serializer.Deserialize<FeedMessage>(stream);
foreach (FeedEntity entity in feed.Entities) {
if (entity.Vehicle != null && ( entity.Vehicle.StopId.Contains(line) && entity.Vehicle.StopId.Contains(lineDirection)))
{
Console.WriteLine(entity.Vehicle.CurrentStatus);
}
}
}
catch (HttpRequestException e)
{
//redacted
}
}
}