public TileGroupEmergingWorker(TileGroup group, ITileQueue emergingQueue, ITileQueue existingQueue = null)
            : base(group, emergingQueue, false)
        {
            _existingQueue = existingQueue ?? emergingQueue;

            _debounceTimer = new System.Timers.Timer(DebounceEvalIntervalSeconds);
            _debounceTimer.Elapsed += (s, e) => ProcessDebounceQueue();
            _debounceQueue = new Dictionary<string, EmergingTileContents>();

            _watcher = new FileSystemWatcher(Group.FullPath, "*.*");
            _watcher.IncludeSubdirectories = true;
            _watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite | NotifyFilters.Size;
            _watcher.Created += (s, e) =>
            {
                // Trace.TraceInformation("-----", e.FullPath);
                // Trace.TraceInformation("File/directory create event for {0}.", e.FullPath);
                try
                {
                    Task.Run(async () =>
                    {
                        await Task.Delay(50);
                        DebounceEnqueue(e.FullPath);
                    });
                }
                catch (Exception ex)
                {
                    Trace.TraceError("An exception occurred debouncing after a Create event: {0}", ex.Message);

                    if (ex.InnerException != null)
                    {
                        Trace.TraceError("Inner exception: {0}", ex.InnerException.Message);
                    }
                }
            };
            _watcher.Changed += (s, e) =>
            {
                // Trace.TraceInformation("-----", e.FullPath);
                // Trace.TraceInformation("File/directory change event ({0}) for {1}.", e.ChangeType, e.FullPath);
                try
                {
                    Task.Run(async () =>
                    {
                        await Task.Delay(50);
                        DebounceEnqueue(e.FullPath);
                    });
                }
                catch (Exception ex)
                {
                    Trace.TraceError("An exception occurred debouncing after a Changed event: {0}", ex.Message);

                    if (ex.InnerException != null)
                    {
                        Trace.TraceError("Inner exception: {0}", ex.InnerException.Message);
                    }
                }
            };
        }
 public TileGroupDiscoverWorker(TileGroup group, ITileQueue queue, bool isExisting = false)
 {
     Group = group;
     IsExisting = isExisting;
     StartTime = DateTime.MinValue;
     Queue = queue;
     DiscoveredCount = 0;
     IsComplete = false;
 }
        private Tile CreateTile(TileGroup group, string id, int zIndex, double z, bool haveAcquisition = true)
        {
            Tile tile = TileFactory.Create(group.FullPath + Path.DirectorySeparatorChar + id, group.RelativePath, 0, 2);

            tile.Contents.Position = new Position<double>() { X = 1.1, Y = 2.2, Z = z };
            tile.Contents.LatticePosition = new Position<int>() { X = 0, Y = 0, Z = zIndex };
            tile.IsEvaluated = true;
            tile.HaveAcquisition = haveAcquisition;
            tile.HaveMicroscope = true;

            return tile;
        }
 public TileGroupExistingWorker(TileGroup group, ITileQueue queue)
     : base(group, queue, true)
 {
 }
        private TileGroup CreateOrGetTileGroup(int groupIndex, string fullPath, string relPath, out bool wasCreated)
        {
            var tileGroup = Groups.FirstOrDefault((g) => g.Id == groupIndex);

            if (tileGroup == null)
            {
                wasCreated = true;

                tileGroup = new TileGroup() { Id = groupIndex, FullPath = fullPath, RelativePath = relPath };

                // Propagate with additional context.
                tileGroup.TileDataChanged += (s, e) =>
                {
                    e.SetDayIndex(this.Index);
                    e.SetDayLocation(Date.ToString("yyyy-MM-dd"));
                    RaiseTileDataChanged(e);
                };

                // Just propagate.
                tileGroup.IncompleteCollectionChanged += (s, e) => OnCollectionChanged(IncompleteCollectionChanged, e);

                // Just propagate.
                tileGroup.TileCollectionChanged += (s, e) => OnCollectionChanged(TileCollectionChanged, e);

                _tileGroups.Add(tileGroup);
                OnCollectionChangedAdd(GroupCollectionChanged, tileGroup);
            }
            else
            {
                wasCreated = false;
            }

            return tileGroup;
        }