/// <summary> /// Tìm kiếm file theo đường dẫn programlist /// </summary> /// <param name="programListPath"></param> /// <returns></returns> private FileInfoDs FindByProgramList(string programListPath) { ExcelApp.Application excelApp = new ExcelApp.Application(); FileInfoDs fileInfoDs = new FileInfoDs(); try { ExcelApp.Workbook excelBook = excelApp.Workbooks.Open(programListPath); ExcelApp._Worksheet excelSheet = excelBook.Sheets[1]; ExcelApp.Range excelRange = excelSheet.UsedRange; int rows = excelRange.Rows.Count; for (int i = 4; i < rows; i++) { FileInfoDs.FileInfoRow row = fileInfoDs.FileInfo.NewFileInfoRow(); row.FileUrl = excelRange.Cells[i, 5].Value2.ToString(); row.FileName = excelRange.Cells[i, 6].Value2.ToString(); row.status = excelRange.Cells[i, 8].Value2.ToString(); // ghép đường dẫn tương đối string relativePath = Path.Combine(row.FileUrl, row.FileName); // ghép full đương dẫn file(đường dẫn tương đối có \\ đằng trước nên ko combine được) string absolutePath = string.Format("{0}{1}", txtSourcePath.Text, relativePath); row.checkexist = File.Exists(absolutePath) ? ApConst.ExistStatus : ApConst.NotExistStatus; fileInfoDs.FileInfo.AddFileInfoRow(row); } } catch (Exception) { MessageBox.Show("Check File Data Again!"); return(null); } finally { excelApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp); } return(fileInfoDs); }
/// <summary> /// Find By PathSource /// </summary> /// <returns></returns> private FileInfoDs FindBySource() { FileInfoDs fileInfoDs = new FileInfoDs(); string repoDir = this.txtSourcePath.Text; List <string> lstFileKey = new List <string>(File.ReadAllLines(extSettingPath)); using (var repo = new Repository(repoDir)) { #region Get Files Un Commit foreach (var item in repo.RetrieveStatus()) { if (lstFileKey.Contains(Path.GetExtension(item.FilePath).Trim())) { if (item.State == FileStatus.NewInWorkdir || item.State == FileStatus.ModifiedInWorkdir || item.State == FileStatus.NewInIndex || item.State == FileStatus.ModifiedInIndex) { string gitFolderPath = item.FilePath.ToString(); string displayFolderPath = gitFolderPath.Contains(forwardSlashChar) ? @"\" + gitFolderPath.Substring(0, gitFolderPath.LastIndexOf(forwardSlashChar)).Replace(@"/", @"\") : @"\"; if (CheckInvalidFiles(displayFolderPath)) { continue; } string strFileName = gitFolderPath.Contains(forwardSlashChar) ? gitFolderPath.Substring(gitFolderPath.LastIndexOf(forwardSlashChar) + 1) : gitFolderPath; if (CheckInvalidFiles(strFileName)) { continue; } string status = string.Empty; if (item.State == FileStatus.NewInWorkdir || item.State == FileStatus.NewInIndex) { status = ApConst.AddStatus; } else if (item.State == FileStatus.ModifiedInWorkdir || item.State == FileStatus.ModifiedInIndex) { status = ApConst.UpdateStatus; } FileInfoDs.FileInfoRow unCommitRow = fileInfoDs.FileInfo.NewFileInfoRow(); unCommitRow.FileUrl = displayFolderPath; unCommitRow.FileName = strFileName; unCommitRow.status = status; unCommitRow.checkexist = ApConst.NotcommitStatus; fileInfoDs.FileInfo.AddFileInfoRow(unCommitRow); unCommitRow.AcceptChanges(); } } } #endregion #region Get Files Commit var test = repo.Commits.Where(x => x.Committer.When >= DateTimeGetChangeControl.Value.Date).OrderBy(x => x.Committer.When); foreach (Commit commit in repo.Commits.Where(x => x.Committer.When >= DateTimeGetChangeControl.Value.Date).OrderBy(x => x.Committer.When)) { string commiter = commit.Committer.Name; foreach (var parent in commit.Parents) { foreach (TreeEntryChanges change in repo.Diff.Compare <TreeChanges>(parent.Tree, commit.Tree)) { FileInfoDs.FileInfoRow fileInfoRow = fileInfoDs.FileInfo.NewFileInfoRow(); string gitFolderPath = change.OldPath.ToString(); if (CheckInvalidFiles(gitFolderPath)) { continue; } string displayFolderPath = gitFolderPath.Contains(forwardSlashChar) ? @"\" + gitFolderPath.Substring(0, gitFolderPath.LastIndexOf(forwardSlashChar)).Replace(@"/", @"\") : @"\"; if (CheckInvalidFiles(displayFolderPath)) { continue; } string strFileName = gitFolderPath.Contains(forwardSlashChar) ? gitFolderPath.Substring(gitFolderPath.LastIndexOf(forwardSlashChar) + 1) : gitFolderPath; if (CheckInvalidFiles(strFileName)) { continue; } string gitFolderNewPath = string.Empty; string displayFolderNewPath = string.Empty; string strNewFileName = string.Empty; if (change.OldPath.ToString() != change.Path.ToString()) { gitFolderNewPath = change.Path.ToString(); displayFolderNewPath = gitFolderNewPath.Contains(forwardSlashChar) ? @"\" + gitFolderNewPath.Substring(0, gitFolderNewPath.LastIndexOf(forwardSlashChar)).Replace(@"/", @"\") : @"\"; strNewFileName = gitFolderNewPath.Contains(forwardSlashChar) ? gitFolderNewPath.Substring(gitFolderNewPath.LastIndexOf(forwardSlashChar) + 1) : gitFolderNewPath; } string status = this.GetStatusToGit(change.Status); if (lstFileKey.Contains(Path.GetExtension(gitFolderPath).Trim())) { // kiểm tra file đã tồn tại trên grid hay chưa FileInfoDs.FileInfoRow rowFileExist = fileInfoDs.FileInfo.Where(x => x.FileUrl == displayFolderPath && x.FileName == strFileName).FirstOrDefault(); if (rowFileExist == null) { fileInfoRow.FileUrl = displayFolderPath; fileInfoRow.FileName = strFileName; fileInfoRow.status = status; fileInfoRow.Commiter = commiter; fileInfoDs.FileInfo.AddFileInfoRow(fileInfoRow); fileInfoRow.AcceptChanges(); } else { if (status == ApConst.DeleteStatus) { fileInfoDs.FileInfo.Rows.Remove(rowFileExist); } else if (status == ApConst.RenameStatus) { rowFileExist.BeginEdit(); rowFileExist.FileUrl = displayFolderNewPath; rowFileExist.FileName = strNewFileName; rowFileExist.Commiter = commiter; rowFileExist.EndEdit(); fileInfoDs.FileInfo.AcceptChanges(); } } } } } } #endregion return(fileInfoDs); } }