示例#1
0
        public ILineWriter Create(string filePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath is null");
            }
            if (_writers.ContainsKey(filePath))
            {
                throw new ArgumentException("filePath is already being used by another LineWriter");
            }

            LineWriter lineWriter = new LineWriter(filePath,
                                                   disposeCallback: () =>
            {
                if (_writers.ContainsKey(filePath))
                {
                    _writers.Remove(filePath);
                }

                // If there are no more writers then stop the write thread.
                if (_writers.Count == 0)
                {
                    StopWriteThread();
                }
            });

            // Start the write thread if this is the first writer we are creating.
            if (_writers.Count == 0)
            {
                StartWriteThread();
            }

            _writers.Add(lineWriter.FilePath, lineWriter);
            return(lineWriter);
        }
示例#2
0
        public void Run()
        {
            InnerWriter = new LineWriter(new StringWriter());
            Load();
            Convert();
            if (RootNodeTypeName == null)
            {
                RootNodeType     = Classes.First();
                RootNodeTypeName = Classes.First().Name;
            }
            else
            {
                RootNodeType = GetClass(RootNodeTypeName);
            }
            Usings.ForEach(t => WriteLine("using {0};", t));
            WriteLine("namespace {0}", Namespace);
            BeginBlock();

            foreach (var ce in Classes)
            {
                GenerateClass(ce);
            }
            if (GenerateEnum)
            {
                GenerateEnumDecl();
            }
            GenerateVisitorInterfaces();
            EndBlock();
            Output = ((StringWriter)InnerWriter.InnerWriter).GetStringBuilder().ToString();
            if (OutputFilename.IsNotNullOrEmpty())
            {
                File.WriteAllText(OutputFilename, Output);
            }
        }
示例#3
0
 public YAMLWriter(TextWriter tw, int initialdepth, int horizontalthresh, IDictionary <Type, bool> bbd)
 {
     Depth            = new string(' ', initialdepth);
     HorizontalThresh = horizontalthresh;
     Lw                  = new LineWriter(tw, 0);
     BBD                 = bbd;
     VertWriter          = new LeafWriter(this, VertNeedsQuotes, s => LineBreak.IsMatch(s));
     HorizontalArrWriter = new LeafWriter(this, HArrNeedsQuotes, s => false);
     HorizontalDicWriter = new LeafWriter(this, HDicNeedsQuotes, s => false);
 }
示例#4
0
        private void ReadTaskMain()
        {
            bool         keepOnReading = true;
            StreamReader reader        = null;

            while (keepOnReading)
            {
                // If not already reading, find something to read
                if (reader == null)
                {
                    reader = GetStreamReader();
                }

                // Check for data on our current reader
                if (reader != null)
                {
                    string line;
                    try
                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            LineWriter.WriteLine(line);
                        }
                    }
                    catch (IOException ex)
                    {
                        LineWriter.WriteLine(string.Format(">>>> {0} <<<<", ex.Message));
                        reader = null;
                        continue;
                    }
                }

                // Check for file system events
                WatcherEvent watcherEvent = null;
                lock (eventQueueLock)
                {
                    if (eventQueue.Count == 0)
                    {
                        Monitor.Wait(eventQueueLock, FilePollingMs);
                    }
                    if (eventQueue.Count > 0)
                    {
                        watcherEvent  = eventQueue.Dequeue();
                        keepOnReading = watcherEvent != null;
                    }
                }
                if (watcherEvent != null)
                {
                    reader = HandleWatcherEvent(reader, watcherEvent);
                }
            }
        }
