Beispiel #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;
        }
Beispiel #2
0
 public BuildDocumentHTMLArgs(String path, ProcessingProgress pp)
 {
     this.path = path;
     this.pp = pp;
 }
Beispiel #3
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;
        }
Beispiel #4
0
        /// <summary>
        /// Evaluate the presentation in order to determine the number of operations required for exporting it
        /// </summary>
        /// <param name="presentation">presentation</param>
        /// <param name="pp">processing progress</param>
        /// <returns></returns>
        private int EvaluatePresentation(Presentation presentation, ProcessingProgress pp)
        {
            int numberOfOperations = 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 <= 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);
                }
            }

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName = "Evaluating document";
            pp.CurrentOperationTotalElements = charts.Count;
            pp.CurrentOperationElement = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            //for every chart
            for (int j = 0; j < charts.Count; j++)
            {

                Microsoft.Office.Interop.PowerPoint.Shape chart = charts.ElementAt(j);

                numberOfOperations++;

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

                //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)
                    {
                        numberOfOperations++;
                    }
                }
                else
                {

                    //for every horizontal face
                    for (int k = 0; k < DocumentService.CHART_HORIZONTAL_FACES; k++)
                    {
                        numberOfOperations++;

                        //for every vertical face
                        for (int l = 0; l < DocumentService.CHART_VERTICAL_FACES; l++)
                        {
                            numberOfOperations++;
                        }

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

                            //for every vertical face
                            for (int m = 0; m < DocumentService.CHART_VERTICAL_FACES; m++)
                            {
                                numberOfOperations++;
                            }
                        }
                    }
                }
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = j + 1;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            }
            return numberOfOperations;
        }
Beispiel #5
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;
        }
Beispiel #6
0
        /// <summary>
        /// process a generated html sheet to ensure compatibility with kinesis
        /// it removes all javascript functions
        /// 
        /// modifying an office html generated file, it will cut off the support for all languages, so an UTF-8 character encoding will be forced
        /// </summary>
        /// <param name="path">the full path of the generated html sheet</param>
        private void ProcessSheet(String path, ProcessingProgress pp, int pageNumber)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName = "Page " + pageNumber;
            pp.CurrentOperationTotalElements = 2;
            pp.CurrentOperationElement = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            System.IO.StreamReader fileI = new System.IO.StreamReader(path);
            String content = fileI.ReadToEnd();
            fileI.Close();

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

            System.IO.StreamWriter fileO = new System.IO.StreamWriter(path, false);
            fileO.WriteLine(TrimScript(content));
            fileO.Flush();
            fileO.Close();

            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationElement = 2;
            pp.OverallOperationElement++;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
        }
Beispiel #7
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;
        }
Beispiel #8
0
        private int EvaluateWorkbook(Workbook workbook, ProcessingProgress pp)
        {
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            pp.CurrentOperationName = "Evaluating document";
            pp.CurrentOperationTotalElements = workbook.Sheets.Count;
            pp.CurrentOperationElement = 0;
            //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//

            int numberOfOperations = 0;

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

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

                    //for every chart
                    for (int j = 1; j <= chartObjects.Count; j++)
                    {

                        numberOfOperations++;

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

                        int chartType = GetChartType(chart);

                        //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)
                            {
                                numberOfOperations++;
                            }
                        }
                        else
                        {

                            //for every horizontal face
                            for (int k = 0; k < DocumentService.CHART_HORIZONTAL_FACES; k++)
                            {
                                numberOfOperations++;

                                //for every vertical face
                                for (int l = 0; l < DocumentService.CHART_VERTICAL_FACES; l++)
                                {
                                    numberOfOperations++;
                                }

                                //some chart types, like 3D pie, does not support elevation less than 0
                                if (SupportsNegativeElevation(chart))
                                {
                                    //for every vertical face
                                    for (int m = 0; m < DocumentService.CHART_VERTICAL_FACES; m++)
                                    {
                                        numberOfOperations++;
                                    }
                                }
                            }
                        }
                    }
                }
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
                pp.CurrentOperationElement = i;
                //~~~~~~~~~~~~~progress~~~~~~~~~~~~~//
            }

            return numberOfOperations;
        }
Beispiel #9
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;
        }
