Beispiel #1
0
        /// <summary>
        /// main method that runs soap api, take a rdl in report server and change it.
        /// </summary>
        /// <param name="urlEndPoint">The report Server url.</param>
        /// <param name="inputReportPath">The path of input report file.</param>
        /// <param name="outputPath"> The path of output file.</param>
        /// <param name="downloadPath">The path to store original rdl and rds file.</param>
        /// <returns>the output file path.</returns>
        public string RunSoap(string urlEndPoint, string inputReportPath, string outputPath = "./", string downloadPath = "./testFiles/")
        {
            Directory.CreateDirectory(outputPath);
            Directory.CreateDirectory(downloadPath);

            string reportName     = Path.GetFileNameWithoutExtension(inputReportPath);
            string outputFileName = Path.Combine(outputPath, reportName + ReportFileExtension);

            RdlFileIO rdlFileIO = new RdlFileIO(urlEndPoint);

            var rdlFilePath = rdlFileIO.DownloadRdl(inputReportPath, downloadPath);

            XElement[]   dataSets    = rdlFileIO.GetDataSets(inputReportPath, out Dictionary <string, XElement> referenceDataSetMap);
            DataSource[] dataSources = rdlFileIO.GetDataSources(inputReportPath);

            var dataSourceFilePath   = Path.Combine(downloadPath, reportName + DataSourceFileExtension);
            var dataSetDirectoryPath = downloadPath + reportName + "_DataSets";

            rdlFileIO.WriteDataSetContent(dataSets, dataSetDirectoryPath);
            rdlFileIO.WriteDataSourceContent(dataSources, dataSourceFilePath);

            ConvertFile(rdlFilePath, dataSources, referenceDataSetMap, outputPath);

            Console.WriteLine($"Conversion from  {inputReportPath}  to  {outputFileName}  Completed.");
            return(outputFileName);
        }
Beispiel #2
0
        private void ConvertAndUploadReport(PowerBIClientWrapper powerBIClient, RdlFileIO rdlFileIO, string reportPath)
        {
            var reportName = Path.GetFileName(reportPath);
            var report     = rdlFileIO.DownloadRdl(reportPath);

            SaveAndCopyStream(reportName, report, $"output\\{reportName}_original.rdl");

            if (powerBIClient.ExistReport(reportName))
            {
                Trace($"CONFLICT : {reportName}  A report with the same name already exists in the workspace");
            }
            else
            {
                try
                {
                    XElement[]   dataSets    = rdlFileIO.GetDataSets(reportPath, out Dictionary <KeyValuePair <string, string>, XElement> referenceDataSetMap);
                    DataSource[] dataSources = rdlFileIO.GetDataSources(reportPath);

                    var convertedFile = ConvertFile(reportPath, report, dataSources, referenceDataSetMap);
                    SaveAndCopyStream(reportName, convertedFile, $"output\\{reportName}_convert.rdl");

                    powerBIClient.UploadRDL(reportName + ReportFileExtension, convertedFile);

                    Trace($"SUCCESS : {reportName}  The file is successfully uploaded");
                }
                catch (HttpOperationException httpException)
                {
                    string errorMessage;
                    string requestId = String.Empty;
                    if (httpException?.Response?.Headers.ContainsKey("RequestId") == true)
                    {
                        requestId = httpException.Response.Headers["RequestId"].First();
                    }

                    if (httpException.Response.Headers.TryGetValue("X-PowerBI-Error-Details", out IEnumerable <string> returnedJsonStr))
                    {
                        if (returnedJsonStr.Count() != 1)
                        {
                            Trace($"FAILED TO UPLOAD : {reportName} RequestId:{requestId} {httpException.Message}");
                        }
                        else
                        {
                            string jsonString         = returnedJsonStr.First();
                            var    returnedJsonDetail = JObject.Parse(jsonString);
                            errorMessage = returnedJsonDetail["error"]["pbi.error"]["details"][2]["detail"]["value"].Value <string>();
                            Trace($"FAILED TO UPLOAD :  {reportName} RequestId:{requestId} {errorMessage}");
                        }
                    }
                    else
                    {
                        Trace($"FAILED TO UPLOAD : {reportName} RequestId:{requestId} {httpException.Message}");
                    }
                }
                catch (Exception e)
                {
                    Trace($"FAILED : {reportName} {e.Message}");
                }
            }
        }