示例#5
0
        public override void Write(LineWriter writer)
        {
            writer.WriteLine($"{Tag}({Category}) = {Value}");
            {
                base.Write(writer);

                var nestedWriter = writer.Nest();
                foreach (var keyValue in Values)
                {
                    nestedWriter.WriteLine(keyValue.Key + " = " + keyValue.Value);
                }
            }
            writer.WriteLine("End" + Tag);
        }
        public void TextIndent_WithZeroLevel_ReturnsEmptyIndent()
        {
            // Arrange
            LineWriter lineWriter = new LineWriter();
            int        level      = 0;
            string     expected   = "";
            string     output;

            // Act
            output = lineWriter.TextIndent(level);

            // Assert
            Assert.AreEqual(expected, output, "Text indent is not correct");
        }
        public void BuildOrganogram_ShouldBuildCorrectOrganogram()
        {
            // Arrange
            var        dataReaderMock = new Mock <DataReader>(); // Mock of Data Reader
            LineWriter lineWriter     = new LineWriter();

            List <EmployeeModel> employeeModelList = new List <EmployeeModel>();

            //Test Data
            EmployeeModel model1 = new EmployeeModel(3, 0, "A", "A", "A", "A", "A", "1", "2", "3");
            EmployeeModel model2 = new EmployeeModel(1, 2, "B", "B", "B", "B", "B", "1", "2", "3");
            EmployeeModel model3 = new EmployeeModel(4, 2, "C", "C", "B", "C", "C", "1", "2", "3");
            EmployeeModel model4 = new EmployeeModel(2, 0, "D", "D", "B", "D", "D", "1", "2", "3");
            EmployeeModel model5 = new EmployeeModel(5, 1, "E", "E", "B", "E", "E", "1", "2", "3");

            employeeModelList.Add(model1);
            employeeModelList.Add(model2);
            employeeModelList.Add(model3);
            employeeModelList.Add(model4);
            employeeModelList.Add(model5);

            // Manual creating of organogram
            Employee        employee1     = new Employee(model1, 0);
            Employee        employee3     = new Employee(model3, 1);
            Employee        employee5     = new Employee(model5, 2);
            List <Employee> inferiorList2 = new List <Employee>();

            inferiorList2.Add(employee5);
            Employee        employee2     = new Employee(model2, inferiorList2, 1);
            List <Employee> expected      = new List <Employee>();
            List <Employee> inferiorList4 = new List <Employee>();

            inferiorList4.Add(employee2);
            inferiorList4.Add(employee3);
            Employee employee4 = new Employee(model4, inferiorList4, 0);

            expected.Add(employee1);
            expected.Add(employee4);


            dataReaderMock.Setup(x => x.ReadFromFile(It.IsAny <string>())).Returns(employeeModelList); // Mock method
            Organogram organogram = new Organogram(lineWriter, dataReaderMock.Object);

            // Act
            List <Employee> outputOgranogram = organogram.BuildOrganogram();

            // Assert
            CollectionAssert.AreEqual(expected, outputOgranogram);
        }
示例#8
0
        public void ConsoleLog()
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                if (LineWriter.notRead())
                {
                    for (int i = 0; i < LineWriter.console.Count; i++)
                    {
                        string line         = LineWriter.console[i];
                        LineBreak linebreak = new LineBreak();
                        CONSOLE.Text       += "\n" + line; // Linebreak

                        LineWriter.console.Remove(line);   // Remove stuff
                    }
                }
            }));
        }
示例#9
0
        private StreamReader GetStreamReader()
        {
            StreamReader streamReader = null;

            var filePath = FindFilePath();

            if (filePath != null)
            {
                streamReader = FindTailOf(filePath);
                if (streamReader != null)
                {
                    LineWriter.WriteLine(string.Format("++++++ File: {0} ++++++", filePath));
                    OnFileFound(filePath);
                }
            }
            return(streamReader);
        }
        public void WriteLine_ShouldDisplayCorrectText()
        {
            using (var sw = new StringWriter())
            {
                // Arrange
                LineWriter lineWriter = new LineWriter();
                Console.SetOut(sw);
                int           hierarchyLevel = 0;
                EmployeeModel employeeModel  = new EmployeeModel(1, 0, "A", "B", "C", "D", "E", "1", "2", "3");
                Employee      employee       = new Employee(employeeModel, hierarchyLevel);
                string        expected       = "1, 0, A, B, C, D, E";

                // Act
                lineWriter.WriteLine(employee);
                var result = sw.ToString().Trim();

                // Assert
                Assert.AreEqual(expected, result, "Employee was not corectly displayed");
            }
        }
