Exemplo n.º 1
0
        /// <summary>
        /// Parses the Stroke Data string and converts it into ICanvasStrokeElement.
        /// </summary>
        /// <param name="strokeData">Stroke Data string</param>
        /// <returns>ICanvasStrokeElement</returns>
        internal static ICanvasStrokeElement Parse(string strokeData)
        {
            var matches = RegexFactory.CanvasStrokeRegex.Matches(strokeData);

            // If no match is found or no captures in the match, then it means
            // that the stroke data is invalid.
            if (matches.Count == 0)
            {
                ThrowForZeroCount();
            }

            // If the match contains more than one captures, it means that there
            // are multiple CanvasStrokes present in the stroke data. There should
            // be only one CanvasStroke defined in the stroke data.
            if (matches.Count > 1)
            {
                ThrowForNotOneCount();
            }

            // There should be only one match
            var match         = matches[0];
            var strokeElement = new CanvasStrokeElement(match);

            // Perform validation to check if there are any invalid characters in the stroke data that were not captured
            var preValidationCount  = RegexFactory.ValidationRegex.Replace(strokeData, string.Empty).Length;
            var postValidationCount = strokeElement.ValidationCount;

            // If there are invalid characters, extract them and add them to the ArgumentException message
            if (preValidationCount != postValidationCount)
            {
Exemplo n.º 2
0
                static void ThrowForInvalidCharacters(CanvasStrokeElement strokeElement, string strokeData)
                {
                    var parseIndex = 0;

                    if (!string.IsNullOrWhiteSpace(strokeElement.Data))
                    {
                        parseIndex = strokeData.IndexOf(strokeElement.Data, parseIndex, StringComparison.Ordinal);
                    }

                    var errorString = strokeData.Substring(parseIndex);

                    if (errorString.Length > 30)
                    {
                        errorString = $"{errorString.Substring(0, 30)}...";
                    }

                    throw new ArgumentException($"STROKE_ERR003:Stroke data contains invalid characters!\nIndex: {parseIndex}\n{errorString}");
                }
        /// <summary>
        /// Parses the Stroke Data string and converts it into ICanvasStrokeElement
        /// </summary>
        /// <param name="strokeData">Stroke Data string</param>
        /// <returns>ICanvasStrokeElement</returns>
        internal static ICanvasStrokeElement Parse(string strokeData)
        {
            var matches = RegexFactory.CanvasStrokeRegex.Matches(strokeData);

            // If no match is found or no captures in the match, then it means
            // that the stroke data is invalid.
            if ((matches == null) || (matches.Count == 0))
            {
                throw new ArgumentException($"Invalid Stroke data!\nStroke Data: {strokeData}", nameof(strokeData));
            }

            // If the match contains more than one captures, it means that there
            // are multiple CanvasStrokes present in the stroke data. There should
            // be only one CanvasStroke defined in the stroke data.
            if (matches.Count > 1)
            {
                throw new ArgumentException("Multiple CanvasStrokes defined in Stroke Data! " +
                                            "There should be only one CanvasStroke definition within the Stroke Data. " +
                                            "You can either remove CanvasStroke definitions or split the Stroke Data " +
                                            "into multiple Stroke Data and call the CanvasObject.CreateStroke() method on each of them." +
                                            $"\nStroke Data: {strokeData}");
            }

            // There should be only one match
            var match         = matches[0];
            var strokeElement = new CanvasStrokeElement(match);

            // Perform validation to check if there are any invalid characters in the stroke data that were not captured
            var preValidationCount = RegexFactory.ValidationRegex.Replace(strokeData, string.Empty).Length;

            var postValidationCount = strokeElement.ValidationCount;

            if (preValidationCount != postValidationCount)
            {
                throw new ArgumentException($"Stroke data contains invalid characters!\nStroke Data: {strokeData}", nameof(strokeData));
            }

            return(strokeElement);
        }