public void ShowDiffWindow(FileDiffModel parameter, int id) { var window = ShowWindow <DiffWindow>(id); // todo id is generated in filediff, we can use more elegant solution to prevent duplicates. It won't work in cases like user reopen detail view if (window.ViewModel == null) { var vm = (DiffWindowControlViewModel)_diffFactory.CreateExport().Value; window.ViewModel = vm; vm.Initialize(parameter); vm.WhenAnyValue(x => x.FileDiff).Where(x => x != null).Subscribe(x => window.Caption = $"Diff ({x.DisplayFileName})"); } }
public FileDiffModel GetFileDifference(string fileName) { var local = Directory.GetFiles(localFolderPath); var remote = Directory.GetFiles(remoteFolderPath); var localFilePath = local.FirstOrDefault(n => Path.GetFileName(n).Equals(fileName, StringComparison.OrdinalIgnoreCase)); var remoteFilePath = remote.FirstOrDefault(n => Path.GetFileName(n).Equals(fileName, StringComparison.OrdinalIgnoreCase)); if (localFilePath == null || remoteFilePath == null) { throw new InvalidOperationException(); } var result = new FileDiffModel { Name = fileName, RemoteDetectedEncoding = DetectEncoding(remoteFilePath), LocalDetectedEncoding = DetectEncoding(localFilePath) }; var localFileDifferentText = string.Empty; var remoteFileDifferentText = string.Empty; var localFileContents = File.ReadAllLines(localFilePath); var remoteFileContents = File.ReadAllLines(remoteFilePath); var differentLineIndex = 0; if (ignoreEncoding || result.RemoteDetectedEncoding.GetType() == result.LocalDetectedEncoding.GetType()) { differentLineIndex = GetFirstDiscrepancyIndex(localFilePath, remoteFilePath); } if (differentLineIndex < localFileContents.Length) { localFileDifferentText = localFileContents[differentLineIndex]; } if (differentLineIndex < remoteFileContents.Length) { remoteFileDifferentText = remoteFileContents[differentLineIndex]; } result.DifferentLineIndex = differentLineIndex; result.LocalFirstDifferentLineText = localFileDifferentText; result.RemoteFirstDifferentLineText = remoteFileDifferentText; return(result); }
public MainWindow() { InitializeComponent(); DataContext = new FileDiffModel(TabControl); }