示例#11
0
 public override void Execute(IJobExecutionContext context) =>
 LineWriter.WriteLine($"[Job 1] Execute called at \t{DateTime.Now.TimeOfDay}");
示例#12
0
        bool WriteHorizontalCollection(ref int idx, string open, string close, Func <YNode, bool> write)
        {
            if (!List[idx].IsLeaf)
            {
                return(false);
            }
            int           i           = idx;
            int           childdepth  = List[i].Depth;
            List <string> annotations = null;
            var           tmp         = Lw;
            string        res;

            try {
                var sw = new StringWriter();
                Lw = new LineWriter(sw, 0);
                var sb = sw.GetStringBuilder();
                Lw.Write(open); // to avoid WriteDepthSpace
                var sep = "";
                do
                {
                    var r = List[i];
                    if (!r.IsLeaf)
                    {
                        return(false);
                    }
                    Write(0, sep);
                    sep = ", ";
                    string s = GetAnnotation(i, r);
                    if (s != null)
                    {
                        int len = sb.Length;
                        if (annotations == null)
                        {
                            annotations = new List <string>();
                        }
                        annotations.Add(string.Concat("#", new string(' ', len - 1), "^", s));
                    }
                    if (!write(r))
                    {
                        return(false);
                    }
                    if (sb.Length >= HorizontalThresh)
                    {
                        return(false);
                    }
                    ++i;
                } while(HasDepth(i, childdepth));
                Write(0, close);
                idx = i;
                res = sb.ToString();
            }
            finally  {
                Lw = tmp;
            }
            WriteDepthSpace(childdepth);
            int curcolumn = Lw.Column;

            Write(childdepth, res);
            if (annotations != null)
            {
                foreach (string s in annotations)
                {
                    EndLine();
                    Lw.Write(new string(' ', curcolumn));
                    Lw.Write(s);
                }
            }
            return(true);
        }
示例#13
0
 bool WriteHorizontalCollection(ref int idx,string open,string close,Func<YNode,bool> write) {
     if(!List[idx].IsLeaf) return false;
     int i=idx;
     int childdepth=List[i].Depth;
     List<string> annotations=null;
     var tmp=Lw;
     string res;
     try {
         var sw=new StringWriter();
         Lw=new LineWriter(sw,0);
         var sb=sw.GetStringBuilder();
         Lw.Write(open); // to avoid WriteDepthSpace
         var sep="";
         do {
             var r=List[i];
             if(!r.IsLeaf) return false;
             Write(0,sep);
             sep=", ";
             string s=GetAnnotation(i,r);
             if(s!=null) {
                 int len=sb.Length;
                 if(annotations==null) annotations=new List<string>();
                 annotations.Add(string.Concat("#",new string(' ',len-1),"^",s));
             }
             if(!write(r)) return false;
             if(sb.Length>=HorizontalThresh) return false;
             ++i;
         } while(HasDepth(i,childdepth));
         Write(0,close);
         idx=i;
         res=sb.ToString();
     }
     finally  {
         Lw=tmp;
     }
     WriteDepthSpace(childdepth);
     int curcolumn=Lw.Column;
     Write(childdepth,res);
     if(annotations!=null) {
         foreach(string s in annotations) {
             EndLine();
             Lw.Write(new string(' ',curcolumn));
             Lw.Write(s);
         }
     }
     return true;
 }
示例#14
0
 public YAMLWriter(TextWriter tw,int initialdepth,int horizontalthresh,IDictionary<Type,bool> bbd) {
     Depth=new string(' ',initialdepth);
     HorizontalThresh=horizontalthresh;
     Lw=new LineWriter(tw,0);
     BBD=bbd;
     VertWriter=new LeafWriter(this,VertNeedsQuotes,s=>LineBreak.IsMatch(s));
     HorizontalArrWriter=new LeafWriter(this,HArrNeedsQuotes,s=>false);
     HorizontalDicWriter=new LeafWriter(this,HDicNeedsQuotes,s=>false);
 }
示例#15
0
 public ConsoleTestReporter(LineWriter output) => this.output = output;
示例#16
0
 public override void Write(LineWriter writer)
 {
     writer.WriteLine(Line.Content);
 }