Beispiel #10
0
        /// <summary>
        /// Create new Document
        /// </summary>
        /// <param name="path">Source document path</param>
        /// <param name="worker">Who do all the job</param>
        /// <returns>created KineSis document</returns>
        public static Document CreateNewDocument(String path, BackgroundWorker worker)
        {
            Profile profile = ProfileManager.ActiveProfile;

            //update static variables with active profile ones
            DocumentService.SLIDE_WIDTH = profile.SlideWidth;
            DocumentService.TEMP_DIRECTORY = profile.TempFolder;
            DocumentService.CHART_WIDTH = profile.ChartWidth;
            DocumentService.CHART_HORIZONTAL_FACES = profile.ChartHorizontalFaces;
            DocumentService.CHART_VERTICAL_FACES = profile.ChartVerticalFaces;

            //get a helper for parsing document
            FileInfo file = new FileInfo(path);
            DocumentHelper helper = GetHelperForDocument(path);

            if (helper == null)
            {
                return null;
            }

            //create a processing progress
            ProcessingProgress pp = new ProcessingProgress(worker);

            //start parsing
            Document document = null;
            try
            {
                document = helper.ParseNewDocument(path, pp);
            }
            catch (Exception ex)
            {
                pp.OverallOperationName = "[Exception] " + ex.Message;
                //    pp.OverallOperationTotalElements = 1;
                //    MessageBox.Show(ex.Message);
            }
            return document;
        }
Beispiel #11
0
        /// <summary>
        /// After document was parsed, now it's time for charts, processed concurrent with presentation
        /// </summary>
        /// <param name="path">Source document path</param>
        /// <param name="worker">Background Worker</param>
        /// <param name="document">Current KineSis Document</param>
        public static void CreateNewDocumentCharts(String path, BackgroundWorker worker, Document document)
        {
            FileInfo file = new FileInfo(path);

            DocumentHelper helper = GetHelperForDocument(path);

            if (helper != null)
            {
                ProcessingProgress pp = new ProcessingProgress(worker);
                try
                {
                    if (helper is PowerPointDocumentHelper)
                    {
                        PowerPointDocumentHelper h = (PowerPointDocumentHelper)helper;
                        h.ParseNewDocumentCharts(path, pp, document);
                    }
                    else if (helper is ExcelDocumentHelper)
                    {
                        ExcelDocumentHelper h = (ExcelDocumentHelper)helper;
                        h.ParseNewDocumentCharts(path, pp, document);
                    }
                    else if (helper is WordDocumentHelper)
                    {
                        WordDocumentHelper h = (WordDocumentHelper)helper;
                        h.ParseNewDocumentCharts(path, pp, document);
                    }
                }
                catch (Exception ex)
                {
                    pp.OverallOperationName = "[Exception] " + ex.Message;
                    //    pp.OverallOperationTotalElements = 1;
                    //    MessageBox.Show(ex.Message);
                }

                Document.serialize(document, TEMP_DIRECTORY + "\\" + document.Location + ".xml");

                ProfileManager.AddDocumentToActive(document.Name, document.Location);
                ProfileManager.Serialize();
            }
        }
