/// <summary> /// Open the corresponding file on label click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LblfileName_1_MouseDown(object sender, MouseButtonEventArgs e) { try { System.Windows.Controls.Label srcLabel = e.Source as System.Windows.Controls.Label; //to know which label call this handler string fileName = srcLabel.Content.ToString(); string fileSearchPath = CommitWindow.pushDirectory; string[] folders = Directory.GetDirectories(fileSearchPath); foreach (string folder in folders) { string folderName = folder.Split('\\')[folder.Split('\\').Length - 1]; if (folderName == fileName) { string[] files = Directory.GetFiles(folder); foreach (string file in files) { string replacedString = file.Split('\\')[file.Split('\\').Length - 1]; //Need to add commit info with filename to get the searched file int rowNumberOfSrcLabel = Convert.ToInt32(((srcLabel.Name).Split('_'))[1]); Label modifiedTime = FindName("lblfileDate_" + (rowNumberOfSrcLabel)) as Label; Label modifedBy = FindName("lblModifiedBy_" + (rowNumberOfSrcLabel)) as Label; string searchFileName = modifiedTime.Content.ToString() + "_" + modifedBy.Content.ToString() + "_" + fileName; searchFileName = searchFileName.Replace(":", "_"); //string flname = replacedString.Split('_')[replacedString.Split('_').Length-1]; if (replacedString == searchFileName) { NotepadPPGateway notepadPPGateway = new NotepadPPGateway(); //Save as file with temp prefix for temporary opening string tempFileName = "temp_" + fileName; string tempFileSavePath = CommitWindow.pushDirectory + "\\" + tempFileName; notepadPPGateway.openFile(file); notepadPPGateway.SaveCurrentFile(tempFileSavePath); notepadPPGateway.openFile(file); notepadPPGateway.CloseCurrentFile(); this.Close(); break; } } } } } catch { //Write error log here } }
private void btnCommit_Click(object sender, EventArgs e) { //Check its pml file or not NotepadPPGateway notepadPPGatewayTemp = new NotepadPPGateway(); string pathTemp = notepadPPGatewayTemp.GetCurrentFilePath(); string currentFileNameTemp = Path.GetFileName(pathTemp); bool isPml = Utility.isPml(currentFileNameTemp); //True if this is a PML file //Take the commit message string[] commitMessage = richTxtCommit.Lines; int i = 0; //Getting commit message foreach (string s in commitMessage) { commitMessage[i] = Utility.commentSpecifier + "Commit Message:$ " + commitMessage[i]; i++; } if (!(commitMessage.Length == 0)) { NotepadPPGateway notepadPPGateway = new NotepadPPGateway(); //Save the file to original location string path = notepadPPGateway.GetCurrentFilePath(); //check the file is committed file or not. if (path.Contains("temp")) { MessageBox.Show("This file can not be committed. Revert to this version before committing."); return; } currentFileDirectory = path;//for later use notepadPPGateway.SaveCurrentFile(); //Save the file to another directory string currentFileName = Path.GetFileName(path); string userName = Environment.UserName; DateTime now = System.DateTime.Now; string pushedFileName = now.ToString() + "_" + userName + "_" + currentFileName; pushedFileName = pushedFileName.Replace(":", "_"); pushedFileName = pushedFileName.Replace(@"\", "_"); //Create directory for the original file if (Directory.Exists(pushDirectory) && !(pushDirectory == "") && Directory.Exists(rootDirectory) && !(rootDirectory == "") && Directory.Exists(codeDirectory) && !(codeDirectory == "") && Directory.Exists(finalDirectoryForEncryption) && !(finalDirectoryForEncryption == "")) { Directory.CreateDirectory(pushDirectory + "\\" + currentFileName); string pushedFileDirectory = pushDirectory + "\\" + currentFileName + "\\" + pushedFileName; notepadPPGateway.SaveCurrentFile(pushedFileDirectory); //Open the file from remote directory and write commit message on top of it as comment and save AddCommitMessageToFileTop(commitMessage, pushedFileDirectory); MessageBox.Show("Successfully Committed"); //Closing the save as file and opening the original file notepadPPGateway.CloseCurrentFile(); notepadPPGateway.openFile(path); //Only pml files can be commited as final if ((chkFinal.Checked == true || chkEmergency.Checked == true) && isPml == false) { MessageBox.Show("Only PML file can be committed as Final"); return; } if (chkFinal.Checked == true) { //Check file path contains code directory of PML files if (path.Contains(codeDirectory)) { string strucDirectory = (path.Replace(codeDirectory, "")).Replace(currentFileName, ""); string newDirectory = finalDirectoryForEncryption + strucDirectory; Directory.CreateDirectory(newDirectory); if (File.Exists(newDirectory + currentFileName)) { File.Delete(newDirectory + currentFileName); File.Copy(path, newDirectory + currentFileName); } else { File.Copy(path, newDirectory + currentFileName); } } else { MessageBox.Show("File should be opened from code directory to make as final"); } } else if (chkEmergency.Checked == true) { //Check file path contains code directory of PML files if (path.Contains(codeDirectory)) { //To copy on final directory for encryption //Same name on same if else conflicts so 'New' added string strucDirectoryNew = (path.Replace(codeDirectory, "")).Replace(currentFileName, ""); string newDirectoryNew = finalDirectoryForEncryption + strucDirectoryNew; if (!Directory.Exists(newDirectoryNew)) { Directory.CreateDirectory(newDirectoryNew); } if (File.Exists(newDirectoryNew + currentFileName)) { File.Delete(newDirectoryNew + currentFileName); File.Copy(path, newDirectoryNew + currentFileName); } else { File.Copy(path, newDirectoryNew + currentFileName); } //To copy on emergency directory to get immediately newDirectoryNew = emergencyDirectory + strucDirectoryNew; if (!Directory.Exists(newDirectoryNew)) { Directory.CreateDirectory(newDirectoryNew); } if (File.Exists(newDirectoryNew + currentFileName)) { File.Delete(newDirectoryNew + currentFileName); File.Copy(path, newDirectoryNew + currentFileName); } else { File.Copy(path, newDirectoryNew + currentFileName); } //Utility.pmlindexAppend(emergencyDirectory + "\\" + "pml.index", newDirectoryNew + currentFileName); } else { MessageBox.Show("File should be opened from code directory to make as final"); } } } else { MessageBox.Show("Invalid Directory"); } //Close the commit form and dispose this.Close(); this.Dispose(); } else { MessageBox.Show("Write a Commit Message before commiting code describing changes"); } }