Compare commits

..

2 Commits

Author SHA1 Message Date
jtalborough
83c76340fc fix: reapply fixes for fileIO 4 series 2023-05-09 09:08:28 -04:00
Andrew Welker
3fe5d89904 Merge pull request #1105 from PepperDash/hotfix/remove-old-workflow
Delete add-issues-to-project.yml
2023-04-27 12:54:08 -06:00
4 changed files with 206 additions and 297 deletions

View File

@@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
@@ -9,7 +8,6 @@ namespace PepperDash_Essentials_Core.Devices
/// <summary> /// <summary>
/// Interface for any device that is able to control it'spower and has a configurable reboot time /// Interface for any device that is able to control it'spower and has a configurable reboot time
/// </summary> /// </summary>
[Obsolete("PepperDash_Essentials_Core.Devices is Deprecated - use PepperDash.Essentials.Core")]
public interface IHasPowerCycle : IKeyName, IHasPowerControlWithFeedback public interface IHasPowerCycle : IKeyName, IHasPowerControlWithFeedback
{ {
/// <summary> /// <summary>
@@ -26,7 +24,6 @@ namespace PepperDash_Essentials_Core.Devices
/// <summary> /// <summary>
/// Interface for any device that contains a collection of IHasPowerReboot Devices /// Interface for any device that contains a collection of IHasPowerReboot Devices
/// </summary> /// </summary>
[Obsolete("PepperDash_Essentials_Core.Devices is Deprecated - use PepperDash.Essentials.Core")]
public interface IHasControlledPowerOutlets : IKeyName public interface IHasControlledPowerOutlets : IKeyName
{ {
/// <summary> /// <summary>

View File

@@ -1,87 +0,0 @@
using Crestron.SimplSharp;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Interface for any device that has a battery that can be monitored
/// </summary>
public interface IHasBatteryStats : IKeyName
{
int BatteryPercentage { get; }
int BatteryCautionThresholdPercentage { get; }
int BatteryWarningThresholdPercentage { get; }
BoolFeedback BatteryIsWarningFeedback { get; }
BoolFeedback BatteryIsCautionFeedback { get; }
BoolFeedback BatteryIsOkFeedback { get; }
IntFeedback BatteryPercentageFeedback { get; }
}
/// <summary>
/// Interface for any device that has a battery that can be monitored and the ability to charge and discharge
/// </summary>
public interface IHasBatteryCharging : IHasBatteryStats
{
BoolFeedback BatteryIsCharging { get; }
}
/// <summary>
/// Interface for any device that has multiple batteries that can be monitored
/// </summary>
public interface IHasBatteries : IKeyName
{
ReadOnlyDictionary<string, IHasBatteryStats> Batteries { get; }
}
public interface IHasBatteryStatsExtended : IHasBatteryStats
{
int InputVoltage { get; }
int OutputVoltage { get; }
int InptuCurrent { get; }
int OutputCurrent { get; }
IntFeedback InputVoltageFeedback { get; }
IntFeedback OutputVoltageFeedback { get; }
IntFeedback InputCurrentFeedback { get; }
IntFeedback OutputCurrentFeedback { get; }
}
/// <summary>
/// Interface for any device that is able to control its power, has a configurable reboot time, and has batteries that can be monitored
/// </summary>
public interface IHasPowerCycleWithBattery : IHasPowerCycle, IHasBatteryStats
{
}
/// <summary>
/// Interface for any device that is able to control it's power and has a configurable reboot time
/// </summary>
public interface IHasPowerCycle : IKeyName, IHasPowerControlWithFeedback
{
/// <summary>
/// Delay between power off and power on for reboot
/// </summary>
int PowerCycleTimeMs { get; }
/// <summary>
/// Reboot outlet
/// </summary>
void PowerCycle();
}
/// <summary>
/// Interface for any device that contains a collection of IHasPowerReboot Devices
/// </summary>
public interface IHasControlledPowerOutlets : IKeyName
{
/// <summary>
/// Collection of IPduOutlets
/// </summary>
ReadOnlyDictionary<int, IHasPowerCycle> PduOutlets { get; }
}
}

View File

@@ -9,18 +9,18 @@ using Crestron.SimplSharpPro.CrestronThread;
namespace PepperDash.Essentials.Core namespace PepperDash.Essentials.Core
{ {
public static class FileIO public static class FileIO
{ {
static CCriticalSection fileLock = new CCriticalSection(); static CCriticalSection fileLock = new CCriticalSection();
public delegate void GotFileEventHandler(object sender, FileEventArgs e); public delegate void GotFileEventHandler(object sender, FileEventArgs e);
public static event GotFileEventHandler GotFileEvent; public static event GotFileEventHandler GotFileEvent;
/// <summary> /// <summary>
/// Get the full file info from a path/filename, can include wildcards. /// Get the full file info from a path/filename, can include wildcards.
/// </summary> /// </summary>
/// <param name="fileName"></param> /// <param name="fileName"></param>
/// <returns></returns> /// <returns></returns>
public static FileInfo[] GetFiles(string fileName) public static FileInfo[] GetFiles(string fileName)
{ {
string fullFilePath = Global.FilePathPrefix + fileName; string fullFilePath = Global.FilePathPrefix + fileName;
@@ -54,228 +54,228 @@ namespace PepperDash.Essentials.Core
} }
/// <summary> /// <summary>
/// Get the data from string path/filename /// Get the data from string path/filename
/// </summary> /// </summary>
/// <param name="fileName"></param> /// <param name="fileName"></param>
/// <returns></returns> /// <returns></returns>
public static string ReadDataFromFile(string fileName) public static string ReadDataFromFile(string fileName)
{ {
try try
{ {
return ReadDataFromFile(GetFile(fileName)); return ReadDataFromFile(GetFile(fileName));
} }
catch (Exception e) catch (Exception e)
{ {
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e); Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
return ""; return "";
} }
} }
/// <summary> /// <summary>
/// Get the data with fileInfo object /// Get the data with fileInfo object
/// </summary> /// </summary>
/// <param name="fileName"></param> /// <param name="fileName"></param>
/// <returns></returns> /// <returns></returns>
public static string ReadDataFromFile(FileInfo file) public static string ReadDataFromFile(FileInfo file)
{ {
try try
{ {
if (fileLock.TryEnter()) if (fileLock.TryEnter())
{ {
DirectoryInfo dirInfo = new DirectoryInfo(file.DirectoryName); DirectoryInfo dirInfo = new DirectoryInfo(file.DirectoryName);
Debug.Console(2, "FileIO Getting Data {0}", file.FullName); Debug.Console(2, "FileIO Getting Data {0}", file.FullName);
if (File.Exists(file.FullName)) if (File.Exists(file.FullName))
{ {
using (StreamReader r = new StreamReader(file.FullName)) using (StreamReader r = new StreamReader(file.FullName))
{ {
return r.ReadToEnd(); return r.ReadToEnd();
} }
} }
else else
{ {
Debug.Console(2, "File {0} does not exsist", file.FullName); Debug.Console(2, "File {0} does not exsist", file.FullName);
return ""; return "";
} }
} }
else else
{ {
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock"); Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
return ""; return "";
} }
}
catch (Exception e)
{
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
return "";
}
finally
{
if (fileLock != null && !fileLock.Disposed)
fileLock.Leave();
} }
} catch (Exception e)
{
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
return "";
}
finally
{
if (fileLock != null && !fileLock.Disposed)
fileLock.Leave();
}
}
public static void ReadDataFromFileASync(string fileName) public static void ReadDataFromFileASync(string fileName)
{ {
try try
{ {
ReadDataFromFileASync(GetFile(fileName)); ReadDataFromFileASync(GetFile(fileName));
} }
catch (Exception e) catch (Exception e)
{ {
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e); Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
} }
} }
public static void ReadDataFromFileASync(FileInfo file) public static void ReadDataFromFileASync(FileInfo file)
{ {
try try
{ {
CrestronInvoke.BeginInvoke(o => _ReadDataFromFileASync(file)); CrestronInvoke.BeginInvoke(o => _ReadDataFromFileASync(file));
} }
catch (Exception e) catch (Exception e)
{ {
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e); Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
} }
} }
private static void _ReadDataFromFileASync(FileInfo file) private static void _ReadDataFromFileASync(FileInfo file)
{ {
string data; string data;
try try
{ {
if (fileLock.TryEnter()) if (fileLock.TryEnter())
{ {
DirectoryInfo dirInfo = new DirectoryInfo(file.Name); DirectoryInfo dirInfo = new DirectoryInfo(file.Name);
Debug.Console(2, "FileIO Getting Data {0}", file.FullName); Debug.Console(2, "FileIO Getting Data {0}", file.FullName);
if (File.Exists(file.FullName)) if (File.Exists(file.FullName))
{ {
using (StreamReader r = new StreamReader(file.FullName)) using (StreamReader r = new StreamReader(file.FullName))
{ {
data = r.ReadToEnd(); data = r.ReadToEnd();
} }
} }
else else
{ {
Debug.Console(2, "File {0} Does not exsist", file.FullName); Debug.Console(2, "File {0} Does not exsist", file.FullName);
data = ""; data = "";
} }
GotFileEvent.Invoke(null, new FileEventArgs(data)); GotFileEvent.Invoke(null, new FileEventArgs(data));
} }
else else
{ {
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock"); Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
} }
} }
catch (Exception e) catch (Exception e)
{ {
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e); Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO read failed: \r{0}", e);
data = ""; data = "";
} }
finally finally
{ {
if (fileLock != null && !fileLock.Disposed) if (fileLock != null && !fileLock.Disposed)
fileLock.Leave(); fileLock.Leave();
} }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
/// <param name="filePath"></param> /// <param name="filePath"></param>
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
/// <param name="filePath"></param> /// <param name="filePath"></param>
public static void WriteDataToFile(string data, string filePath) public static void WriteDataToFile(string data, string filePath)
{ {
Thread _WriteFileThread; Thread _WriteFileThread;
_WriteFileThread = new Thread((O) => _WriteFileMethod(data, Global.FilePathPrefix + "/" + filePath), null, Thread.eThreadStartOptions.CreateSuspended); _WriteFileThread = new Thread((O) => _WriteFileMethod(data, Global.FilePathPrefix + "/" + filePath), null, Thread.eThreadStartOptions.CreateSuspended);
_WriteFileThread.Priority = Thread.eThreadPriority.LowestPriority; _WriteFileThread.Priority = Thread.eThreadPriority.LowestPriority;
_WriteFileThread.Start(); _WriteFileThread.Start();
Debug.Console(0, Debug.ErrorLogLevel.Notice, "New WriteFile Thread"); Debug.Console(0, Debug.ErrorLogLevel.Notice, "New WriteFile Thread");
} }
static object _WriteFileMethod(string data, string filePath) static object _WriteFileMethod(string data, string filePath)
{ {
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to write file: '{0}'", filePath); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to write file: '{0}'", filePath);
try try
{ {
if (fileLock.TryEnter()) if (fileLock.TryEnter())
{ {
using (StreamWriter sw = new StreamWriter(filePath)) using (StreamWriter sw = new StreamWriter(filePath))
{ {
sw.Write(data); sw.Write(data);
sw.Flush(); sw.Flush();
} }
} }
else else
{ {
Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock"); Debug.Console(0, Debug.ErrorLogLevel.Error, "FileIO Unable to enter FileLock");
} }
} }
catch (Exception e) catch (Exception e)
{ {
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO write failed: \r{0}", e); Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: FileIO write failed: \r{0}", e);
} }
finally finally
{ {
if (fileLock != null && !fileLock.Disposed) if (fileLock != null && !fileLock.Disposed)
fileLock.Leave(); fileLock.Leave();
} }
return null; return null;
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static bool FileIoUnitTest() public static bool FileIoUnitTest()
{ {
var testData = "Testing FileIO"; var testData = "Testing FileIO";
FileIO.WriteDataToFile(testData, "\\user\\FileIOTest.pdt"); FileIO.WriteDataToFile(testData, "\\user\\FileIOTest.pdt");
var file = FileIO.GetFile("\\user\\*FileIOTest*"); var file = FileIO.GetFile("\\user\\*FileIOTest*");
var readData = FileIO.ReadDataFromFile(file);
Debug.Console(0, "Returned {0}", readData);
File.Delete(file.FullName);
if (testData == readData)
{
return true;
}
else
{
return false;
}
}
} var readData = FileIO.ReadDataFromFile(file);
public class FileEventArgs Debug.Console(0, "Returned {0}", readData);
{ File.Delete(file.FullName);
public FileEventArgs(string data) { Data = data; } if (testData == readData)
public string Data { get; private set; } // readonly {
return true;
}
else
{
return false;
}
}
} }
public class FileEventArgs
{
public FileEventArgs(string data) { Data = data; }
public string Data { get; private set; } // readonly
}
} }

View File

@@ -200,7 +200,6 @@
<Compile Include="Crestron IO\Relay\GenericRelayDevice.cs" /> <Compile Include="Crestron IO\Relay\GenericRelayDevice.cs" />
<Compile Include="Crestron IO\Relay\ISwitchedOutput.cs" /> <Compile Include="Crestron IO\Relay\ISwitchedOutput.cs" />
<Compile Include="Crestron IO\StatusSign\StatusSignController.cs" /> <Compile Include="Crestron IO\StatusSign\StatusSignController.cs" />
<Compile Include="Devices\PowerInterfaces.cs" />
<Compile Include="Web\RequestHandlers\AppDebugRequestHandler.cs" /> <Compile Include="Web\RequestHandlers\AppDebugRequestHandler.cs" />
<Compile Include="Web\RequestHandlers\GetFeedbacksForDeviceRequestHandler.cs" /> <Compile Include="Web\RequestHandlers\GetFeedbacksForDeviceRequestHandler.cs" />
<Compile Include="Web\EssentialsWebApiHelpers.cs" /> <Compile Include="Web\EssentialsWebApiHelpers.cs" />