Skip to content

Commit 73afcba

Browse files
authored
Merge pull request #1034 from twpol/feature/fix-menu-notifications
Fix menu notifications
2 parents 1af7264 + b6b9325 commit 73afcba

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

Source/Menu/Notifications/NotificationManager.cs

+23-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
using System.Linq;
2323
using System.Net;
2424
using System.Resources;
25-
using System.Runtime.InteropServices;
2625
using System.Text;
2726
using System.Windows;
2827
using System.Windows.Forms;
@@ -32,6 +31,7 @@
3231
using ORTS.Updater;
3332
using static ORTS.Common.SystemInfo;
3433
using static Menu.Notifications.NotificationPage;
34+
using Newtonsoft.Json.Serialization;
3535

3636
// Behaviour
3737
// Notifications are read only once as a background task at start into Notifications.
@@ -126,7 +126,7 @@ public void CheckNotifications()
126126
Notifications.NotificationList = IncludeValid(Notifications.NotificationList);
127127
Notifications.NotificationList = SortByDate(Notifications.NotificationList);
128128
}
129-
catch (WebException ex)
129+
catch (Exception ex)
130130
{
131131
Error = ex;
132132
}
@@ -154,7 +154,7 @@ public Notifications GetNotifications()
154154
notificationsSerial = GetRemoteJson();
155155
}
156156

157-
var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto };
157+
var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, SerializationBinder = new NotificationSerializationBinder() };
158158
var jsonInput = JsonConvert.DeserializeObject<Notifications>(notificationsSerial, jsonSettings);
159159

160160
NewPages.Count = 0;
@@ -626,7 +626,7 @@ public OverrideParameterList GetOverrideParameters()
626626
// Input from local file into a string
627627
var overrideParametersSerial = File.ReadAllText(filename);
628628

629-
var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto };
629+
var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, SerializationBinder = new NotificationSerializationBinder() };
630630
var jsonInput = JsonConvert.DeserializeObject<OverrideParameterList>(overrideParametersSerial, jsonSettings);
631631

632632
return jsonInput;
@@ -690,5 +690,24 @@ public void AppendToLog(string record)
690690
using (StreamWriter sw = File.AppendText(LogFile)) sw.WriteLine(record);
691691
}
692692
#endregion
693+
694+
class NotificationSerializationBinder : ISerializationBinder
695+
{
696+
public void BindToName(Type serializedType, out string assemblyName, out string typeName)
697+
{
698+
throw new NotImplementedException();
699+
}
700+
701+
public Type BindToType(string assemblyName, string typeName)
702+
{
703+
if (assemblyName == "Menu")
704+
{
705+
var ns = typeof(Notifications).Namespace;
706+
var name = typeName.Split('.').Last();
707+
return typeof(Notifications).Assembly.GetType($"{ns}.{name}");
708+
}
709+
return null;
710+
}
711+
}
693712
}
694713
}

0 commit comments

Comments
 (0)