Exemplo n.º 1
0
        public void Manipulate_IgnoreSpecialWordsCorrectWork()
        {
            var input = new[] { "a", "b", "c", "d", "e", "f", "g", "h" };

            A.CallTo(() => textReader.Read(A <string> .Ignored))
            .Returns(new[] { "a", "b", "c", "d" });
            Manipulate(input).Should()
            .BeEquivalentTo("e", "f", "g", "h");
        }
Exemplo n.º 2
0
        public static async Tasks.Task <string> ReadPast(this ITextReader me, Func <char, bool> predicate)
        {
            Text.Builder result = await me.Empty ? null : "";
            char?        next;

            while ((next = await me.Read(predicate.Negate())).HasValue)
            {
                result += next.Value;
            }
            if ((next = await me.Read(predicate)).HasValue)
            {
                result += next.Value;
            }
            return(result);
        }
        /// <summary>
        /// Fluent step final - Use configured reader to read file
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        IReaderResult IInitializedAndSecurizedReader.ReadFile(string path)
        {
            var accessGranted = true;

            if (_accessManager != null)
            {
                accessGranted = _accessManager.CanAccess(path, _identity);
            }

            if (!accessGranted)
            {
                return(new ReaderResult(false, string.Empty));
            }

            var fileContent = File.ReadAllText(path);

            if (_encryptor != null)
            {
                fileContent = _encryptor.Decrypt(fileContent);
            }

            var contentRead = _textReader.Read(fileContent);

            return(new ReaderResult(true, contentRead));
        }
Exemplo n.º 4
0
 public static void ConsumesAll(ITextReader r)
 {
     while (!r.EndOfFile)
     {
         r.Read();
     }
 }
Exemplo n.º 5
0
        public static string ReadsAll(ITextReader r)
        {
            var buff = new StringBuilder();

            while (!r.EndOfFile)
            {
                buff.Append((char)r.Read());
            }
            return(buff.ToString());
        }
