예제 #1
0
 private void ReceivedCollect(CollectorMessage.Collect message)
 {
     foreach (string sourceFolder in this.sourceFolders)
     {
         string[] files = Directory.GetFiles(sourceFolder, "*.png").Concat(Directory.GetFiles(sourceFolder, "*.jpg")).ToArray();
         foreach (string file in files)
         {
             try
             {
                 string sourceName     = Path.GetFileNameWithoutExtension(file);
                 string sourceExt      = Path.GetExtension(file);
                 string targetName     = $"{sourceName}.{sourceExt}";
                 int    idx            = 0;
                 string targetFullname = Path.Combine(this.destinationFolder, targetName);
                 while (File.Exists(targetFullname))
                 {
                     targetName     = $"{sourceName}.{idx:D3}.{sourceExt}";
                     targetFullname = Path.Combine(this.destinationFolder, targetName);
                     idx++;
                 }
                 File.Move(file, targetFullname);
                 this.processor.Tell(new CollectorMessage.Success(targetFullname));
             }
             catch (Exception ex)
             {
                 log.Error(ex, "Failed to move '{0}' to collection destination", file);
             }
         }
     }
 }
예제 #2
0
        protected override void PreStart()
        {
            IActorRef self = Self;

            CollectorMessage.Collect collect = new CollectorMessage.Collect();

            for (int i = 0; i < this.sourceFolders.Length; i++)
            {
                this.pngWatchers[i] = new FileSystemWatcher()
                {
                    Path   = this.sourceFolders[i],
                    Filter = "*.png",
                    EnableRaisingEvents = false,
                };
                this.pngWatchers[i].Changed += new FileSystemEventHandler((sender, e) => { self.Tell(collect); });
                this.jpgWatchers[i]          = new FileSystemWatcher()
                {
                    Path   = this.sourceFolders[i],
                    Filter = "*.jpg",
                    EnableRaisingEvents = false,
                };
                this.jpgWatchers[i].Changed += new FileSystemEventHandler((sender, e) => { self.Tell(collect); });
            }

            this.subIntervalScan = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(INTERVAL_SCAN, INTERVAL_SCAN, Self, new CollectorMessage.Collect(), Self);
        }