Beispiel #1
0
        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));
        }
Beispiel #2
0
 /// <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();
 }
Beispiel #3
0
 protected override void PostStop()
 {
     _observer.Dispose();
     _observer = null;
     _fileStreamReader.Close();
     _fileStreamReader.Dispose();
     base.PostStop();
 }
Beispiel #4
0
 protected override void PostStop()
 {
     _observer.Dispose();
     _observer = null;
     _fileStreamReader.Close();
     _fileStreamReader.Dispose();
     base.PostStop();
 }
Beispiel #5
0
 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()));
 }
Beispiel #6
0
 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()));
 }
Beispiel #7
0
        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));
        }
Beispiel #9
0
        protected override void PostStop()
        {
            // clean up resources
            _observer?.Dispose();
            _observer = null;
            _fileStreamReader?.Close();
            _fileStreamReader?.Dispose();
            _fileStreamReader = null;

            base.PostStop();
        }
Beispiel #10
0
        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()));
        }
Beispiel #11
0
        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));
        }
Beispiel #12
0
        /// <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));
        }
Beispiel #13
0
        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));
        }
Beispiel #14
0
        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();
        }
Beispiel #15
0
        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));
        }
Beispiel #16
0
        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));
        }
Beispiel #17
0
        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));
        }
Beispiel #18
0
        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));
        }
Beispiel #19
0
        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();
        }
Beispiel #20
0
        /// <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));
        }
Beispiel #21
0
        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));
        }
Beispiel #22
0
        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));
        }
Beispiel #23
0
        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));
        }
Beispiel #24
0
        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));
        }
Beispiel #25
0
        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));
        }
Beispiel #26
0
        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));
        }
        // 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));
        }