|
22 | 22 | using System.Linq;
|
23 | 23 | using System.Net;
|
24 | 24 | using System.Resources;
|
25 |
| -using System.Runtime.InteropServices; |
26 | 25 | using System.Text;
|
27 | 26 | using System.Windows;
|
28 | 27 | using System.Windows.Forms;
|
|
32 | 31 | using ORTS.Updater;
|
33 | 32 | using static ORTS.Common.SystemInfo;
|
34 | 33 | using static Menu.Notifications.NotificationPage;
|
| 34 | +using Newtonsoft.Json.Serialization; |
35 | 35 |
|
36 | 36 | // Behaviour
|
37 | 37 | // Notifications are read only once as a background task at start into Notifications.
|
@@ -126,7 +126,7 @@ public void CheckNotifications()
|
126 | 126 | Notifications.NotificationList = IncludeValid(Notifications.NotificationList);
|
127 | 127 | Notifications.NotificationList = SortByDate(Notifications.NotificationList);
|
128 | 128 | }
|
129 |
| - catch (WebException ex) |
| 129 | + catch (Exception ex) |
130 | 130 | {
|
131 | 131 | Error = ex;
|
132 | 132 | }
|
@@ -154,7 +154,7 @@ public Notifications GetNotifications()
|
154 | 154 | notificationsSerial = GetRemoteJson();
|
155 | 155 | }
|
156 | 156 |
|
157 |
| - var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }; |
| 157 | + var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, SerializationBinder = new NotificationSerializationBinder() }; |
158 | 158 | var jsonInput = JsonConvert.DeserializeObject<Notifications>(notificationsSerial, jsonSettings);
|
159 | 159 |
|
160 | 160 | NewPages.Count = 0;
|
@@ -626,7 +626,7 @@ public OverrideParameterList GetOverrideParameters()
|
626 | 626 | // Input from local file into a string
|
627 | 627 | var overrideParametersSerial = File.ReadAllText(filename);
|
628 | 628 |
|
629 |
| - var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }; |
| 629 | + var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, SerializationBinder = new NotificationSerializationBinder() }; |
630 | 630 | var jsonInput = JsonConvert.DeserializeObject<OverrideParameterList>(overrideParametersSerial, jsonSettings);
|
631 | 631 |
|
632 | 632 | return jsonInput;
|
@@ -690,5 +690,24 @@ public void AppendToLog(string record)
|
690 | 690 | using (StreamWriter sw = File.AppendText(LogFile)) sw.WriteLine(record);
|
691 | 691 | }
|
692 | 692 | #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 | + } |
693 | 712 | }
|
694 | 713 | }
|
0 commit comments