Esempio n. 1
0
        public Dictionary <IVisio.Shape, IList <UserDefinedCellCells> > Get(VisioScripting.Models.TargetShapes targets)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            var prop_dic = new Dictionary <IVisio.Shape, IList <UserDefinedCellCells> >();

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(prop_dic);
            }

            var application     = this._client.Application.Get();
            var page            = application.ActivePage;
            var list_user_props = UserDefinedCellHelper.Get(page, targets.Shapes);

            for (int i = 0; i < targets.Shapes.Count; i++)
            {
                var shape = targets.Shapes[i];
                var props = list_user_props[i];
                prop_dic[shape] = props;
            }

            return(prop_dic);
        }
Esempio n. 2
0
        public void UserDefinedCells_ValueQuoting()
        {
            var page1 = this.GetNewPage();
            var s1    = page1.DrawRectangle(0, 0, 2, 2);

            var p1 = UserDefinedCellHelper.Get(s1);

            Assert.AreEqual(0, p1.Count);

            UserDefinedCellHelper.Set(s1, "FOO1", "1", null);
            UserDefinedCellHelper.Set(s1, "FOO2", "2", null);
            UserDefinedCellHelper.Set(s1, "FOO3", "3\"4", null);

            var p2 = UserDefinedCellHelper.Get(s1);

            Assert.AreEqual(3, p2.Count);

            Assert.AreEqual("FOO1", p2[0].Name);
            Assert.AreEqual("\"1\"", p2[0].Value.Formula.Value);

            Assert.AreEqual("FOO2", p2[1].Name);
            Assert.AreEqual("\"2\"", p2[1].Value.Formula.Value);

            Assert.AreEqual("FOO3", p2[2].Name);
            Assert.AreEqual("\"3\"\"4\"", p2[2].Value.Formula.Value);

            page1.Delete(0);
        }
Esempio n. 3
0
        public void UserDefinedCells_SetForMultipleShapes()
        {
            var page1 = this.GetNewPage();
            var s1    = page1.DrawRectangle(0, 0, 2, 2);
            var s2    = page1.DrawRectangle(0, 0, 2, 2);
            var s3    = page1.DrawRectangle(0, 0, 2, 2);
            var s4    = page1.DrawRectangle(0, 0, 2, 2);

            UserDefinedCellHelper.Set(s1, "FOO1", "1", "p1");
            UserDefinedCellHelper.Set(s2, "FOO2", "2", "p2");
            UserDefinedCellHelper.Set(s2, "FOO3", "3", "p3");
            UserDefinedCellHelper.Set(s4, "FOO4", "4", "p4");
            UserDefinedCellHelper.Set(s4, "FOO5", "5", "p4");
            UserDefinedCellHelper.Set(s4, "FOO6", "6", "p6");

            var shapeids = new[] { s1, s2, s3, s4 };
            var allprops = UserDefinedCellHelper.Get(page1, shapeids);

            Assert.AreEqual(4, allprops.Count);
            Assert.AreEqual(1, allprops[0].Count);
            Assert.AreEqual(2, allprops[1].Count);
            Assert.AreEqual(0, allprops[2].Count);
            Assert.AreEqual(3, allprops[3].Count);

            Assert.AreEqual("\"1\"", allprops[0][0].Value.Formula.Value);
            Assert.AreEqual("\"2\"", allprops[1][0].Value.Formula.Value);
            Assert.AreEqual("\"3\"", allprops[1][1].Value.Formula.Value);
            Assert.AreEqual("\"4\"", allprops[3][0].Value.Formula.Value);
            Assert.AreEqual("\"5\"", allprops[3][1].Value.Formula.Value);
            Assert.AreEqual("\"6\"", allprops[3][2].Value.Formula.Value);
            page1.Delete(0);
        }
