Пример #1
0
        public void ShapeSheet_Query_TestDuplicates()
        {
            // Ensure that duplicate cells are caught
            var q1 = new VisioAutomation.ShapeSheet.Queries.Query();

            q1.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX");

            bool caught_exc1 = false;

            try
            {
                q1.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX");
            }
            catch (System.ArgumentException)
            {
                caught_exc1 = true;
            }

            Assert.IsTrue(caught_exc1);

            // Ensure that duplicate sections are caught

            var q2 = new VisioAutomation.ShapeSheet.Queries.Query();

            q2.AddSubQuery(IVisio.VisSectionIndices.visSectionObject);

            bool caught_exc2 = false;

            try
            {
                q2.AddSubQuery(IVisio.VisSectionIndices.visSectionObject);
            }
            catch (System.ArgumentException)
            {
                caught_exc2 = true;
            }

            Assert.IsTrue(caught_exc2);

            // Ensure that Duplicates in Section Queries Are caught -
            var q3  = new VisioAutomation.ShapeSheet.Queries.Query();
            var sec = q3.AddSubQuery(IVisio.VisSectionIndices.visSectionObject);

            sec.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX");
            bool caught_exc3 = false;

            try
            {
                sec.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX");
            }
            catch (System.ArgumentException)
            {
                caught_exc3 = true;
            }

            Assert.IsTrue(caught_exc3);
        }
Пример #2
0
        public void ShapeSheet_Query_Demo_MultipleShapes_Verify_Out_Of_order()
        {
            var page1 = this.GetNewPage(new VisioAutomation.Drawing.Size(10, 10));

            // draw a simple shape
            var sa = page1.DrawRectangle(-1, -1, 0, 0);
            var s1 = page1.DrawRectangle(0, 0, 2, 2);
            var sb = page1.DrawRectangle(-1, -1, 0, 0);
            var s2 = page1.DrawRectangle(4, 4, 6, 6);
            var s3 = page1.DrawRectangle(5, 5, 7, 7);

            // notice that the shapes are created as 0, 1,2,3
            // but are queried as 2, 3, 1
            var shapeids = new List <int> {
                s2.ID, s3.ID, s1.ID
            };

            Assert.AreEqual(5, page1.Shapes.Count);

            var query    = new VisioAutomation.ShapeSheet.Queries.Query();
            var col_pinx = query.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX");
            var col_piny = query.AddCell(VA.ShapeSheet.SRCConstants.PinY, "PinY");

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

            var expected_formulas = new[, ]
            {
                { "5 in", "5 in" },
                { "6 in", "6 in" },
                { "1 in", "1 in" }
            };

            var expected_results = new[, ]
            {
                { 5.0, 5.0 },
                { 6.0, 6.0 },
                { 1.0, 1.0 }
            };


            for (int row = 0; row < data_results.Count; row++)
            {
                for (int col = 0; col < query.Cells.Count; col++)
                {
                    Assert.AreEqual(expected_formulas[row, col], data_formulas[row].Cells[col]);
                    Assert.AreEqual(expected_results[row, col], data_results[row].Cells[col]);
                }
            }

            page1.Delete(0);
        }
Пример #3
0
        public void ShapeSheet_Query_SectionCells_have_names()
        {
            var query = new VisioAutomation.ShapeSheet.Queries.Query();

            var sec_char = query.AddSubQuery(IVisio.VisSectionIndices.visSectionCharacter);

            Assert.AreEqual("Character", sec_char.Name);

            var sec_obj = query.AddSubQuery(IVisio.VisSectionIndices.visSectionObject);

            Assert.AreEqual("Object", sec_obj.Name);
        }
