Added initial filesystem set up that puts all folders in place on initial run

This commit is contained in:
Heath Volmer
2018-01-09 15:58:38 -07:00
parent 857d10f0b2
commit ac4ef972fe
9 changed files with 441 additions and 382 deletions

View File

@@ -16,13 +16,21 @@ namespace PepperDash.Essentials
{ {
public static EssentialsConfig ConfigObject { get; private set; } public static EssentialsConfig ConfigObject { get; private set; }
public static void LoadConfig2() public static bool LoadConfig2()
{ {
Debug.Console(0, "Using unmerged system/template configs."); Debug.Console(0, "Using unmerged system/template configs.");
try try
{ {
using (StreamReader fs = new StreamReader(string.Format(@"\NVRAM\program{0}\ConfigurationFile.json", var filePath = string.Format(@"\NVRAM\program{0}\ConfigurationFile.json",
InitialParametersClass.ApplicationNumber))) InitialParametersClass.ApplicationNumber);
if (!File.Exists(filePath))
{
Debug.Console(0,
"ERROR: Configuration file not present. Please load file to {0} and reset program", filePath);
return false;
}
using (StreamReader fs = new StreamReader(filePath))
{ {
var doubleObj = JObject.Parse(fs.ReadToEnd()); var doubleObj = JObject.Parse(fs.ReadToEnd());
ConfigObject = MergeConfigs(doubleObj).ToObject<EssentialsConfig>(); ConfigObject = MergeConfigs(doubleObj).ToObject<EssentialsConfig>();
@@ -38,13 +46,13 @@ namespace PepperDash.Essentials
{ {
ConfigObject.TemplateUrl= doubleObj["template_url"].Value<string>(); ConfigObject.TemplateUrl= doubleObj["template_url"].Value<string>();
} }
} }
return true;
} }
catch (Exception e) catch (Exception e)
{ {
Debug.Console(0, "Config failed: \r{0}", e); Debug.Console(0, "ERROR: Config load failed: \r{0}", e);
return false;
} }
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.CrestronThread; using Crestron.SimplSharpPro.CrestronThread;
using PepperDash.Core; using PepperDash.Core;
@@ -49,33 +50,82 @@ namespace PepperDash.Essentials
/// </summary> /// </summary>
public void GoWithLoad() public void GoWithLoad()
{ {
// var thread = new Thread(o => try
// { {
try CrestronConsole.AddNewConsoleCommand(EnablePortalSync, "portalsync", "Loads Portal Sync",
ConsoleAccessLevelEnum.AccessOperator);
//PortalSync = new PepperDashPortalSyncClient();
Debug.Console(0, "Starting Essentials load from configuration");
var filesReady = SetupFilesystem();
if (filesReady)
{ {
CrestronConsole.AddNewConsoleCommand(EnablePortalSync, "portalsync", "Loads Portal Sync", Debug.Console(0, "Folder structure verified. Loading config...");
ConsoleAccessLevelEnum.AccessOperator); if (!ConfigReader.LoadConfig2())
return;
//PortalSync = new PepperDashPortalSyncClient();
Debug.Console(0, "Starting Essentials load from configuration");
ConfigReader.LoadConfig2();
LoadDevices(); LoadDevices();
LoadTieLines(); LoadTieLines();
LoadRooms(); LoadRooms();
LogoServer = new HttpLogoServer(8080, @"\html\logo"); try
{
LogoServer = new HttpLogoServer(8080, @"\html\logo");
}
catch (Exception e)
{
Debug.Console(0, "WARNING: Logo server cannot be started on port 8080:\n{0}", e);
}
DeviceManager.ActivateAll(); DeviceManager.ActivateAll();
Debug.Console(0, "Essentials load complete\r" + Debug.Console(0, "Essentials load complete\r" +
"-------------------------------------------------------------"); "-------------------------------------------------------------");
}
catch (Exception e)
{
Debug.Console(0, "FATAL INITIALIZE ERROR. System is in an inconsistent state:\r{0}", e);
} }
// return null; else
// }, null); {
Debug.Console(0,
"------------------------------------------------\n" +
"------------------------------------------------\n" +
"------------------------------------------------\n" +
"Essentials file structure setup completed.\n" +
"Please load config, sgd and ir files and\n" +
"restart program.\n" +
"------------------------------------------------\n" +
"------------------------------------------------\n" +
"------------------------------------------------");
}
}
catch (Exception e)
{
Debug.Console(0, "FATAL INITIALIZE ERROR. System is in an inconsistent state:\r{0}", e);
}
}
/// <summary>
/// Verifies filesystem is set up. IR, SGD, and program1 folders
/// </summary>
bool SetupFilesystem()
{
Debug.Console(0, "Verifying and/or creating folder structure");
var appNum = InitialParametersClass.ApplicationNumber;
var configDir = @"\NVRAM\Program" + appNum;
var configExists = Directory.Exists(configDir);
if (!configExists)
Directory.Create(configDir);
var irDir = string.Format(@"\NVRAM\Program{0}\ir", appNum);
if (!Directory.Exists(irDir))
Directory.Create(irDir);
var sgdDir = string.Format(@"\NVRAM\Program{0}\sgd", appNum);
if (!Directory.Exists(sgdDir))
Directory.Create(sgdDir);
return configExists;
} }
public void EnablePortalSync(string s) public void EnablePortalSync(string s)

View File

@@ -139,7 +139,7 @@
<Compile Include="Room\Config\EssentialsHuddleVtc1PropertiesConfig.cs" /> <Compile Include="Room\Config\EssentialsHuddleVtc1PropertiesConfig.cs" />
<Compile Include="Room\Config\EssentialsRoomEmergencyConfig.cs" /> <Compile Include="Room\Config\EssentialsRoomEmergencyConfig.cs" />
<Compile Include="Room\Cotija\CotijaConfig.cs" /> <Compile Include="Room\Cotija\CotijaConfig.cs" />
<Compile Include="Room\Cotija\CotijaRoomBridge.cs" /> <Compile Include="Room\Cotija\RoomBridges\CotijaEssentialsHuddleSpaceRoomBridge.cs" />
<Compile Include="Room\Cotija\DeviceTypeInterfaces\IChannelExtensions.cs" /> <Compile Include="Room\Cotija\DeviceTypeInterfaces\IChannelExtensions.cs" />
<Compile Include="Room\Cotija\DeviceTypeInterfaces\IColorExtensions.cs" /> <Compile Include="Room\Cotija\DeviceTypeInterfaces\IColorExtensions.cs" />
<Compile Include="Room\Cotija\DeviceTypeInterfaces\IDPadExtensions.cs" /> <Compile Include="Room\Cotija\DeviceTypeInterfaces\IDPadExtensions.cs" />

View File

@@ -4,5 +4,5 @@
[assembly: AssemblyCompany("PepperDash Technology Corp")] [assembly: AssemblyCompany("PepperDash Technology Corp")]
[assembly: AssemblyProduct("PepperDashEssentials")] [assembly: AssemblyProduct("PepperDashEssentials")]
[assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2017")] [assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2017")]
[assembly: AssemblyVersion("1.0.15.*")] [assembly: AssemblyVersion("1.0.17.*")]

View File

@@ -53,6 +53,7 @@ namespace PepperDash.Essentials
public CotijaSystemController(string key, string name, CotijaConfig config) : base(key, name) public CotijaSystemController(string key, string name, CotijaConfig config) : base(key, name)
{ {
Config = config; Config = config;
Debug.Console(0, this, "Mobile UI controller initializing for server:{0}", config.ServerUrl);
CotijaRooms = new List<CotijaEssentialsHuddleSpaceRoomBridge>(); CotijaRooms = new List<CotijaEssentialsHuddleSpaceRoomBridge>();

View File

@@ -98,7 +98,7 @@ namespace PepperDash.Essentials
+ @"\sgd\" + props.SgdFile; + @"\sgd\" + props.SgdFile;
if (!File.Exists(sgdName)) if (!File.Exists(sgdName))
{ {
Debug.Console(0, this, "WARNING: Smart object file '{0}' not present. Exiting TSW load", sgdName); Debug.Console(0, this, "ERROR: Smart object file '{0}' not present. Exiting TSW load", sgdName);
return; return;
} }