mirror of
				https://github.com/9ParsonsB/Pulsar.git
				synced 2025-10-31 15:36:42 -04:00 
			
		
		
		
	Improve tracking of line position in files. Added JournalPoke method.
This commit is contained in:
		| @@ -45,6 +45,7 @@ namespace Observatory | ||||
|             journalWatcher.EnableRaisingEvents = true; | ||||
|             statusWatcher.EnableRaisingEvents = true; | ||||
|             monitoring = true; | ||||
|             JournalPoke(); | ||||
|         } | ||||
|  | ||||
|         public void Stop() | ||||
| @@ -198,9 +199,9 @@ namespace Observatory | ||||
|         { | ||||
|             var fileContent = ReadAllLines(eventArgs.FullPath); | ||||
|  | ||||
|             if (currentLine[eventArgs.FullPath] == -1) | ||||
|             if (!currentLine.ContainsKey(eventArgs.FullPath)) | ||||
|             { | ||||
|                 currentLine[eventArgs.FullPath] = fileContent.Count - 1; | ||||
|                 currentLine.Add(eventArgs.FullPath, fileContent.Count - 1); | ||||
|             } | ||||
|  | ||||
|             foreach (string line in fileContent.Skip(currentLine[eventArgs.FullPath])) | ||||
| @@ -226,7 +227,7 @@ namespace Observatory | ||||
|  | ||||
|         private void LogCreatedEvent(object source, FileSystemEventArgs eventArgs) | ||||
|         { | ||||
|             currentLine[eventArgs.FullPath] = 0; | ||||
|             currentLine.Add(eventArgs.FullPath, 0); | ||||
|             LogChangedEvent(source, eventArgs); | ||||
|         } | ||||
|  | ||||
| @@ -241,6 +242,33 @@ namespace Observatory | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Touches most recent journal file once every 250ms while LogMonitor is monitoring. | ||||
|         /// Forces pending file writes to flush to disk and fires change events for new journal lines. | ||||
|         /// </summary> | ||||
|         private async void JournalPoke() | ||||
|         { | ||||
|             await System.Threading.Tasks.Task.Run(() =>  | ||||
|             {  | ||||
|                 while (monitoring) | ||||
|                 { | ||||
|                     FileInfo fileToPoke = null; | ||||
|  | ||||
|                     foreach (var file in new DirectoryInfo(Properties.Core.Default.JournalFolder).GetFiles("Journal.????????????.??.log")) | ||||
|                     { | ||||
|                         if (fileToPoke == null || string.Compare(file.Name, fileToPoke.Name) > 0) | ||||
|                         { | ||||
|                             fileToPoke = file; | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|                     using FileStream stream = fileToPoke.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | ||||
|                     stream.Close(); | ||||
|                     System.Threading.Thread.Sleep(250); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         private static string GetSavedGamesPath() | ||||
|         { | ||||
|             if (Environment.OSVersion.Version.Major < 6) throw new NotSupportedException(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user