Compare commits

...

3 Commits

Author SHA1 Message Date
Trevor Payne
03ef3d88ea fix: update console print statements to include explicit newline declarations 2023-04-14 10:42:52 -05:00
jta
7247d74ce8 fix: issue with file path on four sereis
refactor: remove redundnet /
2023-04-14 10:42:52 -05:00
jta
6b35ea6192 feature: fileio now uses Global.FilePathPrefix as its directory
All read wirtes now use the current working essentials directory. This resolves issues between 3 series, 4 series, and VC-4
2023-04-14 10:42:52 -05:00
5 changed files with 133 additions and 53 deletions

View File

@@ -93,7 +93,7 @@ namespace PepperDash.Essentials
CrestronConsole.AddNewConsoleCommand(s =>
{
foreach (var tl in TieLineCollection.Default)
CrestronConsole.ConsoleCommandResponse(" {0}\r\n", tl);
CrestronConsole.ConsoleCommandResponse(" {0}{1}", tl, CrestronEnvironment.NewLine);
},
"listtielines", "Prints out all tie lines", ConsoleAccessLevelEnum.AccessOperator);
@@ -107,11 +107,12 @@ namespace PepperDash.Essentials
CrestronConsole.AddNewConsoleCommand(s =>
CrestronConsole.ConsoleCommandResponse(
"This system can be found at the following URLs:\r\n" +
"System URL: {0}\r\n" +
"Template URL: {1}",
"This system can be found at the following URLs:{2}" +
"System URL: {0}{2}" +
"Template URL: {1}{2}",
ConfigReader.ConfigObject.SystemUrl,
ConfigReader.ConfigObject.TemplateUrl),
ConfigReader.ConfigObject.TemplateUrl,
CrestronEnvironment.NewLine),
"portalinfo",
"Shows portal URLS from configuration",
ConsoleAccessLevelEnum.AccessOperator);

View File

@@ -388,17 +388,17 @@ namespace PepperDash.Essentials.Core
var outputPorts = ((device as IRoutingOutputs) != null) ? (device as IRoutingOutputs).OutputPorts : null;
if (inputPorts != null)
{
CrestronConsole.ConsoleCommandResponse("Device {0} has {1} Input Ports:", s, inputPorts.Count);
CrestronConsole.ConsoleCommandResponse("Device {0} has {1} Input Ports:{2}", s, inputPorts.Count, CrestronEnvironment.NewLine);
foreach (var routingInputPort in inputPorts)
{
CrestronConsole.ConsoleCommandResponse("{0}", routingInputPort.Key);
CrestronConsole.ConsoleCommandResponse("{0}{1}", routingInputPort.Key, CrestronEnvironment.NewLine);
}
}
if (outputPorts == null) return;
CrestronConsole.ConsoleCommandResponse("Device {0} has {1} Output Ports:", s, outputPorts.Count);
CrestronConsole.ConsoleCommandResponse("Device {0} has {1} Output Ports:{2}", s, outputPorts.Count, CrestronEnvironment.NewLine);
foreach (var routingOutputPort in outputPorts)
{
CrestronConsole.ConsoleCommandResponse("{0}", routingOutputPort.Key);
CrestronConsole.ConsoleCommandResponse("{0}{1}", routingOutputPort.Key, CrestronEnvironment.NewLine);
}
}

View File

