public bool DeleteCustomCommand(CustomCommand customCommand) { //Delete the entry from custom command file var copyCustomCommandsDT = CustomCommandsDT.Copy(); foreach (DataRow dataRow in copyCustomCommandsDT.Rows) { if (dataRow[Constants.Name].ToString() == customCommand.Name) { copyCustomCommandsDT.Rows.Remove(dataRow); break; } } //delete from profile custom command file var profileCommandsDT = _xmlOperations.GetXml(customCommand.Profile.CommandFilePath); var copyProfileCommandsDT = profileCommandsDT.Copy(); foreach (DataRow dataRow in copyProfileCommandsDT.Rows) { if (dataRow[Constants.Name].ToString() == customCommand.Name) { copyProfileCommandsDT.Rows.Remove(dataRow); break; } } _xmlOperations.WriteXml(copyCustomCommandsDT, _customCommandsFilePath); CustomCommandsDT = copyCustomCommandsDT; _xmlOperations.WriteXml(copyProfileCommandsDT, customCommand.Profile.CommandFilePath); return(true); }
public bool AddCustomCommand(CustomCommand customCommand) { var copyCustomCommandsDT = CustomCommandsDT.Copy(); DataRow customCommandRow = copyCustomCommandsDT.NewRow(); customCommandRow[Constants.Name] = customCommand.Name; customCommandRow[Constants.Profile] = customCommand.Profile.Name; copyCustomCommandsDT.Rows.Add(customCommandRow); //2. Read the ProfileCommands file customCommand.Profile.CommandFilePath = GetProfileCommandPath(customCommand.Profile.Name); DataTable profileCommandsDT; profileCommandsDT = _xmlOperations.GetXml(customCommand.Profile.CommandFilePath); if (profileCommandsDT == null) { profileCommandsDT = GetDefaultProfileCommandDT(); } var copyProfileCommandsDT = profileCommandsDT.Copy(); DataRow profileCommandRow = copyProfileCommandsDT.NewRow(); profileCommandRow[Constants.Name] = customCommand.Name; profileCommandRow[Constants.ActionScript] = customCommand.ActionScript; profileCommandRow[Constants.Parameter] = customCommand.Parameter; copyProfileCommandsDT.Rows.Add(profileCommandRow); _xmlOperations.WriteXml(copyCustomCommandsDT, _customCommandsFilePath); CustomCommandsDT = copyCustomCommandsDT; _xmlOperations.WriteXml(copyProfileCommandsDT, customCommand.Profile.CommandFilePath); return(true); }
public bool DeleteProfile(string profileName) { //Delete the profile from profile config _profileManager.Delete(profileName); //delete the custom commands stored with that profile name var copyCustomCommandsDT = CustomCommandsDT.Copy(); foreach (DataRow dataRow in copyCustomCommandsDT.Rows) { if (dataRow[Constants.Name].ToString() == profileName) { copyCustomCommandsDT.Rows.Remove(dataRow); break; } } _xmlOperations.WriteXml(copyCustomCommandsDT, _customCommandsFilePath, XmlType.Profile); CustomCommandsDT = copyCustomCommandsDT; return(true); }
public bool UpdateProfile(Profile oldProfile, Profile newProfile) { _profileManager.Update(oldProfile, newProfile); var copyCustomCommandsDT = CustomCommandsDT.Copy(); foreach (DataRow dr in copyCustomCommandsDT.Rows) { if (dr[Constants.Profile].ToString() == oldProfile.Name) { //found the row, so update dr[Constants.Profile] = newProfile.Name; } else { continue; } } _xmlOperations.WriteXml(copyCustomCommandsDT, _customCommandsFilePath, XmlType.Profile); CustomCommandsDT = copyCustomCommandsDT; return(true); }
public bool UpdateCustomCommand(CustomCommand oldCustomCommand, CustomCommand newCustomCommand) { //Find custom command row //looping through the datatable and update bool isProfileChanged = false; DataTable oldProfileCommandsDT, newProfileCommandsDT, copyOldProfileCommandsDT, profileCommandsDT, copyprofileCommandsDT, copynewProfileCommandsDT; oldProfileCommandsDT = null; newProfileCommandsDT = null; copyOldProfileCommandsDT = null; profileCommandsDT = null; copyprofileCommandsDT = null; copynewProfileCommandsDT = null; var copyCustomCommandsDT = CustomCommandsDT.Copy(); foreach (DataRow dr in copyCustomCommandsDT.Rows) { if (dr[Constants.Name].ToString() == oldCustomCommand.Name) { //found the row, so update if (dr[Constants.Profile].ToString() != newCustomCommand.Profile.Name) { isProfileChanged = true; } dr[Constants.Name] = newCustomCommand.Name; dr[Constants.Profile] = newCustomCommand.Profile.Name; } else { continue; } } //find profile custom command row if (isProfileChanged) { oldCustomCommand.Profile.CommandFilePath = GetProfileCommandPath(oldCustomCommand.Profile.Name); newCustomCommand.Profile.CommandFilePath = GetProfileCommandPath(newCustomCommand.Profile.Name); oldProfileCommandsDT = _xmlOperations.GetXml(oldCustomCommand.Profile.CommandFilePath); newProfileCommandsDT = _xmlOperations.GetXml(newCustomCommand.Profile.CommandFilePath); if (newProfileCommandsDT == null) { newProfileCommandsDT = GetDefaultProfileCommandDT(); } copynewProfileCommandsDT = newProfileCommandsDT.Copy(); //add new custom command to new profile command DataRow newProfileCommandRow = copynewProfileCommandsDT.NewRow(); newProfileCommandRow[Constants.Name] = newCustomCommand.Name; newProfileCommandRow[Constants.ActionScript] = newCustomCommand.ActionScript; newProfileCommandRow[Constants.Parameter] = newCustomCommand.Parameter; copynewProfileCommandsDT.Rows.Add(newProfileCommandRow); //remove from old profile command copyOldProfileCommandsDT = oldProfileCommandsDT.Copy(); foreach (DataRow dataRow in copyOldProfileCommandsDT.Rows) { if (dataRow[Constants.Name].ToString() == oldCustomCommand.Name) { copyOldProfileCommandsDT.Rows.Remove(dataRow); break; } } } else { oldCustomCommand.Profile.CommandFilePath = GetProfileCommandPath(oldCustomCommand.Profile.Name); profileCommandsDT = _xmlOperations.GetXml(oldCustomCommand.Profile.CommandFilePath); copyprofileCommandsDT = profileCommandsDT.Copy(); foreach (DataRow dr in copyprofileCommandsDT.Rows) { if (dr[Constants.Name].ToString() == oldCustomCommand.Name) { dr[Constants.Name] = newCustomCommand.Name; dr[Constants.ActionScript] = newCustomCommand.ActionScript; dr[Constants.Parameter] = newCustomCommand.Parameter; } else { continue; } } } //apply changes _xmlOperations.WriteXml(copyCustomCommandsDT, _customCommandsFilePath); CustomCommandsDT = copyCustomCommandsDT; if (copyOldProfileCommandsDT != null) { _xmlOperations.WriteXml(copyOldProfileCommandsDT, oldCustomCommand.Profile.CommandFilePath); } if (copynewProfileCommandsDT != null) { _xmlOperations.WriteXml(copynewProfileCommandsDT, newCustomCommand.Profile.CommandFilePath); } if (copyprofileCommandsDT != null)//if not profile chagnge { _xmlOperations.WriteXml(copyprofileCommandsDT, oldCustomCommand.Profile.CommandFilePath); } return(true); }