public static void HandleEliteEvents(object sender, JournalEventArgs e) { var evt = ((JournalEventArgs)e).OriginalEvent.Value <string>("event"); if (string.IsNullOrWhiteSpace(evt)) { return; } switch (evt) { case "UnderAttack": // When written: when under fire(same time as the Under Attack voice message) var underAttackInfo = (UnderAttackEvent.UnderAttackEventArgs)e; if (underAttackInfo.Target == "You") { EliteData.UnderAttack = true; EliteData.LastUnderAttackEvent = DateTime.Now; } break; } }
private void NavigatedCore() { JournalEventArgs eventArguments = null; JournalEntry journalEntry1 = this.CreateJournalEntry(); JournalEntry journalEntry2 = this.CreateJournalEntry(); this.Journal.Navigated += (sender, args) => eventArguments = args; this.EnqueueCallback(() => this.Journal.AddHistoryPoint(journalEntry1)); this.EnqueueConditional(() => eventArguments != null && this.NavigatedCount == 1); this.EnqueueCallback(() => { // Validate the new operation is reported correctly. Assert.AreEqual <JournalEntry>(journalEntry1, this.Journal.CurrentEntry); Assert.AreEqual <NavigationMode>(NavigationMode.New, eventArguments.NavigationMode); Assert.AreEqual <string>(journalEntry1.Name, eventArguments.Name); Assert.AreEqual <Uri>(journalEntry1.Source, eventArguments.Uri); eventArguments = null; }); this.EnqueueCallback(() => this.Journal.AddHistoryPoint(journalEntry2)); this.EnqueueConditional(() => eventArguments != null && this.NavigatedCount == 2); this.EnqueueCallback(() => { // Validate the new operation is reported correctly. Assert.AreEqual <JournalEntry>(journalEntry2, this.Journal.CurrentEntry); Assert.AreEqual <NavigationMode>(NavigationMode.New, eventArguments.NavigationMode); Assert.AreEqual <string>(journalEntry2.Name, eventArguments.Name); Assert.AreEqual <Uri>(journalEntry2.Source, eventArguments.Uri); eventArguments = null; }); this.EnqueueCallback(() => this.Journal.GoBack()); this.EnqueueConditional(() => eventArguments != null && this.NavigatedCount == 3); this.EnqueueCallback(() => { // Validate the back operation is reported correctly. Assert.AreEqual <JournalEntry>(journalEntry1, this.Journal.CurrentEntry); Assert.AreEqual <NavigationMode>(NavigationMode.Back, eventArguments.NavigationMode); Assert.AreEqual <string>(journalEntry1.Name, eventArguments.Name); Assert.AreEqual <Uri>(journalEntry1.Source, eventArguments.Uri); eventArguments = null; }); this.EnqueueCallback(() => this.Journal.GoForward()); this.EnqueueConditional(() => eventArguments != null && this.NavigatedCount == 4); this.EnqueueCallback(() => { // Validate the forward operation is reported correctly. Assert.AreEqual <JournalEntry>(journalEntry2, this.Journal.CurrentEntry); Assert.AreEqual <NavigationMode>(NavigationMode.Forward, eventArguments.NavigationMode); Assert.AreEqual <string>(journalEntry2.Name, eventArguments.Name); Assert.AreEqual <Uri>(journalEntry2.Source, eventArguments.Uri); eventArguments = null; }); this.EnqueueTestComplete(); }
protected virtual void OnJournalEventRecieved(JournalEventArgs e) { EventHandler<JournalEventArgs> myEvent = JournalEventRecieved; if (myEvent != null) { myEvent(this, e); } }
protected virtual void OnJournalEventRecieved(JournalEventArgs e) { EventHandler <JournalEventArgs> myEvent = JournalEventRecieved; if (myEvent != null) { myEvent(this, e); } }
static void LogEvent(object sender, JournalEventArgs e) { Console.WriteLine($"The event {e.Log.GetEventName()} dated {e.Log.GetDateTime()}."); if (e.Log.GetEventName() == "Commander") { Console.WriteLine($"{e.Log.GetRawJson()}"); } }
/// <summary> /// Raises the Navigated event. /// </summary> /// <param name="name">A value representing a journal entry name.</param> /// <param name="uri">A value representing a journal entry URI.</param> /// <param name="mode">A value representing a journal entry navigation mode.</param> protected void OnNavigated(string name, Uri uri, NavigationMode mode) { EventHandler <JournalEventArgs> eventHandler = this.Navigated; if (eventHandler != null) { JournalEventArgs args = new JournalEventArgs(name, uri, mode); eventHandler(this, args); } }
/// <summary> /// injects a event from outside into the journal event handling /// </summary> /// <param name="newJournalArgItem"></param> internal void InjectJournalEvent(JournalEventArgs newJournalArgItem) { try { JournalEventRecieved.Raise(this, newJournalArgItem); } catch (Exception ex) { throw new Exception("Error while injecting a event", ex); } }
private void Journal_Navigated(object sender, JournalEventArgs args) { if (this._journalIsAddingHistoryPoint == false) { NavigationOperation navOp = this._currentNavigation; if (navOp == null || navOp.SuppressNotifications == false) { this.NavigateCore(args.Uri, args.NavigationMode, true /*suppressJournalAdd*/, false /*isRedirect*/); } } }
public void HandleEliteEvents(object sender, JournalEventArgs e) { AsyncHelper.RunSync(HandleDisplay); }
private void JournalScannerWorker() { SingleThreadLogger logger = new SingleThreadLogger(ThreadLoggerType.FileScanner); String latestFile = ""; StreamReader journalStreamReader = null; FileStream journalFileStream = null; JournalEvent eventName; String rawEventName; DateTime rawTimeStamp; string dataLine; JToken journalEntry = ""; List <String> newFiles = new List <string>(); Boolean isFirstRun = true; Boolean gotLatestEvent = false; JToken latestLocationEvent = null; JToken latestFileHeader = null; String lastEvent = ""; DateTime lastEventTime = DateTime.MinValue; List <JournalEventArgs> history = new List <JournalEventArgs>(); Boolean isZeroRun = false; m_NewFileDetected = false; Boolean missingMessagePossible = true; Int32 errorCount = 0; Boolean parsingError = false; if (m_extLogging) { logger.Log("scanning started"); } do { try { if (!isFirstRun && missingMessagePossible && String.IsNullOrWhiteSpace(m_LastScan_JournalFile)) { if (m_extLogging) { logger.Log("Can't find E:D journal file!"); } Program.MainForm.AddComboboxLine(Program.MainForm.txtEventInfo, "Can't find E:D journal file!"); missingMessagePossible = false; } // new files needed or notified ? if (String.IsNullOrWhiteSpace(m_LastScan_JournalFile) && (newFiles.Count == 0)) { if (m_extLogging) { logger.Log("new files"); } // get jounal for the first time, get only the latest IOrderedEnumerable <string> journals = Directory.EnumerateFiles(m_SavedgamesPath, "Journal.*.log", SearchOption.TopDirectoryOnly).OrderByDescending(x => x); if ((journals.Count() > 0) && (GetTimeValueFromFilename(journals.ElementAt <String>(0)) > 0)) { m_LastScan_JournalFile = journals.ElementAt <String>(0); } if (isFirstRun) { isZeroRun = true; } } else if (m_NewFileDetected || isFirstRun) { if (m_extLogging) { logger.Log("first run"); } // check for new files m_NewFileDetected = false; IOrderedEnumerable <string> journals = Directory.EnumerateFiles(m_SavedgamesPath, "Journal.*.log", SearchOption.TopDirectoryOnly).OrderByDescending(File.GetLastWriteTime); foreach (String newFile in journals) { Debug.Print(newFile); // add every new file, but only if // - it's "timevalue" is newer than the "timevalue" of the current file // - it's last write time is not longer than 24 hours ago if ((GetTimeValueFromFilename(newFile) > GetTimeValueFromFilename(m_LastScan_JournalFile)) && ((DateTime.UtcNow - File.GetLastWriteTime(newFile)).TotalHours < 24)) { if (!newFiles.Contains(newFile)) { var pos = newFiles.FindIndex(x => (GetTimeValueFromFilename(x) > GetTimeValueFromFilename(newFile))) + 1; newFiles.Insert(pos, newFile); } } else { // now comes the older files break; } } } isFirstRun = false; // check current file for existence, get another if necessary and existing, filter out "dead bodies" if (!String.IsNullOrWhiteSpace(m_LastScan_JournalFile)) { if (!File.Exists(m_LastScan_JournalFile)) { if (m_extLogging) { logger.Log("file not existing : " + m_LastScan_JournalFile); } m_LastScan_JournalFile = ""; } } if (String.IsNullOrWhiteSpace(m_LastScan_JournalFile) && (newFiles.Count > 0)) { for (int i = (newFiles.Count - 1); i >= 0; i--) { if (File.Exists(newFiles[i])) { // new "current" file m_LastScan_JournalFile = newFiles[i]; newFiles.RemoveAt(i); break; } else { // dead body newFiles.RemoveAt(i); } } } if (!String.IsNullOrWhiteSpace(m_LastScan_JournalFile)) { if (m_extLogging) { logger.Log("check file for new events : " + Path.GetFileName(m_LastScan_JournalFile) + " (" + gotLatestEvent + ")"); } missingMessagePossible = false; // we still have a current file if (journalFileStream == null) { Program.DBCon.setIniValue(DB_GROUPNAME, "LastScan_JournalFile", m_LastScan_JournalFile); journalFileStream = File.Open(m_LastScan_JournalFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); journalStreamReader = new StreamReader(journalFileStream); } while (!journalStreamReader.EndOfStream) { // get json object dataLine = journalStreamReader.ReadLine(); if (m_extLogging) { logger.Log("new line from : " + Path.GetFileName(m_LastScan_JournalFile) + " : " + dataLine); } parsingError = false; try { journalEntry = JsonConvert.DeserializeObject <JToken>(dataLine); } catch (Exception ex) { parsingError = true; String msg = "Error while parsing json string from file '" + Path.GetFileName(m_LastScan_JournalFile) + "' : \n<" + dataLine + ">"; logger.Log(ErrorViewer.GetErrorMessage(ref msg, ex)); } if (!parsingError) { // identify the event rawEventName = journalEntry.Value <String>("event"); rawTimeStamp = journalEntry.Value <DateTime>("timestamp"); if (rawEventName == JournalEvent.Died.ToString()) { Debug.Print("here"); } if ((rawEventName != null) && (rawTimeStamp != null)) { if (!Enum.TryParse <JournalEvent>(rawEventName, out eventName)) { eventName = JournalEvent.Not_Supported; } if (gotLatestEvent) { // every recognized event is accepted as new lastEvent = rawEventName; lastEventTime = rawTimeStamp; SubmitReferenceEvents(ref latestLocationEvent, ref latestFileHeader, ref logger); // pre-check for base data which is currently not in the database. switch (eventName) { case JournalEvent.Location: case JournalEvent.Docked: case JournalEvent.FSDJump: case JournalEvent.Resurrect: if (m_extLogging) { logger.Log("accepted (pre) : " + eventName.ToString()); } Debug.Print("accepted (pre) : " + eventName.ToString()); BasedataEventArgs newBasedataArgItem = new BasedataEventArgs() { EventType = JournalEvent.Basedata, System = journalEntry.Value <String>("StarSystem").NToString(""), Station = journalEntry.Value <String>("StationName").NToString("") }; if (journalEntry.Value <Object>("StarPos") != null) { newBasedataArgItem.Coordinates = new Point3Dbl((Double)journalEntry["StarPos"][0], (Double)journalEntry["StarPos"][1], (Double)journalEntry["StarPos"][2]); } BasedataEventRecieved.Raise(this, newBasedataArgItem); break; } // switch what to do switch (eventName) { case JournalEvent.Fileheader: case JournalEvent.Location: case JournalEvent.Docked: case JournalEvent.Undocked: case JournalEvent.SupercruiseEntry: case JournalEvent.SupercruiseExit: case JournalEvent.Liftoff: case JournalEvent.Touchdown: case JournalEvent.FSDJump: case JournalEvent.Died: case JournalEvent.Resurrect: case JournalEvent.Scan: case JournalEvent.MissionAccepted: case JournalEvent.MissionCompleted: case JournalEvent.MissionAbandoned: case JournalEvent.MissionFailed: case JournalEvent.LoadGame: /*******************************************************/ /*************** send events ******************/ /*******************************************************/ if (eventName == JournalEvent.Docked) { Debug.Print("stop"); } if (m_extLogging) { logger.Log("accepted : " + eventName.ToString()); } Debug.Print("accepted : " + eventName.ToString()); JournalEventArgs newJournalArgItem = new JournalEventArgs() { EventType = eventName, Data = journalEntry, History = history }; JournalEventRecieved.Raise(this, newJournalArgItem); newJournalArgItem.History = null; history.Insert(0, newJournalArgItem); if (history.Count > 5) { history.RemoveAt(5); } break; default: Debug.Print("ignored (contact): <" + rawEventName + ">"); break; } } else { if (isZeroRun) { // every recognized event is accepted as new lastEvent = rawEventName; lastEventTime = rawTimeStamp; } // switch what to do switch (eventName) { case JournalEvent.Fileheader: latestFileHeader = journalEntry; Program.MainForm.AddComboboxLine(Program.MainForm.txtEventInfo, "Initial fileheader found"); break; case JournalEvent.Location: latestLocationEvent = journalEntry; break; case JournalEvent.SupercruiseExit: if (latestLocationEvent != null) { latestLocationEvent["StarSystem"] = journalEntry["StarSystem"]; latestLocationEvent["Body"] = journalEntry["Body"]; latestLocationEvent["BodyType"] = journalEntry["BodyType"]; } break; case JournalEvent.SupercruiseEntry: if (latestLocationEvent != null) { latestLocationEvent["StarSystem"] = journalEntry["StarSystem"]; latestLocationEvent["StationName"] = ""; latestLocationEvent["Docked"] = "false"; latestLocationEvent["Body"] = ""; latestLocationEvent["BodyType"] = ""; latestLocationEvent["StationType"] = ""; } break; case JournalEvent.FSDJump: if (latestLocationEvent != null) { latestLocationEvent["StarSystem"] = journalEntry["StarSystem"]; latestLocationEvent["StationName"] = ""; latestLocationEvent["Docked"] = "false"; latestLocationEvent["StarPos"] = journalEntry["StarPos"]; latestLocationEvent["Body"] = journalEntry["Body"]; latestLocationEvent["BodyType"] = journalEntry["BodyType"]; latestLocationEvent["Faction"] = journalEntry["Faction"]; latestLocationEvent["Allegiance"] = journalEntry["Allegiance"]; latestLocationEvent["Economy"] = journalEntry["Economy"]; latestLocationEvent["Government"] = journalEntry["Government"]; latestLocationEvent["Security"] = journalEntry["Security"]; latestLocationEvent["StationType"] = ""; } break; case JournalEvent.Docked: if (latestLocationEvent != null) { latestLocationEvent["StarSystem"] = journalEntry["StarSystem"]; latestLocationEvent["StationName"] = journalEntry["StationName"]; latestLocationEvent["Docked"] = "true"; latestLocationEvent["StationType"] = journalEntry["StationType"];; } break; default: //Debug.Print("ignored (seeking) : <" + rawEventName + ">"); break; } } } } } if (lastEventTime > DateTime.MinValue) { if (m_extLogging) { logger.Log("write new time"); } // only rewrite if we've got a new event Program.DBCon.setIniValue(DB_GROUPNAME, "LastScan_Event", lastEvent); Program.DBCon.setIniValue(DB_GROUPNAME, "LastScan_TimeStamp", lastEventTime.ToString()); lastEventTime = DateTime.MinValue; } if (isZeroRun) { gotLatestEvent = true; } if (newFiles.Count > 0) { if (m_extLogging) { logger.Log("still have new files"); } // prepare switching to next file if (journalFileStream != null) { journalFileStream.Dispose(); } if (journalStreamReader != null) { journalStreamReader.Dispose(); } journalFileStream = null; journalStreamReader = null; m_LastScan_JournalFile = ""; } else if (!gotLatestEvent) { // it's the end of the actual file -> so we found the latest item gotLatestEvent = true; if (m_extLogging) { logger.Log("force latest event"); } } if (gotLatestEvent) { SubmitReferenceEvents(ref latestLocationEvent, ref latestFileHeader, ref logger); } } isZeroRun = false; errorCount = 0; } catch (Exception ex) { errorCount++; Program.MainForm.AddComboboxLine(Program.MainForm.txtEventInfo, "Error while parsing E:D journal !"); Debug.Print("AnalyseError"); String msg = "Error in the journal scanner main routine"; logger.Log(ErrorViewer.GetErrorMessage(ref msg, ex)); if (lastEventTime > DateTime.MinValue) { // only rewrite if we've got a new event Program.DBCon.setIniValue(DB_GROUPNAME, "LastScan_Event", lastEvent); Program.DBCon.setIniValue(DB_GROUPNAME, "LastScan_TimeStamp", lastEventTime.ToString()); lastEventTime = DateTime.MinValue; } if (errorCount > 1) { // prepare switching to next file if (journalFileStream != null) { journalFileStream.Dispose(); } if (journalStreamReader != null) { journalStreamReader.Dispose(); } journalFileStream = null; journalStreamReader = null; gotLatestEvent = false; } } if (newFiles.Count == 0) { Thread.Sleep(1000); // Because the current file is opened by ED with a permanent write stream no changed event // raises reliably in the SystemFileWatcher. With Sleep(1000) we get every second the chance to // to detect new data with the line // while (!journalStreamReader.EndOfStream) } else { Debug.Print("because new files : " + DateTime.UtcNow); } }while (!m_Stop); // clean up if (journalFileStream != null) { journalFileStream.Dispose(); } if (journalStreamReader != null) { journalStreamReader.Dispose(); } if (m_extLogging) { logger.Log("stopped !"); } }
public static void HandleEliteEvents(object sender, JournalEventArgs e) { var evt = ((JournalEventArgs)e).OriginalEvent.Value <string>("event"); if (string.IsNullOrWhiteSpace(evt)) { return; } switch (evt) { case "Location": //When written: at startup, or when being resurrected at a station var locationInfo = (LocationEvent.LocationEventArgs)e; EliteData.StarSystem = locationInfo.StarSystem; break; case "ApproachBody": // When written: when in Supercruise, and distance from planet drops to within the 'Orbital Cruise' zone var approachBodyInfo = (ApproachBodyEvent.ApproachBodyEventArgs)e; EliteData.StarSystem = approachBodyInfo.StarSystem; break; case "LeaveBody": //When written: when flying away from a planet, and distance increases above the 'Orbital Cruise' altitude var leaveBodyInfo = (LeaveBodyEvent.LeaveBodyEventArgs)e; EliteData.StarSystem = leaveBodyInfo.StarSystem; break; case "Docked": // When written: when landing at landing pad in a space station, outpost, or surface settlement var dockedInfo = (DockedEvent.DockedEventArgs)e; EliteData.StarSystem = dockedInfo.StarSystem; break; case "FSDJump": //When written: when jumping from one star system to another var fsdJumpInfo = (FSDJumpEvent.FSDJumpEventArgs)e; EliteData.StarSystem = fsdJumpInfo.StarSystem; break; case "SupercruiseExit": //When written: leaving supercruise for normal space var supercruiseExitInfo = (SupercruiseExitEvent.SupercruiseExitEventArgs)e; EliteData.StarSystem = supercruiseExitInfo.StarSystem; break; case "FSDTarget": //When written: when selecting a star system to jump to var fsdTargetInfo = (FSDTargetEvent.FSDTargetEventArgs)e; EliteData.FsdTargetName = fsdTargetInfo.Name; EliteData.RemainingJumpsInRoute = fsdTargetInfo.RemainingJumpsInRoute; EliteData.StarClass = fsdTargetInfo.StarClass; break; case "UnderAttack": // When written: when under fire(same time as the Under Attack voice message) var underAttackInfo = (UnderAttackEvent.UnderAttackEventArgs)e; if (underAttackInfo.Target == "You") { EliteData.UnderAttack = true; EliteData.LastUnderAttackEvent = DateTime.Now; } break; case "Cargo": var cargoInfo = (CargoEvent.CargoEventArgs)e; /* * if (cargoInfo.Vessel == "Ship") * { * if (cargoInfo.Inventory == null) * { * cargoInfo = Program.JournalWatcher.ReadCargoJson(); * } * * if (cargoInfo.Inventory != null) * { * EliteData.LimpetCount = * cargoInfo.Inventory.Where(x => x.Name.ToLower().Contains("drones")).Sum(x => x.Count); * } * } */ break; case "Died": var diedInfo = (DiedEvent.DiedEventArgs)e; EliteData.LimpetCount = 0; break; } }
void Client_OnJournalGetPrevious(object sender, JournalEventArgs e) { Deployment.Current.Dispatcher.BeginInvoke(new Action(delegate { List<JournalItemInfo> old = ViewModel.Journal; old.AddRange(e.JournalItems); ViewModel.Journal = old; ViewModel.IsUpdating = false; })); }
static void _Client_OnJournalUpdated(object sender, JournalEventArgs e) { Deployment.Current.Dispatcher.BeginInvoke(new Action(delegate { ViewModel.Journal = e.JournalItems; ViewModel.IsUpdating = false; })); }
void Client_OnJournalUpdated(object sender, JournalEventArgs e) { Items = e.JournalItems; NotifyPropertyChanged("Items"); }
private void JournalScannerWorker() { SingleThreadLogger logger = new SingleThreadLogger(ThreadLoggerType.FileScanner); String latestFile = ""; StreamReader journalStreamReader = null; FileStream journalFileStream = null; JournalEvent eventName; String rawEventName; DateTime rawTimeStamp; string dataLine; JToken journalEntry = ""; List<String> newFiles = new List<string>(); Boolean isFirstRun = true; Boolean gotLatestEvent = false; JToken latestLocationEvent = null; JToken latestFileHeader = null; String lastEvent = ""; DateTime lastEventTime = DateTime.MinValue; List<JournalEventArgs> history = new List<JournalEventArgs>(); Boolean isZeroRun = false; m_NewFileDetected = false; Boolean missingMessagePossible = true; Int32 errorCount = 0; Boolean parsingError = false; if(m_extLogging) logger.Log("scanning started"); do { try { if(!isFirstRun && missingMessagePossible && String.IsNullOrWhiteSpace(m_LastScan_JournalFile)) { if(m_extLogging) logger.Log("Can't find E:D journal file!"); Program.MainForm.AddComboboxLine(Program.MainForm.txtEventInfo, "Can't find E:D journal file!"); missingMessagePossible = false; } // new files needed or notified ? if(String.IsNullOrWhiteSpace(m_LastScan_JournalFile) && (newFiles.Count == 0)) { if(m_extLogging) logger.Log("new files"); // get jounal for the first time, get only the latest IOrderedEnumerable<string> journals = Directory.EnumerateFiles(m_SavedgamesPath, "Journal.*.log", SearchOption.TopDirectoryOnly).OrderByDescending(x => x); if ((journals.Count() > 0) && (GetTimeValueFromFilename(journals.ElementAt<String>(0)) > 0)) m_LastScan_JournalFile = journals.ElementAt<String>(0); if(isFirstRun) isZeroRun = true; } else if(m_NewFileDetected || isFirstRun) { if(m_extLogging) logger.Log("first run"); // check for new files m_NewFileDetected = false; IOrderedEnumerable<string> journals =Directory.EnumerateFiles(m_SavedgamesPath, "Journal.*.log", SearchOption.TopDirectoryOnly).OrderByDescending(File.GetLastWriteTime); foreach (String newFile in journals) { Debug.Print(newFile); // add every new file, but only if // - it's "timevalue" is newer than the "timevalue" of the current file // - it's last write time is not longer than 24 hours ago if((GetTimeValueFromFilename(newFile) > GetTimeValueFromFilename(m_LastScan_JournalFile)) && ((DateTime.Now - File.GetLastWriteTime(newFile)).TotalHours < 24)) { if(!newFiles.Contains(newFile)) { var pos = newFiles.FindIndex(x => (GetTimeValueFromFilename(x) > GetTimeValueFromFilename(newFile))) + 1; newFiles.Insert(pos, newFile); } } else { // now comes the older files break; } } } isFirstRun = false; // check current file for existence, get another if necessary and existing, filter out "dead bodies" if (!String.IsNullOrWhiteSpace(m_LastScan_JournalFile)) { if(!File.Exists(m_LastScan_JournalFile)) { if(m_extLogging) logger.Log("file not existing : " + m_LastScan_JournalFile); m_LastScan_JournalFile = ""; } } if(String.IsNullOrWhiteSpace(m_LastScan_JournalFile) && (newFiles.Count > 0)) { for (int i = (newFiles.Count-1); i >= 0; i--) { if(File.Exists(newFiles[i])) { // new "current" file m_LastScan_JournalFile = newFiles[i]; newFiles.RemoveAt(i); break; } else { // dead body newFiles.RemoveAt(i); } } } if (!String.IsNullOrWhiteSpace(m_LastScan_JournalFile)) { if(m_extLogging) logger.Log("check file for new events : " + Path.GetFileName(m_LastScan_JournalFile) + " (" + gotLatestEvent +")"); missingMessagePossible = false; // we still have a current file if(journalFileStream == null) { Program.DBCon.setIniValue(DB_GROUPNAME, "LastScan_JournalFile", m_LastScan_JournalFile); journalFileStream = File.Open(m_LastScan_JournalFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); journalStreamReader = new StreamReader(journalFileStream); } while (!journalStreamReader.EndOfStream) { // get json object dataLine = journalStreamReader.ReadLine(); if(m_extLogging) logger.Log("new line from : " + Path.GetFileName(m_LastScan_JournalFile) + " : " + dataLine); parsingError = false; try { journalEntry = JsonConvert.DeserializeObject<JToken>(dataLine); } catch (Exception ex) { parsingError = true; String msg = "Error while parsing json string from file '" + Path.GetFileName(m_LastScan_JournalFile) + "' : \n<" + dataLine + ">"; logger.Log(ErrorViewer.GetErrorMessage(ref msg, ex)); } if(!parsingError) { // identify the event rawEventName = journalEntry.Value<String>("event"); rawTimeStamp = journalEntry.Value<DateTime>("timestamp"); if(rawEventName == JournalEvent.Died.ToString()) Debug.Print("here"); if ((rawEventName != null) && (rawTimeStamp != null)) { if(!Enum.TryParse<JournalEvent>(rawEventName, out eventName)) { eventName = JournalEvent.Not_Supported; } if(gotLatestEvent) { // every recognized event is accepted as new lastEvent = rawEventName; lastEventTime = rawTimeStamp; SubmitReferenceEvents(ref latestLocationEvent, ref latestFileHeader, ref logger); // pre-check for base data which is currently not in the database. switch (eventName) { case JournalEvent.Location: case JournalEvent.Docked: case JournalEvent.FSDJump: case JournalEvent.Resurrect: if(m_extLogging) logger.Log("accepted (pre) : " + eventName.ToString()); Debug.Print("accepted (pre) : " + eventName.ToString()); BasedataEventArgs newBasedataArgItem = new BasedataEventArgs() { EventType = JournalEvent.Basedata, System = journalEntry.Value<String>("StarSystem").NToString(""), Station = journalEntry.Value<String>("StationName").NToString("") }; if(journalEntry.Value<Object>("StarPos") != null) { newBasedataArgItem.Coordinates = new Point3Dbl((Double)journalEntry["StarPos"][0], (Double)journalEntry["StarPos"][1], (Double)journalEntry["StarPos"][2]); } BasedataEventRecieved.Raise(this, newBasedataArgItem); break; } // switch what to do switch (eventName) { case JournalEvent.Fileheader: case JournalEvent.Location: case JournalEvent.Docked: case JournalEvent.Undocked: case JournalEvent.SupercruiseEntry: case JournalEvent.SupercruiseExit: case JournalEvent.Liftoff: case JournalEvent.Touchdown: case JournalEvent.FSDJump: case JournalEvent.Died: case JournalEvent.Resurrect: case JournalEvent.Scan: if(eventName == JournalEvent.Docked) Debug.Print("stop"); if(m_extLogging) logger.Log("accepted : " + eventName.ToString()); Debug.Print("accepted : " + eventName.ToString()); JournalEventArgs newJournalArgItem = new JournalEventArgs() { EventType = eventName, Data = journalEntry, History = history }; JournalEventRecieved.Raise(this, newJournalArgItem); newJournalArgItem.History = null; history.Insert(0, newJournalArgItem); if(history.Count > 5) history.RemoveAt(5); break; default: Debug.Print("ignored (contact): <" + rawEventName + ">"); break; } } else { if(isZeroRun) { // every recognized event is accepted as new lastEvent = rawEventName; lastEventTime = rawTimeStamp; } // switch what to do switch (eventName) { case JournalEvent.Fileheader: latestFileHeader = journalEntry; Program.MainForm.AddComboboxLine(Program.MainForm.txtEventInfo, "Initial fileheader found"); break; case JournalEvent.Location: latestLocationEvent = journalEntry; break; case JournalEvent.SupercruiseExit: if(latestLocationEvent != null) { latestLocationEvent["StarSystem"] = journalEntry["StarSystem"]; latestLocationEvent["Body"] = journalEntry["Body"]; latestLocationEvent["BodyType"] = journalEntry["BodyType"]; } break; case JournalEvent.SupercruiseEntry: if(latestLocationEvent != null) { latestLocationEvent["StarSystem"] = journalEntry["StarSystem"]; latestLocationEvent["StationName"] = ""; latestLocationEvent["Docked"] = "false"; latestLocationEvent["Body"] = ""; latestLocationEvent["BodyType"] = ""; latestLocationEvent["StationType"] = ""; } break; case JournalEvent.FSDJump: if(latestLocationEvent != null) { latestLocationEvent["StarSystem"] = journalEntry["StarSystem"]; latestLocationEvent["StationName"] = ""; latestLocationEvent["Docked"] = "false"; latestLocationEvent["StarPos"] = journalEntry["StarPos"]; latestLocationEvent["Body"] = journalEntry["Body"]; latestLocationEvent["BodyType"] = journalEntry["BodyType"]; latestLocationEvent["Faction"] = journalEntry["Faction"]; latestLocationEvent["Allegiance"] = journalEntry["Allegiance"]; latestLocationEvent["Economy"] = journalEntry["Economy"]; latestLocationEvent["Government"] = journalEntry["Government"]; latestLocationEvent["Security"] = journalEntry["Security"]; latestLocationEvent["StationType"] = ""; } break; case JournalEvent.Docked: if(latestLocationEvent != null) { latestLocationEvent["StarSystem"] = journalEntry["StarSystem"]; latestLocationEvent["StationName"] = journalEntry["StationName"]; latestLocationEvent["Docked"] = "true"; latestLocationEvent["StationType"] = journalEntry["StationType"];; } break; default: Debug.Print("ignored (seeking) : <" + rawEventName + ">"); break; } } } } } if(lastEventTime > DateTime.MinValue) { if(m_extLogging) logger.Log("write new time"); // only rewrite if we've got a new event Program.DBCon.setIniValue(DB_GROUPNAME, "LastScan_Event", lastEvent); Program.DBCon.setIniValue(DB_GROUPNAME, "LastScan_TimeStamp", lastEventTime.ToString()); lastEventTime = DateTime.MinValue; } if(isZeroRun) gotLatestEvent = true; if(newFiles.Count > 0) { if(m_extLogging) logger.Log("still have new files"); // prepare switching to next file if(journalFileStream != null) journalFileStream.Dispose(); if(journalStreamReader != null) journalStreamReader.Dispose(); journalFileStream = null; journalStreamReader = null; m_LastScan_JournalFile = ""; } else if(!gotLatestEvent) { // it's the end of the actual file -> so we found the latest item gotLatestEvent = true; if(m_extLogging) logger.Log("force latest event"); } if(gotLatestEvent) SubmitReferenceEvents(ref latestLocationEvent, ref latestFileHeader, ref logger); } isZeroRun = false; errorCount = 0; } catch (Exception ex) { errorCount++; Program.MainForm.AddComboboxLine(Program.MainForm.txtEventInfo, "Error while parsing E:D journal !"); Debug.Print("AnalyseError"); String msg = "Error in the journal scanner main routine"; logger.Log(ErrorViewer.GetErrorMessage(ref msg, ex)); if (lastEventTime > DateTime.MinValue) { // only rewrite if we've got a new event Program.DBCon.setIniValue(DB_GROUPNAME, "LastScan_Event", lastEvent); Program.DBCon.setIniValue(DB_GROUPNAME, "LastScan_TimeStamp", lastEventTime.ToString()); lastEventTime = DateTime.MinValue; } if(errorCount > 1) { // prepare switching to next file if(journalFileStream != null) journalFileStream.Dispose(); if(journalStreamReader != null) journalStreamReader.Dispose(); journalFileStream = null; journalStreamReader = null; gotLatestEvent = false; } } if (newFiles.Count == 0) { Thread.Sleep(1000); // Because the current file is opened by ED with a permanent write stream no changed event // raises reliably in the SystemFileWatcher. With Sleep(1000) we get every second the chance to // to detect new data with the line // while (!journalStreamReader.EndOfStream) } else Debug.Print("because new files : " + DateTime.Now); }while (!m_Stop); // clean up if(journalFileStream != null) journalFileStream.Dispose(); if(journalStreamReader != null) journalStreamReader.Dispose(); if(m_extLogging) logger.Log("stopped !"); }