@@ -21,35 +21,37 @@ namespace PepperDash.Essentials.Core
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static FileInfo[] GetFiles(string fileName)
{
DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(fileName));
var files = dirInfo.GetFiles(Path.GetFileName(fileName));
Debug.Console(0, "FileIO found: {0}, {1}", files.Count(), fileName);
if (files.Count() > 0)
{
return files;
}
else
{
return null;
}
}
public static FileInfo[] GetFiles(string fileName)
{
string fullFilePath = Global.FilePathPrefix + fileName;
DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(fullFilePath));
var files = dirInfo.GetFiles(Path.GetFileName(fullFilePath));
Debug.Console(0, "FileIO found: {0}, {1}", files.Count(), fullFilePath);
if (files.Count() > 0)
{
return files;
}
else
{
return null;
}
}
public static FileInfo GetFile(string fileName)
{
DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(fileName));
var files = dirInfo.GetFiles(Path.GetFileName(fileName));
Debug.Console(0, "FileIO found: {0}, {1}", files.Count(), fileName);
if (files.Count() > 0)
{
return files.FirstOrDefault();
}
else
{
return null;
}
}
public static FileInfo GetFile(string fileName)
{
string fullFilePath = Global.FilePathPrefix + fileName;
DirectoryInfo dirInfo = new DirectoryInfo(Path.GetDirectoryName(fullFilePath));
var files = dirInfo.GetFiles(Path.GetFileName(fullFilePath));
Debug.Console(0, "FileIO found: {0}, {1}", files.Count(), fullFilePath);
if (files.Count() > 0)
{
return files.FirstOrDefault();
}
else
{
return null;
}
}
/// <summary>
@@ -81,7 +83,7 @@ namespace PepperDash.Essentials.Core
{
if (fileLock.TryEnter())
{
DirectoryInfo dirInfo = new DirectoryInfo(file.Name);
DirectoryInfo dirInfo = new DirectoryInfo(file.DirectoryName);
Debug.Console(2, "FileIO Getting Data {0}", file.FullName);
if (File.Exists(file.FullName))
@@ -202,7 +204,7 @@ namespace PepperDash.Essentials.Core
public static void WriteDataToFile(string data, string filePath)
{
Thread _WriteFileThread;
_WriteFileThread = new Thread((O) => _WriteFileMethod(data, filePath), null, Thread.eThreadStartOptions.CreateSuspended);
_WriteFileThread = new Thread((O) => _WriteFileMethod(data, Global.FilePathPrefix + "/" + filePath), null, Thread.eThreadStartOptions.CreateSuspended);
_WriteFileThread.Priority = Thread.eThreadPriority.LowestPriority;
_WriteFileThread.Start();
Debug.Console(0, Debug.ErrorLogLevel.Notice, "New WriteFile Thread");
@@ -217,7 +219,8 @@ namespace PepperDash.Essentials.Core
{
if (fileLock.TryEnter())
{
using (StreamWriter sw = new StreamWriter(filePath))
using (StreamWriter sw = new StreamWriter(filePath))
{
sw.Write(data);
sw.Flush();

View File

@@ -6,7 +6,7 @@ using System.Text;
using Crestron.SimplSharp.Reflection;
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Ssh;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
@@ -234,7 +234,7 @@ namespace PepperDash.Essentials.Core
/// </summary>
public void PrintJoinMapInfo()
{
var sb = JoinmapStringBuilder();
var sb = JoinmapStringBuilderPrint();
CrestronConsole.ConsoleCommandResponse(sb.ToString());
}
@@ -273,6 +273,50 @@ namespace PepperDash.Essentials.Core
return sb;
}
private StringBuilder JoinmapStringBuilderPrint()
{
var sb = new StringBuilder();
// Get the joins of each type and print them
var digitals =
Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Digital) == eJoinType.Digital)
.ToDictionary(j => j.Key, j => j.Value);
var analogs =
Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Analog) == eJoinType.Analog)
.ToDictionary(j => j.Key, j => j.Value);
var serials =
Joins.Where(j => (j.Value.Metadata.JoinType & eJoinType.Serial) == eJoinType.Serial)
.ToDictionary(j => j.Key, j => j.Value);
const string description = "description";
var descriptionLengthAnchor = description.Length;
var descriptionLength =
(from @join in Joins select @join.Value into j select j.Metadata.Description.Length).Concat(new[] { descriptionLengthAnchor })
.Max();
sb.AppendLine(String.Format("# {0}" + CrestronEnvironment.NewLine, GetType().Name));
sb.AppendLine(CrestronEnvironment.NewLine);
sb.AppendLine("## Digitals");
sb.AppendLine(CrestronEnvironment.NewLine + CrestronEnvironment.NewLine);
// Get the joins of each type and print them
var digitalSb = PrintAppendJoinList(GetSortedJoins(digitals), descriptionLength);
digitalSb.AppendLine(CrestronEnvironment.NewLine);
digitalSb.AppendLine("## Analogs");
var analogSb = PrintAppendJoinList(GetSortedJoins(analogs), descriptionLength);
analogSb.AppendLine(CrestronEnvironment.NewLine);
analogSb.AppendLine("## Serials");
var serialSb = PrintAppendJoinList(GetSortedJoins(serials), descriptionLength);
serialSb.AppendLine(CrestronEnvironment.NewLine);
sb.EnsureCapacity(sb.Length + digitalSb.Length + analogSb.Length + serialSb.Length);
sb.Append(digitalSb + CrestronEnvironment.NewLine + CrestronEnvironment.NewLine).Append(analogSb + CrestronEnvironment.NewLine + CrestronEnvironment.NewLine).Append(serialSb + CrestronEnvironment.NewLine);
return sb;
}
/// <summary>
/// Prints the join information to console
/// </summary>
@@ -280,9 +324,7 @@ namespace PepperDash.Essentials.Core
{
var pluginType = GetType().Name;
CrestronConsole.ConsoleCommandResponse("{0}:\n", pluginType);
CrestronConsole.ConsoleCommandResponse("{0}:" + CrestronEnvironment.NewLine, pluginType);
WriteJoinmapMarkdown(JoinmapStringBuilder(), pluginType, bridgeKey, deviceKey);
@@ -295,7 +337,7 @@ namespace PepperDash.Essentials.Core
using (var sw = new StreamWriter(fileName))
{
sw.WriteLine(stringBuilder.ToString());
CrestronConsole.ConsoleCommandResponse("Joinmap Readme generated and written to {0}", fileName);
CrestronConsole.ConsoleCommandResponse("Joinmap Readme generated and written to {0}" + CrestronEnvironment.NewLine, fileName);
}
}
@@ -323,13 +365,13 @@ namespace PepperDash.Essentials.Core
const int joinSpanLen = 9;
const int typeLen = 19;
const int capabilitiesLen = 12;
var descriptionLen = (from @join in joins select @join.Value into j select j.Metadata.Description.Length).Concat(new[] {11}).Max();
var descriptionLen = (from @join in joins select @join.Value into j select j.Metadata.Description.Length).Concat(new[] { 11 }).Max();
//build header
sb.AppendLine(String.Format(stringFormatter,
String.Format("Join Number").PadRight(joinNumberLen, ' '),
String.Format("Join Span").PadRight(joinSpanLen, ' '),
String.Format("Description").PadRight(descriptionLen, ' '),
sb.AppendLine(String.Format(stringFormatter,
String.Format("Join Number").PadRight(joinNumberLen, ' '),
String.Format("Join Span").PadRight(joinSpanLen, ' '),
String.Format("Description").PadRight(descriptionLen, ' '),
String.Format("Type").PadRight(typeLen, ' '),
String.Format("Capabilities").PadRight(capabilitiesLen, ' ')));
//build table seperator
@@ -348,6 +390,40 @@ namespace PepperDash.Essentials.Core
return sb;
}
private static StringBuilder PrintAppendJoinList(List<KeyValuePair<string, JoinDataComplete>> joins,
int descriptionLength)
{
var sb = new StringBuilder();
const string stringFormatter = "| {0} | {1} | {2} | {3} | {4} |";
const int joinNumberLen = 11;
const int joinSpanLen = 9;
const int typeLen = 19;
const int capabilitiesLen = 12;
//build header
sb.AppendLine(String.Format(stringFormatter,
String.Format("Join Number").PadRight(joinNumberLen, ' '),
String.Format("Join Span").PadRight(joinSpanLen, ' '),
String.Format("Description").PadRight(descriptionLength, ' '),
String.Format("Type").PadRight(typeLen, ' '),
String.Format("Capabilities").PadRight(capabilitiesLen, ' ')) + CrestronEnvironment.NewLine);
//build table seperator
sb.AppendLine(String.Format(stringFormatter,
new String('-', joinNumberLen),
new String('-', joinSpanLen),
new String('-', descriptionLength),
new String('-', typeLen),
new String('-', capabilitiesLen)) + CrestronEnvironment.NewLine);
foreach (var join in joins)
{
sb.AppendLine(join.Value.GetMarkdownFormattedData(stringFormatter, descriptionLength) +
CrestronEnvironment.NewLine);
}
sb.AppendLine();
return sb;
}
/// <summary>
/// Attempts to find the matching key for the custom join and if found overwrites the default JoinData with the custom
/// </summary>

View File

@@ -195,10 +195,10 @@ namespace PepperDash.Essentials
public static void ReportAssemblyVersions(string command)
{
CrestronConsole.ConsoleCommandResponse("Loaded Assemblies:");
CrestronConsole.ConsoleCommandResponse("Loaded Assemblies:" + CrestronEnvironment.NewLine);
foreach (var assembly in LoadedAssemblies)
{
CrestronConsole.ConsoleCommandResponse("{0} Version: {1}", assembly.Name, assembly.Version);
CrestronConsole.ConsoleCommandResponse("{0} Version: {1}" + CrestronEnvironment.NewLine, assembly.Name, assembly.Version);
}
}