Compare commits

...

8 Commits

Author SHA1 Message Date
Andrew Welker
659896a669 Merge branch 'development' into feature/fix-IBasicVolumeWithFeedback 2022-06-21 15:41:10 -05:00
Andrew Welker
fe7bc332ec Merge branch 'development' into feature/fix-IBasicVolumeWithFeedback 2022-06-21 13:12:26 -05:00
jta
ebd978d917 Fix IBasicVolumeControls
fix: revert a change that split the interface but could break backwards compatibility #955
2022-06-13 13:22:23 -05:00
jta
1c252521f0 Merge branch 'feature/fileio-async' into feature/fix-IBasicVolumeWithFeedback 2022-06-13 13:13:38 -05:00
jta
641fa2101d fix for IBasicVolumeWithFeedback
fix: for a change that split the interface but could break backwards compatibility #955
2022-06-13 13:01:04 -05:00
jta
0500a359b8 Merge tag '1.10.1' into feature/fileio-async
# Conflicts:
#	essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/JoinMaps/VideoCodecControllerJoinMap.cs
2022-06-13 12:34:15 -05:00
jta
50e94eb373 File IO Rate Limiting
feature: adds rate limiting for FileIO
2022-06-07 12:54:28 -04:00
jta
96dbd44a04 FileIO fix for 4 series
fix: removes unnecessary DirectoryInfo call which would fail on 4 series
2022-06-06 12:55:46 -04:00
2 changed files with 58 additions and 11 deletions

View File

@@ -9,8 +9,11 @@ namespace PepperDash.Essentials.Core
/// <summary>
/// Defines minimal volume and mute control methods
/// </summary>
public interface IBasicVolumeControls : IHasVolumeControl, IHasMuteControl
public interface IBasicVolumeControls
{
void VolumeUp(bool pressRelease);
void VolumeDown(bool pressRelease);
void MuteToggle();
}
/// <summary>
@@ -52,8 +55,13 @@ namespace PepperDash.Essentials.Core
/// <summary>
/// Adds feedback and direct volume level set to IBasicVolumeControls
/// </summary>
public interface IBasicVolumeWithFeedback : IBasicVolumeControls, IHasVolumeControlWithFeedback, IHasMuteControlWithFeedback
public interface IBasicVolumeWithFeedback : IBasicVolumeControls
{
BoolFeedback MuteFeedback { get; }
void MuteOn();
void MuteOff();
void SetVolume(ushort level);
IntFeedback VolumeLevelFeedback { get; }
}
/// <summary>

View File

@@ -15,12 +15,19 @@ namespace PepperDash.Essentials.Core
static CCriticalSection fileLock = new CCriticalSection();
public delegate void GotFileEventHandler(object sender, FileEventArgs e);
public static event GotFileEventHandler GotFileEvent;
private static Dictionary<string, CTimer> WriteTimers;
public const long WriteTimeout = 5000;
/// <summary>
/// Get the full file info from a path/filename, can include wildcards.
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
///
static FileIO()
{
WriteTimers = new Dictionary<string, CTimer>();
}
public static FileInfo[] GetFiles(string fileName)
{
DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(fileName));
@@ -35,7 +42,7 @@ namespace PepperDash.Essentials.Core
return null;
}
}
public static FileInfo GetFile(string fileName)
{
DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(fileName));
@@ -81,7 +88,6 @@ namespace PepperDash.Essentials.Core
{
if (fileLock.TryEnter())
{
DirectoryInfo dirInfo = new DirectoryInfo(file.Name);
Debug.Console(2, "FileIO Getting Data {0}", file.FullName);
if (File.Exists(file.FullName))
@@ -169,7 +175,8 @@ namespace PepperDash.Essentials.Core
}
else
{
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock retrying");
}
}
@@ -189,6 +196,41 @@ namespace PepperDash.Essentials.Core
}
/// <summary>
/// Resets (or starts) the write timer
/// </summary>
static void ResetTimer(string data, string filePath)
{
try
{
if (WriteTimers.ContainsKey(filePath))
{
WriteTimers[filePath].Stop();
WriteTimers[filePath] = null;
WriteTimers.Remove(filePath);
}
WriteTimers.Add(filePath, new CTimer((o) =>
{
Thread _WriteFileThread;
_WriteFileThread = new Thread((O) => _WriteFileMethod(data, filePath), null, Thread.eThreadStartOptions.CreateSuspended);
_WriteFileThread.Priority = Thread.eThreadPriority.LowestPriority;
_WriteFileThread.Start();
Debug.Console(0, Debug.ErrorLogLevel.Notice, "New WriteFile Thread");
WriteTimers.Remove(filePath);
}, WriteTimeout));
Debug.Console(0, "FileIO write timer has been reset.");
}
catch (Exception e)
{
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO ResetTimer failed: \r{0}", e);
data = "";
}
}
/// <summary>
///
/// </summary>
@@ -201,11 +243,7 @@ namespace PepperDash.Essentials.Core
/// <param name="filePath"></param>
public static void WriteDataToFile(string data, string filePath)
{
Thread _WriteFileThread;
_WriteFileThread = new Thread((O) => _WriteFileMethod(data, filePath), null, Thread.eThreadStartOptions.CreateSuspended);
_WriteFileThread.Priority = Thread.eThreadPriority.LowestPriority;
_WriteFileThread.Start();
Debug.Console(0, Debug.ErrorLogLevel.Notice, "New WriteFile Thread");
ResetTimer(data, filePath);
}
@@ -240,6 +278,7 @@ namespace PepperDash.Essentials.Core
fileLock.Leave();
}
Debug.Console(0, Debug.ErrorLogLevel.Notice, "File Written to : '{0}'", filePath);
return null;
}