Skip to content

Commit

Permalink
Merge pull request #3 from BunnyTub/cutting-edge
Browse files Browse the repository at this point in the history
Merge cutting edge changes into master
  • Loading branch information
BunnyTub authored Nov 29, 2024
2 parents e53b67c + eaf1f38 commit 823e6bd
Show file tree
Hide file tree
Showing 17 changed files with 1,965 additions and 672 deletions.
40 changes: 34 additions & 6 deletions SharpENDEC/App.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="SharpENDEC.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
<section name="Soft_Weather_Radio.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
<section name="SharpENDEC.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Soft_Weather_Radio.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" />
</startup>
<userSettings>
<SharpENDEC.Properties.Settings>
Expand Down Expand Up @@ -141,17 +141,45 @@
</setting>
<setting name="AllowedLocations_Geocodes" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</value>
</setting>
<setting name="AllowedLocations_CLC" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</value>
</setting>
<setting name="UseFrench" serializeAs="String">
<value>False</value>
</setting>
</Soft_Weather_Radio.Properties.Settings>
</userSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.1.0" newVersion="6.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Win32.Registry" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.5.0" newVersion="4.1.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
935 changes: 837 additions & 98 deletions SharpENDEC/ENDEC/AlertProcessor.cs

Large diffs are not rendered by default.

387 changes: 28 additions & 359 deletions SharpENDEC/ENDEC/DataProcessor.cs

Large diffs are not rendered by default.

31 changes: 17 additions & 14 deletions SharpENDEC/ENDEC/FeedCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace SharpENDEC
Expand Down Expand Up @@ -64,7 +63,7 @@ private void Receive(string host, int port, string delimiter)
}
catch (IOException e)
{
ConsoleExt.WriteLine($"[{host}:{port}] {e.Message}", ConsoleColor.Red);
ConsoleExt.WriteLineErr($"[{host}:{port}] {e.Message}");
return;
}
Thread.Sleep(1000);
Expand Down Expand Up @@ -93,8 +92,8 @@ private void Receive(string host, int port, string delimiter)
if (chunk.Contains(delimiter))
{
ConsoleExt.WriteLine($"[{host}:{port}] {LanguageStrings.ProcessedStream(Settings.Default.CurrentLanguage, data.Count, now)}");
string capturedSent = Regex.Match(dataReceived, @"<sent>\s*(.*?)\s*</sent>", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline).Groups[1].Value.Replace("-", "_").Replace("+", "p").Replace(":", "_");
string capturedIdent = Regex.Match(dataReceived, @"<identifier>\s*(.*?)\s*</identifier>", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline).Groups[1].Value.Replace("-", "_").Replace("+", "p").Replace(":", "_");
string capturedSent = SentRegex.Match(dataReceived).Groups[1].Value.Replace("-", "_").Replace("+", "p").Replace(":", "_");
string capturedIdent = IdentifierRegex.Match(dataReceived).Groups[1].Value.Replace("-", "_").Replace("+", "p").Replace(":", "_");
string filename = $"{capturedSent}I{capturedIdent}.xml";

if (SharpDataQueue.Any(x => x.Name == filename) || SharpDataHistory.Any(x => x.Name == filename))
Expand All @@ -104,15 +103,17 @@ private void Receive(string host, int port, string delimiter)
else
{
SharpDataQueue.Add(new SharpDataItem(filename, dataReceived));
ConsoleExt.WriteLine($"[{host}:{port}] {LanguageStrings.FileDownloaded(Settings.Default.CurrentLanguage, host)}");
ConsoleExt.WriteLine($"[{host}:{port}] {LanguageStrings.FileDownloaded(Settings.Default.CurrentLanguage)}");
}
dataReceived = string.Empty;
}
else
{
if (data.Count > 10000000)
{
throw new Exception($"[{host}:{port}] The data exceeds the 10 MB limit. The server may be malfunctioning.");
//throw new OverflowException($"[{host}:{port}] The data exceeds the 10 MB limit. The server may be malfunctioning.");
ConsoleExt.WriteLineErr($"[{host}:{port}] The data exceeds the 10 MB limit. The server may be malfunctioning.");
return;
}
else ConsoleExt.WriteLine($"[{host}:{port}] {data.Count} bytes total including the current chunk.");
}
Expand All @@ -121,13 +122,13 @@ private void Receive(string host, int port, string delimiter)
}
catch (SocketException e)
{
ConsoleExt.WriteLine($"[{host}:{port}] {e.Message}");
ConsoleExt.WriteLineErr($"[{host}:{port}] {e.Message}");
Thread.Sleep(1000);
return;
}
catch (TimeoutException)
{
ConsoleExt.WriteLine($"[{host}:{port}] {LanguageStrings.HostTimedOut(Settings.Default.CurrentLanguage, host)}");
ConsoleExt.WriteLineErr($"[{host}:{port}] {LanguageStrings.HostTimedOut(Settings.Default.CurrentLanguage, host)}");
return;
}
catch (ThreadAbortException)
Expand All @@ -140,6 +141,8 @@ private void Receive(string host, int port, string delimiter)

