private async void OnFileChanged(object sender, FileSystemEventArgs e)
        {            // There is a bug in the FileSystemWatcher that causes this event
            // to sometimes be called twice. This is not an amazing workaround but
            // the best StackOverflow could provide me. 😝
            // https://stackoverflow.com/questions/449993/vb-net-filesystemwatcher-multiple-change-events/450046#450046
            if (e.ChangeType == WatcherChangeTypes.Changed)
            {
                if (DateTime.Now.Subtract(_lastTimeFileWatcherEventRaised).TotalMilliseconds < 500)
                {
                    return;
                }

                _logger.LogTrace($"File changed {e.FullPath} in mounted volume {ContainerPath}.");

                _lastTimeFileWatcherEventRaised = DateTime.Now;

                var path          = e.FullPath;
                var relativePath  = Path.GetRelativePath(HostPath, path).Replace("\\", "/");
                var containerPath = _hostPathInfo.IsFile ? ContainerPath : $"{ContainerPath}/{relativePath}";

                if (!_gitignore.IsIgnored(relativePath))
                {
                    await _notify.Notify(ContainerID, containerPath);
                }
                else
                {
                    _logger.LogTrace($"Filepath ({relativePath}) is ignored, not triggering notifiers!");
                }
            }
        }
示例#2
0
        public async Task Notify(string containerID, string pathChanged)
        {
            _logger.LogTrace($"Syncing change for {pathChanged} inside container ({containerID}.");

            var cmd = new string[] { "sh", "-c", String.Format(SYNC_FILE_CMD, pathChanged) };

            using (var result = await _dockerService.Exec(containerID, cmd))
            {
                if (result.ExitCode == 1)
                {
                    await LogError(containerID, pathChanged, result.Stderr);
                }
            }
        }