From 0c9a31d6520730147766347557cdf1a211e8f675 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Wed, 6 Oct 2021 15:25:50 +1300 Subject: [PATCH] Added solution files --- RadioBroadcaster.Server/App.config | 6 + RadioBroadcaster.Server/App.xaml | 9 + RadioBroadcaster.Server/App.xaml.cs | 17 + RadioBroadcaster.Server/FileEngine.cs | 52 +++ RadioBroadcaster.Server/LogManager.cs | 149 +++++++ RadioBroadcaster.Server/MainWindow.xaml | 48 +++ RadioBroadcaster.Server/MainWindow.xaml.cs | 255 ++++++++++++ RadioBroadcaster.Server/MediaEngine.cs | 379 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 55 +++ .../Properties/Resources.Designer.cs | 71 ++++ .../Properties/Resources.resx | 117 ++++++ .../Properties/Settings.Designer.cs | 30 ++ .../Properties/Settings.settings | 7 + .../RadioBroadcaster.Server.csproj | 102 +++++ RadioBroadcaster.Server/SerialManager.cs | 260 ++++++++++++ RadioBroadcaster.Server/Stations.cs | 84 ++++ RadioBroadcaster.sln | 25 ++ 17 files changed, 1666 insertions(+) create mode 100644 RadioBroadcaster.Server/App.config create mode 100644 RadioBroadcaster.Server/App.xaml create mode 100644 RadioBroadcaster.Server/App.xaml.cs create mode 100644 RadioBroadcaster.Server/FileEngine.cs create mode 100644 RadioBroadcaster.Server/LogManager.cs create mode 100644 RadioBroadcaster.Server/MainWindow.xaml create mode 100644 RadioBroadcaster.Server/MainWindow.xaml.cs create mode 100644 RadioBroadcaster.Server/MediaEngine.cs create mode 100644 RadioBroadcaster.Server/Properties/AssemblyInfo.cs create mode 100644 RadioBroadcaster.Server/Properties/Resources.Designer.cs create mode 100644 RadioBroadcaster.Server/Properties/Resources.resx create mode 100644 RadioBroadcaster.Server/Properties/Settings.Designer.cs create mode 100644 RadioBroadcaster.Server/Properties/Settings.settings create mode 100644 RadioBroadcaster.Server/RadioBroadcaster.Server.csproj create mode 100644 RadioBroadcaster.Server/SerialManager.cs create mode 100644 RadioBroadcaster.Server/Stations.cs create mode 100644 RadioBroadcaster.sln diff --git a/RadioBroadcaster.Server/App.config b/RadioBroadcaster.Server/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/RadioBroadcaster.Server/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/RadioBroadcaster.Server/App.xaml b/RadioBroadcaster.Server/App.xaml new file mode 100644 index 0000000..102de7a --- /dev/null +++ b/RadioBroadcaster.Server/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/RadioBroadcaster.Server/App.xaml.cs b/RadioBroadcaster.Server/App.xaml.cs new file mode 100644 index 0000000..d7f5095 --- /dev/null +++ b/RadioBroadcaster.Server/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace RadioBroadcaster.Server +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/RadioBroadcaster.Server/FileEngine.cs b/RadioBroadcaster.Server/FileEngine.cs new file mode 100644 index 0000000..b81f22d --- /dev/null +++ b/RadioBroadcaster.Server/FileEngine.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; + +namespace RadioBroadcaster.Server +{ + static class FileEngine + { + static string[] WriteBuffer = new string[1024]; + static int LastWrite = -1; + static int LastAddition = -1; + static bool IsCurrentlyActive = false; + public static string logLocation = ""; + public static void Write(string TextToWrite) + { + LastAddition = LastAddition + 1; + if(LastAddition > 1023) + { + LastAddition = 0; + } + WriteBuffer[LastAddition] = TextToWrite; + if (!IsCurrentlyActive) + { + + } + } + static void WriteManager() + { + FileStream fs = File.OpenWrite(logLocation); + fs.Position = fs.Length; // Set position to the end of the stream. + while(LastWrite != LastAddition) + { + DoWrite(fs); + } + fs.Close(); + IsCurrentlyActive = false; + } + static void DoWrite(FileStream fileStream) + { + LastWrite = LastWrite + 1; + if(LastWrite > 1023) + { + LastWrite = 0; + } + byte[] utf8Bytes = Encoding.UTF8.GetBytes(WriteBuffer[LastWrite]); + fileStream.Write(utf8Bytes, 0, utf8Bytes.Length); + } + } +} diff --git a/RadioBroadcaster.Server/LogManager.cs b/RadioBroadcaster.Server/LogManager.cs new file mode 100644 index 0000000..9273738 --- /dev/null +++ b/RadioBroadcaster.Server/LogManager.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; + +namespace RadioBroadcaster.Server +{ + static class LogManager + { + static string[] LogItems = new string[1024]; + static string[] SerialItems = new string[128]; + static int currentLogPosition = 0; + static int lastLogAddition = 0; + + static int currentSerialPosition = 0; + static int lastSerialPosition = 0; + + static string logLocation = System.Reflection.Assembly.GetExecutingAssembly().Location.Remove(System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf("\\")) + "\\outputLog"; + static string serialLocation = System.Reflection.Assembly.GetExecutingAssembly().Location.Remove(System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf("\\")) + "\\SerialLog"; + + static bool LogItemsIsRunning = false; + static bool SerialItemsIsRunning = false; + + static bool isDebug = false; + + static bool IsCurrentlyActive = false; + + public static void Init() + { + WriteLogTimer = new System.Timers.Timer(1000); + WriteLogTimer.Elapsed += WriteLogTimer_Elapsed; + WriteLogTimer.Start(); + try + { + if (DateTime.Now.Subtract(File.GetLastWriteTime(serialLocation)).TotalDays > 14) // As the serial log could contain a massive amount of data, we wipe it after some time + { + File.WriteAllBytes(serialLocation, new byte[] { 0x00 }); + } + else + { + FileStream fs = File.OpenRead(serialLocation); + if (fs.Length > 10737418240) // > 10GB + { + fs.Dispose(); + File.WriteAllBytes(serialLocation, new byte[] { 0x00 }); + } + } + } + catch + { + // We don't absolutely need to do anything here + } + + } + + private static void WriteLogTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + if (!LogItemsIsRunning) + { + LogItemsIsRunning = true; + WriteManager(); + LogItemsIsRunning = false; + } + if (!SerialItemsIsRunning) + { + SerialItemsIsRunning = true; + SerialWriteManager(); + SerialItemsIsRunning = false; + } + } + + public static void Write(string TextToWrite) + { + lastLogAddition = lastLogAddition + 1; + if (lastLogAddition > 1023) + { + lastLogAddition = 0; + } + LogItems[lastLogAddition] = TextToWrite; + if (!IsCurrentlyActive) + { + + } + } + static void WriteManager() + { + FileStream fs = File.OpenWrite(logLocation); + fs.Position = fs.Length; // Set position to the end of the stream. + while (currentLogPosition != lastLogAddition) + { + DoWrite(fs); + } + fs.Close(); + IsCurrentlyActive = false; + } + static void DoWrite(FileStream fileStream) + { + currentLogPosition = currentLogPosition + 1; + if (currentLogPosition > 1023) + { + currentLogPosition = 0; + } + byte[] utf8Bytes = Encoding.UTF8.GetBytes(LogItems[currentLogPosition] + Environment.NewLine); + fileStream.Write(utf8Bytes, 0, utf8Bytes.Length); + LogItems[currentLogPosition] = ""; // Clear some mem + } + /// + /// Logs serial data + /// + /// + public static void WriteSerial(string TextToWrite) + { + if (isDebug) + { + lastSerialPosition = lastSerialPosition + 1; + if (lastSerialPosition > 127) + { + lastSerialPosition = 0; + } + SerialItems[lastSerialPosition] = TextToWrite; + } + } + public static void SerialWriteManager() + { + FileStream fs = File.OpenWrite(serialLocation); + fs.Position = fs.Length; // Set position to the end of the stream. + while (currentSerialPosition != lastSerialPosition) + { + SerialDoWrite(fs); + } + fs.Close(); + IsCurrentlyActive = false; + } + static void SerialDoWrite(FileStream fileStream) + { + currentSerialPosition = currentSerialPosition + 1; + if (currentSerialPosition > 127) + { + currentSerialPosition = 0; + } + byte[] utf8Bytes = Encoding.UTF8.GetBytes(SerialItems[currentSerialPosition] + "\t"+ DateTime.Now.ToShortTimeString() + Environment.NewLine); + fileStream.Write(utf8Bytes, 0, utf8Bytes.Length); + SerialItems[currentSerialPosition] = ""; // Clear some mem + } + private static System.Timers.Timer WriteLogTimer; + } +} diff --git a/RadioBroadcaster.Server/MainWindow.xaml b/RadioBroadcaster.Server/MainWindow.xaml new file mode 100644 index 0000000..9319eb1 --- /dev/null +++ b/RadioBroadcaster.Server/MainWindow.xaml @@ -0,0 +1,48 @@ + + + + + + + + + + + +