private void ReportErrors(NumberTexts sourceNumberTexts, NumberTexts targetNumberTexts, ISegmentPair segmentPair) { var sourceNumbersTotal = sourceNumberTexts.Texts.Count; var targetNumbersTotal = targetNumberTexts.Texts.Count; var errorPairsTotal = sourceNumbersTotal > targetNumbersTotal ? sourceNumbersTotal : targetNumbersTotal; for (var i = 0; i < errorPairsTotal; i++) { var extendedReportInfo = GetExtendedReport(i, sourceNumberTexts, targetNumberTexts); if (extendedReportInfo.Message is null) { continue; } if (VerificationSettings.ReportExtendedMessages && MessageReporter is IBilingualContentMessageReporterWithExtendedData extendedMessageReporter) { extendedMessageReporter.ReportMessage(this, PluginResources.Plugin_Name, extendedReportInfo.ErrorLevel, extendedReportInfo.Message, new TextLocation(new Location(segmentPair.Target, true), extendedReportInfo.Report.TargetRange.StartIndex), new TextLocation(new Location(segmentPair.Target, false), extendedReportInfo.Report.TargetRange.Length), extendedReportInfo.Report); } else { MessageReporter.ReportMessage(this, PluginResources.Plugin_Name, extendedReportInfo.ErrorLevel, extendedReportInfo.Message, new TextLocation(new Location(segmentPair.Target, true), extendedReportInfo.Report.TargetRange.StartIndex), new TextLocation(new Location(segmentPair.Target, false), extendedReportInfo.Report.TargetRange.Length)); } } }
private static bool RunPackagingSequence(PreConfigurationState preConfigurationState, ApplicationData applicationData, out PackagedApplication packagedApplication) { try { var packager = new Packager(applicationData, preConfigurationState.InstallerOutputDestination); packagedApplication = packager.CreatePackage(); return(true); } catch (Exception ex) { HostCore.Log.Error("Packaging failed", ex); MessageReporter.Show(FormatMessageFor(ex) + "\r\nCheck the log files or the extended information for troubleshooting.", "Packaging failed!", ex, MessageBoxButtons.OK, MessageBoxIcon.Error); // ToDo: Clean up first! packagedApplication = null; return(false); } }
/// <summary> /// Helper function that counts the words in the current target segment. /// If the word count (i.e. number of spaces + 1) exceeds the maximum count /// that was set through the properties, a message should be added to the /// Messages window of SDL Trados Studio. /// </summary> /// <param name="targetSegment"></param> #region output message private void CheckWordCount(ISegment targetSegment) { int pos = 0, count = 0; char c = ' '; while ((pos = targetSegment.ToString().IndexOf(c, pos)) != -1) { count++; pos++; } count++; if (count > MaxWordCount) { MessageReporter.ReportMessage(this, Resources.Plugin_Name, ErrorLevel.Warning, string.Format(Resources.MsgWordCountExceeded, count, MaxWordCount), new TextLocation(new Location(targetSegment, true), 0), new TextLocation(new Location(targetSegment, false), targetSegment.ToString().Length - 1)); } }
private void ReportErrors(ISegmentPair segmentPair, List <ErrorReporting> errorMessages) { foreach (var errorMessage in errorMessages) { if (errorMessage.ExtendedErrorMessage != string.Empty && VerificationSettings.ReportExtendedMessages) { if (MessageReporter is IBilingualContentMessageReporterWithExtendedData extendedMessageReporter) { var messageDataModel = new MessageDataModel { SourceIssues = errorMessage.SourceNumberIssues?.Replace(Environment.NewLine, string.Empty), TargetIssues = errorMessage.TargetNumberIssues?.Replace(Environment.NewLine, string.Empty), ReplacementSuggestion = segmentPair.Target, InitialSourceIssues = errorMessage.InitialSourceNumber, InitialTargetIssues = errorMessage.InitialTargetNumber, ErrorMessage = errorMessage.ErrorMessage, IsHindiVerification = errorMessage.IsHindiVerification }; var extendedData = new NumberVerifierMessageData(messageDataModel); extendedMessageReporter.ReportMessage(this, PluginResources.Plugin_Name, errorMessage.ErrorLevel, errorMessage.ExtendedErrorMessage, new TextLocation(new Location(segmentPair.Target, true), 0), new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1), extendedData); } } else if (errorMessage.ErrorMessage != string.Empty) { if (!string.IsNullOrEmpty(errorMessage.TargetNumberIssues)) { if (errorMessage.ErrorMessage == PluginResources.Error_AlphanumericsModified) { var alphaList = new List <string>(); List <string> alphaTargetList = new List <string>(); var alphanumericsText = Regex.Matches(errorMessage.TargetNumberIssues, @"^-?\u2212?(^(?=.*[a-zA-Z{0}])(?=.*[0-9]).+$)"); foreach (Match alphanumericText in alphanumericsText) { var words = Regex.Split(alphanumericText.Value, @"\s"); alphaList.AddRange( from word in words from Match match in Regex.Matches(word.Normalize(NormalizationForm.FormKC), @"^-?\u2212?(^(?=.*[a-zA-Z{0}])(?=.*[0-9]).+$)") select match.Value); foreach (var alphaElement in alphaList) { var alphanumericTarget = $@"""{alphaElement}"""; alphaTargetList.Add(alphanumericTarget); } var alphanumericRes = string.Join(", ", alphaTargetList.ToArray()); errorMessage.ErrorMessage = string.Concat(errorMessage.ErrorMessage, " (", alphanumericRes, ")"); } } else { var targetNumbers = new List <string>(); var numbers = Regex.Matches(errorMessage.TargetNumberIssues, @"[\+\-]?\s*[0-9\.\,]*[Ee]?[\+\-]?\d+", RegexOptions.Singleline); foreach (var value in numbers) { var targetNumber = $@"""{value}"""; targetNumbers.Add(targetNumber); } var res = string.Join(", ", targetNumbers.ToArray()); errorMessage.ErrorMessage = string.Concat(errorMessage.ErrorMessage, " (", res, ")"); } } MessageReporter.ReportMessage(this, PluginResources.Plugin_Name, errorMessage.ErrorLevel, errorMessage.ErrorMessage, new TextLocation(new Location(segmentPair.Target, true), 0), new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1)); } } }