using System.Collections.Generic;
using StTelemetryExt;
namespace TelemetryExtractorTestApp
{
class Program
{
static StanagTelemetryExtractor extractor;
static object ConsoleLock = new object();
static void Main(string[] args)
{
Console.WriteLine(@"Usage: TelemetryExtractorTestApp.exe C:\Movie\KLV\ScottKlv.ts");
if (args.Count() == 0)
{
Console.WriteLine("Please provide file path");
Console.ReadKey(true);
return;
}
extractor = new StanagTelemetryExtractor();
if (extractor.Activate("TelemetryExtractor", @"C:\MyLicenseFile.lic", "505536B2-1ABF5491-3F28B6D0-AF46D13B") == false)
ReportError("License not valid. Demo mode activated. Only 10 first packets will be processed");
else
Console.WriteLine("License Ok");
extractor.MetadataPidDetectionCompleteEvent += new MetadataPidDetectionCompleteHandler(extractor_MetadataPidDetectionCompleteEvent);
extractor.PacketReadyEvent +=
new StTelemetryExtractor.PacketReadyHandler(extractor_ExtractorPacketReadyEvent);
extractor.SegmentProcessingEvent += new SegmentProcessingHandler(extractor_SegmentProcessingEvent);
extractor.ExtractorErrorEvent +=
new StTelemetryExtractor.ExtractorErrorHandler(extractor_ExtractorErrorEvent);
extractor.ExtractorMessageEvent +=
new StTelemetryExtractor.ExtractorMessageHandler(extractor_ExtractorMessageEvent);
extractor.ExtractorCompleteEvent +=
new StTelemetryExtractor.ExtractorCompleteHandler(extractor_ExtractorCompleteEvent);
extractor.ValidateChecksum = true;
foreach( var f in args)
{
Console.WriteLine("Add File {0}", f);
extractor.AddFile( f, null );
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine("\nS - Start Processing.");
Console.WriteLine("\nE - Stop Processing.");
Console.WriteLine("\nESC/Q - Quit.");
Console.WriteLine(Environment.NewLine);
ConsoleKeyInfo cki = new ConsoleKeyInfo();
do
{
cki = Console.ReadKey(true);
switch (cki.Key)
{
case ConsoleKey.S:
Console.WriteLine("\nStart Processing.");
extractor.Start();
break;
case ConsoleKey.E:
Console.WriteLine("\nStop KlvProcessing");
extractor.Stop();
break;
}
Thread.Sleep(200);
} while (cki.Key != ConsoleKey.Q && cki.Key != ConsoleKey.Escape);
extractor.Stop();
}
static void extractor_MetadataPidDetectionCompleteEvent(MetadataPidDetectionCompleteArgs e)
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("Detection complete. {0} Klv Pid(s) found:", e.pids.Count());
Console.ResetColor();
foreach (var pid in e.pids)
{
Console.WriteLine(string.Format("{0} (0x{1})", pid.ToString(), pid.ToString("X3")));
}
}
}
static void extractor_ExtractorPacketReadyEvent(List<EG601Item> pckt, Int64 offset)
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write("Packet {0} klvs\t received\t ", pckt.Count);
Console.ResetColor();
Console.Write("Time {0}. Offset {1}\n", pckt[0].ConvertedValueStr, offset);
}
}
static void extractor_SegmentProcessingEvent(SegmentProcessingArgs e)
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("Segment {0} processing started.", e.Path);
else
Console.Write("Segment {0} processing complete. {1} klv packets processed.", e.Path, e.PacketCount);
Console.ResetColor();
Console.WriteLine(Environment.NewLine);
}
}
static void extractor_ExtractorCompleteEvent()
{
lock (ConsoleLock)
{
Console.WriteLine("Extraction complete. {0} packets processed", extractor.TotalKlvPacketsProcessed);
}
}
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(e.Message);
Console.ResetColor();
}
}
{
ReportError(e.Message);
}
static void ReportError(string format, params object[] args)
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(format, args);
Console.WriteLine(Environment.NewLine);
Console.ResetColor();
}
}
}
}