Example #1
0
        protected ValidatableViewModel(ArrayFormat errorFormat = ArrayFormat.First)
        {
            ErrorsContainer = new ErrorsContainer();
            ErrorsContainer.ErrorsChanged += OnErrorsChanged;

            dataErrorInfoProvider = new DataErrorInfoProvider(ErrorsContainer, errorFormat, ObjectErrorPropertyName);
        }
Example #2
0
        public void TextToFormattedArray_TextWasCorrectlyFormattedToArray()
        {
            ArrayFormat arrayFormat = new ArrayFormat();
            string      fileName    = System.IO.Directory.GetCurrentDirectory().Replace(@"ExerciseOrderBy.Tests\bin\Debug", @"\ExerciseOrderBy\input.txt");

            string lowerText = System.IO.File.ReadAllText(fileName).ToLower();

            string[] formattedArray = arrayFormat.TextToFormattedArray(lowerText);

            Assert.AreEqual("String[]", formattedArray.GetType().Name, "String was not correctly convert to array");
        }
Example #3
0
        public void OrderByAscending_StringArrayWasCorrectlyOrderedByAscending()
        {
            ArrayFormat arrayFormat = new ArrayFormat();
            string      fileName    = System.IO.Directory.GetCurrentDirectory().Replace(@"ExerciseOrderBy.Tests\bin\Debug", @"\ExerciseOrderBy\input.txt");

            string lowerText = System.IO.File.ReadAllText(fileName).ToLower();

            string[] formattedArray = arrayFormat.TextToFormattedArray(lowerText);
            string[] orderedArray   = arrayFormat.OrderByAscending(formattedArray);

            Assert.IsTrue(arrayFormat.IsAlphabeticallySorted(orderedArray), "String is not alphabetically ordered after method execution");
        }
Example #4
0
        public void FormatSpecialCharacters_StringWasCorrectlyFormattedToStringWithoutSpecialCharacters()
        {
            ArrayFormat arrayFormat = new ArrayFormat();
            string      fileName    = System.IO.Directory.GetCurrentDirectory().Replace(@"ExerciseOrderBy.Tests\bin\Debug", @"\ExerciseOrderBy\input.txt");

            string lowerText = System.IO.File.ReadAllText(fileName).ToLower();
            string text      = arrayFormat.FormatSpecialCharacters(lowerText);

            var regexItem = new Regex("^[a-zA-Z0-9 ]*$");

            Assert.IsTrue(regexItem.IsMatch(text), "Formatted message contains at least one special character");
        }
Example #5
0
        public static Func <IEnumerable <object>, string> GetErrorFormatter(ArrayFormat arrayFormat)
        {
            switch (arrayFormat)
            {
            case ArrayFormat.First:
                return(GetFirstString);

            case ArrayFormat.Multiline:
                return(GetMultilineString);

            default:
                throw new ArgumentOutOfRangeException("arrayFormat");
            }
        }
Example #6
0
        /// <summary>
        /// Converts text into an Array-friendly format
        /// </summary>
        /// <param name="content">The text to format</param>
        /// <param name="type">The desired output type</param>
        /// <returns>Array friendly format</returns>
        public static async Task <string> ArrayStructureAsync(string content, ArrayFormat type)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(null);
            }

            const string pattern = @"\w+";

            var matches = Regex.Matches(content, pattern);

            AffectedCharacter = matches.Count;

            string[] words;
            try
            {
                words = await Task.Run(() => matches.Cast <Match>().Select(word => word.Value).ToArray());
            }
            catch (Exception ex)
            {
                //_logger.Error($"Content size = {content.Length}", ex);
                throw;
            }
            if (type == ArrayFormat.String)
            {
                words = await Task.Run(() => words.Select(word => $"\"{word}\"").ToArray());
            }
            else if (type == ArrayFormat.Char)
            {
                words = await Task.Run(() => words.Select(word => $"\'{word}\'").ToArray());
            }
            var modifiedWords = await Task.Run(() => String.Join(",", words));


            return(modifiedWords);
        }
 public DataErrorInfoProvider(IErrorsContainer <TError> errorsContainer, ArrayFormat arrayFormat = ArrayFormat.First, string objectPropertyName = "")
     : this(errorsContainer, ArrayFormatter.GetErrorFormatter(arrayFormat) as Func <IEnumerable <TError>, string>, objectPropertyName)
 {
 }
        public async Task ArrayFormatShouldFormatToArray(string givenInput, ArrayFormat format, string expectedOutput)
        {
            string actual = await StringHelper.ArrayStructureAsync(givenInput, format);

            Assert.Equal(expectedOutput, actual);
        }
        public static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Incorrect number of args, usage: arrayFormat.exe filename wrapColumn formatSpec");
                return;
            }
            String inputFile = args[0];
            // read wrap column
            int wrap;

            try {
                wrap = Int32.Parse(args[1]);
            }
            catch (Exception e) {
                Console.WriteLine("Bad input, cannot read wrap column: " + args[1]);
                Console.WriteLine(e.Message);
                return;
            }
            switch (args[2])
            {
            case "Fill":
                format = ArrayFormat.Fill;
                break;

            case "UniformCount":
                format = ArrayFormat.UniformCount;
                break;

            case "UniformCountStrict":
                format = ArrayFormat.UniformCountStrict;
                break;

            case "Column":
                format = ArrayFormat.Column;
                break;

            case "ColumnStrict":
                format = ArrayFormat.ColumnStrict;
                break;

            case "Adjust":
                format = ArrayFormat.Adjust;
                break;

            case "Set":
                format = ArrayFormat.Set;
                break;

            default:
                throw new Exception("Unknown format specification: " + args[2]);
            }

            String[] sarray = InputStrings(inputFile);
            Page     page   = null;

            switch (format)
            {
            case ArrayFormat.Fill:

                page = new Text(wrap);
                ArrayMethods hi = new ArrayMethods();

                Console.WriteLine("SET");
                hi.Column(sarray, wrap, page, false);
                foreach (Line t in page.Lines)
                {
                    Console.WriteLine(t.ToString());
                }
                break;

            case ArrayFormat.UniformCount:
                break;

            case ArrayFormat.UniformCountStrict:
                break;

            case ArrayFormat.Column:
                break;

            case ArrayFormat.ColumnStrict:
                break;

            case ArrayFormat.Adjust:
                break;

            case ArrayFormat.Set:
                break;

            default:
                throw new Exception("Unknown format specification: " + args[2]);
            }
            page.ToFile(inputFile + outputFileSuffix);
            //Console.ReadLine();
        }
Example #10
0
        public static bool SupportsFormat(this IMeshArray array, ArrayFormat format)
        {
            Ensure.That(array, nameof(array)).IsNotNull();

            return((array.FormatMask & (uint)format) > 0);
        }