Beispiel #12
0
        /// <summary>
        /// Draw processing progress
        /// </summary>
        /// <param name="canvas">canvas where the progress will be drawn</param>
        /// <param name="pp">active processing progress</param>
        public static void DrawProgress(Canvas canvas, ProcessingProgress pp)
        {
            canvas.Background = ProfileManager.MinimalView ? System.Windows.Media.Brushes.Transparent : ProfileManager.ActiveProfile.BackgroundColor;

            String currentOperationName = pp.CurrentOperationName;
            Double currentOperation = ((Double)pp.CurrentOperationElement * 100 / (Double)pp.CurrentOperationTotalElements);
            String currentOperationProgress = String.Format("{0:00.00}", currentOperation) + " %";

            String overallOperationName = pp.OverallOperationName;
            Double overallOperation = ((Double)pp.OverallOperationElement * 100 / (Double)pp.OverallOperationTotalElements);
            String overallOperationProgress = String.Format("{0:00.00}", overallOperation) + " %";

            canvas.Children.Clear();

            double sixth = canvas.Height / 6;
            double tenth = canvas.Width / 10;

            //current
            System.Windows.Shapes.Rectangle currentOperationOuterRect = new System.Windows.Shapes.Rectangle();
            currentOperationOuterRect.Width = canvas.Width - tenth;
            currentOperationOuterRect.Height = sixth;
            currentOperationOuterRect.Stroke = ProfileManager.ActiveProfile.SecondaryColor;
            currentOperationOuterRect.StrokeThickness = 2;
            currentOperationOuterRect.Fill = ProfileManager.ActiveProfile.BackgroundColor;
            currentOperationOuterRect.Margin = new Thickness(tenth / 2, sixth, 0, 0);

            System.Windows.Shapes.Rectangle currentOperationInnerRect = new System.Windows.Shapes.Rectangle();
            currentOperationInnerRect.Width = ((canvas.Width - tenth - 6) * currentOperation) / 100;
            currentOperationInnerRect.Height = sixth - 6;
            currentOperationInnerRect.Stroke = ProfileManager.ActiveProfile.BackgroundColor;
            currentOperationInnerRect.StrokeThickness = 2;
            currentOperationInnerRect.Fill = ProfileManager.ActiveProfile.SecondaryColor;
            currentOperationInnerRect.Margin = new Thickness((tenth + 6) / 2, sixth + 3, 0, 0);

            TextBlock currentOperationTextBlock = new TextBlock();
            currentOperationTextBlock.Text = currentOperationName + "  [ " + currentOperationProgress + " ]";
            currentOperationTextBlock.Foreground = ProfileManager.ActiveProfile.SecondaryColor;
            currentOperationTextBlock.FontSize = sixth / 1.5;
            currentOperationTextBlock.Width = canvas.Width;
            currentOperationTextBlock.FontFamily = new System.Windows.Media.FontFamily("Century Gothic");

            currentOperationTextBlock.TextAlignment = TextAlignment.Center;

            //overall
            System.Windows.Shapes.Rectangle overallOperationOuterRect = new System.Windows.Shapes.Rectangle();
            overallOperationOuterRect.Width = canvas.Width - tenth;
            overallOperationOuterRect.Height = sixth;
            overallOperationOuterRect.Stroke = ProfileManager.ActiveProfile.PrimaryColor;
            overallOperationOuterRect.StrokeThickness = 2;
            overallOperationOuterRect.Fill = ProfileManager.ActiveProfile.BackgroundColor;
            overallOperationOuterRect.Margin = new Thickness(tenth / 2, 4 * sixth, 0, 0);

            System.Windows.Shapes.Rectangle overallOperationInnerRect = new System.Windows.Shapes.Rectangle();
            overallOperationInnerRect.Width = ProfileManager.MinimalView ? ((canvas.Width - tenth) * overallOperation) / 100 : ((canvas.Width - tenth - 6) * overallOperation) / 100;
            overallOperationInnerRect.Height = ProfileManager.MinimalView ? sixth - 2 : sixth - 6;
            overallOperationInnerRect.Stroke = ProfileManager.ActiveProfile.BackgroundColor;
            overallOperationInnerRect.StrokeThickness = ProfileManager.MinimalView ? 0 : 2;
            overallOperationInnerRect.Fill = ProfileManager.ActiveProfile.PrimaryColor;
            overallOperationInnerRect.Margin = ProfileManager.MinimalView ? new Thickness(tenth / 2 + 1, 4 * sixth + 1, 0, 0) : new Thickness((tenth + 6) / 2, 4 * sixth + 3, 0, 0);

            TextBlock overallOperationTextBlock = new TextBlock();
            overallOperationTextBlock.Text = overallOperationName + "  [ " + overallOperationProgress + " ]";
            overallOperationTextBlock.Foreground = ProfileManager.ActiveProfile.PrimaryColor;
            overallOperationTextBlock.FontSize = sixth / 1.5;
            overallOperationTextBlock.Width = canvas.Width;
            overallOperationTextBlock.Margin = new Thickness(0, 3 * sixth, 0, 0);
            overallOperationTextBlock.FontFamily = new System.Windows.Media.FontFamily("Century Gothic");

            overallOperationTextBlock.TextAlignment = TextAlignment.Center;

            if (!ProfileManager.MinimalView) canvas.Children.Add(currentOperationTextBlock);
            if (!ProfileManager.MinimalView) canvas.Children.Add(currentOperationOuterRect);
            if (!ProfileManager.MinimalView) canvas.Children.Add(currentOperationInnerRect);

            if (!ProfileManager.MinimalView) canvas.Children.Add(overallOperationTextBlock);
            canvas.Children.Add(overallOperationOuterRect);
            canvas.Children.Add(overallOperationInnerRect);
            canvas.UpdateLayout();

            canvas.Refresh();
        }