private void DriveInserted(object sender, string s) { _logger.LogInfo($"\"{s}\" : Inserted"); var configurationFile = _configurationFileService.GetConfigurationFile(s); if (configurationFile == null) { _logger.LogInfo($"\"{s}\" : No configuration file found on drive - Use the CameraConfigurator to create one."); return; } var videosOnDrive = _videoFileService.GetAllVideoFiles(s); var videosInConfig = configurationFile.VideoPaths.ToList(); var newVideos = videosOnDrive.Except(videosInConfig).Select(newVideo => Path.Combine(s, newVideo)).ToList(); if (!newVideos.Any()) { _logger.LogInfo($"\"{s}\" : There's no new videos on the drive - Nothing to copy."); return; } foreach (var newVideo in newVideos) { var ext = Path.GetExtension(newVideo); var counter = 1; var destinationFolder = Path.Combine(ConfigurationManager.AppSettings["VideoFolderPath"], $"{DateTime.Now:yyyy-MM-dd}"); var destinationFileName = $"{configurationFile.LastName}_{configurationFile.FirstName}_{counter}{ext}"; var destinationPath = Path.Combine(destinationFolder, destinationFileName); if (!Directory.Exists(destinationFolder)) { Directory.CreateDirectory(destinationFolder); } while (File.Exists(destinationPath)) { counter++; destinationFileName = $"{configurationFile.LastName}_{configurationFile.FirstName}_{counter}{ext}"; destinationPath = Path.Combine(destinationFolder, destinationFileName); } _logger.LogInfo($"\"{s}\" : Start copying {newVideo} to {destinationPath}."); File.Copy(newVideo, destinationPath); _logger.LogInfo($"\"{s}\" : End copying {newVideo} to {destinationPath}."); videosInConfig.Add(newVideo); _configurationFileService.CreateConfigurationFile(s, new Domain.Model.Configuration(configurationFile.LastName, configurationFile.FirstName, configurationFile.LicenceNumber, videosInConfig)); _logger.LogInfo($"\"{s}\" : Configuration file updated."); } }
public CameraConfiguratorViewModel(string driveName, IWindowService windowService, IConfigurationFileService configurationFileService, IVideoFileService videoFileService) { DriveName = driveName; _windowService = windowService; _configurationFileService = configurationFileService; _videoFileService = videoFileService; var config = _configurationFileService.GetConfigurationFile(DriveName); FirstName = config?.FirstName; LastName = config?.LastName; LicenceNumber = config?.LicenceNumber; _videoPaths = _videoFileService.GetAllVideoFiles(driveName); InitCommands(); this.PropertyChanged += (sender, args) => { ConfigureCommand.IsEnabled = CheckFormValues(); }; }
public async Task <IActionResult> GetFiles() { var files = await _videoFileService.GetAllVideoFiles(); return(new JsonResult(files)); }