Пример #1
0
        static void Main(string[] args)
        {
            MyActorSystem = ActorSystem.Create("MyActorSystem");

            StreamWriterFactory writerEvenFactory = new StreamWriterFactory();
            Props     csvWriterProps = Props.Create(() => new CsvWriterActor(writerEvenFactory));
            IActorRef csvWriterActor = MyActorSystem.ActorOf(csvWriterProps, "csvWriterActor");

            StreamReaderFactory readerFactory = new StreamReaderFactory();
            Props     csvReaderProps          = Props.Create(() => new CsvReaderActor(csvWriterActor, readerFactory));
            IActorRef csvReaderActor          = MyActorSystem.ActorOf(csvReaderProps, "csvReaderActor");

            var readFileMessage = new ReadFile(ConfigurationManager.AppSettings["FilePath"]);

            csvReaderActor.Tell(readFileMessage);

            MyActorSystem.WhenTerminated.Wait();
        }
Пример #2
0
        protected void ReadCsv(ReadFile message)
        {
            // Open files
            var evenFilePathAppConfig = new EvenOpenFile(ConfigurationManager.AppSettings["EvenFilePath"]);

            _csvWriterActor.Tell(evenFilePathAppConfig);

            var oddFilePathAppConfig = new OddOpenFile(ConfigurationManager.AppSettings["OddFilePath"]);

            _csvWriterActor.Tell(oddFilePathAppConfig);

            // Write to them
            using (StreamReader reader = _streamReaderFactory.Create(message.FilePath))
            {
                while (!reader.EndOfStream)
                {
                    var strline = reader.ReadLine();
                    if (strline != null)
                    {
                        var values = strline.Split(',');

                        foreach (var item in values)
                        {
                            var writeNumberMessage = new WriteNumber(Int32.Parse(item));
                            _csvWriterActor.Tell(writeNumberMessage);
                        }
                    }
                }
            }

            // Close the files
            var evenCloseFileMessage = new EvenCloseFile();

            _csvWriterActor.Tell(evenCloseFileMessage);

            var oddCloseFileMessage = new OddCloseFile();

            _csvWriterActor.Tell(oddCloseFileMessage);
        }