Skip to content

Commit b77fc36

Browse files
Merge pull request #1240 from PepperDash/codec-messenger-issues
Codec messenger serialization issues
2 parents 157ef33 + 1fe8993 commit b77fc36

9 files changed

Lines changed: 335 additions & 207 deletions

File tree

src/PepperDash.Essentials.Core/Routing/RoutingInputPort.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23

34

45
namespace PepperDash.Essentials.Core
@@ -8,10 +9,11 @@ namespace PepperDash.Essentials.Core
89
/// </summary>
910
public class RoutingInputPort : RoutingPort
1011
{
11-
/// <summary>
12-
/// The IRoutingInputs object this lives on
13-
/// </summary>
14-
public IRoutingInputs ParentDevice { get; private set; }
12+
/// <summary>
13+
/// The IRoutingInputs object this lives on
14+
/// </summary>
15+
[JsonIgnore]
16+
public IRoutingInputs ParentDevice { get; private set; }
1517

1618
/// <summary>
1719
/// Constructor for a basic RoutingInputPort

src/PepperDash.Essentials.Core/Routing/RoutingOutputPort.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23

34

45
namespace PepperDash.Essentials.Core
56
{
67
public class RoutingOutputPort : RoutingPort
7-
{
8-
/// <summary>
9-
/// The IRoutingOutputs object this port lives on
10-
/// </summary>
11-
public IRoutingOutputs ParentDevice { get; private set; }
8+
{
9+
/// <summary>
10+
/// The IRoutingOutputs object this port lives on
11+
/// </summary>
12+
///
13+
[JsonIgnore]
14+
public IRoutingOutputs ParentDevice { get; private set; }
1215

1316
public InUseTracking InUseTracker { get; private set; }
1417

src/PepperDash.Essentials.Core/Routing/RoutingPortCollection.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44

5-
using PepperDash.Core;
6-
7-
85
namespace PepperDash.Essentials.Core
96
{
107
/// <summary>

src/PepperDash.Essentials.Devices.Common/Cameras/CameraBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public abstract class CameraBase : ReconfigurableDevice, IRoutingOutputs
3737

3838
#region IRoutingOutputs Members
3939

40+
[JsonIgnore]
4041
public RoutingPortCollection<RoutingOutputPort> OutputPorts { get; protected set; }
4142

4243
#endregion

src/PepperDash.Essentials.MobileControl.Messengers/Messengers/DevicePresetsModelMessenger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private void SavePresets(List<PresetChannel> presets)
4343
protected override void RegisterActions()
4444

4545
{
46-
AddAction("/presets/fullStatus", (id, content) =>
46+
AddAction("/fullStatus", (id, content) =>
4747
{
4848
this.LogInformation("getting full status for client {id}", id);
4949
try
@@ -56,7 +56,7 @@ protected override void RegisterActions()
5656
}
5757
});
5858

59-
AddAction("/presets/recall", (id, content) =>
59+
AddAction("/recall", (id, content) =>
6060
{
6161
var p = content.ToObject<PresetChannelMessage>();
6262

@@ -70,7 +70,7 @@ protected override void RegisterActions()
7070
RecallPreset(dev, p.Preset.Channel);
7171
});
7272

73-
AddAction("/presets/save", (id, content) =>
73+
AddAction("/save", (id, content) =>
7474
{
7575
var presets = content.ToObject<List<PresetChannel>>();
7676

src/PepperDash.Essentials.MobileControl.Messengers/Messengers/ISelectableItemsMessenger.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
using Newtonsoft.Json.Converters;
33
using Newtonsoft.Json.Linq;
44
using PepperDash.Core;
5+
using PepperDash.Core.Logging;
56
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
7+
using System;
8+
using System.Collections.Generic;
69

710
namespace PepperDash.Essentials.AppServer.Messengers
811
{
@@ -56,10 +59,32 @@ protected override void RegisterActions()
5659

5760
private void SendFullStatus()
5861
{
59-
var stateObject = new JObject();
60-
stateObject[_propName] = JToken.FromObject(itemDevice, serializer);
61-
PostStatusMessage(stateObject);
62+
try
63+
{
64+
this.LogInformation("Sending full status");
65+
66+
var stateObject = new ISelectableItemsStateMessage<TKey>
67+
{
68+
Items = itemDevice.Items,
69+
CurrentItem = itemDevice.CurrentItem
70+
};
71+
72+
PostStatusMessage(stateObject);
73+
}
74+
catch (Exception e)
75+
{
76+
this.LogError("Error sending full status: {0}", e.Message);
77+
}
6278
}
6379
}
6480

81+
public class ISelectableItemsStateMessage<TKey> : DeviceStateMessageBase
82+
{
83+
[JsonProperty("items")]
84+
public Dictionary<TKey, ISelectableItem> Items { get; set; }
85+
86+
[JsonProperty("currentItem")]
87+
public TKey CurrentItem { get; set; }
88+
}
89+
6590
}

src/PepperDash.Essentials.MobileControl.Messengers/Messengers/MessengerBase.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Newtonsoft.Json;
22
using Newtonsoft.Json.Linq;
33
using PepperDash.Core;
4+
using PepperDash.Core.Logging;
45
using PepperDash.Essentials.Core;
56
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
67
using System;
@@ -152,11 +153,13 @@ protected void PostStatusMessage(DeviceStateMessageBase message, string clientId
152153

153154
message.Name = _device.Name;
154155

155-
PostStatusMessage(JToken.FromObject(message), MessagePath, clientId);
156+
var token = JToken.FromObject(message);
157+
158+
PostStatusMessage(token, MessagePath, clientId);
156159
}
157160
catch (Exception ex)
158161
{
159-
Debug.LogMessage(ex, "Exception posting status message", this);
162+
this.LogError(ex, "Exception posting status message for {messagePath} to {clientId}", MessagePath, clientId ?? "all clients");
160163
}
161164
}
162165

@@ -173,11 +176,13 @@ protected void PostStatusMessage(string type, DeviceStateMessageBase deviceState
173176

174177
deviceState.MessageBasePath = MessagePath;
175178

176-
PostStatusMessage(JToken.FromObject(deviceState), type, clientId);
179+
var token = JToken.FromObject(deviceState);
180+
181+
PostStatusMessage(token, type, clientId);
177182
}
178183
catch (Exception ex)
179184
{
180-
Debug.LogMessage(ex, "Exception posting status message", this);
185+
this.LogError(ex, "Exception posting status message for {type} to {clientId}", type, clientId ?? "all clients");
181186
}
182187
}
183188

0 commit comments

Comments
 (0)