WebAPI: Added LookupSuccess to user and preset event args to trigger found/not-found pulses in Simpl

This commit is contained in:
Heath Volmer
2017-02-27 12:13:23 -07:00
parent f154afb885
commit 721275ee2c
14 changed files with 42 additions and 17 deletions

View File

@@ -36,15 +36,26 @@ namespace PepperDash.Core.WebApi.Presets
/// </summary>
public class PresetReceivedEventArgs : EventArgs
{
public Preset Preset { get; private set; }
/// <summary>
/// True when the preset is found
/// </summary>
public bool LookupSuccess { get; private set; }
/// <summary>
/// S+ helper for stupid S+
/// </summary>
public ushort ULookupSuccess { get { return (ushort)(LookupSuccess ? 1 : 0); } }
public Preset Preset { get; private set; }
/// <summary>
/// For Simpl+
/// </summary>
public PresetReceivedEventArgs() { }
public PresetReceivedEventArgs(Preset preset)
public PresetReceivedEventArgs(Preset preset, bool success)
{
LookupSuccess = success;
Preset = preset;
}
}

View File

@@ -26,6 +26,16 @@ namespace PepperDash.Core.WebApi.Presets
/// </summary>
public class UserReceivedEventArgs : EventArgs
{
/// <summary>
/// True when user is found
/// </summary>
public bool LookupSuccess { get; private set; }
/// <summary>
/// For stupid S+
/// </summary>
public ushort ULookupSuccess { get { return (ushort)(LookupSuccess ? 1 : 0); } }
public User User { get; private set; }
/// <summary>
@@ -33,8 +43,9 @@ namespace PepperDash.Core.WebApi.Presets
/// </summary>
public UserReceivedEventArgs() { }
public UserReceivedEventArgs(User user)
public UserReceivedEventArgs(User user, bool success)
{
LookupSuccess = success;
User = user;
}
}

View File

@@ -77,18 +77,18 @@ namespace PepperDash.Core.WebApi.Presets
client.HostVerification = false;
client.PeerVerification = false;
var resp = client.Dispatch(req);
var handler = UserReceived;
if (resp.Code == 200)
{
CrestronConsole.PrintLine("Received: {0}", resp.ContentString);
//CrestronConsole.PrintLine("Received: {0}", resp.ContentString);
var user = JsonConvert.DeserializeObject<User>(resp.ContentString);
#warning CHECK for user success here??
CurrentUser = user;
var handler = UserReceived;
if (handler != null)
UserReceived(this, new UserReceivedEventArgs(user));
UserReceived(this, new UserReceivedEventArgs(user, true));
}
else
CrestronConsole.PrintLine("No user received: {0}", resp.Code);
if (handler != null)
UserReceived(this, new UserReceivedEventArgs(null, false));
}
/// <summary>
@@ -111,6 +111,7 @@ namespace PepperDash.Core.WebApi.Presets
PresetNumber = presetNumber
};
var handler = PresetReceived;
try
{
if (!UrlBase.StartsWith("https"))
@@ -130,27 +131,28 @@ namespace PepperDash.Core.WebApi.Presets
var resp = client.Dispatch(req);
if (resp.Code == 200) // got it
{
Debug.Console(1, this, "Received: {0}", resp.ContentString);
//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.");
//Debug.Console(1, this, "Loaded preset has no data. Loading default template.");
LoadDefaultPresetData();
return;
}
J2SMaster.LoadWithJson(preset.Data);
var handler = PresetReceived;
if (handler != null)
PresetReceived(this, new PresetReceivedEventArgs(preset));
PresetReceived(this, new PresetReceivedEventArgs(preset, true));
}
else // no existing preset
{
CurrentPreset = new Preset();
LoadDefaultPresetData();
if (handler != null)
PresetReceived(this, new PresetReceivedEventArgs(null, false));
}
}
catch (HttpException e)
@@ -158,6 +160,8 @@ namespace PepperDash.Core.WebApi.Presets
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));
}
}