Пример #4
0
        public void ShapeSheet_Query_SectionRowHandling()
        {
            var page1 = this.GetNewPage();
            var s1    = page1.DrawRectangle(0, 0, 2, 2);
            var s2    = page1.DrawRectangle(2, 1, 3, 3);
            var s3    = page1.DrawRectangle(3, 1, 4, 2);
            var s4    = page1.DrawRectangle(4, -1, 5, 1);

            VACUSTPROP.CustomPropertyHelper.Set(s1, "S1P1", "1");
            VACUSTPROP.CustomPropertyHelper.Set(s2, "S2P1", "2");
            VACUSTPROP.CustomPropertyHelper.Set(s2, "S2P2", "3");
            //set nothing for s3
            VACUSTPROP.CustomPropertyHelper.Set(s4, "S3P1", "4");
            VACUSTPROP.CustomPropertyHelper.Set(s4, "S3P2", "5");
            VACUSTPROP.CustomPropertyHelper.Set(s4, "S3P3", "6");

            var query = new VisioAutomation.ShapeSheet.Queries.Query();

            var prop_sec  = query.AddSubQuery(IVisio.VisSectionIndices.visSectionProp);
            var value_col = prop_sec.AddCell(VA.ShapeSheet.SRCConstants.Prop_Value, "Value");

            var shapeids = new[] { s1.ID, s2.ID, s3.ID, s4.ID };

            var surface = new ShapeSheetSurface(page1);
            var data    = query.GetFormulasAndResults(surface, shapeids);

            Assert.AreEqual(4, data.Count);
            Assert.AreEqual(1, data[0].Sections[prop_sec].Rows.Count);
            Assert.AreEqual(2, data[1].Sections[prop_sec].Rows.Count);
            Assert.AreEqual(0, data[2].Sections[prop_sec].Rows.Count);
            Assert.AreEqual(3, data[3].Sections[prop_sec].Rows.Count);

            Assert.AreEqual("\"1\"", data[0].Sections[prop_sec].Rows[0].Cells[0].Formula);
            Assert.AreEqual("\"2\"", data[1].Sections[prop_sec].Rows[0].Cells[0].Formula);
            Assert.AreEqual("\"3\"", data[1].Sections[prop_sec].Rows[1].Cells[0].Formula);
            Assert.AreEqual("\"4\"", data[3].Sections[prop_sec].Rows[0].Cells[0].Formula);
            Assert.AreEqual("\"5\"", data[3].Sections[prop_sec].Rows[1].Cells[0].Formula);
            Assert.AreEqual("\"6\"", data[3].Sections[prop_sec].Rows[2].Cells[0].Formula);


            Assert.AreEqual("1", data[0].Sections[prop_sec].Rows[0].Cells[0].Result);
            Assert.AreEqual("2", data[1].Sections[prop_sec].Rows[0].Cells[0].Result);
            Assert.AreEqual("3", data[1].Sections[prop_sec].Rows[1].Cells[0].Result);
            Assert.AreEqual("4", data[3].Sections[prop_sec].Rows[0].Cells[0].Result);
            Assert.AreEqual("5", data[3].Sections[prop_sec].Rows[1].Cells[0].Result);
            Assert.AreEqual("6", data[3].Sections[prop_sec].Rows[2].Cells[0].Result);

            page1.Delete(0);
        }
