Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/PepperDash.Core/Logging/DebugContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace PepperDash.Core
/// <summary>
/// Represents a debugging context
/// </summary>
[Obsolete("DebugContext is no longer supported and will be removed in a future release.")]
public class DebugContext
{
/// <summary>
Expand Down
211 changes: 106 additions & 105 deletions src/PepperDash.Core/WebApi/Presets/WebApiPasscodeClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Crestron.SimplSharp; // For Basic SIMPL# Classes
using Crestron.SimplSharp; // For Basic SIMPL# Classes
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp.Net.Http;
using Crestron.SimplSharp.Net.Https;
Expand All @@ -10,24 +10,25 @@

namespace PepperDash.Core.WebApi.Presets
{
/// <summary>
/// Passcode client for the WebApi
/// </summary>
/// <summary>
/// Passcode client for the WebApi
/// </summary>
[Obsolete("WebApiPasscodeClient is no longer supported and will be removed in a future release.")]
public class WebApiPasscodeClient : IKeyed
{
/// <summary>
/// Notifies when user received
/// </summary>
/// <summary>
/// Notifies when user received
/// </summary>
public event EventHandler<UserReceivedEventArgs> UserReceived;

/// <summary>
/// Notifies when Preset received
/// </summary>
/// <summary>
/// Notifies when Preset received
/// </summary>
public event EventHandler<PresetReceivedEventArgs> PresetReceived;

/// <summary>
/// Gets or sets the Key
/// </summary>
/// <summary>
/// Gets or sets the Key
/// </summary>
public string Key { get; private set; }

//string JsonMasterKey;
Expand All @@ -54,13 +55,13 @@ public WebApiPasscodeClient()
{
}

/// <summary>
/// Initializes the instance
/// </summary>
/// <param name="key"></param>
/// <param name="jsonMasterKey"></param>
/// <param name="urlBase"></param>
/// <param name="defaultPresetJsonFilePath"></param>
/// <summary>
/// Initializes the instance
/// </summary>
/// <param name="key"></param>
/// <param name="jsonMasterKey"></param>
/// <param name="urlBase"></param>
/// <param name="defaultPresetJsonFilePath"></param>
public void Initialize(string key, string jsonMasterKey, string urlBase, string defaultPresetJsonFilePath)
{
Key = key;
Expand All @@ -73,54 +74,54 @@ public void Initialize(string key, string jsonMasterKey, string urlBase, string
J2SMaster.Initialize(jsonMasterKey);
}

/// <summary>
/// Gets the user for a passcode
/// </summary>
/// <param name="passcode"></param>
/// <summary>
/// GetUserForPasscode method
/// </summary>
/// <summary>
/// Gets the user for a passcode
/// </summary>
/// <param name="passcode"></param>
/// <summary>
/// GetUserForPasscode method
/// </summary>
public void GetUserForPasscode(string passcode)
{
// Bullshit duplicate code here... These two cases should be the same
// except for https/http and the certificate ignores
if (!UrlBase.StartsWith("https"))
return;
var req = new HttpsClientRequest();
req.Url = new UrlParser(UrlBase + "/api/users/dopin");
req.RequestType = Crestron.SimplSharp.Net.Https.RequestType.Post;
req.Header.AddHeader(new HttpsHeader("Content-Type", "application/json"));
req.Header.AddHeader(new HttpsHeader("Accept", "application/json"));
var jo = new JObject();
jo.Add("pin", passcode);
req.ContentString = jo.ToString();
// Bullshit duplicate code here... These two cases should be the same
// except for https/http and the certificate ignores
if (!UrlBase.StartsWith("https"))
return;
var req = new HttpsClientRequest();
req.Url = new UrlParser(UrlBase + "/api/users/dopin");
req.RequestType = Crestron.SimplSharp.Net.Https.RequestType.Post;
req.Header.AddHeader(new HttpsHeader("Content-Type", "application/json"));
req.Header.AddHeader(new HttpsHeader("Accept", "application/json"));
var jo = new JObject();
jo.Add("pin", passcode);
req.ContentString = jo.ToString();

var client = new HttpsClient();
client.HostVerification = false;
client.PeerVerification = false;
var resp = client.Dispatch(req);
var handler = UserReceived;
if (resp.Code == 200)
{
//CrestronConsole.PrintLine("Received: {0}", resp.ContentString);
var user = JsonConvert.DeserializeObject<User>(resp.ContentString);
CurrentUser = user;
if (handler != null)
UserReceived(this, new UserReceivedEventArgs(user, true));
}
else
if (handler != null)
UserReceived(this, new UserReceivedEventArgs(null, false));
var client = new HttpsClient();
client.HostVerification = false;
client.PeerVerification = false;
var resp = client.Dispatch(req);
var handler = UserReceived;
if (resp.Code == 200)
{
//CrestronConsole.PrintLine("Received: {0}", resp.ContentString);
var user = JsonConvert.DeserializeObject<User>(resp.ContentString);
CurrentUser = user;
if (handler != null)
handler(this, new UserReceivedEventArgs(user, true));
}
else
if (handler != null)
handler(this, new UserReceivedEventArgs(null, false));
}

/// <summary>
///
/// </summary>
/// <param name="roomTypeId"></param>
/// <param name="presetNumber"></param>
/// <summary>
/// GetPresetForThisUser method
/// </summary>
/// <summary>
/// GetPresetForThisUser method
/// </summary>
public void GetPresetForThisUser(int roomTypeId, int presetNumber)
{
if (CurrentUser == null)
Expand All @@ -136,57 +137,57 @@ public void GetPresetForThisUser(int roomTypeId, int presetNumber)
PresetNumber = presetNumber
};

var handler = PresetReceived;
var handler = PresetReceived;
try
{
if (!UrlBase.StartsWith("https"))
return;
var req = new HttpsClientRequest();
req.Url = new UrlParser(UrlBase + "/api/presets/userandroom");
req.RequestType = Crestron.SimplSharp.Net.Https.RequestType.Post;
req.Header.AddHeader(new HttpsHeader("Content-Type", "application/json"));
req.Header.AddHeader(new HttpsHeader("Accept", "application/json"));
req.ContentString = JsonConvert.SerializeObject(msg);
if (!UrlBase.StartsWith("https"))
return;
var req = new HttpsClientRequest();
req.Url = new UrlParser(UrlBase + "/api/presets/userandroom");
req.RequestType = Crestron.SimplSharp.Net.Https.RequestType.Post;
req.Header.AddHeader(new HttpsHeader("Content-Type", "application/json"));
req.Header.AddHeader(new HttpsHeader("Accept", "application/json"));
req.ContentString = JsonConvert.SerializeObject(msg);

var client = new HttpsClient();
client.HostVerification = false;
client.PeerVerification = false;
var client = new HttpsClient();
client.HostVerification = false;
client.PeerVerification = false;

// ask for the preset
var resp = client.Dispatch(req);
if (resp.Code == 200) // got it
{
//Debug.Console(1, this, "Received: {0}", resp.ContentString);
var preset = JsonConvert.DeserializeObject<Preset>(resp.ContentString);
CurrentPreset = preset;
// ask for the preset
var resp = client.Dispatch(req);
if (resp.Code == 200) // got it
{
//Debug.Console(1, this, "Received: {0}", resp.ContentString);
var preset = JsonConvert.DeserializeObject<Preset>(resp.ContentString);
CurrentPreset = preset;

//if there's no preset data, load the template
if (preset.Data == null || preset.Data.Trim() == string.Empty || JObject.Parse(preset.Data).Count == 0)
{
//Debug.Console(1, this, "Loaded preset has no data. Loading default template.");
LoadDefaultPresetData();
return;
}
//if there's no preset data, load the template
if (preset.Data == null || preset.Data.Trim() == string.Empty || JObject.Parse(preset.Data).Count == 0)
{
//Debug.Console(1, this, "Loaded preset has no data. Loading default template.");
LoadDefaultPresetData();
return;
}

J2SMaster.LoadWithJson(preset.Data);
if (handler != null)
PresetReceived(this, new PresetReceivedEventArgs(preset, true));
}
else // no existing preset
{
CurrentPreset = new Preset();
LoadDefaultPresetData();
if (handler != null)
PresetReceived(this, new PresetReceivedEventArgs(null, false));
}
J2SMaster.LoadWithJson(preset.Data);
if (handler != null)
handler(this, new PresetReceivedEventArgs(preset, true));
}
else // no existing preset
{
CurrentPreset = new Preset();
LoadDefaultPresetData();
if (handler != null)
handler(this, new PresetReceivedEventArgs(null, false));
}
}
catch (HttpException e)
{
var resp = e.Response;
Debug.Console(1, this, "No preset received (code {0}). Loading default template", resp.Code);
LoadDefaultPresetData();
if (handler != null)
PresetReceived(this, new PresetReceivedEventArgs(null, false));
if (handler != null)
PresetReceived(this, new PresetReceivedEventArgs(null, false));
}
}

Expand Down Expand Up @@ -218,14 +219,14 @@ void LoadDefaultPresetData()
/// </summary>
/// <param name="roomTypeId"></param>
/// <param name="presetNumber"></param>
/// <summary>
/// SavePresetForThisUser method
/// </summary>
/// <summary>
/// SavePresetForThisUser method
/// </summary>
public void SavePresetForThisUser(int roomTypeId, int presetNumber)
{
if (CurrentPreset == null)
LoadDefaultPresetData();
//return;
//return;

//// A new preset needs to have its numbers set
//if (CurrentPreset.IsNewPreset)
Expand All @@ -245,8 +246,8 @@ void SaveCallback(string json)
{
CurrentPreset.Data = json;

if (!UrlBase.StartsWith("https"))
return;
if (!UrlBase.StartsWith("https"))
return;
var req = new HttpsClientRequest();
req.RequestType = Crestron.SimplSharp.Net.Https.RequestType.Post;
req.Url = new UrlParser(string.Format("{0}/api/presets/addorchange", UrlBase));
Expand All @@ -255,8 +256,8 @@ void SaveCallback(string json)
req.ContentString = JsonConvert.SerializeObject(CurrentPreset);

var client = new HttpsClient();
client.HostVerification = false;
client.PeerVerification = false;
client.HostVerification = false;
client.PeerVerification = false;
try
{
var resp = client.Dispatch(req);
Expand Down
25 changes: 13 additions & 12 deletions src/PepperDash.Essentials.Core/Config/Essentials/ConfigUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace PepperDash.Essentials.Core.Config
/// <summary>
/// ConfigUpdater class
/// </summary>
[Obsolete("ConfigUpdater is no longer supported and will be removed in a future release.")]
public static class ConfigUpdater
{
/// <summary>
Expand Down Expand Up @@ -81,15 +82,15 @@ static void OnStatusUpdate(eUpdateStatus status)
{
var handler = ConfigStatusChanged;

if(handler != null)
if (handler != null)
{
handler(typeof(ConfigUpdater), new ConfigStatusEventArgs(status));
}
}

static void WriteConfigToFile(string configData)
{
var filePath = Global.FilePathPrefix+ "configurationFile-updated.json";
var filePath = Global.FilePathPrefix + "configurationFile-updated.json";

try
{
Expand All @@ -104,7 +105,7 @@ static void WriteConfigToFile(string configData)
Debug.LogMessage(LogEventLevel.Debug, "Error parsing new config: {0}", e);

OnStatusUpdate(eUpdateStatus.UpdateFailed);
}
}
}

/// <summary>
Expand Down Expand Up @@ -149,11 +150,11 @@ static void MoveFilesToArchiveFolder(FileInfo[] files)
// Directory exists, first clear any contents
var archivedConfigFiles = ConfigReader.GetConfigFiles(archiveDirectoryPath + Global.DirectorySeparator + Global.ConfigFileName + ".bak");

if(archivedConfigFiles != null || archivedConfigFiles.Length > 0)
if (archivedConfigFiles != null && archivedConfigFiles.Length > 0)
{
Debug.LogMessage(LogEventLevel.Information, "{0} Existing files found in archive folder. Deleting.", archivedConfigFiles.Length);

for (int i = 0; i < archivedConfigFiles.Length; i++ )
for (int i = 0; i < archivedConfigFiles.Length; i++)
{
var file = archivedConfigFiles[i];
Debug.LogMessage(LogEventLevel.Information, "Deleting archived file: '{0}'", file.FullName);
Expand All @@ -170,9 +171,9 @@ static void MoveFilesToArchiveFolder(FileInfo[] files)

// Moves the file and appends the .bak extension
var fileDest = archiveDirectoryPath + "/" + file.Name + ".bak";
if(!File.Exists(fileDest))
if (!File.Exists(fileDest))
{
file.MoveTo(fileDest);
file.MoveTo(fileDest);
}
else
Debug.LogMessage(LogEventLevel.Information, "Cannot move file to archive folder. Existing file already exists with same name: '{0}'", fileDest);
Expand Down Expand Up @@ -207,15 +208,15 @@ static void RestartProgram()

CrestronConsole.SendControlSystemCommand(string.Format("progreset -p:{0}", InitialParametersClass.ApplicationNumber), ref response);

Debug.LogMessage(LogEventLevel.Debug, "Console Response: {0}", response);
Debug.LogMessage(LogEventLevel.Debug, "Console Response: {0}", response);
}

}

/// <summary>
/// Enumeration of eUpdateStatus values
/// </summary>
public enum eUpdateStatus
/// <summary>
/// Enumeration of eUpdateStatus values
/// </summary>
public enum eUpdateStatus
{
/// <summary>
/// UpdateStarted status
Expand Down
Loading