private FindNotificationsResponse.NotificationResult FindNotifications(string placeId, int start) { const string FunctionAdmin = "findNotifications"; const string Function = "notification"; const string Start = "start"; const string PlaceId = "placeId"; Parameters parameters = new Parameters() { { Start, start }, { PlaceId, placeId } }; HttpWebRequest webRequest = GetWebRequest("GET", isAdminConnection ? FunctionAdmin : Function, parameters); FindNotificationsResponse response = GetJSONresponse <FindNotificationsResponse>(webRequest); // returns 500 if storeId unknown at Plot back-end server if (response == null) { throw new Exception("No response."); } // check the result codes: response.Check(); FindNotificationsResponse.NotificationResult ret = response.Result ?? new FindNotificationsResponse.NotificationResult() { Total = 0 }; if (ret.Data == null) { ret.Data = new FindNotificationsResponse.NotificationResult.Notification[] { } } ; return(ret); }
private IList <SelectNotification> FindNotifications(string storeId, int start, int max) // max -> -1 = ALL (no max), 0 = one page (default size) { List <FindNotificationsResponse.NotificationResult.Notification> ret = new List <FindNotificationsResponse.NotificationResult.Notification>(); while (true) { // get one page (from start) FindNotificationsResponse.NotificationResult res = FindNotifications(storeId, start); // save (grand) total (for this store) found (not thread safe) TotalNotifications = res.Total; if (res.Data.Count() == 0) // strange error? { break; } // add them all ret.AddRange(res.Data); if (max == MaxOnePage) { break; } if (max != MaxNone) // a 'real' max (> 0) { if (ret.Count() >= max) { // remove if too many while (ret.Count() > max) { ret.Remove(ret.Last()); } break; } } if (ret.Count() == res.Total) // no more available { break; } // next: start += res.Data.Count(); } return(ret.Select(s => new SelectNotification() { ID = s.ID, StoreId = s.StoreId, State = s.State.AsEnum <State>(), Message = s.Message, Data = s.Data, MatchRange = s.MatchRange, Created = s.Created.AsDateTime(true).Value, Timespans = s.Timespans == null ? new Plot.Entities.SelectNotification.Timespan[] { } : s.Timespans.Select(t => new Plot.Entities.SelectNotification.Timespan() { Start = t.Start.AsDateTime(), End = t.End.AsDateTime() }).ToArray() }).ToList()); }