public TailActor(IActorRef reportActor, string fileUri) { _reportActor = reportActor; _fileUri = fileUri; _fileObserver = new FileObserver(fileUri); var self = Self; _fileObserver.OnError += e => { self.Tell(new FileErrored(e.Message)); }; _fileObserver.OnChanged += () => { self.Tell(new FileChanged()); }; _fileObserver.Start(); var fileStream = new FileStream(fileUri, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _streamReader = new StreamReader(fileStream, Encoding.UTF8); var initialText = _streamReader.ReadToEnd(); Self.Tell(new InitialRead(initialText)); }
/// <summary> /// Cleanup OS handles for <see cref="fileStreamReader"/> and <see cref="FileObserver"/>. /// </summary> protected override void PostStop() { this.observer.Dispose(); this.observer = null; this.fileStreamReader.Close(); this.fileStreamReader.Dispose(); base.PostStop(); }
protected override void PostStop() { _observer.Dispose(); _observer = null; _fileStreamReader.Close(); _fileStreamReader.Dispose(); base.PostStop(); }
protected override void PreStart() { base.PreStart(); observer = new FileObserver(Self, Path.GetFullPath(filePath)); observer.Start(); fileStream = new FileStream(Path.GetFullPath(filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); fileStreamReader = new StreamReader(filePath, Encoding.UTF8); Self.Tell(new InitialRead(filePath, fileStreamReader.ReadToEnd())); }
protected override void PostStop() { // clean up _observer.Dispose(); _observer = null; _streamReader.Close(); _streamReader.Dispose(); base.PostStop(); }
protected override void PreStart() { _observer = new FileObserver(Self, Path.GetFullPath(_filePath)); _observer.Start(); _fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(_filePath, text)); }
protected override void PostStop() { // clean up resources _observer?.Dispose(); _observer = null; _fileStreamReader?.Close(); _fileStreamReader?.Dispose(); _fileStreamReader = null; base.PostStop(); }
protected override void PreStart() { _observer = new FileObserver(Self, _fullFilePath); _observer.Start(); _fileStream = new FileStream(_fullFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); Self.Tell(new InitialRead(_filePath, _fileStreamReader.ReadToEnd())); }
protected override void PreStart() { _fileObserver = new FileObserver(Self, Path.GetFullPath(_filePath)); _fileObserver.Start(); _fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(_filePath, text)); }
/// <summary> /// Initialization logic for actor that will tail changes to a file /// </summary> protected override void PreStart() { // start watching the file for changes _observer = new FileObserver(Self, Path.GetFullPath(_filePath)); _observer.Start(); //open the file stream with shared read/write permissions (so file can be written to while open) _fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); //read the initial contents of the file var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(_filePath, text)); }
protected override void PreStart() { //start watching file for changes _observer = new FileObserver(Self, Path.GetFullPath(_filepath)); _observer.Start(); //open file stream to write to file while it is open _fileStream = new FileStream(Path.GetFullPath(_filepath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); //read initial file contents and send to console as first message var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(_filepath, text)); }
protected override void PreStart() { // start watching file for changes _observer = new FileObserver(Self, Path.GetFullPath(_filePath)); _observer.Start(); // open the file stream with shared read/write permissions (so file can be written to while open) var fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.ReadWrite); _fileStreamReader = new StreamReader(fileStream, Encoding.UTF8); // the file probably has changed so start reading it Self.Tell(new FileWrite(_filePath)); base.PreStart(); }
public TailActor(IActorRef reporterActor, string filePath) { _reporterActor = reporterActor; _fileObserver = new FileObserver(Self, Path.GetFullPath(filePath)); _fileObserver.Start(); _fileStream = new FileStream(Path.GetFullPath(filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(filePath, text)); }
protected override void PreStart() { observer = new FileObserver(Self, Path.GetFullPath(filePath)); observer.Start(); // open the file stream with shared read/write permissions // (so file can be written to while open) fileStream = new FileStream(Path.GetFullPath(filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); fileStreamReader = new StreamReader(fileStream, Encoding.UTF8); // read the initial contents of the file and send it to console as first msg string text = fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(filePath, text)); }
public TailActor(IActorRef reporterActor, string filePath) { _reporterActor = reporterActor; _filePath = filePath; _observer = new FileObserver(Self, Path.GetFullPath(_filePath)); _observer.Start(); _fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(_filePath, text)); }
protected override void PreStart() { var fullPath = Path.GetFullPath(this._filePath); this._observer = new FileObserver(Self, fullPath); this._observer.Start(); this._fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); this._fileStreamReader = new StreamReader(this._fileStream); var text = this._fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(this._filePath, text)); }
/// <summary> /// Initialization logic for actor that will tail changes to a file. /// </summary> protected override void PreStart() { // start watching file for changes _observer = new FileObserver(Self, Path.GetFullPath(_filePath)); _observer.Start(); // open the file stream with shared read/write permissions (so file can be written to while open) _fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); // read the initial contents of the file and send it to console as first message var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(_filePath, text)); }
protected override void PreStart() { //start watching file _observer = new FileObserver(Self, Path.GetFullPath(_filePath)); _observer.Start(); //open file with shared r/w permissions so it can be written to while open _fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); //read initial file contents and swend as message to console var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(_filePath, text)); }
protected override void PreStart() { // start watching file for changes -- giving ourselves as reference // so that the observer can send messages to us. Note the observer is not // an Actor itself. Messages are sent to us with NoSender. _observer = new FileObserver(Self, Path.GetFullPath(_filePath)); // open the file stream with shared read/write permissions // (so file can be written to while open) _fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); // read the initial contents of the file and send it to console as first msg var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(_filePath, text)); }
public TailActor(IActorRef reporterActor, string filePath) { _reporterActor = reporterActor; _filePath = filePath; // start watching file for changes _observer = new FileObserver(Self, Path.GetFullPath(_filePath)); _observer.Start(); // open the file stream with shared read/write permissions (so file can be written to while open) _fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); // read the initial contents of the file and send it to console as first message var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(_filePath, text)); }
public TailActor(IActorRef reporterActor, string filePath) { _reporterActor = reporterActor; _filePath = filePath; // start watching file for changes _observer = new FileObserver(Self, Path.GetFullPath(_filePath)); _observer.Start(); // open the file stream with shared read/write permissions // (so file can be written to while open) _fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8); // read the initial contents of the file and send it to console as first msg var text = _fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(_filePath, text)); }
// we moved all the initialization logic from the constructor // down below to PreStart! /// <summary> /// Initialization logic for actor that will tail changes to a file. /// </summary> protected override void PreStart() { base.PreStart(); string fullPath = Path.GetFullPath(this.filePath); // start watching file for changes observer = new FileObserver(Self, fullPath); observer.Start(); // open the file stream with shared read/write permissions (so file can be written to while open) fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); fileStreamReader = new StreamReader(fileStream); // read the initial contents of the file and send it to console as first message string text = fileStreamReader.ReadToEnd(); Self.Tell(new InitialRead(filePath, text)); }