public bool Main()
{
if (!SharpDataQueue.IsNull()) SharpDataQueue.Clear();
if (!SharpDataHistory.IsNull()) SharpDataHistory.Clear();
SharpDataQueue = new List<SharpDataItem>();
SharpDataHistory = new List<SharpDataItem>();

Expand All @@ -149,7 +152,7 @@ void StartServerConnection()
{
Thread thread = new Thread(() => Receive(server, 8080, "</alert>"));
thread.Start();
ClientThreads.Add(thread);
CaptureThreads.Add(thread);
ConsoleExt.WriteLine($"{LanguageStrings.StartingConnection(Settings.Default.CurrentLanguage, server, 8080)}", ConsoleColor.DarkGray);
Thread.Sleep(250);
}
Expand All @@ -161,25 +164,25 @@ void StartServerConnection()
{
while (true)
{
for (int i = 0; i < ClientThreads.Count; i++)
for (int i = 0; i < CaptureThreads.Count; i++)
{
if (!ClientThreads[i].IsAlive)
if (!CaptureThreads[i].IsAlive)
{
if (!ShutdownCapture)
{
ConsoleExt.WriteLine($"{LanguageStrings.RestartingAfterException(Settings.Default.CurrentLanguage)}");
string server = Settings.Default.CanadianServers[i];
Thread newThread = new Thread(() => Receive(server, 8080, "</alert>"));
newThread.Start();
ClientThreads[i] = newThread;
CaptureThreads[i] = newThread;
}
}
}

if (ShutdownCapture)
{
lock (ClientThreads)
foreach (var thread in ClientThreads)
lock (CaptureThreads)
foreach (var thread in CaptureThreads)
{
try
{
Expand Down
110 changes: 110 additions & 0 deletions SharpENDEC/ENDEC/RegexList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System.Text.RegularExpressions;

namespace SharpENDEC
{
public static partial class ENDEC
{
//public static readonly Regex ValueNameRegex = new Regex(
// @"<valueName>([^<]+)</valueName>\s*<value>([^<]+)</value>",
// RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex SentRegex = new Regex(
@"<sent>\s*(.*?)\s*</sent>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex StatusRegex = new Regex(
@"<status>\s*(.*?)\s*</status>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex MessageTypeRegex = new Regex(
@"<msgType>\s*(.*?)\s*</msgType>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex BroadcastImmediatelyRegex = new Regex(
@"<valueName>layer:SOREM:1.0:Broadcast_Immediately</valueName>\s*<value>\s*(.*?)\s*</value>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex UrgencyRegex = new Regex(
@"<urgency>\s*(.*?)\s*</urgency>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex SeverityRegex = new Regex(
@"<severity>\s*(.*?)\s*</severity>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex InfoRegex = new Regex(
@"<info>\s*(.*?)\s*</info>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex EffectiveRegex = new Regex(
@"<effective>\s*(.*?)\s*</effective>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex ExpiresRegex = new Regex(
@"<expires>\s*(.*?)\s*</expires>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex EventRegex = new Regex(
@"<event>\s*(.*?)\s*</event>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);
public static readonly Regex EventTypeRegex = new Regex(
@"<valueName>layer:EC-MSC-SMC:1.0:Alert_Name</valueName>\s*<value>\s*(.*?)\s*</value>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex LanguageRegex = new Regex(
@"<language>\s*(.*?)\s*</language>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex SenderNameRegex = new Regex(
@"<senderName>\s*(.*?)\s*</senderName>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex CoverageRegex = new Regex(
@"<valueName>layer:EC-MSC-SMC:1.0:Alert_Coverage</valueName>\s*<value>\s*(.*?)\s*</value>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex DescriptionRegex = new Regex(
@"<description>\s*(.*?)\s*</description>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex InstructionRegex = new Regex(
@"<instruction>\s*(.*?)\s*</instruction>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex BroadcastTextRegex = new Regex(
@"<valueName>layer:SOREM:1.0:Broadcast_Text</valueName>\s*<value>\s*(.*?)\s*</value>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex AreaDescriptionRegex = new Regex(
@"<areaDesc>\s*(.*?)\s*</areaDesc>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex ResourceDescriptionRegex = new Regex(
@"<resourceDesc>\s*(.*?)\s*</resourceDesc>\s*(.*?)\s*</resource>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex DerefURIRegex = new Regex(
@"<derefUri>\s*(.*?)\s*</derefUri>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex TypeURIRegex = new Regex(
@"<uri>\s*(.*?)\s*</uri>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex MimeRegex = new Regex(
@"<mimeType>\s*(.*?)\s*</mimeType>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex IdentifierRegex = new Regex(
@"<identifier>\s*(.*?)\s*</identifier>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex ReferencesRegex = new Regex(
@"<references>\s*(.*?)\s*</references>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);

public static readonly Regex LocationRegex = new Regex(
@"<geocode>\s*<valueName>profile:CAP-CP:Location:0.3</valueName>\s*<value>\s*(.*?)\s*</value>",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Singleline);
}
}
Loading

0 comments on commit 823e6bd

Please sign in to comment.