/// <summary> /// Loads a configuration file /// </summary> public static bool LoadConfigFile(string path, LineProcessor processor) { if (!File.Exists(path)) { FileInfo info = new FileInfo(path); if (!info.Directory.Exists) { info.Directory.Create(); } info.Create().Dispose(); return(false); } using (StreamReader reader = new StreamReader(File.OpenRead(path))) { string key, value; while (!reader.EndOfStream) { if (ParseLine(reader, out key, out value)) { try { processor(key, value); } catch { Logger.LogF("Hit error at key={0} and value={1}", LogType.Error, key, value); continue; } } } reader.Close(); } return(true); }
public static bool Read <T>(string path, ref T state, LineProcessor <T> processor, char separator = '=', bool trimValue = true) { if (!File.Exists(path)) { return(false); } using (CP437Reader reader = new CP437Reader(path)) { string line; while ((line = reader.ReadLine()) != null) { int index = ParseLine(line, path, separator); if (index == -1) { continue; } string key = line.Substring(0, index), value = line.Substring(index + 1); if (trimValue) { value = value.Trim(); } try { processor(key.Trim(), value, ref state); } catch (Exception ex) { Server.ErrorLog(ex); Server.s.Log("Line \"" + line + "\" in " + path + " caused an error"); } } } return(true); }
public static void TransformFileInFlight(string templateDimCoreName, string SCDType6TemplateDirectory, string OutputDirectory, string DimensionSchema, string templateSchema, string StagingSchema, LineProcessorConfig lineProcessorConfigNK, LineProcessorConfig lineProcessorConfigDim, string file) // public static void TransformFileInFlight(string templateDimCoreName, ParsedArgs parsedArgs, string StagingSchema, LineProcessorConfig lineProcessorConfigNK, LineProcessorConfig lineProcessorConfigDim, string file) { String source = SCDType6TemplateDirectory + file; String destination = OutputDirectory + file.Split('\\')[1].Replace("templateDimCoreName", templateDimCoreName); using (StreamReader reader = new StreamReader(source)) using (StreamWriter writer = new StreamWriter(destination, false, Encoding.UTF8)) { while (!reader.EndOfStream) { string line = reader.ReadLine(); line = line.Replace("templateDimCoreName", templateDimCoreName); line = line.Replace("templateSchema", templateSchema); line = line.Replace("dimensionSchema", DimensionSchema); line = line.Replace("StagingSchema", StagingSchema); if (!line.Contains("/*Sample*/")) { LineProcessor lineProcessorNK = new LineProcessor(line, lineProcessorConfigNK); line = lineProcessorNK.GetLine(); LineProcessor lineProcessorDim = new LineProcessor(line, lineProcessorConfigDim); line = lineProcessorDim.GetLine(); writer.WriteLine(line); } } } }
private Task <LineProcessorResults> ProcessAsync(LineProcessor processor) { var observer = new LineEventHandler(); processor.Process(observer); return(observer.Task); }
public void ParseLineWithConfigurationForDataTypeSetsHasOperationToTrue() { //setup var objectUnderTest = new TotalTempLineProcessor(); objectUnderTest.SetHeader(GetValidHeader()); var moqInstructions = new Mock <ILineProcessInstructions>(); var testInstruction = new LineProcessor() { Period = periodChoice.LastValue, OperationType = statisticCalculation.Average, VariableType = "CashPrem" }; moqInstructions.Setup(x => x.Processors).Returns(new Dictionary <string, ILineProcessor>() { { testInstruction.Key, testInstruction } }); moqInstructions.Setup(t => t.ExtractPeriodValueOfInterest(It.IsAny <List <PeriodValue> >(), It.IsAny <string>())) .Returns(new List <RelevantValue>() { new RelevantValue() { Value = _testValues[4] } }); //execute var lines = objectUnderTest.ParseLine(GetCashPrem(), moqInstructions.Object); //assert Assert.IsTrue(lines.First().HasOperation); Assert.AreEqual(_testValues[4], lines.First().ValueOfRelevance); }
public static bool Read <T>(string path, ref T state, LineProcessor <T> processor, char separator = '=', bool trimValue = true) { if (!File.Exists(path)) { return(false); } using (StreamReader r = new StreamReader(path)) { string line, key, value; while ((line = r.ReadLine()) != null) { ParseLine(line, separator, out key, out value); if (key == null) { continue; } try { if (trimValue) { value = value.Trim(); } processor(key.Trim(), value, ref state); } catch (Exception ex) { Logger.LogError(ex); Logger.Log(LogType.Warning, "Line \"{0}\" in {1} caused an error", line, path); } } } return(true); }
public static bool Read(string path, Action <string, string> processor, char separator = '=', bool trimValue = true) { object obj = null; LineProcessor <object> del = (string key, string value, ref object state) => { processor(key, value); }; return(Read(path, ref obj, del, separator, trimValue)); }
protected void ProcessLines(System.IO.TextReader sr, LineProcessor processor) { while (sr.Peek() != -1) { var line = sr.ReadLine(); this.ProcessLine(line, processor); } }
private void ProcessLines(TextReader sr, LineProcessor processor) { while (sr.Peek() != -1) { var line = sr.ReadLine(); this.ProcessLine(line, processor); } }
public static SourceFile ParseSourceFile(string filePath) { // chain the parsing passes together var scanner = new Scanner(filePath, File.ReadAllText(filePath)); var lineProcessor = new LineProcessor(scanner); var parser = new MagpieParser(lineProcessor); return parser.SourceFile(); }
public void MustProcessSetLine() { // Simple Insert var processor = new LineProcessor(new MsSqlType("mssql.sql"), new MySqlType("mysql.sql")); var mssqlLine = "SET IDENTITY_INSERT [dbo].[accounts] ON"; var mysqlLine = processor.ProcessLine(mssqlLine); var expectedMySql = ""; Assert.Equal(expectedMySql, mysqlLine); }
public void MustProcessInsertLine() { // Simple Insert var processor = new LineProcessor(new MsSqlType("mssql.sql"), new MySqlType("mysql.sql")); var mssqlLine = "INSERT [dbo].[accounts] ([id], [create_date], [name], [email], [username], [password], [is_active], [deleted], [ClientId], [AuthMethod], [ProfileId]) VALUES (1, CAST(N'2015-03-27T10:44:10.323' AS DateTime), N'Admin', N'*****@*****.**', N'*****@*****.**', N'481F6CC0511143CCDD7E2D1B1B94FAF0A700A8B49CD13922A70B5AE28ACAA8C5', 1, 0, 0, 0, 1)"; var mysqlLine = processor.ProcessLine(mssqlLine); var expectedMySql = "INSERT accounts (id, create_date, name, email, username, password, is_active, deleted, ClientId, AuthMethod, ProfileId) VALUES (1, CAST(N'2015-03-27T10:44:10.323' AS DateTime), N'Admin', N'*****@*****.**', N'*****@*****.**', N'481F6CC0511143CCDD7E2D1B1B94FAF0A700A8B49CD13922A70B5AE28ACAA8C5', 1, 0, 0, 0, 1);"; Assert.Equal(expectedMySql, mysqlLine); }
public void MustProcessEmptyLine() { // Simple Insert var processor = new LineProcessor(new MsSqlType("mssql.sql"), new MySqlType("mysql.sql")); var mssqlLine = ""; var mysqlLine = processor.ProcessLine(mssqlLine); var expectedMySql = ""; Assert.Equal(expectedMySql, mysqlLine); }
public void ValidateSplitList_NothingIfValid() { //Arrange String Input = "/*a|bbb|ccc*/"; LineProcessor LineProcessor = new LineProcessor(Input); //Act //Assert Assert.That(delegate { LineProcessor.ValidateSplitList(); }, Throws.Nothing); }
public void ValidateSplitList_ExceptionIfNotValid() { //Arrange String Input = "/*a|bbb|ccc|ddd*/"; LineProcessor LineProcessor = new LineProcessor(Input); //Act //Assert Assert.Throws <ExpectedNumberOfElementsNotFoundException>(delegate { LineProcessor.ValidateSplitList(); }); }
public void DetermineControlFlow_JustReturnLine__ExceptionIfHasSQLBlockCommentButNoSplitChar() { //Arrange String Input = "A String /*SqlComment*/ asdf"; LineProcessor LineProcessor = new LineProcessor(Input); //Act //Assert Assert.Throws <ExpectedNumberOfElementsNotFoundException>(delegate { LineProcessor.DetermineControlFlow_JustReturnLine(); }); }
public void GetLine_Default() { //Arrange String Input = "A String asdf"; String Expected = Input; LineProcessor LineProcessor = new LineProcessor(Input); //Act String Actual = LineProcessor.GetLine(); //Assert Assert.AreEqual(Expected, Actual); }
public void GetComment() { //Arrange String Expected = "SqlComm*en/t"; String Input = "A String /*SqlComm*en/t*/ asdf"; LineProcessor LineProcessor = new LineProcessor(Input); //Act String Actual = LineProcessor.GetComment(); //Assert Assert.AreEqual(Expected, Actual); }
public void ConfirmHasComment_FalseIfNoSQLBlockComment() { //Arrange Boolean Expected = false; String Input = "A String //NotASqlComment"; LineProcessor LineProcessor = new LineProcessor(Input); //Act Boolean Actual = LineProcessor.CheckHasComment(); //Assert Assert.AreEqual(Expected, Actual); }
public void DetermineControlFlow_JustReturnLine__FalseIfPassesValidation() { //Arrange Boolean Expected = false; String Input = "A String /*Sql|Com|ment*/ asdf"; LineProcessor LineProcessor = new LineProcessor(Input); //Act Boolean Actual = LineProcessor.DetermineControlFlow_JustReturnLine(); //Assert Assert.AreEqual(Expected, Actual); }
public static void ShouldProcessSlangLine() { LineProcessor lineProcessor = new LineProcessor(); lineProcessor.Execute("glob is I"); string SlangWord = "glob"; string SlangWordMappedRomanValue = "I"; Assert.True(LineProcessor.SlangWordMapping.ContainsKey(SlangWord)); Assert.True(LineProcessor.SlangWordMapping.ContainsValue(SlangWordMappedRomanValue)); }
public void LineProcessor_ShouldReturn4TagSegments_WhenReceiveLineWith4Tags() { // ARRANGE ILineProcessor lineProcessor = new LineProcessor <MockLineSegment>(); string lineText = "My <bold> text </bold> have <s> 4 </s> tags"; // ACT lineProcessor.ProcessLine(lineText); // ASSERT Assert.AreEqual(4, lineProcessor.Segments.Count(s => s.IsTag)); }
public void LineProcessor_ShouldReturnSegmentsEquivalentToTheOriginalText() { // ARRANGE ILineProcessor lineProcessor = new LineProcessor <MockLineSegment>(); string lineText = "My <bold> text </bold> have <s> 4 </s> tags"; // ACT lineProcessor.ProcessLine(lineText); // ASSERT Assert.AreEqual(lineText, string.Join(string.Empty, lineProcessor.Segments.Select(s => s.DisplayText))); }
public void LineProcessor_ShouldReturn9Segments_WhenReceiveLineWith4InnerTags() { // ARRANGE ILineProcessor lineProcessor = new LineProcessor <MockLineSegment>(); string lineText = "My <bold> text </bold> have <s> 9 </s> segments"; // ACT lineProcessor.ProcessLine(lineText); // ASSERT Assert.AreEqual(9, lineProcessor.Segments.Count()); }
public void LineProcessor_ShouldReturn9Segments_WhenReceiveLineWith4TagsSurroundedByWhiteSpaces() { // ARRANGE ILineProcessor lineProcessor = new LineProcessor <MockLineSegment>(); string lineText = " <bold>My text </bold> have <s> 9 segments</s> "; // ACT lineProcessor.ProcessLine(lineText); // ASSERT Assert.AreEqual(9, lineProcessor.Segments.Count()); }
public void DetermineControlFlow_JustReturnLine__TrueIfNoSQLBlockComment() { //Arrange Boolean Expected = true; String Input = "A String asdf"; LineProcessor LineProcessor = new LineProcessor(Input); //Act Boolean Actual = LineProcessor.DetermineControlFlow_JustReturnLine(); //Assert Assert.AreEqual(Expected, Actual); }
public void ConfirmHasComment_TrueIfHasSQLBlockComment() { //Arrange Boolean Expected = true; String Input = "A String /*SqlComment*/ asdf"; LineProcessor LineProcessor = new LineProcessor(Input); //Act Boolean Actual = LineProcessor.CheckHasComment(); //Assert Assert.AreEqual(Expected, Actual); }
public void GetInputWithoutComment_RemovesCommentAndTrims() { //Arrange String Expected = "A String"; String Input = "A String /*a|bbb|cccc*/"; LineProcessor LineProcessor = new LineProcessor(Input); //Act String Actual = LineProcessor.GetInputWithoutComment(); //Assert Assert.AreEqual(Expected, Actual); }
public void FormatJoinString_NotFirst() { //Arrange LineProcessor lineProcessor = new LineProcessor(); Boolean isFirst = false; String joinString = ","; String Expected = ", "; //Act String Actual = lineProcessor.FormatJoinString(joinString, isFirst); //Assert Assert.AreEqual(Expected, Actual); }
// GET: Line public static string getLineName(int lineId) { string lineName = null; var lineData = LineProcessor.getLineName(lineId); foreach (var row in lineData) { lineName = row.lineName; } return(lineName); }
protected void ProcessScriptTests(string scriptFileName, LineProcessor processor) { this.WriteMessage("Testing: {0}", scriptFileName); var instream = this.GetScriptFile(scriptFileName); var sr = new StreamReader(instream); try { this.ProcessLines(sr, processor); } finally { sr.Close(); } }
private void ProcessLines(TextReader sr, LineProcessor processor) { int lineNumber = 1; bool success = true; while (sr.Peek() != -1) { string line = sr.ReadLine(); success = ProcessLine(line, processor, lineNumber++) && success; } if (!success) Assert.Fail(); }
private bool ProcessLine(string line, LineProcessor processor, int lineNumber) { if (line.StartsWith("'")) return true; try { string[] arr = line.Split(SEPARATOR_CHAR); processor(arr); } catch (Exception ex) { WriteMessage("Failed line({1}): {0} failed with {2} ({3})", line, lineNumber, ex.Message, ex.GetType().FullName); return false; } return true; }
protected void ProcessScriptTests(string scriptFileName, LineProcessor processor) { this.WriteMessage("Testing: {0}", scriptFileName); System.IO.Stream instream = this.GetScriptFile(scriptFileName); System.IO.StreamReader sr = new System.IO.StreamReader(instream); try { this.ProcessLines(sr, processor); } finally { sr.Close(); } }
static void Main(string[] args) { var processor = new LineProcessor(args); processor.Process(); }