public void ShapeSheet_Query_TestDuplicates()
        {
            // Ensure that duplicate cells are caught
            var q1 = new VA.ShapeSheet.Query.CellQuery();

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

            bool caught_exc1 = false;

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

            Assert.IsTrue(caught_exc1);

            // Ensure that duplicate sections are caught

            var q2 = new VA.ShapeSheet.Query.CellQuery();

            q2.AddSection(IVisio.VisSectionIndices.visSectionObject);

            bool caught_exc2 = false;

            try
            {
                q2.AddSection(IVisio.VisSectionIndices.visSectionObject);
            }
            catch (VA.AutomationException)
            {
                caught_exc2 = true;
            }

            Assert.IsTrue(caught_exc2);

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

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

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

            Assert.IsTrue(caught_exc3);
        }
        public void ShapeSheet_Query_SectionCells_have_names()
        {
            var query = new VA.ShapeSheet.Query.CellQuery();

            var sec_char = query.AddSection(IVisio.VisSectionIndices.visSectionCharacter);
            Assert.AreEqual("Character", sec_char.Name);

            var sec_obj = query.AddSection(IVisio.VisSectionIndices.visSectionObject);
            Assert.AreEqual("Object", sec_obj.Name);

        }
        public void ShapeSheet_Query_SectionCells_have_names()
        {
            var query = new VA.ShapeSheet.Query.CellQuery();

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

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

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

            Assert.AreEqual("Object", sec_obj.Name);
        }
        public void ShapeSheet_Query_Demo_AllCellsAndSections()
        {
            var doc1  = this.GetNewDoc();
            var page1 = doc1.Pages[1];

            VisioAutomationTest.SetPageSize(page1, this.StandardPageSize);

            // draw simple shapes
            var s1 = page1.DrawRectangle(0, 0, 1, 1);
            var s2 = page1.DrawRectangle(2, 2, 3, 3);


            var query = new VA.ShapeSheet.Query.CellQuery();

            var name_to_src         = VA.ShapeSheet.SRCConstants.GetSRCDictionary();
            var section_to_secquery = new Dictionary <short, VA.ShapeSheet.Query.SectionColumn>();

            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 if ((src.Section == (short)IVisio.VisSectionIndices.visSectionFirst) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionFirstComponent) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionLast) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionInval) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionNone) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionFirst) ||
                         (src.Section == (short)IVisio.VisSectionIndices.visSectionLastComponent)
                         )
                {
                    //skip
                }
                else
                {
                    VA.ShapeSheet.Query.SectionColumn sec;
                    if (!section_to_secquery.ContainsKey(src.Section))
                    {
                        sec = query.AddSection((IVisio.VisSectionIndices)src.Section);
                        section_to_secquery[src.Section] = sec;
                    }
                    else
                    {
                        sec = section_to_secquery[src.Section];
                    }
                    sec.AddCell(src.Cell, name);
                }
            }

            var formulas1 = query.GetFormulas(s1);
            var formulas2 = query.GetFormulas(page1, new [] { s1.ID, s2.ID });

            doc1.Close(true);
        }
        public void ShapeSheet_Query_Demo_AllCellsAndSections()
        {
            var doc1 = this.GetNewDoc();
            var page1 = doc1.Pages[1];
            VisioAutomationTest.SetPageSize(page1, this.StandardPageSize);

            // draw simple shapes
            var s1 = page1.DrawRectangle(0,0,1,1);
            var s2 = page1.DrawRectangle(2,2,3,3);

            var query = new VA.ShapeSheet.Query.CellQuery();

            var name_to_src = VA.ShapeSheet.SRCConstants.GetSRCDictionary();
            var section_to_secquery = new Dictionary<short,VA.ShapeSheet.Query.SectionColumn>();

            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 if ((src.Section == (short) IVisio.VisSectionIndices.visSectionFirst)
                         || (src.Section == (short) IVisio.VisSectionIndices.visSectionFirstComponent)
                         || (src.Section == (short) IVisio.VisSectionIndices.visSectionLast)
                         || (src.Section == (short) IVisio.VisSectionIndices.visSectionInval)
                         || (src.Section == (short) IVisio.VisSectionIndices.visSectionNone)
                         || (src.Section == (short) IVisio.VisSectionIndices.visSectionFirst)
                         || (src.Section == (short) IVisio.VisSectionIndices.visSectionLastComponent)
                    )
                {
                    //skip
                }
                else
                {
                    VA.ShapeSheet.Query.SectionColumn sec;
                    if (!section_to_secquery.ContainsKey(src.Section))
                    {
                        sec = query.AddSection((IVisio.VisSectionIndices)src.Section);
                        section_to_secquery[src.Section] = sec;
                    }
                    else
                    {
                        sec = section_to_secquery[src.Section];
                    }
                    sec.AddCell(src.Cell, name);
                }
            }

            var formulas1 = query.GetFormulas(s1);
            var formulas2 = query.GetFormulas(page1,new [] {s1.ID,s2.ID});

            doc1.Close(true);
        }
        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.UserDefinedCellsHelper.Set(s1, "foo", "bar", null);

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

            var formulas = queryex.GetFormulas(page1, shapes.Select(s => s.ID).ToList());

            page1.Delete(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 VA.ShapeSheet.Query.CellQuery();

            var prop_sec  = query.AddSection(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 data = query.GetCellData <double>(
                page1,
                shapeids);

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

            AssertVA.AreEqual("\"1\"", 1.0, data[0].Sections[prop_sec][0][0]);
            AssertVA.AreEqual("\"2\"", 2.0, data[1].Sections[prop_sec][0][0]);
            AssertVA.AreEqual("\"3\"", 3.0, data[1].Sections[prop_sec][1][0]);
            AssertVA.AreEqual("\"4\"", 4.0, data[3].Sections[prop_sec][0][0]);
            AssertVA.AreEqual("\"5\"", 5.0, data[3].Sections[prop_sec][1][0]);
            AssertVA.AreEqual("\"6\"", 6.0, data[3].Sections[prop_sec][2][0]);

            page1.Delete(0);
        }
Пример #8
0
        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.UserDefinedCellsHelper.Set(s1, "foo", "bar", null);

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

            var formulas = queryex.GetFormulas(page1, shapes.Select(s => s.ID).ToList());


            page1.Delete(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 VA.ShapeSheet.Query.CellQuery();
            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.AddSection(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 formulas = query.GetFormulas(page1, shapeids);

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

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

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

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

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

            // now retrieve the results with GetResults as strings

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

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

            page1.Delete(0);
            doc1.Close(true);
        }
        public void ShapeSheet_Query_TestDuplicates()
        {
            // Ensure that duplicate cells are caught
            var q1 = new VA.ShapeSheet.Query.CellQuery();
            q1.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX");

            bool caught_exc1 = false;
            try
            {
                q1.AddCell(VA.ShapeSheet.SRCConstants.PinX, "PinX");
            }
            catch (VA.AutomationException)
            {
                caught_exc1 = true;
            }

            Assert.IsTrue(caught_exc1);

            // Ensure that duplicate sections are caught

            var q2 = new VA.ShapeSheet.Query.CellQuery();
            q2.AddSection(IVisio.VisSectionIndices.visSectionObject);

            bool caught_exc2 = false;
            try
            {
                q2.AddSection(IVisio.VisSectionIndices.visSectionObject);
            }
            catch (VA.AutomationException)
            {
                caught_exc2 = true;
            }

            Assert.IsTrue(caught_exc2);

            // Ensure that Duplicates in Section Queries Are caught - 
            var q3 = new VA.ShapeSheet.Query.CellQuery();
            var sec = q3.AddSection(IVisio.VisSectionIndices.visSectionObject);
            sec.AddCell(VA.ShapeSheet.SRCConstants.PinX.Cell,"PinX");
            bool caught_exc3 = false;
            try
            {
                sec.AddCell(VA.ShapeSheet.SRCConstants.PinX.Cell, "PinX");
            }
            catch (VA.AutomationException)
            {
                caught_exc3 = true;
            }

            Assert.IsTrue(caught_exc3);
        }
        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 VA.ShapeSheet.Query.CellQuery();
            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.AddSection(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 formulas = query.GetFormulas(page1, shapeids);

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

            // now retrieve the results with GetResults as floats
            var float_results = query.GetResults<double>(page1,shapeids);
            Assert.IsNotNull(float_results);
            Assert.AreEqual(40.0, float_results[0][col_filpat]);

            // now retrieve the results with GetResults as ints
            var int_results = query.GetResults<int>(page1,shapeids);
            Assert.AreEqual(40, int_results[0][col_filpat]);

            // now retrieve the results with GetResults as strings

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

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

            page1.Delete(0);
            doc1.Close(true);
        }
        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 VA.ShapeSheet.Query.CellQuery();

            var prop_sec = query.AddSection(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 data = query.GetCellData<double>(
                page1,
                shapeids);

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

            AssertVA.AreEqual("\"1\"", 1.0, data[0].Sections[prop_sec][0][0]);
            AssertVA.AreEqual("\"2\"", 2.0, data[1].Sections[prop_sec][0][0]);
            AssertVA.AreEqual("\"3\"", 3.0, data[1].Sections[prop_sec][1][0]);
            AssertVA.AreEqual("\"4\"", 4.0, data[3].Sections[prop_sec][0][0]);
            AssertVA.AreEqual("\"5\"", 5.0, data[3].Sections[prop_sec][1][0]);
            AssertVA.AreEqual("\"6\"", 6.0, data[3].Sections[prop_sec][2][0]);

            page1.Delete(0);
        }