using Microsoft.AspNetCore.Mvc;
using System;
using System.IO;

namespace WebDesigner_CustomSharedDataSources.Implementation
{
    public class HomeController : Controller
    {
        private static readonly DirectoryInfo ResourcesRootDirectory =
            new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "resources"));

        public IActionResult Index()
        {
            var reportPath = Path.Combine(ResourcesRootDirectory.FullName, "test.rdlx");
            var fileInfo = new FileInfo(reportPath);
            using (var pageReport = new GrapeCity.ActiveReports.PageReport(fileInfo))
            {
                try
                {
                    var pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();

                    System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyPDF");
                    outputDirectory.Create();

                    // Set the rendering extension and render the report.
                    var pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
                    GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory,
                            System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
                    outputProvider.OverwriteOutputFile = true;

                    // outputProvider.OverwriteOutputFile = true;
                    pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting);
                   
                }
                catch (Exception ex)
                {
                    throw;
                }
            }

            return View();
        }
    }
}