Esempio n. 4
0
        public void UserDefinedCells_GetSet()
        {
            var page1 = this.GetNewPage();

            var s1 = page1.DrawRectangle(0, 0, 2, 2);

            // By default a shape has ZERO custom Properties
            Assert.AreEqual(0, UserDefinedCellHelper.GetCount(s1));

            // Add a Custom Property
            UserDefinedCellHelper.Set(s1, "FOO1", "BAR", null);
            Assert.AreEqual(1, UserDefinedCellHelper.GetCount(s1));
            // Check that it is called FOO1
            Assert.AreEqual(true, UserDefinedCellHelper.Contains(s1, "FOO1"));

            // Check that non-existent properties can't be found
            Assert.AreEqual(false, CustomPropertyHelper.Contains(s1, "FOOX"));

            var udcs = UserDefinedCellHelper.Get(s1);

            Assert.AreEqual(1, udcs.Count);
            Assert.AreEqual("FOO1", udcs[0].Name);
            Assert.AreEqual("\"BAR\"", udcs[0].Value.Formula);
            Assert.AreEqual("\"\"", udcs[0].Prompt.Formula);

            // Verify that we can set the value without affecting the prompt
            UserDefinedCellHelper.Set(s1, "FOO1", "BEER", null);
            udcs = UserDefinedCellHelper.Get(s1);
            Assert.AreEqual(1, udcs.Count);
            Assert.AreEqual("FOO1", udcs[0].Name);
            Assert.AreEqual("\"BEER\"", udcs[0].Value.Formula);
            Assert.AreEqual("\"\"", udcs[0].Prompt.Formula);

            // Verify that we can set passing in nulls changes nothing
            UserDefinedCellHelper.Set(s1, "FOO1", null, null);
            udcs = UserDefinedCellHelper.Get(s1);
            Assert.AreEqual(1, udcs.Count);
            Assert.AreEqual("FOO1", udcs[0].Name);
            Assert.AreEqual("\"BEER\"", udcs[0].Value.Formula);
            Assert.AreEqual("\"\"", udcs[0].Prompt.Formula);

            // Verify that we can set the prompt without affecting the value
            UserDefinedCellHelper.Set(s1, "FOO1", null, "Prompt1");
            udcs = UserDefinedCellHelper.Get(s1);
            Assert.AreEqual(1, udcs.Count);
            Assert.AreEqual("FOO1", udcs[0].Name);
            Assert.AreEqual("\"BEER\"", udcs[0].Value.Formula);
            Assert.AreEqual("\"Prompt1\"", udcs[0].Prompt.Formula);

            // Delete that custom property
            UserDefinedCellHelper.Delete(s1, "FOO1");
            // Verify that we have zero Custom Properties
            Assert.AreEqual(0, UserDefinedCellHelper.GetCount(s1));

            page1.Delete(0);
        }
Esempio n. 5
0
        public void Scripting_Drop_Container_Master_Object()
        {
            var pagesize = new VA.Drawing.Size(4, 4);
            var client   = this.GetScriptingClient();

            // Create the page
            client.Document.New();
            client.Page.New(pagesize, false);

            var application = client.Application.Get();
            var active_page = application.ActivePage;

            // Load the stencils and find the masters
            var basic_stencil = client.Document.OpenStencil("Basic_U.VSS");
            var master        = client.Master.Get("Rectangle", basic_stencil);

            // Drop the rectangle
            client.Master.Drop(master, new VA.Drawing.Point(2, 2));

            // Select the rectangle... it should already be selected, but just make sure
            client.Selection.SelectAll();

            // Drop the container... since the rectangle is selected... it will automatically make it a member of the container
            var app = active_page.Application;

            var ver = client.Application.Version;
            var cont_master_name = ver.Major >= 15 ? "Plain" : "Container 1";

            var stencil_type       = IVisio.VisBuiltInStencilTypes.visBuiltInStencilContainers;
            var measurement_system = IVisio.VisMeasurementSystem.visMSUS;
            var containers_file    = app.GetBuiltInStencilFile(stencil_type, measurement_system);
            var containers_doc     = app.Documents.OpenStencil(containers_file);
            var masters            = containers_doc.Masters;
            var container_master   = masters.ItemU[cont_master_name];
            var dropped_container  = client.Master.DropContainer(container_master);

            // Verify
            var shapes = active_page.Shapes;

            // There should be two shapes... the rectangle and the container
            Assert.AreEqual(2, shapes.Count);

            // Verify that we did indeed drop a container
            Assert.AreEqual("Container",
                            UserDefinedCellHelper
                            .Get(dropped_container)
                            .First(s => s.Name == "msvStructureType")
                            .Value.Result);

            // cleanup
            client.Document.Close(true);
        }
Esempio n. 6
0
        public void UserDefinedCells_GetFromMultipleShapes()
        {
            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 };

            UserDefinedCellHelper.Set(s1, "foo", "bar", null);
            var props1 = UserDefinedCellHelper.Get(page1, shapes);

            Assert.AreEqual(2, props1.Count);
            Assert.AreEqual(1, props1[0].Count);
            Assert.AreEqual(0, props1[1].Count);

            page1.Delete(0);
        }