mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 04:34:56 +00:00
Added ConfigWriter class. Updated AV Funciton Driver UI classes to show shutdown prompt when room about to shut down for vacancy.
This commit is contained in:
67
PepperDashEssentials/Config/ConfigWriter.cs
Normal file
67
PepperDashEssentials/Config/ConfigWriter.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using PepperDash.Core;
|
||||||
|
using PepperDash.Essentials.Core;
|
||||||
|
using PepperDash.Essentials.Core.Config;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials
|
||||||
|
{
|
||||||
|
public class ConfigWriter
|
||||||
|
{
|
||||||
|
|
||||||
|
public static bool WriteConfig()
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Writing Configuration to file");
|
||||||
|
|
||||||
|
var fileLock = new CCriticalSection();
|
||||||
|
|
||||||
|
|
||||||
|
var filePath = Global.FilePathPrefix + "LocalConfig" + Global.DirectorySeparator + "configurationFile.json";
|
||||||
|
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to write config file: '{0}'", filePath);
|
||||||
|
|
||||||
|
var configData = JsonConvert.SerializeObject(ConfigReader.ConfigObject);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
if (fileLock.TryEnter())
|
||||||
|
{
|
||||||
|
using (StreamWriter sw = new StreamWriter(filePath))
|
||||||
|
{
|
||||||
|
sw.Write(configData);
|
||||||
|
sw.Flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to enter FileLock");
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: Config write failed: \r{0}", e);
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (fileLock != null && !fileLock.Disposed)
|
||||||
|
fileLock.Leave();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,8 @@ namespace PepperDash.Essentials
|
|||||||
//CrestronConsole.AddNewConsoleCommand(s => GoWithLoad(), "go", "Loads configuration file",
|
//CrestronConsole.AddNewConsoleCommand(s => GoWithLoad(), "go", "Loads configuration file",
|
||||||
// ConsoleAccessLevelEnum.AccessOperator);
|
// ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
|
||||||
|
CrestronConsole.AddNewConsoleCommand(S => { ConfigWriter.WriteConfig(); }, "writeconfig", "writes the current config to a file", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
|
||||||
CrestronConsole.AddNewConsoleCommand(s =>
|
CrestronConsole.AddNewConsoleCommand(s =>
|
||||||
{
|
{
|
||||||
foreach (var tl in TieLineCollection.Default)
|
foreach (var tl in TieLineCollection.Default)
|
||||||
|
|||||||
@@ -127,6 +127,7 @@
|
|||||||
<Compile Include="Configuration ORIGINAL\Factories\DisplayFactory.cs" />
|
<Compile Include="Configuration ORIGINAL\Factories\DisplayFactory.cs" />
|
||||||
<Compile Include="Configuration ORIGINAL\Factories\FactoryHelper.cs" />
|
<Compile Include="Configuration ORIGINAL\Factories\FactoryHelper.cs" />
|
||||||
<Compile Include="Config\ConfigReader.cs" />
|
<Compile Include="Config\ConfigReader.cs" />
|
||||||
|
<Compile Include="Config\ConfigWriter.cs" />
|
||||||
<Compile Include="Config\EssentialsConfig.cs" />
|
<Compile Include="Config\EssentialsConfig.cs" />
|
||||||
<Compile Include="Factory\DeviceFactory.cs" />
|
<Compile Include="Factory\DeviceFactory.cs" />
|
||||||
<Compile Include="Devices\Amplifier.cs" />
|
<Compile Include="Devices\Amplifier.cs" />
|
||||||
|
|||||||
@@ -273,8 +273,6 @@ namespace PepperDash.Essentials.Room.Behaviours
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CalculateAndSetAcknowledgeExpirationTimeout(ScheduledEvent schEvent, DateTime time1, DateTime time2)
|
void CalculateAndSetAcknowledgeExpirationTimeout(ScheduledEvent schEvent, DateTime time1, DateTime time2)
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "time1.Hour = {0}", time1.Hour);
|
Debug.Console(1, this, "time1.Hour = {0}", time1.Hour);
|
||||||
@@ -421,7 +419,7 @@ namespace PepperDash.Essentials.Room.Behaviours
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Callback for event that enables feature
|
/// Callback for event that enables feature. Enables feature if config property is true
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="SchEvent"></param>
|
/// <param name="SchEvent"></param>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
@@ -437,7 +435,7 @@ namespace PepperDash.Essentials.Room.Behaviours
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Callback for event that enables feature
|
/// Callback for event that enables feature. Disables feature
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="SchEvent"></param>
|
/// <param name="SchEvent"></param>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
|
|||||||
Submodule essentials-framework updated: 5c2202723f...bf9115f17b
Reference in New Issue
Block a user