private LineAccess <T> GetLineAccess <T>()
        {
            if (lineAccessDictionary.TryGetValue(typeof(T), out var ret))
            {
                return((LineAccess <T>)ret);
            }
            var first       = FirstLine;
            var headerSplit = splitter.Split(firstLine, new List <char[]>(), new List <char>()).Select(t => t.Trim()).ToArray();
            var access      = new LineAccess <T>(headerSplit, converter);

            lineAccessDictionary.Add(typeof(T), access);
            return(access);
        }
예제 #2
0
        public void LineCount(string input, int expected)
        {
            var target = new LineSplitter(input);
            var actual = target.Split().Count();

            Assert.Equal(expected, actual);
        }
예제 #3
0
        private IEnumerable <string[]> SplitLine(string path)
        {
            var creator = IsPlainText ?
                          (IStreamCreator) new PlainTextMemoryStreamCreator() :
                          new TextFileStreamCreator();

            using (var stream = creator.Create(path, Encoding))
                using (var reader = new StreamReader(stream, Encoding))
                {
                    while (0 <= reader.Peek())
                    {
                        var value = reader.ReadLine();
                        if (value.Contains(EndOfFile))
                        {
                            continue;
                        }

                        var lines = Split(value, FixedRecordLength);

                        foreach (var line in lines)
                        {
                            var fields = LineSplitter?.Split(line).Select(field => field.Trim());

                            yield return(fields.ToArray());
                        }
                    }
                }
        }
예제 #4
0
 public void NotSameNumberOrTicks_IsNotFilledCode()
 {
     LineSplitter
     .Split("````\nLine 1```\nLine 2\n````")
     .Is(new List <LineOrFenced>()
     {
         new LineOrFenced("Line 1```\nLine 2", true, null)
     });
 }
예제 #5
0
 public void JustCodeBlock_IsFilledCode_WithFourTicks()
 {
     LineSplitter
     .Split("````\nLine 1\nLine 2\n````")
     .Is(new List <LineOrFenced>()
     {
         new LineOrFenced("Line 1\nLine 2", true, null)
     });
 }
예제 #6
0
 public void EmptyString_IsEmptyList()
 {
     LineSplitter
     .Split("")
     .Is(new List <LineOrFenced>()
     {
         new LineOrFenced("")
     });
 }
예제 #7
0
 public void EndingTicks_IsFilledCode_WithoutNewLineBefore()
 {
     LineSplitter
     .Split("```\nLine 1\nLine 2```")
     .Is(new List <LineOrFenced>()
     {
         new LineOrFenced("Line 1\nLine 2", true, null)
     });
 }
예제 #8
0
 public void InfoString_IsFound()
 {
     LineSplitter
     .Split("```python")
     .Is(new List <LineOrFenced>()
     {
         new LineOrFenced("", true, "python")
     });
 }
예제 #9
0
 public void JustOpening_IsEmptyCode()
 {
     LineSplitter
     .Split("```")
     .Is(new List <LineOrFenced>()
     {
         new LineOrFenced("", true, null)
     });
 }
예제 #10
0
        void RenderToConsole(ActivityElement element, ICommandOutputProvider commandOutputProvider, string indent)
        {
            if (!IsPrintable(element))
            {
                return;
            }

            if (element.Status == ActivityStatus.Success)
            {
                Console.ForegroundColor = ConsoleColor.Green;
            }
            else if (element.Status == ActivityStatus.SuccessWithWarning)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
            }
            else if (element.Status == ActivityStatus.Failed)
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }
            Console.WriteLine("{0}         {1}: {2}", indent, element.Status, element.Name);
            Console.ResetColor();

            foreach (var logEntry in element.LogElements)
            {
                if (logEntry.Category == "Error" || logEntry.Category == "Fatal")
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                else if (logEntry.Category == "Warning")
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                }

                Console.WriteLine("{0}{1,-8}   {2}", indent, logEntry.Category, LineSplitter.Split(indent + new string(' ', 11), logEntry.MessageText));
                Console.ResetColor();
            }

            foreach (var child in element.Children)
            {
                RenderToConsole(child, commandOutputProvider, indent + "  ");
            }
        }
