示例#1
0
        /// <summary>
        /// The following member performs the actual verification. It traverses the segment pairs of the current document,
        /// and checks whether a particular segment has any context information (count > 0). It then determines whether
        /// the display code is identical to the display code entered in the plug-in settings.
        /// If this is the case, it determines whether the target segment is actually identical to the source segment.
        /// If not, a warning message will be generated, which is then displayed between the source and target segments,
        /// and in the Messages window of SDL Trados Studio.
        /// </summary>
        /// <param name="paragraphUnit"></param>
        #region "verify"
        private void CheckParagraphUnit(IParagraphUnit paragraphUnit)
        {
            // Declare and reset target segment text.
            string completeTextTarget = "";

            // loop through the whole paragraph unit
            foreach (ISegmentPair segmentPair in paragraphUnit.SegmentPairs)
            {
                // Determine if context information is available,
                // and if the context equals the one specified in the user interface.
                if (paragraphUnit.Properties.Contexts.Contexts.Count > 0 &&
                    paragraphUnit.Properties.Contexts.Contexts[0].DisplayCode == VerificationSettings.CheckContext.Value)
                {
                    // Check whether target differs from source.
                    // If this is the case, then output a warning message
                    if (segmentPair.Source.ToString() != segmentPair.Target.ToString())
                    {
                        // Generate the plain text information if ConsiderTags is not true.
                        #region "GetPlainText"
                        completeTextTarget += TextGeneratorProcessor.GetPlainText(segmentPair.Target, VerificationSettings.ConsiderTags.Value);
                        #endregion

                        #region ReportingMessage
                        if (MessageReporter is IBilingualContentMessageReporterWithExtendedData)
                        {
                            #region CreateExtendedData
                            string context = paragraphUnit.Properties.Contexts.Contexts[0].DisplayCode;
                            IdenticalVerifierMessageData extendedData = new IdenticalVerifierMessageData(completeTextTarget +
                                                                                                         " - must be identical to source because the paragraph has context " + context + ".", segmentPair.Source);
                            #endregion

                            #region ReportingMessageWithExtendedData
                            IBilingualContentMessageReporterWithExtendedData extendedMessageReporter = (IBilingualContentMessageReporterWithExtendedData)MessageReporter;
                            extendedMessageReporter.ReportMessage(this, PluginResources.Plugin_Name,
                                                                  ErrorLevel.Warning, PluginResources.Error_NotIdentical,
                                                                  new TextLocation(new Location(segmentPair.Target, true), 0),
                                                                  new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1),
                                                                  extendedData);
                            #endregion
                        }
                        else
                        {
                            #region ReportingMessageWithoutExtendedData
                            MessageReporter.ReportMessage(this, PluginResources.Plugin_Name,
                                                          ErrorLevel.Warning, PluginResources.Error_NotIdentical,
                                                          new TextLocation(new Location(segmentPair.Target, true), 0),
                                                          new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1));
                            #endregion
                        }
                        #endregion
                    }
                }
            }
        }
        /// <summary>
        /// The following member performs the actual verification. It traverses the segment pairs of the current document,
        /// and checks whether a particular segment has any context information (count > 0). It then determines whether
        /// the display code is identical to the display code entered in the plug-in settings.
        /// If this is the case, it determines whether the target segment is actually identical to the source segment.
        /// If not, a warning message will be generated, which is then displayed between the source and target segments,
        /// and in the Messages window of SDL Trados Studio.
        /// </summary>
        /// <param name="paragraphUnit"></param>
        #region "verify"
        private void CheckParagraphUnit(IParagraphUnit paragraphUnit)
        {
            if (paragraphUnit.Properties.Contexts is null)
            {
                return;
            }
            // Declare and reset target segment text.
            var completeTextTarget = string.Empty;

            // loop through the whole paragraph unit
            foreach (var segmentPair in paragraphUnit.SegmentPairs)
            {
                var paragraphContexts = paragraphUnit.Properties.Contexts.Contexts;
                if (paragraphContexts is null)
                {
                    return;
                }

                // Determine if context information is available,
                // and if the context contains the one specified in the user interface.
                var paragraphContainsCheckContext =
                    paragraphContexts.Any(c => c.DisplayCode != null && c.DisplayCode.Contains(VerificationSettings.CheckContext.Value));

                if (!paragraphContainsCheckContext)
                {
                    continue;
                }
                if (segmentPair.Source.ToString() != segmentPair.Target.ToString())
                {
                    // Generate the plain text information if ConsiderTags is not true.
                    #region "GetPlainText"
                    completeTextTarget += TextGeneratorProcessor.GetPlainText(segmentPair.Target, VerificationSettings.ConsiderTags.Value);
                    #endregion

                    #region ReportingMessage
                    if (MessageReporter is IBilingualContentMessageReporterWithExtendedData)
                    {
                        #region CreateExtendedData
                        var context      = paragraphUnit.Properties.Contexts.Contexts[0].DisplayCode;
                        var extendedData = new IdenticalVerifierMessageData(completeTextTarget +
                                                                            " - must be identical to source because the paragraph has context " + context + ".", segmentPair.Source);
                        #endregion

                        #region ReportingMessageWithExtendedData
                        var extendedMessageReporter = (IBilingualContentMessageReporterWithExtendedData)MessageReporter;
                        extendedMessageReporter.ReportMessage(this, PluginResources.Plugin_Name,
                                                              ErrorLevel.Warning, PluginResources.Error_NotIdentical,
                                                              new TextLocation(new Location(segmentPair.Target, true), 0),
                                                              new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1),
                                                              extendedData);
                        #endregion
                    }
                    else
                    {
                        #region ReportingMessageWithoutExtendedData
                        MessageReporter.ReportMessage(this, PluginResources.Plugin_Name,
                                                      ErrorLevel.Warning, PluginResources.Error_NotIdentical,
                                                      new TextLocation(new Location(segmentPair.Target, true), 0),
                                                      new TextLocation(new Location(segmentPair.Target, false), segmentPair.Target.ToString().Length - 1));
                        #endregion
                    }
                    #endregion
                }
            }
        }