/// <summary> /// Call this method to replace the variables inside your tags template (e.g. {&a }) to their actual values /// </summary> public static string ReplaceTokens(FileTagObject fileTagObject, string tagString) { var output = tagString; foreach (var tuple in new List <Tuple <string, string> > { new Tuple <string, string>(@"({&a\s*})", fileTagObject.ApplicationName), new Tuple <string, string>(@"({&v\s*})", fileTagObject.ApplicationVersion), new Tuple <string, string>(@"({&b\s*})", fileTagObject.BugId), new Tuple <string, string>(@"({&da\s*})", fileTagObject.CorrectionDate), new Tuple <string, string>(@"({&de\s*})", fileTagObject.CorrectionDecription), new Tuple <string, string>(@"({&n\s*})", fileTagObject.CorrectionNumber), new Tuple <string, string>(@"({&w\s*})", fileTagObject.WorkPackage), new Tuple <string, string>(@"({&u\s*})", Config.Instance.UserName) }) { var regex = new Regex(tuple.Item1); var match = regex.Match(output); if (match.Success) { var matchedStr = match.Groups[1].Value; if (matchedStr.Contains(' ')) { // need to replace the same amount of char output = output.Replace(matchedStr, string.Format("{0,-" + matchedStr.Length + @"}", tuple.Item2 ?? "")); } else { output = output.Replace(matchedStr, tuple.Item2 ?? ""); } } } return(output); }
public static void SetFileTags(string filename, string nb, string date, string text, string nomAppli, string version, string chantier, string jira) { if (string.IsNullOrWhiteSpace(filename)) { return; } var obj = new FileTagObject { CorrectionNumber = nb, CorrectionDate = date, CorrectionDecription = text, ApplicationName = nomAppli, ApplicationVersion = version, WorkPackage = chantier, BugId = jira }; // filename exists if (Contains(filename)) { if (filename == LastTag || filename == DefaultTag) { _filesInfo[filename].Clear(); } // modif number exists _filesInfo[filename].RemoveAll(o => o.CorrectionNumber == nb); _filesInfo[filename].Add(obj); } else { _filesInfo.Add(filename, new List <FileTagObject> { obj }); } }
/// <summary> /// Load the dictionnary of file info /// </summary> public static void Import() { _filesInfo.Clear(); Utils.ForEachLine(Config.FileFilesInfo, new byte[0], (i, line) => { var items = line.Split('\t'); if (items.Count() == 8) { var fileName = items[0].Trim(); var fileInfo = new FileTagObject { CorrectionNumber = items[1], CorrectionDate = items[2], CorrectionDecription = items[3].Replace("~n", "\n"), ApplicationName = items[4], ApplicationVersion = items[5], WorkPackage = items[6], BugId = items[7] }; // add to dictionnary if (_filesInfo.ContainsKey(fileName)) { _filesInfo[fileName].Add(fileInfo); } else { _filesInfo.Add(fileName, new List <FileTagObject> { fileInfo }); } } }, Encoding.Default); if (!_filesInfo.ContainsKey(DefaultTag)) { SetFileTags(DefaultTag, "", "", "", "", "", "", ""); } if (!_filesInfo.ContainsKey(LastTag)) { SetFileTags(LastTag, "", "", "", "", "", "", ""); } }
/// <summary> /// called when the user changes the value of the combo box /// </summary> private void SelectedIndexChanged(object sender, EventArgs e) { var val = cb_info.SelectedValue.ToString(); if (val.Equals(FileTag.LastTag) || val.Equals(FileTag.DefaultTag)) _locFileTagObject = FileTag.GetFileTags(val, ""); else { _locFileTagObject = FileTag.GetFileTags(_filename, val); FileTag.SetFileTags(_filename, _locFileTagObject.CorrectionNumber, _locFileTagObject.CorrectionDate, _locFileTagObject.CorrectionDecription, _locFileTagObject.ApplicationName, _locFileTagObject.ApplicationVersion, _locFileTagObject.WorkPackage, _locFileTagObject.BugId); } UpdateView(); }
private void BtClearOnButtonPressed(object sender, EventArgs buttonPressedEventArgs) { _locFileTagObject = new FileTagObject(); UpdateView(); FileHasChanged(); }
/// <summary> /// Call this method to update the content of the form according to the current document /// </summary> public void UpdateInfo() { _filename = Npp.GetCurrentFileName(); // populate combobox var list = new List<ItemCombo> { new ItemCombo {DisplayText = "Last info", Nb = FileTag.LastTag}, new ItemCombo {DisplayText = "Default info", Nb = FileTag.DefaultTag} }; cb_info.DisplayMember = "DisplayText"; cb_info.ValueMember = "Nb"; if (FileTag.Contains(_filename)) { var currentList = FileTag.GetFileTagsList(_filename); _locFileTagObject = currentList.Last(); var i = 2; var lastItemPos = 0; foreach (var fileTag in currentList.OrderByDescending(o => o.CorrectionNumber).ToList()) { list.Add(new ItemCombo { DisplayText = _filename + " # " + fileTag.CorrectionNumber, Nb = fileTag.CorrectionNumber }); if (fileTag.CorrectionNumber.Equals(_locFileTagObject.CorrectionNumber)) lastItemPos = i; i++; } cb_info.DataSource = list; cb_info.SelectedIndex = lastItemPos; } else { _locFileTagObject = FileTag.GetFileTags(Config.Instance.UseDefaultValuesInsteadOfLastValuesInEditTags ? FileTag.DefaultTag : FileTag.LastTag, ""); cb_info.DataSource = list; cb_info.SelectedIndex = Config.Instance.UseDefaultValuesInsteadOfLastValuesInEditTags ? 1 : 0; } UpdateView(); ActiveControl = cb_info; }
public static void SetFileTags(string filename, string nb, string date, string text, string nomAppli, string version, string chantier, string jira) { if (string.IsNullOrWhiteSpace(filename)) return; var obj = new FileTagObject { CorrectionNumber = nb, CorrectionDate = date, CorrectionDecription = text, ApplicationName = nomAppli, ApplicationVersion = version, WorkPackage = chantier, BugId = jira }; // filename exists if (Contains(filename)) { if (filename == LastTag || filename == DefaultTag) _filesInfo[filename].Clear(); // modif number exists _filesInfo[filename].RemoveAll(o => o.CorrectionNumber == nb); _filesInfo[filename].Add(obj); } else { _filesInfo.Add(filename, new List<FileTagObject> { obj }); } }
/// <summary> /// Call this method to replace the variables inside your tags template (e.g. {&a }) to their actual values /// </summary> public static string ReplaceTokens(FileTagObject fileTagObject, string tagString) { var output = tagString; foreach (var tuple in new List<Tuple<string, string>> { new Tuple<string, string>(@"({&a\s*})", fileTagObject.ApplicationName), new Tuple<string, string>(@"({&v\s*})", fileTagObject.ApplicationVersion), new Tuple<string, string>(@"({&b\s*})", fileTagObject.BugId), new Tuple<string, string>(@"({&da\s*})", fileTagObject.CorrectionDate), new Tuple<string, string>(@"({&de\s*})", fileTagObject.CorrectionDecription), new Tuple<string, string>(@"({&n\s*})", fileTagObject.CorrectionNumber), new Tuple<string, string>(@"({&w\s*})", fileTagObject.WorkPackage), new Tuple<string, string>(@"({&u\s*})", Config.Instance.UserName) }) { var regex = new Regex(tuple.Item1); var match = regex.Match(output); if (match.Success) { var matchedStr = match.Groups[1].Value; if (matchedStr.Contains(' ')) { // need to replace the same amount of char output = output.Replace(matchedStr, string.Format("{0,-" + matchedStr.Length + @"}", tuple.Item2 ?? "")); } else { output = output.Replace(matchedStr, tuple.Item2 ?? ""); } } } return output; }
/// <summary> /// Load the dictionnary of file info /// </summary> public static void Import() { _filesInfo.Clear(); Utils.ForEachLine(Config.FileFilesInfo, new byte[0], (i, line) => { var items = line.Split('\t'); if (items.Count() == 8) { var fileName = items[0].Trim(); var fileInfo = new FileTagObject { CorrectionNumber = items[1], CorrectionDate = items[2], CorrectionDecription = items[3].Replace("~n", "\n"), ApplicationName = items[4], ApplicationVersion = items[5], WorkPackage = items[6], BugId = items[7] }; // add to dictionnary if (_filesInfo.ContainsKey(fileName)) { _filesInfo[fileName].Add(fileInfo); } else { _filesInfo.Add(fileName, new List<FileTagObject> { fileInfo }); } } }, Encoding.Default); if (!_filesInfo.ContainsKey(DefaultTag)) SetFileTags(DefaultTag, "", "", "", "", "", "", ""); if (!_filesInfo.ContainsKey(LastTag)) SetFileTags(LastTag, "", "", "", "", "", "", ""); }