public async Task CreateFileMonitor(FileMonitorDto fileMonitorDto) { if (fileMonitorDto == null) { throw new ArgumentNullException(nameof(fileMonitorDto)); } var server = await _legacyContext.GameServers.SingleOrDefaultAsync(s => s.ServerId == fileMonitorDto.ServerId); if (server == null) { throw new NullReferenceException(nameof(server)); } var fileMonitor = new FileMonitors { FileMonitorId = Guid.NewGuid(), FilePath = fileMonitorDto.FilePath, BytesRead = fileMonitorDto.BytesRead, LastRead = DateTime.UtcNow.AddHours(-4), //LastError = string.Empty; GameServerServer = server }; _legacyContext.FileMonitors.Add(fileMonitor); await _legacyContext.SaveChangesAsync(); }
public void AddFileMonitor(string filepath) { foreach (var fileMonitor in FileMonitors) { if (!fileMonitor.FilePath.Equals(filepath, StringComparison.InvariantCultureIgnoreCase)) { continue; } // Already being monitored SelectedFile = fileMonitor; return; } var monitorViewModel = new FileMonitorViewModel ( filepath, Path.GetFileName(filepath), Settings.Default.DefaultEncoding, Settings.Default.BufferedRead ); monitorViewModel.Renamed += MonitorViewModelOnRenamed; monitorViewModel.Updated += MonitorViewModelOnUpdated; FileMonitors.Add(monitorViewModel); SelectedFile = monitorViewModel; }
private void RemoveButton_OnClick(object sender, RoutedEventArgs e) { if (SelectedItem != null) { SelectedItem.Dispose(); FileMonitors.Remove(SelectedItem); } }
private void RemoveFile() { if (SelectedFile == null) { return; } SelectedFile.Dispose(); FileMonitors.Remove(SelectedFile); }
public static FileMonitorDto ToDto(this FileMonitors fileMonitor) { var fileMonitorDto = new FileMonitorDto { FileMonitorId = fileMonitor.FileMonitorId, FilePath = fileMonitor.FilePath, BytesRead = fileMonitor.BytesRead, LastRead = fileMonitor.LastRead, ServerId = fileMonitor.GameServerServer.ServerId, GameServer = fileMonitor.GameServerServer.ToDto() }; return(fileMonitorDto); }
private void AddFileMonitor(string filepath) { var existingMonitor = FileMonitors.FirstOrDefault(m => string.Equals(m.FilePath, filepath, StringComparison.CurrentCultureIgnoreCase)); if (existingMonitor != null) { // Already being monitored SelectedItem = existingMonitor; return; } var monitorViewModel = new FileMonitorViewModel(filepath, GetFileNameForPath(filepath), Settings.Default.DefaultEncoding, Settings.Default.BufferedRead); monitorViewModel.Renamed += MonitorViewModelOnRenamed; monitorViewModel.Updated += MonitorViewModelOnUpdated; FileMonitors.Add(monitorViewModel); SelectedItem = monitorViewModel; }