3030using System . Windows . Forms ;
3131using System . Linq ;
3232using System . Diagnostics ;
33+ using System . Resources ;
34+ using ORTS . Properties ;
3335
3436// Notifications are read only once as a background task at start into NotificationList.
3537// Every time the notifications page is re-visited, the position is discarded and first page is shown.
@@ -72,22 +74,19 @@ public class PageTracking
7274 public Image LastImage { get ; private set ; }
7375 public PageTracking NewPages { get ; private set ; }
7476
75- public NotificationManager ( MainForm mainForm , UpdateManager updateManager , UserSettings settings , Panel panel
76- , Image previousImage
77- , Image nextImage
78- , Image firstImage
79- , Image lastImage
80- )
81- {
77+ public NotificationManager ( MainForm mainForm , ResourceManager resources , UpdateManager updateManager , UserSettings settings , Panel panel )
78+ {
8279 MainForm = mainForm ;
8380 this . UpdateManager = updateManager ;
8481 this . Settings = settings ;
8582 Panel = panel ;
86- PreviousImage = previousImage ;
87- NextImage = nextImage ;
88- FirstImage = firstImage ;
89- LastImage = lastImage ;
9083 NewPages = new PageTracking ( ) ;
84+
85+ // Load images of arrows
86+ PreviousImage = ( Image ) resources . GetObject ( "Notification_previous" ) ;
87+ NextImage = ( Image ) resources . GetObject ( "Notification_next" ) ;
88+ FirstImage = ( Image ) resources . GetObject ( "Notification_first" ) ;
89+ LastImage = ( Image ) resources . GetObject ( "Notification_last" ) ;
9190 }
9291
9392 //TODO Make this a background task
@@ -166,10 +165,16 @@ private string GetRemoteJson()
166165 // Helpful to supply server with data for its log file.
167166 client . Headers [ HttpRequestHeader . UserAgent ] = $ "{ System . Windows . Forms . Application . ProductName } /{ VersionInfo . VersionOrBuild } ";
168167
168+ //TODO
169169 return client . DownloadString ( new Uri ( "https://wepp.co.uk/openrails/notifications2/menu.json" ) ) ;
170170 //return client.DownloadString(new Uri("https://static.openrails.org/api/notifications/menu.json"));
171171 }
172172
173+ /// <summary>
174+ /// Returns a list of Notifications excluding any that fail IncludeIf. Sorts Update channel "none" to the end.
175+ /// </summary>
176+ /// <param name="list"></param>
177+ /// <returns></returns>
173178 private List < Notification > IncludeValid ( List < Notification > list )
174179 {
175180 NewPages . Count = 0 ;
@@ -197,36 +202,21 @@ private List<Notification> SortByDate(List<Notification> list)
197202 }
198203
199204 /// <summary>
200- /// Adds details of the current notifications to the panel
205+ /// Adds details of the current notification to the panel
201206 /// </summary>
202207 public void PopulatePage ( )
203208 {
204- Settings . LastViewNotificationDate = $ "{ DateTime . Today : yyyy-MM-dd} ";
205- Settings . Save ( "LastViewNotificationDate" ) ; // Saves the date on any viewing of notifications
206209 Page = new NotificationPage ( MainForm , Panel , this ) ;
207210
208211 if ( UpdateManager . LastCheckError != null || Error != null )
209212 {
210- NewPages . Count = 0 ;
211- var message = ( UpdateManager . LastCheckError != null )
212- ? UpdateManager . LastCheckError . Message
213- : Error . Message ;
214-
215- // Reports notifications are not available.
216- var channelName = UpdateManager . ChannelName == "" ? "None" : UpdateManager . ChannelName ;
217- var today = DateTime . Now . Date ;
218- Page . NDetailList . Add ( new NTitleControl ( Page , 1 , 1 , $ "{ today : dd-MMM-yy} ", "Notifications are not available" ) ) ;
219- Page . NDetailList . Add ( new NRecordControl ( Page , "Update mode" , 140 , channelName ) ) ;
220- Page . NDetailList . Add ( new NRecordControl ( Page , "Installed version" , 140 , VersionInfo . VersionOrBuild ) ) ;
221-
222- Page . NDetailList . Add ( new NHeadingControl ( Page , "Notifications are not available" , "red" ) ) ;
223- Page . NDetailList . Add ( new NTextControl ( Page , $ "Error: { message } ") ) ;
224- Page . NDetailList . Add ( new NTextControl ( Page , "Is your Internet connected?" ) ) ;
225-
226- Page . NDetailList . Add ( new NRetryControl ( Page , "Retry" , 140 , "Try again to fetch notifications" , MainForm ) ) ;
213+ PopulateRetryPage ( ) ;
227214 }
228215 else
229216 {
217+ Settings . LastViewNotificationDate = $ "{ DateTime . Today : yyyy-MM-dd} ";
218+ Settings . Save ( "LastViewNotificationDate" ) ; // Saves the date on any viewing of notifications
219+
230220 var list = Notifications . NotificationList ;
231221 var n = list [ CurrentNotificationNo ] ;
232222 LogNotification ( n ) ;
@@ -244,6 +234,27 @@ public void PopulatePage()
244234 Page . NDetailList . Add ( new NTextControl ( Page , "(Toggle icon to hide these notifications.)" ) ) ;
245235 }
246236
237+ private void PopulateRetryPage ( )
238+ {
239+ NewPages . Count = 0 ;
240+
241+ // Reports notifications are not available.
242+ var channelName = UpdateManager . ChannelName == "" ? "None" : UpdateManager . ChannelName ;
243+ var today = DateTime . Now . Date ;
244+ Page . NDetailList . Add ( new NTitleControl ( Page , 1 , 1 , $ "{ today : dd-MMM-yy} ", "Notifications are not available" ) ) ;
245+ Page . NDetailList . Add ( new NRecordControl ( Page , "Update mode" , 140 , channelName ) ) ;
246+ Page . NDetailList . Add ( new NRecordControl ( Page , "Installed version" , 140 , VersionInfo . VersionOrBuild ) ) ;
247+
248+ Page . NDetailList . Add ( new NHeadingControl ( Page , "Notifications are not available" , "red" ) ) ;
249+ var message = ( UpdateManager . LastCheckError != null )
250+ ? UpdateManager . LastCheckError . Message
251+ : Error . Message ;
252+ Page . NDetailList . Add ( new NTextControl ( Page , $ "Error: { message } ") ) ;
253+ Page . NDetailList . Add ( new NTextControl ( Page , "Is your Internet connected?" ) ) ;
254+
255+ Page . NDetailList . Add ( new NRetryControl ( Page , "Retry" , 140 , "Try again to fetch notifications" , MainForm ) ) ;
256+ }
257+
247258 #region Process Criteria
248259 private bool AreNotificationChecksMet ( Notification notification )
249260 {
0 commit comments