Exemplo n.º 6
0
 private void ConfigureDefaultFakes()
 {
     A.CallTo(() => textReader.Read(A <string> .Ignored)).Returns(new[] { "t", "y", "f" });
     A.CallTo(() => wordsFilter.FilterWords(A <IEnumerable <string> > .Ignored)).Returns(new[] { "t", "y" });
     A.CallTo(() => wordsCounter.CountWords(A <IEnumerable <string> > .Ignored))
     .Returns(new Dictionary <string, int>()
     {
         { "t", 1 }, { "y", 1 }
     });
     A.CallTo(() => wordsToSizesConverter.GetSizesOf(A <Dictionary <string, int> > .Ignored)).Returns(
         new[] { ("t", new Size(50, 50)), ("y", new Size(50, 50)) }
Exemplo n.º 7
0
        public static ViaEntry ParseEntry(ITextReader reader)
        {
            //SIP/2.0/UDP erlang.bell-telephone.com:5060;branch=z9hG4bK87asdks7
            var entry = new ViaEntry();

            // read SIP/
            reader.ConsumeWhiteSpaces();
            entry.Protocol = reader.ReadUntil("/ \t");
            if (entry.Protocol == null)
                throw new FormatException("Expected Via header to start with 'SIP' or 'SIPS'.");
            reader.ConsumeWhiteSpaces('/');

            // read 2.0/
            entry.SipVersion = reader.ReadUntil("/ \t");
            if (entry.SipVersion == null)
                throw new FormatException("Expected to find sip version in Via header.");
            reader.ConsumeWhiteSpaces('/');

            // read UDP or TCP
            entry.Transport = reader.ReadWord();
            if (entry.Transport == null)
                throw new FormatException("Expected to find transport protocol after sip version in Via header.");
            reader.ConsumeWhiteSpaces();

            entry.Domain = reader.ReadUntil(";: \t");
            if (entry.Domain == null)
                throw new FormatException("Failed to find domain in via header.");
            reader.ConsumeWhiteSpaces();

            if (reader.Current == ':')
            {
                reader.Read();
                reader.ConsumeWhiteSpaces();
                string temp = reader.ReadToEnd("; \t");
                reader.ConsumeWhiteSpaces();
                int port;
                if (!int.TryParse(temp, out port))
                    throw new FormatException("Invalid port specified.");
                entry.Port = port;
            }

            UriParser.ParseParameters(entry.Parameters, reader);
            string rport = entry.Parameters["rport"];
            if (!string.IsNullOrEmpty(rport)) //parameter can exist, but be empty. = rport requested.
            {
                int value;
                if (!int.TryParse(rport, out value))
                    throw new FormatException("RPORT is not a number.");
                entry.Rport = value;
            }

            return entry;
        }
        /// <summary>
        /// Finds the product.
        /// </summary>
        /// <returns>The product.</returns>
        /// <param name="id">The product identifier.</param>
        public Product FindById(int id)
        {
            var linesOfProduct = _textReader.Read(PATH_TO_READ);
            var products       = new List <Product>();

            foreach (var line in linesOfProduct)
            {
                Product product = _productParser.ParseLine(line);
                products.Add(product);
            }
            return(products.SingleOrDefault(x => x.Id == id));
        }
Exemplo n.º 9
0
        public static async Tasks.Task <string> ReadLine(this ITextReader me)
        {
            string result;

            if (me.IsNull() || await me.Empty)
            {
                result = null;
            }
            else
            {
                result = await me.ReadUpTo('\n');

                me.Read('\n').Forget();
            }
            return(result);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Reads the text provided at FilePath and counts the number of occurrences of each word.
        /// </summary>
        /// <param name="FilePath">File path location of the text file that needs to be processed.</param>
        /// <returns>A list of words where each word contains the string value and the number of occurrences in the text.</returns>
        public IList <Word> Analyze(string FilePath)
        {
            IList <String> lines    = textReader.Read(FilePath);
            IList <Word>   wordList = new List <Word>();

            if (lines == null || lines.Count == 0)
            {
                logger.LogInfo("Empty input data is provided to TextAnalyzerService.");
                return(wordList);
            }

            IDictionary <String, int> wordDictionary = new Dictionary <String, int>();

            foreach (String line in lines)
            {
                IList <String> words = CreateWords(line);
                foreach (String word in words)
                {
                    if (word == null)
                    {
                        continue;
                    }

                    if (wordDictionary.ContainsKey(word))
                    {
                        wordDictionary[word]++;
                    }
                    else
                    {
                        wordDictionary.Add(word, 1);
                    }
                }
            }

            // convert dictionary to list of words
            foreach (String key in wordDictionary.Keys)
            {
                Word word = new Word(key, wordDictionary[key]);
                wordList.Add(word);
            }

            return(wordList);
        }
Exemplo n.º 11
0
        public void Perform()
        {
            var text         = textReader.Read(inputFile);
            var textFiltered = wordsFilter.FilterWords(text);
            var wordsCount   = wordsCounter.CountWords(textFiltered);
            var sizes        = wordsToSizesConverter.GetSizesOf(wordsCount).ToArray();

            sizes = sizes.OrderByDescending(x => x.Item2.Width).ThenBy(x => x.Item2.Height).ToArray();

            CCL.Center = new Point(CCL.Center.X, CCL.Center.Y - sizes[0].Item2.Height);
            for (var i = 0; i < sizes.Length; i++)
            {
                CCL.PutNextRectangle(sizes[i].Item2);
            }

            var bitmap = visualiser.DrawRectangles(CCL, sizes);

            imageSaver.Save(bitmap, outputFile);
        }
Exemplo n.º 12
0
        public Result <None> Perform()
        {
            var sizesResult = textReader.Read(inputFile)
                              .Then(wordsFilter.FilterWords)
                              .Then(wordsCounter.CountWords)
                              .Then(wordsToSizesConverter.GetSizesOf)
                              .OnFail(Console.WriteLine);

            if (sizesResult.IsSuccess)
            {
                var sizes = sizesResult.GetValueOrThrow().OrderByDescending(x => x.Item2.Width)
                            .ThenBy(x => x.Item2.Height).ToArray();

                CCL.Center = new Point(CCL.Center.X, CCL.Center.Y - sizes[0].Item2.Height);
                Result <Rectangle> rectangleRes = Result.Fail <Rectangle>("");
                for (var i = 0; i < sizes.Length; i++)
                {
                    rectangleRes = CCL.PutNextRectangle(sizes[i].Item2)
                                   .RefineError("Probably you are giving too small size")
                                   .OnFail(Console.WriteLine);
                    if (!rectangleRes.IsSuccess)
                    {
                        break;
                    }
                }

                if (rectangleRes.IsSuccess)
                {
                    var result = visualiser.DrawRectangles(CCL, sizes).Then(inp => imageSaver.Save(inp, outputFile))
                                 .OnFail(Console.WriteLine);
                    if (result.IsSuccess)
                    {
                        return(Result.Ok());
                    }
                }
            }

            return(Result.Fail <None>("File wasn't created. Try again."));
        }
Exemplo n.º 13
0
    public char[,] TextToArray()
    {
        char[,] levelArray = new char[32, 24];
        var level = _textReader.Read("C:\\level.txt");

        if (level == null)
        {
            Debug.Log("The so called text file is null!");
            return(null);
        }
        Debug.Log(level);
        string[] lines = level.Split('\n');
        for (int Y = 0; Y < lines.Length; Y++)
        {
            var horizon = lines [Y].ToCharArray();
            for (int X = 0; X < horizon.Length; X++)
            {
                levelArray [X, Y] = horizon [X];
            }
        }

        return(levelArray);
    }
Exemplo n.º 14
0
        /// <summary>
        /// Run the program
        /// </summary>
        public void Run()
        {
            string result;

            // for each string that is read
            try
            {
                foreach (string inputString in reader.Read())
                {
                    try
                    {
                        // encode input string
                        result = encoder.Encode(inputString);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Encoding error\r\n{0}", e.Message);
                        break;
                    }

                    try
                    {
                        // write to output
                        writer.Write(result);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Data output error\r\n{0}", e.Message);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Data input error\r\n{0}", e.Message);
            }
        }
Exemplo n.º 15
0
        public static async Tasks.Task <char?> Read(this ITextReader me, Func <char, bool> predicate)
        {
            char?peeked;

            return(!(await me.Empty) && (peeked = await me.Peek()).HasValue && predicate(peeked.Value) ? await me.Read() : null);
        }
Exemplo n.º 16
0
 public void Analyz()
 {
     _reader.Read();
 }
Exemplo n.º 17
0
 public static Tasks.Task <char?> Read(this ITextReader me, params char[] characters)
 {
     return(me.Read(last => characters.Contains(last)));
 }
Exemplo n.º 18
0
 public static Tasks.Task <char?> Read(this ITextReader me, char character)
 {
     return(me.Read(last => last == character));
 }
Exemplo n.º 19
0
 public override int ReadSimply()
 {
     return(_prefixReader.EndOfFile ? _inner.Read() : _prefixReader.Read());
 }
Exemplo n.º 20
0
        public static ViaEntry ParseEntry(ITextReader reader)
        {
            //SIP/2.0/UDP erlang.bell-telephone.com:5060;branch=z9hG4bK87asdks7
            var entry = new ViaEntry();

            // read SIP/
            reader.ConsumeWhiteSpaces();
            entry.Protocol = reader.ReadUntil("/ \t");
            if (entry.Protocol == null)
            {
                throw new FormatException("Expected Via header to start with 'SIP' or 'SIPS'.");
            }
            reader.ConsumeWhiteSpaces('/');

            // read 2.0/
            entry.SipVersion = reader.ReadUntil("/ \t");
            if (entry.SipVersion == null)
            {
                throw new FormatException("Expected to find sip version in Via header.");
            }
            reader.ConsumeWhiteSpaces('/');

            // read UDP or TCP
            entry.Transport = reader.ReadWord();
            if (entry.Transport == null)
            {
                throw new FormatException("Expected to find transport protocol after sip version in Via header.");
            }
            reader.ConsumeWhiteSpaces();

            entry.Domain = reader.ReadUntil(";: \t");
            if (entry.Domain == null)
            {
                throw new FormatException("Failed to find domain in via header.");
            }
            reader.ConsumeWhiteSpaces();

            if (reader.Current == ':')
            {
                reader.Read();
                reader.ConsumeWhiteSpaces();
                string temp = reader.ReadToEnd("; \t");
                reader.ConsumeWhiteSpaces();
                int port;
                if (!int.TryParse(temp, out port))
                {
                    throw new FormatException("Invalid port specified.");
                }
                entry.Port = port;
            }

            UriParser.ParseParameters(entry.Parameters, reader);
            string rport = entry.Parameters["rport"];

            if (!string.IsNullOrEmpty(rport)) //parameter can exist, but be empty. = rport requested.
            {
                int value;
                if (!int.TryParse(rport, out value))
                {
                    throw new FormatException("RPORT is not a number.");
                }
                entry.Rport = value;
            }

            return(entry);
        }
Exemplo n.º 21
0
 public void Write()
 {
     Console.WriteLine(reader.Read());
 }