How to use ExtractCommand method of NBi.Core.Report.FileReportingParser class

Best NBi code snippet using NBi.Core.Report.FileReportingParser.ExtractCommand

FileReportingParserTest.cs

Source:FileReportingParserTest.cs Github

copy

Full Screen

...65 , "Currency_List"66 , "Currency"67 );68 var parser = new FileReportingParser();69 var query = parser.ExtractCommand(request);70 Assert.That(query.Text,71 Does.Contain("SELECT").And72 .Contain("[CurrencyAlternateKey]").And73 .Contain("[DimCurrency]"));74 Assert.That(query.CommandType, Is.EqualTo(CommandType.Text));75 }76 [Test]77 public void ExtractQuery_NonExistingDataSetOneExisting_CorrectExceptionReturned()78 {79 var request = new ReportDataSetRequest(80 string.Empty81 , ReportFileDirectory82 , "Currency_List"83 , "Non Existing"84 );85 var parser = new FileReportingParser();86 var ex = Assert.Throws<ArgumentException>(() => parser.ExtractCommand(request));87 Assert.That(ex.Message, Does.Contain("'Currency'"));88 }89 [Test]90 public void ExtractQuery_NonExistingDataSetMoreThanOneExisting_CorrectExceptionReturned()91 {92 var request = new NBi.Core.Report.ReportDataSetRequest(93 string.Empty94 , ReportFileDirectory95 , "Currency_Rates"96 , "Non Existing"97 );98 var parser = new FileReportingParser();99 var ex = Assert.Throws<ArgumentException>(() => parser.ExtractCommand(request));100 Assert.That(ex.Message, Does.Contain("DataSet1").And.Contain("DataSet2"));101 }102 [Test]103 public void ExtractQuery_NonExistingReport_CorrectExceptionReturned()104 {105 var request = new NBi.Core.Report.ReportDataSetRequest(106 string.Empty107 , ReportFileDirectory108 , "Not Existing"109 , "DataSet1"110 );111 var parser = new FileReportingParser();112 var ex = Assert.Throws<ArgumentException>(() => parser.ExtractCommand(request));113 Assert.That(ex.Message, Does.Contain("No report found"));114 }115 [Test]116 public void ExtractQuery_ExistingReportAndSharedDataSet_CorrectQueryReturned()117 {118 var request = new NBi.Core.Report.ReportDataSetRequest(119 string.Empty120 , ReportFileDirectory121 , "Employee_Sales_Summary"122 , "SalesEmployees2008R2"123 );124 var parser = new FileReportingParser();125 var query = parser.ExtractCommand(request);126 Assert.That(query.Text,127 Does.Contain("SELECT").And128 .Contain("[Sales].[SalesPerson]").And129 .Contain("[HumanResources].[Employee]"));130 Assert.That(query.CommandType, Is.EqualTo(CommandType.Text));131 }132 [Test]133 public void ExtractQuery_ExistingSharedDataSet_CorrectQueryReturned()134 {135 var request = new SharedDatasetRequest(136 string.Empty137 , ReportFileDirectory138 , "SalesEmployees"139 );140 var parser = new FileReportingParser();141 var query = parser.ExtractCommand(request);142 Assert.That(query.Text,143 Does.Contain("SELECT").And144 .Contain("[Sales].[SalesPerson]").And145 .Contain("[HumanResources].[Employee]"));146 Assert.That(query.CommandType, Is.EqualTo(CommandType.Text));147 }148 [Test]149 public void ExtractSProc_ExistingReport_CorrectSProcReturned()150 {151 var request = new NBi.Core.Report.ReportDataSetRequest(152 string.Empty153 , ReportFileDirectory154 , "Currency_List - SProc"155 , "Currency"156 );157 var parser = new FileReportingParser();158 var query = parser.ExtractCommand(request);159 Assert.That(query.Text,160 Is.EqualTo("usp_CurrencyGetAll"));161 Assert.That(query.CommandType, Is.EqualTo(CommandType.StoredProcedure));162 }163 }164}...

Full Screen

