List <Tweet> GetTweetsFromFile(JsFile jsFile) { txtFeedback.Dispatcher.BeginInvoke(new Action(delegate() { txtFeedback.Text += "\nLoading tweets: " + jsFile.FriendlyFilename + " " + jsFile.TweetYear; })); string jsonData = ""; // Case of js file if (String.IsNullOrEmpty(jsFile.OriginZipFile)) { jsonData = File.ReadAllText(jsFile.Path); } else { if (!File.Exists(jsFile.OriginZipFile)) { return(null); } try { using (ZipFile zipArchive = ZipFile.Read(jsFile.OriginZipFile)) { MemoryStream stream = new MemoryStream(); ZipEntry jsonFile = zipArchive[jsFile.Path]; jsonFile.Extract(stream); stream.Position = 0; using (var reader = new StreamReader(stream)) { jsonData = reader.ReadToEnd(); } } } catch (Exception) //file is not a suitable json { ; } } jsonData = jsonData.Substring(jsonData.IndexOf('[') <= 0 ? 0 : jsonData.IndexOf('[') - 1); return(LoadTweetsFromJson(jsonData)); }
List<Tweet> GetTweetsFromFile(JsFile jsFile) { txtFeedback.Dispatcher.BeginInvoke(new Action(delegate() { txtFeedback.Text += "\nLoading tweets: " + jsFile.FriendlyFilename + " " + jsFile.TweetYear; })); string jsonData = ""; // Case of js file if(String.IsNullOrEmpty(jsFile.OriginZipFile)) { jsonData = File.ReadAllText(jsFile.Path); } else { if (!File.Exists(jsFile.OriginZipFile)) return null; try { using (ZipFile zipArchive = ZipFile.Read(jsFile.OriginZipFile)) { MemoryStream stream = new MemoryStream(); ZipEntry jsonFile = zipArchive[jsFile.Path]; jsonFile.Extract(stream); stream.Position = 0; using (var reader = new StreamReader(stream)) { jsonData = reader.ReadToEnd(); } } } catch (Exception) //file is not a suitable json { ; } } jsonData = jsonData.Substring(jsonData.IndexOf('[') <= 0 ? 0 : jsonData.IndexOf('[') - 1); return LoadTweetsFromJson(jsonData); }