public static Task LoadFlatFileAsync(string PathToJson) { Task task = Task.Run(() => { if (!File.Exists(PathToJson)) { throw new System.Exception("Json file not found"); } try { using (FileStream s = new FileStream(PathToJson, FileMode.Open, FileAccess.Read)) using (StreamReader sr = new StreamReader(s)) using (JsonReader reader = new JsonTextReader(sr)) { JsonSerializer serializer = new JsonSerializer(); flatFileData = serializer.Deserialize <FlatFileData>(reader); } } catch (System.Exception) { throw; } if (flatFileData == null) { throw new System.Exception("Deserialize error, check if Json file is valide"); } if (string.IsNullOrEmpty(flatFileData.naglowek?.datagenerowaniadanych)) { throw new System.Exception("Invalide Json file, datagenerowaniadanych is empty"); } if (flatFileData.maski == null || flatFileData.maski.Count <= 0) { throw new System.Exception("Invalide Json file, maski is empty"); } if (flatFileData.skrotypodatnikowczynnych == null || flatFileData.skrotypodatnikowczynnych.Count <= 0) { throw new System.Exception("Invalide Json file, skrotypodatnikowczynnych is empty"); } if (flatFileData.skrotypodatnikowzwolnionych == null || flatFileData.skrotypodatnikowzwolnionych.Count <= 0) { throw new System.Exception("Invalide Json file, skrotypodatnikowzwolnionych is empty"); } }); return(task); }
public static async Task LoadFlatFileAsync(string PathToJson) { if (!File.Exists(PathToJson)) { throw new System.Exception("Json file not found"); } try { using FileStream s = new FileStream(PathToJson, FileMode.Open, FileAccess.Read); flatFileData = await JsonSerializer.DeserializeAsync <FlatFileData>(s, JsonSerializerOptions); } catch (System.Exception) { throw; } if (flatFileData == null) { throw new System.Exception("Deserialize error, check if Json file is valide"); } if (string.IsNullOrEmpty(flatFileData.naglowek?.datagenerowaniadanych)) { throw new System.Exception("Invalide Json file, datagenerowaniadanych is empty"); } if (flatFileData.maski == null || flatFileData.maski.Count <= 0) { throw new System.Exception("Invalide Json file, maski is empty"); } if (flatFileData.skrotypodatnikowczynnych == null || flatFileData.skrotypodatnikowczynnych.Count <= 0) { throw new System.Exception("Invalide Json file, skrotypodatnikowczynnych is empty"); } if (flatFileData.skrotypodatnikowzwolnionych == null || flatFileData.skrotypodatnikowzwolnionych.Count <= 0) { throw new System.Exception("Invalide Json file, skrotypodatnikowzwolnionych is empty"); } }