示例#1
0
        public ReportCommand ExtractQuery(SharedDatasetRequest request)
        {
            var query = ReadQueryFromSharedDataSet(request.Source, request.Path, request.SharedDatasetName);

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

            throw new ArgumentException(string.Format("The requested shared dataset ('{1}') wasn't found on path '{0}'.", request.Path, request.SharedDatasetName));
        }
示例#2
0
        public ReportCommand ExtractQuery(SharedDatasetRequest request)
        {
            var reportName = request.SharedDatasetName.EndsWith(".rsd") ? request.SharedDatasetName : request.SharedDatasetName + ".rsd";

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

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

            //If the file is found then we need to select the query inside the file
            var docXml = new XmlDocument();

            docXml.Load(fullPath);

            var root = docXml.FirstChild;

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

            var xpath = string.Format("//rd:SharedDataSet/rd:DataSet[@Name=\"\"]/rd:Query/rd:CommandText");
            var nsmgr = new XmlNamespaceManager(docXml.NameTable);

            nsmgr.AddNamespace("rd", root.GetNamespaceOfPrefix(string.Empty));
            var node = docXml.SelectSingleNode(xpath, nsmgr);

            if (node != null)
            {
                var text          = node.InnerText; // We've found the query
                var reportCommand = new ReportCommand()
                {
                    Text = text
                };

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

            throw new ArgumentException(string.Format("Cannot find the command text in the shared dataSet at '{0}'", fullPath));
        }
示例#3
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));
        }