Пример #5
0
        private Query create_query_for_all_cells_and_sections()
        {
            var query = new VisioAutomation.ShapeSheet.Queries.Query();

            // Dictionary of Cell Names to SRCs (excluding invalid sections)
            var name_to_src = GetSRCDictionary();

            name_to_src = name_to_src.Where(pair => !section_is_skippable(pair.Value))
                          .ToDictionary(pair => pair.Key, pair => pair.Value);

            // Create a dictionary of the subqueries for each section, this
            // will be reused as fill in the query
            var unique_section_ids  = name_to_src.Select(pair => pair.Value).Select(src => src.Section).Distinct().ToList();
            var section_to_subquery = new Dictionary <short, VisioAutomation.ShapeSheet.Queries.SubQuery>(unique_section_ids.Count);

            foreach (short section_id in unique_section_ids.Where(i => i != (short)IVisio.VisSectionIndices.visSectionObject))
            {
                section_to_subquery[section_id] = query.AddSubQuery((IVisio.VisSectionIndices)section_id);
            }

            // Now for each src add it as a top level cell, or as a cell in
            // a subquery depending on its section index
            foreach (var kv in name_to_src)
            {
                var name = kv.Key;
                var src  = kv.Value;

                if (src.Section == (short)IVisio.VisSectionIndices.visSectionObject)
                {
                    query.AddCell(src, name);
                }
                else
                {
                    // the subquery will always be in the dictionary
                    // because the dictionary was populated in a previous
                    // step
                    var subquery = section_to_subquery[src.Section];
                    subquery.AddCell(src, name);
                }
            }
            return(query);
        }
        public void UserDefinedCells_GetFromMultipleShapes_WithAdditionalProps()
        {
            var page1 = this.GetNewPage();

            var s1     = page1.DrawRectangle(0, 0, 1, 1);
            var s2     = page1.DrawRectangle(1, 1, 2, 2);
            var shapes = new[] { s1, s2 };

            VAUSERCELL.UserDefinedCellHelper.Set(s1, "foo", "bar", null);

            var queryex = new VisioAutomation.ShapeSheet.Queries.Query();
            var sec     = queryex.AddSubQuery(IVisio.VisSectionIndices.visSectionUser);
            var Value   = sec.AddCell(VisioAutomation.ShapeSheet.SRCConstants.User_Value, "Value");
            var Prompt  = sec.AddCell(VisioAutomation.ShapeSheet.SRCConstants.User_Prompt, "Prompt");

            var surface  = new VisioAutomation.ShapeSheet.ShapeSheetSurface(page1);
            var formulas = queryex.GetFormulas(surface, shapes.Select(s => s.ID).ToList());


            page1.Delete(0);
        }
Пример #7
0
 protected ReaderBase()
 {
     this.query = new Query();
 }
Пример #8
0
        public void ShapeSheet_Query_GetResults_SingleShape()
        {
            var doc1  = this.GetNewDoc();
            var page1 = doc1.Pages[1];

            VisioAutomationTest.SetPageSize(page1, this.StandardPageSize);

            // draw a simple shape
            var s1    = page1.DrawRectangle(this.StandardPageSizeRect);
            int s1_id = s1.ID;

            // format it with setformulas
            var fg_cell  = s1.Cells["FillForegnd"];
            var bg_cell  = s1.Cells["FillBkgnd"];
            var pat_cell = s1.Cells["FillPattern"];

            fg_cell.FormulaU  = "RGB(255,0,0)";
            bg_cell.FormulaU  = "RGB(0,0,255)";
            pat_cell.FormulaU = "40";

            // now retrieve the formulas with GetFormulas

            var src_fg     = VA.ShapeSheet.SRCConstants.FillForegnd;
            var src_bg     = VA.ShapeSheet.SRCConstants.FillBkgnd;
            var src_filpat = VA.ShapeSheet.SRCConstants.FillPattern;

            var query      = new VisioAutomation.ShapeSheet.Queries.Query();
            var col_fg     = query.AddCell(src_fg, "FillForegnd");
            var col_bg     = query.AddCell(src_bg, "FillBkgnd");
            var col_filpat = query.AddCell(src_filpat, "FillPattern");
            var sec_char   = query.AddSubQuery(IVisio.VisSectionIndices.visSectionCharacter);

            Assert.AreEqual("Character", sec_char.Name);
            var col_charcase  = sec_char.AddCell(VA.ShapeSheet.SRCConstants.CharCase, "CharCase");
            var col_charcolor = sec_char.AddCell(VA.ShapeSheet.SRCConstants.CharColor, "CharColor");
            var col_chartrans = sec_char.AddCell(VA.ShapeSheet.SRCConstants.CharColorTrans, "CharColorTrans");

            var shapeids = new[] { s1_id };

            var surface  = new ShapeSheetSurface(page1);
            var formulas = query.GetFormulas(surface, shapeids);

            // now verify that the formulas were actually set
            Assert.AreEqual("RGB(255,0,0)", formulas[0].Cells[col_fg]);
            Assert.AreEqual("RGB(0,0,255)", formulas[0].Cells[col_bg]);
            Assert.AreEqual("40", formulas[0].Cells[col_filpat]);

            // now retrieve the results with GetResults as floats
            var float_results = query.GetResults <double>(surface, shapeids);

            Assert.IsNotNull(float_results);
            Assert.AreEqual(40.0, float_results[0].Cells[col_filpat]);

            // now retrieve the results with GetResults as ints
            var int_results = query.GetResults <int>(surface, shapeids);

            Assert.AreEqual(40, int_results[0].Cells[col_filpat]);

            // now retrieve the results with GetResults as strings

            var string_results = query.GetResults <string>(surface, shapeids);

            Assert.AreEqual("RGB(255, 0, 0)", string_results[0].Cells[col_fg]);
            Assert.AreEqual("RGB(0, 0, 255)", string_results[0].Cells[col_bg]);
            Assert.AreEqual("40", string_results[0].Cells[col_filpat]);

            page1.Delete(0);
            doc1.Close(true);
        }
