public void ShapeSheet_Writer_ResultsInt_SingleShape()
        {
            var page1  = this.GetNewPage();
            var shape1 = page1.DrawRectangle(0, 0, 1, 1);

            // Setup the modifications to the cell values
            var writer = new SrcWriter();

            writer.SetValue(LinePattern, 7);

            writer.CommitResults(shape1);

            // Build the query
            var query       = new CellQuery();
            var col_linepat = query.Columns.Add(LinePattern, nameof(LinePattern));

            // Retrieve the values
            var data_formulas = query.GetFormulas(shape1);
            var data_results  = query.GetResults <double>(shape1);

            int rownum = 0;

            // Verify
            Assert.AreEqual("7", data_formulas[rownum][col_linepat]);
            Assert.AreEqual(7, data_results[rownum][col_linepat]);
            page1.Delete(0);
        }
        public void Check_Consistent_ResultTypes()
        {
            var page1  = this.GetNewPage();
            var shape1 = page1.DrawRectangle(0, 0, 1, 1);

            // Setup the modifications to the cell values
            var writer = new SrcWriter();

            writer.SetResult(LinePattern, "7");
            writer.SetResult(XFormPinX, 2);
            writer.Commit(shape1);

            // Build the query
            var query       = new CellQuery();
            var col_linepat = query.Columns.Add(LinePattern, nameof(LinePattern));
            var col_pinx    = query.Columns.Add(XFormPinX, nameof(XFormPinX));

            // Retrieve the values
            var data_formulas = query.GetFormulas(shape1);
            var data_results  = query.GetResults <double>(shape1);

            // Verify
            Assert.AreEqual("7", data_formulas.Cells[col_linepat]);
            Assert.AreEqual(7, data_results.Cells[col_linepat]);

            Assert.AreEqual("2 in", data_formulas.Cells[col_pinx]);
            Assert.AreEqual(2, data_results.Cells[col_pinx]);

            page1.Delete(0);
        }
        public void ShapeSheet_Writer_Formulas_MultipleShapes()
        {
            var page1 = this.GetNewPage();

            var shape1 = page1.DrawRectangle(-1, -1, 0, 0);
            var shape2 = page1.DrawRectangle(-1, -1, 0, 0);
            var shape3 = page1.DrawRectangle(-1, -1, 0, 0);


            // Set the formulas
            var writer = new SidSrcWriter();

            writer.SetValue(shape1.ID16, XFormPinX, 0.5);
            writer.SetValue(shape1.ID16, XFormPinY, 0.5);
            writer.SetValue(shape2.ID16, XFormPinX, 1.5);
            writer.SetValue(shape2.ID16, XFormPinY, 1.5);
            writer.SetValue(shape3.ID16, XFormPinX, 2.5);
            writer.SetValue(shape3.ID16, XFormPinY, 2.5);

            writer.CommitFormulas(page1);

            // Verify that the formulas were set
            var query    = new CellQuery();
            var col_pinx = query.Columns.Add(XFormPinX, nameof(XFormPinX));
            var col_piny = query.Columns.Add(XFormPinY, nameof(XFormPinY));

            var shapeids = new[] { shape1.ID, shape2.ID, shape3.ID };

            var data_formulas = query.GetFormulas(page1, shapeids);
            var data_results  = query.GetResults <double>(page1, shapeids);

            AssertUtil.AreEqual(("0.5 in", 0.5), (data_formulas[0][col_pinx], data_results[0][col_pinx]));
            AssertUtil.AreEqual(("0.5 in", 0.5), (data_formulas[0][col_piny], data_results[0][col_piny]));
            AssertUtil.AreEqual(("1.5 in", 1.5), (data_formulas[1][col_pinx], data_results[1][col_pinx]));
            AssertUtil.AreEqual(("1.5 in", 1.5), (data_formulas[1][col_piny], data_results[1][col_piny]));
            AssertUtil.AreEqual(("2.5 in", 2.5), (data_formulas[2][col_pinx], data_results[2][col_pinx]));
            AssertUtil.AreEqual(("2.5 in", 2.5), (data_formulas[2][col_piny], data_results[2][col_piny]));

            page1.Delete(0);
        }
        public static DataTable QueryToDataTable(CellQuery cell_query, bool getresults, ResultType result_type, IList <int> shapeids, VisioAutomation.SurfaceTarget surface)
        {
            if (!getresults)
            {
                var output = cell_query.GetFormulas(surface, shapeids);
                return(DataTableHelpers.querytable_to_datatable(cell_query, output));
            }

            switch (result_type)
            {
            case ResultType.String:
            {
                var output = cell_query.GetResults <string>(surface, shapeids);
                return(DataTableHelpers.querytable_to_datatable(cell_query, output));
            }

            case ResultType.Boolean:
            {
                var output = cell_query.GetResults <bool>(surface, shapeids);
                return(DataTableHelpers.querytable_to_datatable(cell_query, output));
            }

            case ResultType.Double:
            {
                var output = cell_query.GetResults <double>(surface, shapeids);
                return(DataTableHelpers.querytable_to_datatable(cell_query, output));
            }

            case ResultType.Integer:
            {
                var output = cell_query.GetResults <int>(surface, shapeids);
                return(DataTableHelpers.querytable_to_datatable(cell_query, output));
            }
            }

            throw new System.ArgumentOutOfRangeException("Unsupported Result type");
        }
Beispiel #5
0
        public static void Duplicate(
            IVisio.Page src_page,
            IVisio.Page dest_page)
        {
            init_page_srcs();

            var   app = src_page.Application;
            short copy_paste_flags = (short)IVisio.VisCutCopyPasteCodes.visCopyPasteNoTranslate;

            // handle the source page
            if (src_page == null)
            {
                throw new System.ArgumentNullException(nameof(src_page));
            }

            if (dest_page == null)
            {
                throw new System.ArgumentNullException(nameof(dest_page));
            }

            if (dest_page == src_page)
            {
                throw new System.ArgumentException("Destination Page cannot be Source Page");
            }


            if (src_page != app.ActivePage)
            {
                throw new System.ArgumentException("Source page must be active page.");
            }

            var src_page_shapes = src_page.Shapes;
            int num_src_shapes  = src_page_shapes.Count;

            if (num_src_shapes > 0)
            {
                var active_window = app.ActiveWindow;
                active_window.SelectAll();
                var selection = active_window.Selection;
                selection.Copy(copy_paste_flags);
                active_window.DeselectAll();
            }

            // Get the Cells from the Source
            var query = new CellQuery();
            int i     = 0;

            foreach (var src in page_srcs)
            {
                query.Columns.Add(src, "Col" + i.ToString());
                i++;
            }

            var src_formulas = query.GetFormulas(src_page.PageSheet);

            // Set the Cells on the Destination

            var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

            for (i = 0; i < page_srcs.Count; i++)
            {
                writer.SetFormula(page_srcs[i], src_formulas.Cells[i]);
            }

            writer.Commit(dest_page.PageSheet);

            // make sure the new page looks like the old page
            dest_page.Background = src_page.Background;

            // then paste any contents from the first page
            if (num_src_shapes > 0)
            {
                dest_page.Paste(copy_paste_flags);
            }
        }