Пример #1
0
        /// <summary>
        /// Validates this instance.
        /// </summary>
        public override void Validate()
        {
            int bodyContentVariationsCount = 0;

            if (this.Trace != null)
            {
                this.Trace.Validate();
                bodyContentVariationsCount++;
            }
            if (this.TraceChain != null)
            {
                bodyContentVariationsCount++;
            }
            if (this.Message != null)
            {
                this.Message.Validate();
                bodyContentVariationsCount++;
            }
            if (this.CrashReport != null)
            {
                bodyContentVariationsCount++;
            }

            Assumption.AssertEqual(bodyContentVariationsCount, 1, nameof(bodyContentVariationsCount));
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Classification"/> class.
        /// </summary>
        /// <param name="classifiers">The classifiers.</param>
        protected Classification(IEnumerable <Classifier> classifiers)
        {
            if (classifiers == null)
            {
                this._classifiers     = new HashSet <Classifier>();
                this._classifierTypes = new HashSet <Type>();
            }
            else
            {
                Assumption.AssertTrue(classifiers.Count() == classifiers.Distinct().Count(), nameof(classifiers));

                this._classifiers = new HashSet <Classifier>(classifiers);

                var classifierTypes = this._classifiers.Select(i => i.ClassifierObject.GetType()).ToList();
                this._classifierTypes = new HashSet <Type>(classifierTypes);

                Assumption.AssertEqual(this._classifierTypes.Count, this._classifiers.Count, nameof(this._classifierTypes.Count));
            }

            this.ID = this.GenerateID(this._classifiers);
        }
Пример #3
0
        /// <summary>
        /// Truncates the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="encoding">The encoding.</param>
        /// <param name="encodedBytesLimit">The encoded bytes limit.</param>
        /// <returns></returns>
        public static string?Truncate(string?input, Encoding encoding, int encodedBytesLimit)
        {
            if (input == null)
            {
                return(input); //nothing to truncate...
            }

            byte[] inputEncodedBytes = encoding.GetBytes(input);
            Assumption.AssertEqual(inputEncodedBytes.Length, encoding.GetByteCount(input), nameof(inputEncodedBytes.Length));
            if (inputEncodedBytes.Length <= encodedBytesLimit)
            {
                return(input); //nothing to truncate...
            }

            int truncationIndicatorTotalBytes = encoding.GetByteCount(truncationIndicator);
            int totalBytes = encodedBytesLimit - truncationIndicatorTotalBytes;

            if (totalBytes < 0)
            {
                totalBytes = 0;
            }
            string truncatedInput = encoding.GetString(inputEncodedBytes, 0, totalBytes);

            if ((totalBytes > 0) &&
                (truncatedInput[truncatedInput.Length - 1] != input[truncatedInput.Length - 1])
                )
            {
                truncatedInput = truncatedInput.Substring(0, truncatedInput.Length - 1);
            }

            truncatedInput += truncationIndicator;

            Assumption.AssertTrue(encoding.GetByteCount(
                                      truncatedInput) <= encodedBytesLimit || encodedBytesLimit < truncationIndicatorTotalBytes,
                                  nameof(truncatedInput)
                                  );

            return(truncatedInput);
        }