Пример #9
0
        public void ShapeSheet_Query_GetResults_MultipleShapes()
        {
            var page1 = this.GetNewPage();

            // draw a simple shape
            var s1    = page1.DrawRectangle(this.StandardPageSizeRect);
            int s1_id = s1.ID;

            // format it with setformulas
            var fg_cell  = s1.Cells["FillForegnd"];
            var bg_cell  = s1.Cells["FillBkgnd"];
            var pat_cell = s1.Cells["FillPattern"];

            fg_cell.ResultIU  = 2.0; //red
            bg_cell.ResultIU  = 3.0; //green
            pat_cell.ResultIU = 40.0;

            var src_fg     = VA.ShapeSheet.SRCConstants.FillForegnd;
            var src_bg     = VA.ShapeSheet.SRCConstants.FillBkgnd;
            var src_filpat = VA.ShapeSheet.SRCConstants.FillPattern;

            // now retrieve the formulas with GetFormulas

            var query      = new VisioAutomation.ShapeSheet.Queries.Query();
            var col_fg     = query.AddCell(src_fg, "FillForegnd");
            var col_bg     = query.AddCell(src_bg, "FillBkgnd");
            var col_filpat = query.AddCell(src_filpat, "FillPattern");

            var shapeids = new[] { s1_id };

            var surface  = new ShapeSheetSurface(page1);
            var formulas = query.GetFormulas(surface, shapeids);

            // now verify that the formulas were actually set
            Assert.AreEqual("2", formulas[0].Cells[col_fg]);
            Assert.AreEqual("3", formulas[0].Cells[col_bg]);
            Assert.AreEqual("40", formulas[0].Cells[col_filpat]);

            // now retrieve the results with GetResults as floats
            var float_results = query.GetResults <double>(surface, shapeids);

            Assert.AreEqual(2.0, float_results[0].Cells[col_fg]);
            Assert.AreEqual(3.0, float_results[0].Cells[col_bg]);
            Assert.AreEqual(40.0, float_results[0].Cells[col_filpat]);

            // now retrieve the results with GetResults as ints
            var int_results = query.GetResults <int>(surface, shapeids);

            Assert.AreEqual(2, int_results[0].Cells[col_fg]);
            Assert.AreEqual(3, int_results[0].Cells[col_bg]);
            Assert.AreEqual(40, int_results[0].Cells[col_filpat]);

            // now retrieve the results with GetResults as strings
            var string_results = query.GetResults <string>(surface, shapeids);

            Assert.AreEqual("2", string_results[0].Cells[col_fg]);
            Assert.AreEqual("3", string_results[0].Cells[col_bg]);
            Assert.AreEqual("40", string_results[0].Cells[col_filpat]);

            page1.Delete(0);
        }