예제 #11
0
        public void SetHeader(string header)
        {
            var parts = LineSplitter.Split(header);

            if (ValidateLineParts(parts))
            {
                for (var i = 2; i < parts.Length; i++)
                {
                    _periods.Add(new PeriodDefinition()
                    {
                        Name        = parts[i].Replace("Value", ""),
                        PeriodIndex = i
                    });
                }
            }
            else
            {
                throw new Exception("Invalid Header format");
            }
        }
예제 #12
0
        public void Tildes_IsFilledCode()
        {
            LineSplitter
            .Split("~~~\nLine 1\nLine 2\n~~~")
            .Is(new List <LineOrFenced>()
            {
                new LineOrFenced("Line 1\nLine 2", true, null)
            });

            LineSplitter
            .Split("~~~\nLine 1\nLine 2\n```")
            .IsNot(new List <LineOrFenced>()
            {
                new LineOrFenced("Line 1\nLine 2", true, null)
            });

            LineSplitter
            .Split("~`~\nLine 1\nLine 2\n~`~")
            .IsNot(new List <LineOrFenced>()
            {
                new LineOrFenced("Line 1\nLine 2", true, null)
            });
        }
예제 #13
0
        /// <summary>
        /// Parses a line of tab delimited text into a process instruction
        /// </summary>
        /// <param name="processLine">A tab delimited line of text that confirms to the required format</param>
        public void AddProcessCommand(string processLine)
        {
            var parts = LineSplitter.Split(processLine);

            if (parts.Length != 3)
            {
                throw new Exception(string.Format("Invalid Configuration Line : {0}", processLine));
            }

            var processor = new LineProcessor();

            processor.VariableType = parts[0];

            var statsOp = statisticCalculation.Invalid;

            if (parts[1].TryParseOperationType(out statsOp))
            {
                processor.OperationType = statsOp;
            }
            else
            {
                throw new Exception(string.Format("Unrecognised statistics operation = {0}", parts[1]));
            }

            var period = periodChoice.Invalid;

            if (parts[2].TryParsePeriod(out period))
            {
                processor.Period = period;
            }
            else
            {
                throw new Exception(string.Format("Unrecognised period choice = {0}", parts[2]));
            }

            _processors.Add(processor.Key, processor);
        }
예제 #14
0
        public IEnumerable <TotalTempLine> ParseLine(string line, ILineProcessInstructions instructions)
        {
            var result = new List <TotalTempLine>();

            var parts = LineSplitter.Split(line);

            if (parts.Length < 3)
            {
                result.Add(new TotalTempLine(LineError.InvalidLineFormat(line)));
                return(result);
            }

            //first part - get the scenarie
            int sceneid;

            if (!int.TryParse(parts[0], out sceneid))
            {
                result.Add(new TotalTempLine(LineError.InvalidSceneIdError(parts[0])));
                return(result);
            }


            //get the variable type for this line
            var variableType = parts[1];

            //only execute parsing and calculations if there is an instruction for this variable type
            if (instructions.Processors.Values.Any(e => e.VariableType == variableType))
            {
                var periodValues = new List <PeriodValue>();

                //parse the values
                for (var i = 2; i < parts.Length; i++)
                {
                    double pv;

                    if (double.TryParse(parts[i], out pv))
                    {
                        periodValues.Add(new PeriodValue()
                        {
                            PeriodId = _periods[i - 2].Name,
                            Value    = pv
                        });
                    }
                    else
                    {
                        result.Add(new TotalTempLine(LineError.InvalidValueError(parts[i])));
                    }
                }

                instructions.ExtractPeriodValueOfInterest(periodValues, variableType).ForEach(r => result.Add(new TotalTempLine()
                {
                    HasOperation     = true,
                    ScenarioId       = sceneid,
                    ValueOfRelevance = r.Value,
                    VariableType     = variableType,
                    OperationType    = r.Operation
                }));
            }

            return(result);
        }
예제 #15
0
        public void Split_DifferentSets_ShouldSplitStringCorrect(string line, IEnumerable <string> expected)
        {
            var actual = _sut.Split(line);

            actual.Should().BeEquivalentTo(expected);
        }
        /// <summary>
        /// Split text by lines using line length
        /// </summary>
        /// <param name="text">splitted text</param>
        /// <param name="length">line length</param>
        /// <returns></returns>
        public static string[] SplitByLineLength(this string text, int length)
        {
            LineSplitter _splitter = new LineSplitter(length);

            return(_splitter.Split(text));
        }