Full Screen

FileReportingParser.cs

Source:FileReportingParser.cs Github

copy

Full Screen

...7namespace NBi.Core.Report8{9 class FileReportingParser : IReportingParser10 {11 public ReportingCommand ExtractCommand(ReportDataSetRequest request)12 {13 var reportName = request.ReportName.EndsWith(".rdl") ? request.ReportName : request.ReportName + ".rdl";14 var fullPath = string.Format("{0}{1}{2}", request.Source, request.Path, reportName);15 if (!File.Exists(fullPath))16 throw new ArgumentException(string.Format("No report found on path '{0}{1}' with name '{2}'", request.Source, request.Path, request.ReportName));17 //Load the xml18 var docXml = new XmlDocument();19 docXml.Load(fullPath);20 var root = docXml.FirstChild;21 if (root.NodeType == XmlNodeType.XmlDeclaration)22 root = root.NextSibling;23 //Check that the data set exist24 var xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]", request.DataSetName);25 //var xpath = "//Report";26 var nsmgr = new XmlNamespaceManager(docXml.NameTable);27 nsmgr.AddNamespace("rd", root.GetNamespaceOfPrefix(string.Empty));28 var node = docXml.SelectSingleNode(xpath, nsmgr);29 if (node == null)30 throw BuildDataSetNotFoundException(request, docXml, "//rd:Report/rd:DataSets/rd:DataSet", nsmgr);31 //Search in the xml the DataSet and especially the CommandText within this dataset32 xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]/rd:Query/rd:CommandText", request.DataSetName);33 node = docXml.SelectSingleNode(xpath, nsmgr);34 if (node != null)35 {36 var text = node.InnerText; // Weve fond the query37 var reportCommand = new ReportingCommand() { Text = text };38 xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]/rd:Query/rd:CommandType", request.DataSetName);39 node = docXml.SelectSingleNode(xpath, nsmgr);40 if (node == null)41 reportCommand.CommandType = CommandType.Text;42 else43 reportCommand.CommandType = (CommandType)Enum.Parse(typeof(CommandType), node.InnerText);44 return reportCommand;45 }46 //If not found then we'll check if it's not a shared dataset47 xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]/rd:SharedDataSet/rd:SharedDataSetReference", request.DataSetName);48 node = docXml.SelectSingleNode(xpath, nsmgr);49 if (node == null)50 throw new ArgumentException(string.Format("The data set named '{0}' has been found but no command text or shared dataset reference has been found", request.DataSetName));51 var sharedDataSetName = node.InnerText + ".rsd";52 var subRequest = new SharedDatasetRequest53 (54 request.Source,55 request.Path,56 sharedDataSetName57 );58 return ExtractCommand(subRequest);59 }60 public ReportingCommand ExtractCommand(SharedDatasetRequest request)61 {62 var reportName = request.SharedDatasetName.EndsWith(".rsd") ? request.SharedDatasetName : request.SharedDatasetName + ".rsd";63 var fullPath = string.Format("{0}{1}{2}", request.Source, request.Path, reportName);64 if (!File.Exists(fullPath))65 throw new ArgumentException(string.Format("No shared dataset found on path '{0}{1}' with name '{2}'", request.Source, request.Path, reportName));66 //If the file is found then we need to select the query inside the file67 var docXml = new XmlDocument();68 docXml.Load(fullPath);69 var root = docXml.FirstChild;70 if (root.NodeType == XmlNodeType.XmlDeclaration)71 root = root.NextSibling;72 var xpath = string.Format("//rd:SharedDataSet/rd:DataSet[@Name=\"\"]/rd:Query/rd:CommandText");73 var nsmgr = new XmlNamespaceManager(docXml.NameTable);74 nsmgr.AddNamespace("rd", root.GetNamespaceOfPrefix(string.Empty));...

Full Screen

Full Screen

ExtractCommand

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Report;7{8 {9 static void Main(string[] args)10 {11 FileReportingParser parser = new FileReportingParser();12 string[] command = parser.ExtractCommand("=MyFunction(1,2,3)");13 Console.WriteLine(command[0]);14 Console.WriteLine(command[1]);15 Console.WriteLine(command[2]);16 Console.WriteLine(command[3]);17 Console.WriteLine(command[4]);18 Console.ReadLine();19 }20 }21}

Full Screen

Full Screen

ExtractCommand

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Report;7{8 {9 static void Main(string[] args)10 {11 string file = "C:\\Users\\User\\Desktop\\Report.rdl";12 string command = "SELECT * FROM Table";13 FileReportingParser parser = new FileReportingParser(file);14 var result = parser.ExtractCommand(command);15 }16 }17}

Full Screen

Full Screen

ExtractCommand

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Report;7using NBi.Core.Report.Delimited;8using NBi.Core.Report.File;9using NBi.Core.Report.File.Excel;10using NBi.Core.Report.File.Csv;11using NBi.Core.Report.File.Tsv;12using NBi.Core.Report.File.Json;13using NBi.Core.Report.File.Xml;14using NBi.Core.Report.File.Html;15{16 {17 static void Main(string[] args)18 {19 string file = @"C:\Users\testuser\Desktop\test.csv";20 IReportingParser parser = new FileReportingParser(file);21 IReportingEngine engine = new ReportingEngine(parser);22 var result = engine.Execute("Select * from [Sheet1$]", "Sheet1");23 Console.WriteLine(result);24 Console.WriteLine("Press any key to continue...");25 Console.ReadKey();26 }27 }28}29using System;30using System.Collections.Generic;31using System.Linq;32using System.Text;

Full Screen

Full Screen

ExtractCommand

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Report;7using NBi.Core.Report.FileReporting;8using NBi.Core.Report.FileReporting.Html;9using NBi.Core.Report.FileReporting.Excel;10using NBi.Core.Report.FileReporting.PowerPoint;11using NBi.Core.Report.FileReporting.Pdf;12using NBi.Core.Report.FileReporting.Word;13using NBi.Core.Report.FileReporting.Csv;14using NBi.Core.Report.FileReporting.Json;15using NBi.Core.Report.FileReporting.Xml;16using System.IO;17using System.Data;18{19 {20 static void Main(string[] args)21 {22 string path = @"C:\Users\user\Documents\test.xlsx";23 string query = "SELECT * FROM [Sheet1$]";24 string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;';";25 FileReportingParser parser = new FileReportingParser();26 var result = parser.ExtractCommand(query, connectionString);27 Console.WriteLine(result);28 Console.ReadLine();29 }30 }31}32using System;33using System.Collections.Generic;34using System.Linq;35using System.Text;36using System.Threading.Tasks;37using NBi.Core.Report;38using NBi.Core.Report.FileReporting;39using NBi.Core.Report.FileReporting.Html;40using NBi.Core.Report.FileReporting.Excel;41using NBi.Core.Report.FileReporting.PowerPoint;42using NBi.Core.Report.FileReporting.Pdf;43using NBi.Core.Report.FileReporting.Word;44using NBi.Core.Report.FileReporting.Csv;45using NBi.Core.Report.FileReporting.Json;46using NBi.Core.Report.FileReporting.Xml;47using System.IO;48using System.Data;49{50 {51 static void Main(string[] args)52 {53 string path = @"C:\Users\user\Documents\test.xlsx";54 string query = "SELECT * FROM [Sheet1$]";55 string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;';";56 FileReportingParser parser = new FileReportingParser();57 var result = parser.ExtractCommand(query, connectionString);

Full Screen

Full Screen

ExtractCommand

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Report;7using NBi.Core.Report.FileReporting;8using NBi.Core.Report.FileReporting.Html;9using NBi.Core.Report.FileReporting.Excel;10using NBi.Core.Report.FileReporting.PowerPoint;11using NBi.Core.Report.FileReporting.Pdf;12using NBi.Core.Report.FileReporting.Word;13using NBi.Core.Report.FileReporting.Csv;14using NBi.Core.Report.FileReporting.Tsv;15using NBi.Core.Report.FileReporting.Xml;16using NBi.Core.Report.FileReporting.Json;17{18 {19 static void Main(string[] args)20 {21 FileReportingParser parser = new FileReportingParser();22 FileReport report = new FileReport();23 report.Path = @"C:\temp\test.xlsx";24 report.Type = FileReportType.Excel;25 report.Content = System.IO.File.ReadAllBytes(report.Path);26 report.Format = FileReportFormat.Xlsx;27 report.Sheet = "Sheet1";28 report.Command = "select * from [Sheet1$]";29 report.CommandType = FileReportCommandType.Sql;30 report.ResultType = FileReportResultType.Table;31 report.ResultName = "Result1";32 report.ResultType = FileReportResultType.Table;33 report.ResultName = "Result1";34 report.ResultType = FileReportResultType.Table;35 report.ResultName = "Result1";36 report.ResultType = FileReportResultType.Table;

Full Screen

Full Screen

ExtractCommand

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6{7 {8 static void Main(string[] args)9 {10 string path = @"C:\Users\test\Documents\Visual Studio 2015\Projects\NBi_ExtractCommand\NBi_ExtractCommand\bin\Debug\Report.rdl";11 NBi.Core.Report.FileReportingParser parser = new NBi.Core.Report.FileReportingParser(path);12 NBi.Core.Report.ReportCommand command = parser.ExtractCommand();13 }14 }15}

Full Screen

Full Screen

ExtractCommand

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Report;7using NBi.Core.Report.FileReporting;8using NBi.Core.Report.FileReporting.Parser;9{10 {11 static void Main(string[] args)12 {13 string reportPath = @"C:\Users\Public\Documents\NBi\NBi Test Suite\Report\Report.rdl";14 string commandText = "SELECT * FROM MyTable";15 FileReportingParser parser = new FileReportingParser();16 var command = parser.ExtractCommand(commandText, reportPath);17 }18 }19}20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using System.Threading.Tasks;25using NBi.Core.Report;26using NBi.Core.Report.FileReporting;27using NBi.Core.Report.FileReporting.Parser;28{29 {30 static void Main(string[] args)31 {32 string reportPath = @"C:\Users\Public\Documents\NBi\NBi Test Suite\Report\Report.rdl";33 FileReportingParser parser = new FileReportingParser();34 var command = parser.ExtractCommand(reportPath);35 }36 }37}

Full Screen

Full Screen

ExtractCommand

Using AI Code Generation

copy

Full Screen

1NBi.Core.Report.FileReportingParser parser = new NBi.Core.Report.FileReportingParser();2var data = parser.ExtractCommand("PathToReportFile", "ReportName", "ReportCommand");3foreach (var row in data)4{5 foreach (var item in row)6 {7 Console.WriteLine(item);8 }9}10NBi.Core.Report.FileReportingParser parser = new NBi.Core.Report.FileReportingParser();11var data = parser.ExtractCommand("PathToReportFile", "ReportName", "ReportCommand");12DataTable dt = new DataTable();13foreach (var row in data)14{15 if (dt.Columns.Count == 0)16 {17 foreach (var item in row)18 {19 dt.Columns.Add(item);20 }21 }22 {23 dt.Rows.Add(row);24 }25}26NBi.Core.Report.FileReportingParser parser = new NBi.Core.Report.FileReportingParser();27var data = parser.ExtractCommand("PathToReportFile", "ReportName", "ReportCommand");28DataTable dt = new DataTable();29foreach (var row in data)30{31 if (dt.Columns.Count == 0)32 {33 foreach (var item in row)34 {35 dt.Columns.Add(item);36 }37 }38 {39 dt.Rows.Add(row);40 }41}42StringBuilder sb = new StringBuilder();43 Select(column => column.ColumnName);44sb.AppendLine(string.Join(",", columnNames));45foreach (DataRow row in dt.Rows)46{47 IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());48 sb.AppendLine(string.Join(",", fields));49}50File.WriteAllText("PathToCSVFile", sb.ToString());

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run NBi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in FileReportingParser

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful