Ejemplo n.º 1
0
        private static String DOC_FILES = "document_files"; //document_files

        #endregion Fields

        #region Methods

        Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "Document";
            pp.OverallOperationTotalElements = 2;
            pp.OverallOperationElement = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //directory where all the data will be saved
            String folderName = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);
            System.IO.Directory.CreateDirectory(documentPath);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationElement = 1;
            pp.CurrentOperationName = "Opening";
            pp.CurrentOperationTotalElements = 2;
            pp.CurrentOperationElement = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            Document document = new Document();
            document.Name = path.Substring(path.LastIndexOf(DD) + 1);
            document.Location = folderName;

            //write directory for pages
            String pagesPath = System.IO.Path.Combine(documentPath + DD + DOC_FILES);
            System.IO.Directory.CreateDirectory(pagesPath);

            Page page = new Page();
            page.Name = document.Name;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            pp.OverallOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //location where the page is generated
            page.Location = WriteTextDocument(path, documentPath + DD + DOC_FILES + DD + DOCUMENT_HTML);
            document.Pages.Add(page);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 2;
            pp.OverallOperationElement = 2;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //return the built document
            return document;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// parse an excel document and build a kinesis document model
        /// </summary>
        /// <param name="path">full path of the excel document</param>
        /// <returns>equivalent kinesis document model</returns>
        Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            OpenOfficeApplication();

            //directory where all the data will be saved
            String folderName   = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            System.IO.Directory.CreateDirectory(documentPath);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Opening MS Office";
            pp.CurrentOperationTotalElements = 2;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //open the given excel document
            Workbook workbook = excelApplication.Workbooks.Open(path, ReadOnly: true);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            pp.CurrentOperationName    = "Saving pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //create a new internal document
            Document document = new Document();

            document.Name = workbook.Name;

            //save excel document as html
            workbook.SaveAs(System.IO.Path.Combine(documentPath, "document.html"), XlFileFormat.xlHtml);

            //original document location
            document.Location = folderName;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement       = 2;
            pp.OverallOperationTotalElements = workbook.Sheets.Count + 1;
            pp.OverallOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //for every sheet
            for (int i = 1; i <= workbook.Sheets.Count; i++)
            {
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationName          = "Page " + i;
                pp.CurrentOperationTotalElements = 1;
                pp.CurrentOperationElement       = 0;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                Worksheet worksheet = workbook.Sheets[i];

                //create a new page
                KineSis.ContentManagement.Model.Page page = new KineSis.ContentManagement.Model.Page();
                page.Name = worksheet.Name;

                //standard export location of ms excel when exporting as html
                page.Location = documentPath + DD + DOC_FILES + DD + "sheet" + GetSheetNumber(i) + ".html";


                //add page to the document
                document.Pages.Add(page);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 1;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            }

            //close workbook without saving any possible changes (this way the "Are you sure?" or "Save changes?" dialogs will be supressed)
            workbook.Close(SaveChanges: false);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationElement++;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //every generated page contains several javascript functions which facilitate navigation between sheets and other unnecessary stuff
            //this is an impediment for kinesis web browser, because will block the programatic scrolling
            //get every generated page and remove javascripts

            int pageNumber = 1;

            foreach (KineSis.ContentManagement.Model.Page p in document.Pages)
            {
                ProcessSheet(p.Location, pp, pageNumber++);
            }

            //return the built document
            return(document);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// parse an excel document and build a kinesis document model
        /// </summary>
        /// <param name="path">full path of the excel document</param>
        /// <returns>equivalent kinesis document model</returns>
        public Document ParseNewDocumentCharts(String path, ProcessingProgress pp, Document document)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Charts";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //directory where all the data will be saved
            String folderName   = document.Location;
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Opening MS Office";
            pp.CurrentOperationTotalElements = 1;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //open the given excel document
            Workbook workbook = excelApplication.Workbooks.Open(path, ReadOnly: true);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement       = 1;
            pp.OverallOperationTotalElements = EvaluateWorkbook(workbook, pp);
            pp.OverallOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //for every sheet
            for (int i = 1; i <= workbook.Sheets.Count; i++)
            {
                Worksheet worksheet = workbook.Sheets[i];

                //create a new page
                KineSis.ContentManagement.Model.Page page = document.Pages[i - 1];

                //check if chart generation is wanted
                if (DocumentService.CHART_HORIZONTAL_FACES > 0)
                {
                    //get charts
                    ChartObjects chartObjects = worksheet.ChartObjects(Type.Missing);

                    //create directory for charts
                    String chartPath = System.IO.Path.Combine(documentPath, "charts");
                    System.IO.Directory.CreateDirectory(chartPath);

                    //for every chart
                    for (int j = 1; j <= chartObjects.Count; j++)
                    {
                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                        pp.CurrentOperationName          = "Page " + i + " / Chart " + j + " of " + chartObjects.Count;
                        pp.CurrentOperationTotalElements = EvaluateChart(chartObjects.Item(j).Chart);
                        pp.CurrentOperationElement       = 0;
                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                        KineSis.ContentManagement.Model.Chart mChart = new KineSis.ContentManagement.Model.Chart();

                        //current chart
                        Microsoft.Office.Interop.Excel.Chart chart = chartObjects.Item(j).Chart;

                        mChart.SetThumbnailUrl(GenerateThumbnail(chart, chartPath + DD + i + _ + j + "_thumb"));

                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                        pp.OverallOperationElement++;
                        pp.CurrentOperationElement++;
                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                        if (DocumentService.FORCE_CHART_SIZE)
                        {
                            chart.ChartArea.Height = ((float)DocumentService.CHART_WIDTH * chart.ChartArea.Height) / chart.ChartArea.Width;
                            chart.ChartArea.Width  = DocumentService.CHART_WIDTH;
                        }

                        int chartType = GetChartType(chart);

                        //start from 0 point
                        chart.Rotation = 0;

                        int horizontalAngle = 0;

                        //depending on how many horizontal faces are required, calculate the angle between them
                        if (DocumentService.CHART_HORIZONTAL_FACES > 0)
                        {
                            horizontalAngle = 360 / DocumentService.CHART_HORIZONTAL_FACES;
                        }

                        int verticalAngle = 0;

                        //depending on how many vertical faces are required for a horizontal face, celaculate the angle between them, excluding the vertical face at 90 degrees
                        if (DocumentService.CHART_VERTICAL_FACES > 0)
                        {
                            verticalAngle = 90 / (DocumentService.CHART_VERTICAL_FACES + 1);
                        }

                        if (chart.HasTitle)
                        {
                            mChart.Title = chart.ChartTitle.Caption;
                        }
                        else
                        {
                            mChart.Title = chart.Name;
                        }

                        //does not support rotation (it's plain)
                        if (chartType == 0)
                        {
                            //if horizontal faces number is 0, then no chart will be outputed
                            if (DocumentService.CHART_HORIZONTAL_FACES > 0)
                            {
                                ChartHorizontalView hView = new ChartHorizontalView();

                                //draw chart face as image
                                chart.Export(chartPath + DD + i + _ + j + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FILTER, false);
                                //add to hView
                                hView.ImageUrl = chartPath + DD + i + _ + j + DocumentService.IMAGE_EXTENSION;
                                //add to views
                                mChart.Views.Add(hView);

                                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                pp.OverallOperationElement++;
                                pp.CurrentOperationElement++;
                                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                            }
                        }
                        else
                        {
                            //for every horizontal face
                            for (int k = 0; k < DocumentService.CHART_HORIZONTAL_FACES; k++)
                            {
                                ChartHorizontalView hView = new ChartHorizontalView();
                                //reset elevation
                                chart.Elevation = 0;
                                //export face as image

                                chart.Export(chartPath + DD + i + _ + j + _ + chart.Rotation + _ + chart.Elevation + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FILTER, false);
                                //set bitmap to view
                                hView.ImageUrl = chartPath + DD + i + _ + j + _ + chart.Rotation + _ + chart.Elevation + DocumentService.IMAGE_EXTENSION;

                                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                pp.OverallOperationElement++;
                                pp.CurrentOperationElement++;
                                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                                //for every vertical face
                                for (int l = 0; l < DocumentService.CHART_VERTICAL_FACES; l++)
                                {
                                    ChartVerticalView vView = new ChartVerticalView();
                                    //increse elevation
                                    chart.Elevation += verticalAngle;
                                    //export face as image
                                    chart.Export(chartPath + DD + i + _ + j + _ + chart.Rotation + _ + chart.Elevation + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FILTER, false);

                                    //set bitmap to view
                                    vView.ImageUrl = chartPath + DD + i + _ + j + _ + chart.Rotation + _ + chart.Elevation + DocumentService.IMAGE_EXTENSION;
                                    //add vertical view to horizontal UP list
                                    hView.Up.Add(vView);

                                    //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                    pp.OverallOperationElement++;
                                    pp.CurrentOperationElement++;
                                    //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                }

                                //some chart types, like 3D pie, does not support elevation less than 0
                                if (SupportsNegativeElevation(chart))
                                {
                                    //reset elevation
                                    chart.Elevation = 0;

                                    //for every vertical face
                                    for (int m = 0; m < DocumentService.CHART_VERTICAL_FACES; m++)
                                    {
                                        ChartVerticalView vView = new ChartVerticalView();

                                        //decrease elevation
                                        chart.Elevation -= verticalAngle;
                                        //export face as image
                                        chart.Export(chartPath + DD + i + _ + j + _ + chart.Rotation + _ + chart.Elevation + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FILTER, false);
                                        //set bitmap to vertical view
                                        vView.ImageUrl = chartPath + DD + i + _ + j + _ + chart.Rotation + _ + chart.Elevation + DocumentService.IMAGE_EXTENSION;
                                        //add vertical view to horizontal view DOWN list
                                        hView.Down.Add(vView);

                                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                        pp.OverallOperationElement++;
                                        pp.CurrentOperationElement++;
                                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                    }
                                }

                                //increase horizontal angle in order to get the next horizontal view
                                chart.Rotation += horizontalAngle;
                                //add horizontal view to the chat's views list
                                mChart.Views.Add(hView);
                            }
                        }

                        //add chart to page
                        page.Charts.Add(mChart);
                    }
                }
            }

            //close workbook without saving any possible changes (this way the "Are you sure?" or "Save changes?" dialogs will be supressed)
            workbook.Close(SaveChanges: false);

            CloseOfficeApplication();

            //return the built document
            return(document);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// parse a word document and build a kinesis document model
        /// </summary>
        /// <param name="path">full path of the word document</param>
        /// <returns>equivalent kinesis document model</returns>
        KineSis.ContentManagement.Model.Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            OpenOfficeApplication();

            //directory where all the data will be saved
            String folderName = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);
            System.IO.Directory.CreateDirectory(documentPath);

            // Make this instance of word invisible (Can still see it in the taskmgr).
            wordApplication.Visible = false;

            // Interop requires objects.
            object oMissing = System.Reflection.Missing.Value;
            object isVisible = false;
            object readOnly = false;
            object oInput = path;
            object oOutput = documentPath + DD + DOC_FILES + DD + "document.xps";
            object oFormat = WdSaveFormat.wdFormatXPS;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName = "Opening MS Office";
            pp.CurrentOperationTotalElements = 1;
            pp.CurrentOperationElement = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            // Load a document into our instance of word.exe
            Microsoft.Office.Interop.Word._Document wdoc = wordApplication.Documents.Open(ref oInput, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            // Make this document the active document.
            wdoc.Activate();

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            KineSis.ContentManagement.Model.Document document = new KineSis.ContentManagement.Model.Document();
            document.Name = wdoc.Name;
            document.Location = folderName;

            //write directory for pages
            String pagesPath = documentPath + DD + DOC_FILES;
            System.IO.Directory.CreateDirectory(pagesPath);

            //create a new page
            KineSis.ContentManagement.Model.Page page = new KineSis.ContentManagement.Model.Page();
            page.Name = wdoc.Name;
            page.Location = documentPath + DD + DOC_FILES + DD + "document.html";

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName = "Saving document";
            pp.CurrentOperationTotalElements = 2;
            pp.CurrentOperationElement = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            // Save this document in XPS format.
            wdoc.SaveAs(ref oOutput, ref oFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            wdoc.Close(SaveChanges: false);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 2;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            try
            {
                wdoc.Close(SaveChanges: false);
            }
            catch (Exception)
            {
            }
            //CloseOfficeApplication();
            //wordApplication.Quit(ref oMissing, ref oMissing, ref oMissing);

            BuildDocumentHTMLArgs args = new BuildDocumentHTMLArgs(documentPath + DD + DOC_FILES, pp);

            Thread thread = new Thread(new ParameterizedThreadStart(BuildDocumentHTML));
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start(args);
            thread.Join();

            //build a html page from saved xps
            //BuildDocumentHTML(documentPath + DD + DOC_FILES, pp);

            //add page to document model
            document.Pages.Add(page);

            //delete the generated xps file
            FileInfo fi = new FileInfo(documentPath + DD + DOC_FILES + DD + "document.xps");
            fi.Delete();

            //return built document
            return document;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// parse an excel document and build a kinesis document model
        /// </summary>
        /// <param name="path">full path of the excel document</param>
        /// <returns>equivalent kinesis document model</returns>
        Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            OpenOfficeApplication();

            //directory where all the data will be saved
            String folderName = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);
            System.IO.Directory.CreateDirectory(documentPath);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName = "Opening MS Office";
            pp.CurrentOperationTotalElements = 2;
            pp.CurrentOperationElement = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //open the given excel document
            Workbook workbook = excelApplication.Workbooks.Open(path, ReadOnly: true);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            pp.CurrentOperationName = "Saving pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //create a new internal document
            Document document = new Document();
            document.Name = workbook.Name;

            //save excel document as html
            workbook.SaveAs(System.IO.Path.Combine(documentPath, "document.html"), XlFileFormat.xlHtml);

            //original document location
            document.Location = folderName;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 2;
            pp.OverallOperationTotalElements = workbook.Sheets.Count + 1;
            pp.OverallOperationElement = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //for every sheet
            for (int i = 1; i <= workbook.Sheets.Count; i++)
            {

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationName = "Page " + i;
                pp.CurrentOperationTotalElements = 1;
                pp.CurrentOperationElement = 0;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                Worksheet worksheet = workbook.Sheets[i];

                //create a new page
                KineSis.ContentManagement.Model.Page page = new KineSis.ContentManagement.Model.Page();
                page.Name = worksheet.Name;

                //standard export location of ms excel when exporting as html
                page.Location = documentPath + DD + DOC_FILES + DD + "sheet" + GetSheetNumber(i) + ".html";

                //add page to the document
                document.Pages.Add(page);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 1;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            }

            //close workbook without saving any possible changes (this way the "Are you sure?" or "Save changes?" dialogs will be supressed)
            workbook.Close(SaveChanges: false);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationElement++;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //every generated page contains several javascript functions which facilitate navigation between sheets and other unnecessary stuff
            //this is an impediment for kinesis web browser, because will block the programatic scrolling
            //get every generated page and remove javascripts

            int pageNumber = 1;

            foreach (KineSis.ContentManagement.Model.Page p in document.Pages)
            {
                ProcessSheet(p.Location, pp, pageNumber++);
            }

            //return the built document
            return document;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// parse a word document and build a kinesis document model
        /// </summary>
        /// <param name="path">full path of the word document</param>
        /// <returns>equivalent kinesis document model</returns>
        KineSis.ContentManagement.Model.Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            OpenOfficeApplication();


            //directory where all the data will be saved
            String folderName   = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            System.IO.Directory.CreateDirectory(documentPath);

            // Make this instance of word invisible (Can still see it in the taskmgr).
            wordApplication.Visible = false;

            // Interop requires objects.
            object oMissing  = System.Reflection.Missing.Value;
            object isVisible = false;
            object readOnly  = false;
            object oInput    = path;
            object oOutput   = documentPath + DD + DOC_FILES + DD + "document.xps";
            object oFormat   = WdSaveFormat.wdFormatXPS;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Opening MS Office";
            pp.CurrentOperationTotalElements = 1;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            // Load a document into our instance of word.exe
            Microsoft.Office.Interop.Word._Document wdoc = wordApplication.Documents.Open(ref oInput, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            // Make this document the active document.
            wdoc.Activate();

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            KineSis.ContentManagement.Model.Document document = new KineSis.ContentManagement.Model.Document();
            document.Name     = wdoc.Name;
            document.Location = folderName;

            //write directory for pages
            String pagesPath = documentPath + DD + DOC_FILES;

            System.IO.Directory.CreateDirectory(pagesPath);

            //create a new page
            KineSis.ContentManagement.Model.Page page = new KineSis.ContentManagement.Model.Page();
            page.Name     = wdoc.Name;
            page.Location = documentPath + DD + DOC_FILES + DD + "document.html";

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Saving document";
            pp.CurrentOperationTotalElements = 2;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            // Save this document in XPS format.
            wdoc.SaveAs(ref oOutput, ref oFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            wdoc.Close(SaveChanges: false);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 2;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            try
            {
                wdoc.Close(SaveChanges: false);
            }
            catch (Exception)
            {
            }
            //CloseOfficeApplication();
            //wordApplication.Quit(ref oMissing, ref oMissing, ref oMissing);

            BuildDocumentHTMLArgs args = new BuildDocumentHTMLArgs(documentPath + DD + DOC_FILES, pp);

            Thread thread = new Thread(new ParameterizedThreadStart(BuildDocumentHTML));

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start(args);
            thread.Join();

            //build a html page from saved xps
            //BuildDocumentHTML(documentPath + DD + DOC_FILES, pp);

            //add page to document model
            document.Pages.Add(page);

            //delete the generated xps file
            FileInfo fi = new FileInfo(documentPath + DD + DOC_FILES + DD + "document.xps");

            fi.Delete();

            //return built document
            return(document);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// parse a word document and build a kinesis document model
        /// </summary>
        /// <param name="path">full path of the word document</param>
        /// <returns>equivalent kinesis document model</returns>
        public KineSis.ContentManagement.Model.Document ParseNewDocumentCharts(String path, ProcessingProgress pp, KineSis.ContentManagement.Model.Document document)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Charts";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //directory where all the data will be saved
            String folderName   = document.Location;
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            // Make this instance of word invisible (Can still see it in the taskmgr).
            wordApplication.Visible = false;

            // Interop requires objects.
            object oMissing  = System.Reflection.Missing.Value;
            object isVisible = false;
            object readOnly  = false;
            object oInput    = path;
            object oOutput   = documentPath + DD + DOC_FILES + DD + "document.xps";
            object oFormat   = WdSaveFormat.wdFormatXPS;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Opening MS Office";
            pp.CurrentOperationTotalElements = 1;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            // Load a document into our instance of word.exe
            Microsoft.Office.Interop.Word._Document wdoc = wordApplication.Documents.Open(ref oInput, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            // Make this document the active document.
            wdoc.Activate();

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 1;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //KineSis.ContentManagement.Model.Document document = new KineSis.ContentManagement.Model.Document();
            document.Name     = wdoc.Name;
            document.Location = folderName;

            //create a new page
            KineSis.ContentManagement.Model.Page page = document.Pages[0];


            //check if chart generation is wanted
            if (DocumentService.CHART_HORIZONTAL_FACES > 0)
            {
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationName          = "Transforming";
                pp.CurrentOperationTotalElements = 4;
                pp.CurrentOperationElement       = 0;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                Thread thread = new Thread(new ThreadStart(ClearClipboard));
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Join();

                //handle the charts
                wdoc.Shapes.SelectAll();

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 1;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                wdoc.ActiveWindow.Selection.Copy(); //copy all shapes

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 2;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //open a new powerpoint application
                Presentation presentation = powerPointApplication.Presentations.Add();

                //paste all copied shapes
                presentation.SlideMaster.Shapes.Paste();

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 3;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //clear the clipboard
                //Clipboard.Clear();
                Thread thread1 = new Thread(new ThreadStart(ClearClipboard));
                thread1.SetApartmentState(ApartmentState.STA);
                thread1.Start();
                thread1.Join();

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 4;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                List <Microsoft.Office.Interop.PowerPoint.Shape> charts = new List <Microsoft.Office.Interop.PowerPoint.Shape>();

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.OverallOperationTotalElements = EvaluatePresentation(presentation, pp);
                pp.OverallOperationElement       = 0;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //get all charts
                for (int j = 1; j <= presentation.SlideMaster.Shapes.Count; j++)
                {
                    Microsoft.Office.Interop.PowerPoint.Shape shape = presentation.SlideMaster.Shapes[j];
                    if (shape.HasChart == Microsoft.Office.Core.MsoTriState.msoTrue)
                    {
                        charts.Add(shape);
                    }
                }

                //create directory for charts
                String chartPath = System.IO.Path.Combine(documentPath, "charts");
                System.IO.Directory.CreateDirectory(chartPath);

                //for every chart
                for (int j = 0; j < charts.Count; j++)
                {
                    //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                    pp.CurrentOperationName          = "Chart " + (j + 1) + " of " + charts.Count;
                    pp.CurrentOperationTotalElements = EvaluateChart(charts.ElementAt(j).Chart);
                    pp.CurrentOperationElement       = 0;
                    //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                    KineSis.ContentManagement.Model.Chart     mChart = new KineSis.ContentManagement.Model.Chart();
                    Microsoft.Office.Interop.PowerPoint.Shape chart  = charts.ElementAt(j);

                    mChart.SetThumbnailUrl(GenerateThumbnail(chart, chartPath + DD + j + "_thumb"));

                    //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                    pp.OverallOperationElement++;
                    pp.CurrentOperationElement++;
                    //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                    //set preferred width and height
                    chart.Height = ((float)DocumentService.CHART_WIDTH * chart.Height) / chart.Width;
                    chart.Width  = DocumentService.CHART_WIDTH;

                    //get chart type
                    int chartType = GetChartType(chart.Chart);

                    //reset rotation
                    chart.Chart.Rotation = 0;

                    int horizontalAngle = 0;

                    //depending on how many horizontal faces are required, calculate the angle between them
                    if (DocumentService.CHART_HORIZONTAL_FACES > 0)
                    {
                        horizontalAngle = 360 / DocumentService.CHART_HORIZONTAL_FACES;
                    }

                    int verticalAngle = 0;

                    //depending on how many vertical faces are required for a horizontal face, celaculate the angle between them, excluding the vertical face at 90 degrees
                    if (DocumentService.CHART_VERTICAL_FACES > 0)
                    {
                        verticalAngle = 90 / (DocumentService.CHART_VERTICAL_FACES + 1);
                    }

                    if (chart.Chart.HasTitle)
                    {
                        mChart.Title = chart.Chart.ChartTitle.Caption;
                    }
                    else
                    {
                        mChart.Title = chart.Name;
                    }

                    //does not support rotation (it's plain)
                    if (chartType == 0)
                    {
                        //if horizontal faces number is 0, then no chart will be outputed
                        if (DocumentService.CHART_HORIZONTAL_FACES > 0)
                        {
                            ChartHorizontalView hView = new ChartHorizontalView();
                            //draw chart face as image
                            chart.Export(chartPath + DD + j + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FORMAT);
                            //add to hView
                            hView.ImageUrl = chartPath + DD + j + DocumentService.IMAGE_EXTENSION;
                            //add to views
                            mChart.Views.Add(hView);

                            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                            pp.OverallOperationElement++;
                            pp.CurrentOperationElement++;
                            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                        }
                    }
                    else
                    {
                        //for every horizontal face
                        for (int k = 0; k < DocumentService.CHART_HORIZONTAL_FACES; k++)
                        {
                            ChartHorizontalView hView = new ChartHorizontalView();
                            //reset elevation
                            chart.Chart.Elevation = 0;
                            //export face as image
                            chart.Export(chartPath + DD + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FORMAT);
                            //set bitmap to view
                            hView.ImageUrl = chartPath + DD + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION;

                            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                            pp.OverallOperationElement++;
                            pp.CurrentOperationElement++;
                            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                            //for every vertical face
                            for (int l = 0; l < DocumentService.CHART_VERTICAL_FACES; l++)
                            {
                                ChartVerticalView vView = new ChartVerticalView();

                                //increse elevation
                                chart.Chart.Elevation += verticalAngle;
                                //export face as image
                                chart.Export(chartPath + DD + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FORMAT);
                                //set bitmap to view
                                vView.ImageUrl = chartPath + DD + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION;
                                //add vertical view to horizontal UP list
                                hView.Up.Add(vView);

                                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                pp.OverallOperationElement++;
                                pp.CurrentOperationElement++;
                                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                            }

                            //some chart types, like 3D pie, does not support elevation less than 0
                            if (SupportsNegativeElevation(chart.Chart))
                            {
                                //reset elevation
                                chart.Chart.Elevation = 0;

                                //for every vertical face
                                for (int m = 0; m < DocumentService.CHART_VERTICAL_FACES; m++)
                                {
                                    ChartVerticalView vView = new ChartVerticalView();

                                    //decrease elevation
                                    chart.Chart.Elevation -= verticalAngle;
                                    //export face as image
                                    chart.Export(chartPath + DD + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FORMAT);
                                    //set bitmap to vertical view
                                    vView.ImageUrl = chartPath + DD + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION;
                                    //add vertical view to horizontal view DOWN list
                                    hView.Down.Add(vView);

                                    //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                    pp.OverallOperationElement++;
                                    pp.CurrentOperationElement++;
                                    //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                }
                            }
                            //increase horizontal angle in order to get the next horizontal view
                            chart.Chart.Rotation += horizontalAngle;
                            //add horizontal view to the chat's views list
                            mChart.Views.Add(hView);
                        }
                    }
                    //add chart to page
                    page.Charts.Add(mChart);
                }

                //close presentation
                presentation.Close();
            }

            wdoc.Close(SaveChanges: false);

            CloseOfficeApplication();

            //return built document
            return(document);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// parse a power point document and build a kinesis document model
        /// </summary>
        /// <param name="path">full path of the power point document</param>
        /// <param name="pp">processing progress reporter</param>
        /// <returns>equivalent kinesis document model</returns>
        Document DocumentHelper.ParseNewDocument(String path, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Pages";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            OpenOfficeApplication();

            //directory where all the data will be saved
            String folderName   = DocumentUtil.GenerateDirectoryName();
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            System.IO.Directory.CreateDirectory(documentPath);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Opening MS Office";
            pp.CurrentOperationTotalElements = 1;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //open the presentation
            Presentation presentation = powerPointApplication.Presentations.Open(path, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);

            Document document = new Document();

            document.Name     = presentation.Name;
            document.Location = folderName;

            //write directory for pages
            String pagesPath = System.IO.Path.Combine(documentPath + DD + DOC_FILES);

            System.IO.Directory.CreateDirectory(pagesPath);

            int H = (int)(DocumentService.SLIDE_WIDTH * presentation.SlideMaster.Height / presentation.SlideMaster.Width);
            int W = DocumentService.SLIDE_WIDTH;

            int T_H = (int)(DocumentService.THUMB_WIDTH * H / W);
            int T_W = DocumentService.THUMB_WIDTH;

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement       = 1;
            pp.OverallOperationTotalElements = presentation.Slides.Count;
            pp.OverallOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //for every slide
            for (int i = 1; i <= presentation.Slides.Count; i++)
            {
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationName          = "Page " + i;
                pp.CurrentOperationTotalElements = 4;
                pp.CurrentOperationElement       = 0;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //get slide
                Slide slide = presentation.Slides[i];

                //create a new page
                KineSis.ContentManagement.Model.Page page = new KineSis.ContentManagement.Model.Page();
                page.Name = slide.Name;

                //export the slide as image
                slide.Export(documentPath + DD + DOC_FILES + DD + SLIDE + i + ImageUtil.PNG_EXTENSION, ImageUtil.PNG_FILTER, W, H);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 1;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //export the slide as image
                slide.Export(documentPath + DD + DOC_FILES + DD + SLIDE + i + "_thumb" + ImageUtil.PNG_EXTENSION, ImageUtil.PNG_FILTER, T_W, T_H);

                page.SetThumbnailUrl(documentPath + DD + DOC_FILES + DD + SLIDE + i + "_thumb" + ImageUtil.PNG_EXTENSION);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 2;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //html page location, including the no-zoom version
                page.Location = GenerateHtmlPage(documentPath + DD + DOC_FILES + DD + SLIDE + i);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 3;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                page.LocationNoZoom = GenerateHtmlPageNoZoom(documentPath + DD + DOC_FILES + DD + SLIDE + i);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = 4;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                //add page to document model
                document.Pages.Add(page);

                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.OverallOperationElement = i;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            }

            //close presentation
            presentation.Close();

            //return built document
            return(document);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// parse a power point document and export all charts and shapes
        /// </summary>
        /// <param name="path">full path of the power point document</param>
        /// <returns>equivalent kinesis document model</returns>
        public Document ParseNewDocumentCharts(String path, ProcessingProgress pp, Document document)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.OverallOperationName = "All Document Charts and Shapes";
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //directory where all the data will be saved
            String folderName   = document.Location;
            String documentPath = System.IO.Path.Combine(DocumentService.TEMP_DIRECTORY, folderName);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName          = "Opening MS Office";
            pp.CurrentOperationTotalElements = 1;
            pp.CurrentOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //open the presentation
            Presentation presentation = powerPointApplication.Presentations.Open(path, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement       = 1;
            pp.OverallOperationTotalElements = EvaluatePresentation(presentation, pp);
            pp.OverallOperationElement       = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //for every slide
            for (int i = 1; i <= presentation.Slides.Count; i++)
            {
                //get slide
                Slide slide = presentation.Slides[i];

                //create a new page
                KineSis.ContentManagement.Model.Page page = document.Pages[i - 1];

                //check if chart generation is wanted
                if (DocumentService.CHART_HORIZONTAL_FACES > 0)
                {
                    List <Microsoft.Office.Interop.PowerPoint.Shape> charts = new List <Microsoft.Office.Interop.PowerPoint.Shape>();

                    //get all shapes and charts
                    for (int j = 1; j <= slide.Shapes.Count; j++)
                    {
                        Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[j];
                        if (shape.HasChart == Microsoft.Office.Core.MsoTriState.msoTrue)
                        {
                            charts.Add(shape);
                        }
                    }

                    //create directory for charts
                    String chartPath = System.IO.Path.Combine(documentPath, "charts");
                    System.IO.Directory.CreateDirectory(chartPath);

                    //for every chart
                    for (int j = 0; j < charts.Count; j++)
                    {
                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                        pp.CurrentOperationName          = "Page " + i + " / Chart " + (j + 1) + " of " + charts.Count;
                        pp.CurrentOperationTotalElements = EvaluateChart(charts.ElementAt(j).Chart);
                        pp.CurrentOperationElement       = 0;
                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                        KineSis.ContentManagement.Model.Chart     mChart = new KineSis.ContentManagement.Model.Chart();
                        Microsoft.Office.Interop.PowerPoint.Shape chart  = charts.ElementAt(j);

                        mChart.SetThumbnailUrl(GenerateThumbnail(chart, chartPath + DD + i + _ + j + "_thumb"));

                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                        pp.OverallOperationElement++;
                        pp.CurrentOperationElement++;
                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                        //set preferred width and height
                        chart.Height = ((float)DocumentService.CHART_WIDTH * chart.Height) / chart.Width;
                        chart.Width  = DocumentService.CHART_WIDTH;

                        //get chart type
                        int chartType = GetChartType(chart.Chart);

                        //reset rotation
                        chart.Chart.Rotation = 0;

                        int horizontalAngle = 0;

                        //depending on how many horizontal faces are required, calculate the angle between them
                        if (DocumentService.CHART_HORIZONTAL_FACES > 0)
                        {
                            horizontalAngle = 360 / DocumentService.CHART_HORIZONTAL_FACES;
                        }

                        int verticalAngle = 0;

                        //depending on how many vertical faces are required for a horizontal face, celaculate the angle between them, excluding the vertical face at 90 degrees
                        if (DocumentService.CHART_VERTICAL_FACES > 0)
                        {
                            verticalAngle = 90 / (DocumentService.CHART_VERTICAL_FACES + 1);
                        }

                        if (chart.Chart.HasTitle)
                        {
                            mChart.Title = chart.Chart.ChartTitle.Caption;
                        }
                        else
                        {
                            mChart.Title = chart.Name;
                        }

                        //does not support rotation (it's plain)
                        if (chartType == 0)
                        {
                            //if horizontal faces number is 0, then no chart will be outputed
                            if (DocumentService.CHART_HORIZONTAL_FACES > 0)
                            {
                                ChartHorizontalView hView = new ChartHorizontalView();
                                //draw chart face as image
                                chart.Export(chartPath + DD + i + _ + j + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FORMAT);
                                //add to hView
                                hView.ImageUrl = chartPath + DD + i + _ + j + DocumentService.IMAGE_EXTENSION;
                                //add to views
                                mChart.Views.Add(hView);

                                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                pp.OverallOperationElement++;
                                pp.CurrentOperationElement++;
                                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                            }
                        }
                        else
                        {
                            //for every horizontal face
                            for (int k = 0; k < DocumentService.CHART_HORIZONTAL_FACES; k++)
                            {
                                ChartHorizontalView hView = new ChartHorizontalView();
                                //reset elevation
                                chart.Chart.Elevation = 0;
                                //export face as image
                                chart.Export(chartPath + DD + i + _ + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FORMAT);
                                //set bitmap to view
                                hView.ImageUrl = chartPath + DD + i + _ + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION;

                                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                pp.OverallOperationElement++;
                                pp.CurrentOperationElement++;
                                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

                                //for every vertical face
                                for (int l = 0; l < DocumentService.CHART_VERTICAL_FACES; l++)
                                {
                                    ChartVerticalView vView = new ChartVerticalView();

                                    //increse elevation
                                    chart.Chart.Elevation += verticalAngle;
                                    //export face as image
                                    chart.Export(chartPath + DD + i + _ + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FORMAT);
                                    //set bitmap to view
                                    vView.ImageUrl = chartPath + DD + i + _ + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION;
                                    //add vertical view to horizontal UP list
                                    hView.Up.Add(vView);

                                    //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                    pp.OverallOperationElement++;
                                    pp.CurrentOperationElement++;
                                    //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                }

                                //some chart types, like 3D pie, does not support elevation less than 0
                                if (SupportsNegativeElevation(chart.Chart))
                                {
                                    //reset elevation
                                    chart.Chart.Elevation = 0;

                                    //for every vertical face
                                    for (int m = 0; m < DocumentService.CHART_VERTICAL_FACES; m++)
                                    {
                                        ChartVerticalView vView = new ChartVerticalView();

                                        //decrease elevation
                                        chart.Chart.Elevation -= verticalAngle;
                                        //export face as image
                                        chart.Export(chartPath + DD + i + _ + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION, DocumentService.IMAGE_FORMAT);
                                        //set bitmap to vertical view
                                        vView.ImageUrl = chartPath + DD + i + _ + j + _ + chart.Chart.Rotation + _ + chart.Chart.Elevation + DocumentService.IMAGE_EXTENSION;
                                        //add vertical view to horizontal view DOWN list
                                        hView.Down.Add(vView);

                                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                        pp.OverallOperationElement++;
                                        pp.CurrentOperationElement++;
                                        //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                                    }
                                }

                                //increase horizontal angle in order to get the next horizontal view
                                chart.Chart.Rotation += horizontalAngle;
                                //add horizontal view to the chat's views list
                                mChart.Views.Add(hView);
                            }
                        }

                        //add chart to page
                        page.Charts.Add(mChart);
                    }
                }
            }

            //close presentation
            presentation.Close();

            CloseOfficeApplication();

            //return built document
            return(document);
        }