Beispiel #1
0
        public SipaAcotorV2(IActorRef supervisor)
        {
            supervisor_ = supervisor;
            var log = Context.GetLogger();

            Receive <string>(s =>
            {
                if (s != "export")
                {
                    return;
                }

                numWaiting_++;
                string name = "job" + ++jobCount_;
                var job     = new DoNothingJob(name);

                job.Finished += () =>
                {
                    supervisor_.Tell(new Progress(name, 100));
                    supervisor_.Tell(new Finished(name));

                    log.Info(name + " finished.");
                    numWaiting_--;
                    log.Info("num jobs in pipeline: " + numWaiting_);
                };

                job.Progressed += (percent) =>
                {
                    supervisor_.Tell(new Progress(name, percent));
                };

                job.Started += () =>
                {
                    supervisor_.Tell(new Started(name));
                };

                log.Info(name + " starting");
                log.Info("num jobs in pipeline: " + numWaiting_);
                job.Run();
            });
        }
Beispiel #2
0
        public SipaActor()
        {
            Receive <string>(s =>
            {
                if (s != "export")
                {
                    return;
                }

                var sender = Sender; // close over Sender for use in subsequent event handlers
                numWaiting_++;
                string name      = "exporter" + ++exportCount_;
                var sipaExporter = new DoNothingJob(name);

                sipaExporter.Finished += () =>
                {
                    sender.Tell(new Progress(name, 100));
                    sender.Tell(new Finished(name));
                    Console.WriteLine(name + " finished.");
                    numWaiting_--;
                    Console.WriteLine("num jobs in pipeline: " + numWaiting_);
                };

                sipaExporter.Progressed += (percent) =>
                {
                    sender.Tell(new Progress(name, percent));
                };

                sipaExporter.Started += () =>
                {
                    sender.Tell(new Started(name));
                };

                Console.WriteLine(name + " starting");
                Console.WriteLine("num jobs in pipeline: " + numWaiting_);
                sipaExporter.Run();
            });
        }