public static IEnumerable <T> TryGetSessions() { var res = new List <T>(); if (!Directory.Exists(DataPath)) { return(res); } string[] ses_paths = Directory.GetFiles(DataPath); foreach (var p in ses_paths) { var text = File.ReadAllText(p); res.Add(JsonManager.FromJson <T>(text)); File.Delete(p); } return(res); }
public static async Task <HashSet <TaskModel> > GetTasksAsync() { try { using (var client = new HttpClient { Timeout = WaitingTime }) { var res = await client.GetAsync(new Uri(http, "list")); var json = await res.Content.ReadAsStringAsync(); var res_type = ClassifyResponse(res); SynchChanged?.Invoke(res_type); if (res_type == SyncState.Complete) { return(JsonManager.FromJson <HashSet <TaskModel> >(json)); } else { return(new HashSet <TaskModel>()); } } } catch (Exception ex) { IsSyncSuccessful = false; if (ex is HttpRequestException) { SynchChanged?.Invoke(SyncState.Impossible); } if (ex is TaskCanceledException) { SynchChanged?.Invoke(SyncState.Failed); } return(new HashSet <TaskModel>()); } }