示例#1
0
        public void ExtractQuery_NonExistingReport_CorrectExceptionReturned()
        {
            var request = new NBi.Core.Report.DatasetRequest(
                string.Empty
                , ReportFileDirectory
                , "Not Existing"
                , "DataSet1"
                );

            var parser = new FileParser();
            var ex     = Assert.Throws <ArgumentException>(() => parser.ExtractQuery(request));

            Assert.That(ex.Message, Is.StringContaining("No report found"));
        }
示例#2
0
        public void ExtractQuery_NonExistingDataSetMoreThanOneExisting_CorrectExceptionReturned()
        {
            var request = new NBi.Core.Report.DatasetRequest(
                string.Empty
                , ReportFileDirectory
                , "Currency_Rates"
                , "Non Existing"
                );

            var parser = new FileParser();
            var ex     = Assert.Throws <ArgumentException>(() => parser.ExtractQuery(request));

            Assert.That(ex.Message, Is.StringContaining("DataSet1").And.StringContaining("DataSet2"));
        }
示例#3
0
        public void ExtractSProc_ExistingReport_CorrectSProcReturned()
        {
            var request = new NBi.Core.Report.DatasetRequest(
                string.Empty
                , ReportFileDirectory
                , "Currency_List - SProc"
                , "Currency"
                );

            var parser = new FileParser();
            var query  = parser.ExtractQuery(request);

            Assert.That(query.Text,
                        Is.EqualTo("usp_CurrencyGetAll"));
            Assert.That(query.CommandType, Is.EqualTo(CommandType.StoredProcedure));
        }
示例#4
0
        public void ExtractQuery_ExistingReportAndSharedDataSet_CorrectQueryReturned()
        {
            var request = new NBi.Core.Report.DatasetRequest(
                string.Empty
                , ReportFileDirectory
                , "Employee_Sales_Summary"
                , "SalesEmployees2008R2"
                );

            var parser = new FileParser();
            var query  = parser.ExtractQuery(request);

            Assert.That(query.Text,
                        Is.StringContaining("SELECT").And
                        .StringContaining("[Sales].[SalesPerson]").And
                        .StringContaining("[HumanResources].[Employee]"));
            Assert.That(query.CommandType, Is.EqualTo(CommandType.Text));
        }
示例#5
0
        private Exception BuildDataSetNotFoundException(DatasetRequest request, XmlDocument docXml, string xpath, XmlNamespaceManager nsmgr)
        {
            var nodes        = docXml.SelectNodes(xpath, nsmgr);
            var dataSetFound = new List <String>();

            foreach (XmlNode node in nodes)
            {
                dataSetFound.Add(node.Attributes["Name"].Value);
            }

            if (dataSetFound.Count() > 1)
            {
                throw new ArgumentException(string.Format("The requested dataset ('{2}') wasn't found for the report on path '{0}' with name '{1}'. The datasets for this report are {3}", request.Path, request.ReportName, request.DataSetName, String.Join(", ", dataSetFound.ToArray())));
            }
            else
            {
                throw new ArgumentException(string.Format("The requested dataset ('{2}') wasn't found for the report on path '{0}' with name '{1}'. The dataset for this report is named '{3}'", request.Path, request.ReportName, request.DataSetName, dataSetFound[0]));
            }
        }
示例#6
0
        public ReportCommand ExtractQuery(DatasetRequest request)
        {
            var otherDataSets = new List <string>();
            var query         = SearchDataSet(
                request.Source
                , request.Path
                , request.ReportName
                , request.DataSetName
                , ref otherDataSets);

            if (query == null)
            {
                var reference = SearchSharedDataSet(
                    request.Source
                    , request.Path
                    , request.ReportName
                    , request.DataSetName
                    , ref otherDataSets);
                if (!string.IsNullOrEmpty(reference))
                {
                    query = ReadQueryFromSharedDataSet(request.Source, request.Path, reference);
                }
            }

            if (query != null)
            {
                return(query);
            }

            if (otherDataSets.Count() == 0)
            {
                throw new ArgumentException(string.Format("No report found on path '{0}' with name '{1}'", request.Path, request.ReportName));
            }
            else if (otherDataSets.Count() == 1)
            {
                throw new ArgumentException(string.Format("The requested dataset ('{2}') wasn't found for the report on path '{0}' with name '{1}'. The dataset for this report is {3}", request.Path, request.ReportName, request.DataSetName, otherDataSets[0]));
            }
            else
            {
                throw new ArgumentException(string.Format("The requested dataset ('{2}') wasn't found for the report on path '{0}' with name '{1}'. The datasets for this report are {3}", request.Path, request.ReportName, request.DataSetName, String.Join(", ", otherDataSets.ToArray())));
            }
        }
示例#7
0
        public ReportCommand ExtractQuery(DatasetRequest request)
        {
            var reportName = request.ReportName.EndsWith(".rdl") ? request.ReportName : request.ReportName + ".rdl";

            var fullPath = string.Format("{0}{1}{2}", request.Source, request.Path, reportName);

            if (!File.Exists(fullPath))
            {
                throw new ArgumentException(string.Format("No report found on path '{0}{1}' with name '{2}'", request.Source, request.Path, request.ReportName));
            }

            //Load the xml
            var docXml = new XmlDocument();

            docXml.Load(fullPath);
            var root = docXml.FirstChild;

            if (root.NodeType == XmlNodeType.XmlDeclaration)
            {
                root = root.NextSibling;
            }

            //Check that the data set exist
            var xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]", request.DataSetName);
            //var xpath = "//Report";

            var nsmgr = new XmlNamespaceManager(docXml.NameTable);

            nsmgr.AddNamespace("rd", root.GetNamespaceOfPrefix(string.Empty));

            var node = docXml.SelectSingleNode(xpath, nsmgr);

            if (node == null)
            {
                throw BuildDataSetNotFoundException(request, docXml, "//rd:Report/rd:DataSets/rd:DataSet", nsmgr);
            }

            //Search in the xml the DataSet and especially the CommandText within this dataset
            xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]/rd:Query/rd:CommandText", request.DataSetName);

            node = docXml.SelectSingleNode(xpath, nsmgr);
            if (node != null)
            {
                var text          = node.InnerText; // Weve fond the query
                var reportCommand = new ReportCommand()
                {
                    Text = text
                };

                xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]/rd:Query/rd:CommandType", request.DataSetName);
                node  = docXml.SelectSingleNode(xpath, nsmgr);
                if (node == null)
                {
                    reportCommand.CommandType = CommandType.Text;
                }
                else
                {
                    reportCommand.CommandType = (CommandType)Enum.Parse(typeof(CommandType), node.InnerText);
                }
                return(reportCommand);
            }

            //If not found then we'll check if it's not a shared dataset
            xpath = string.Format("//rd:Report/rd:DataSets/rd:DataSet[@Name=\"{0}\"]/rd:SharedDataSet/rd:SharedDataSetReference", request.DataSetName);
            node  = docXml.SelectSingleNode(xpath, nsmgr);
            if (node == null)
            {
                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));
            }

            var sharedDataSetName = node.InnerText + ".rsd";
            var subRequest        = new SharedDatasetRequest
                                    (
                request.Source,
                request.Path,
                sharedDataSetName
                                    );

            return(ExtractQuery(subRequest));
        }