コード例 #1
0
        public void Delete(TargetShapes targets, string name)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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

            if (name.Length < 1)
            {
                throw new System.ArgumentException("name cannot be empty", nameof(name));
            }

            targets = targets.ResolveShapes(this._client);

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

            using (var undoscope = this._client.Application.NewUndoScope("Delete Custom Property"))
            {
                foreach (var shape in targets.Shapes)
                {
                    CustomPropertyHelper.Delete(shape, name);
                }
            }
        }
コード例 #2
0
        public void SimpleCP()
        {
            var page1 = this.GetNewPage();

            // Draw a shape
            var s1 = page1.DrawRectangle(1, 1, 4, 3);

            int cp_type = 0; // string type

            // Set some properties on it
            CustomPropertyHelper.Set(s1, "FOO1", "\"BAR1\"", cp_type);
            CustomPropertyHelper.Set(s1, "FOO2", "\"BAR2\"", cp_type);
            CustomPropertyHelper.Set(s1, "FOO3", "\"BAR3\"", cp_type);

            // Delete one of those properties
            CustomPropertyHelper.Delete(s1, "FOO2");

            // Set the value of an existing properties
            CustomPropertyHelper.Set(s1, "FOO3", "\"BAR3updated\"", cp_type);

            // retrieve all the properties
            var props = CustomPropertyHelper.GetDictionary(s1, CellValueType.Formula);

            var cp_foo1 = props["FOO1"];
            // var cp_foo2 = props["FOO2"]; there is no prop called FOO2
            var cp_foo3 = props["FOO3"];

            var app = this.GetVisioApplication();
            var doc = app.ActiveDocument;

            if (doc != null)
            {
                doc.Close(true);
            }
        }
コード例 #3
0
        public void CustomProps_SetCustomProps1()
        {
            var page1 = this.GetNewPage();

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

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

            // Add a Custom Property
            var cp = new CustomPropertyCells();

            cp.Value = "\"BAR1\"";
            CustomPropertyHelper.Set(s1, "FOO1", cp);
            // Asset that now we have ONE CustomProperty
            Assert.AreEqual(1, CustomPropertyHelper.GetCount(s1));
            // Check that it is called FOO1
            Assert.AreEqual(true, CustomPropertyHelper.Contains(s1, "FOO1"));

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

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

            page1.Delete(0);
        }
コード例 #4
0
        public void DeleteCustomPropertyWithName(TargetShapes targetshapes, string name)
        {
            if (name == null)
            {
                throw new System.ArgumentNullException(nameof(name));
            }

            if (name.Length < 1)
            {
                throw new System.ArgumentException("name cannot be empty", nameof(name));
            }

            targetshapes = targetshapes.ResolveToShapes(this._client);

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

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(DeleteCustomPropertyWithName)))
            {
                foreach (var shape in targetshapes.Shapes)
                {
                    CustomPropertyHelper.Delete(shape, name);
                }
            }
        }
コード例 #5
0
        public static void SetCustomProperties()
        {
            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            // Draw a shape
            var s1 = page.DrawRectangle(1, 1, 4, 3);

            int cp_type = 0; // string type

            // Set some properties on it
            CustomPropertyHelper.Set(s1, "FOO1", "BAR1", cp_type);
            CustomPropertyHelper.Set(s1, "FOO2", "BAR2", cp_type);
            CustomPropertyHelper.Set(s1, "FOO3", "BAR3", cp_type);

            // Delete one of those properties
            CustomPropertyHelper.Delete(s1, "FOO2");

            // Set the value of an existing properties
            CustomPropertyHelper.Set(s1, "FOO3", "BAR3updated", cp_type);

            // retrieve all the properties
            var props = CustomPropertyHelper.GetCells(s1, CellValueType.Formula);

            var cp_foo1 = props["FOO1"];
            var cp_foo2 = props["FOO2"];
            var cp_foo3 = props["FOO3"];
        }
コード例 #6
0
        public static void Set_Custom_Property_on_multiple_Shapes(IVisio.Document doc)
        {
            // Set Custom Property_on_a_shape

            var page = doc.Pages.Add();
            var s1   = page.DrawRectangle(0, 0, 1, 1);
            var s2   = page.DrawRectangle(2, 2, 4, 4);

            var cp1 = new CustomPropertyCells();

            cp1.Value = "Hello";
            CustomPropertyHelper.Set(s1, "Propname", cp1);

            var cp2 = new CustomPropertyCells();

            cp2.Value = "World";
            CustomPropertyHelper.Set(s2, "Propname", cp2);

            // Retrieve all the Custom properties from multiple shapes

            var shapes = new[] { s1, s2 };
            var props  = CustomPropertyHelper.Get(page, shapes);

            // Delete the properties from the shapes
            CustomPropertyHelper.Delete(s1, "Propname");
            CustomPropertyHelper.Delete(s2, "Propname");

            //cleanup
            page.Delete(0);
        }
コード例 #7
0
        public void CustomProps_GetSet()
        {
            var page1 = this.GetNewPage();

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

            s1.Text = "Checking for Custom Properties";

            // A new rectangle should have zero props
            var c0 = CustomPropertyHelper.Get(s1);

            Assert.AreEqual(0, c0.Count);

            // Set one property
            // Notice that the properties some back double-quoted
            CustomPropertyHelper.Set(s1, "PROP1", "VAL1");
            var c1 = CustomPropertyHelper.Get(s1);

            Assert.AreEqual(1, c1.Count);
            Assert.IsTrue(c1.ContainsKey("PROP1"));
            Assert.AreEqual("\"VAL1\"", c1["PROP1"].Value.Formula);

            // Add another property
            CustomPropertyHelper.Set(s1, "PROP2", "VAL 2");
            var c2 = CustomPropertyHelper.Get(s1);

            Assert.AreEqual(2, c2.Count);
            Assert.IsTrue(c2.ContainsKey("PROP1"));
            Assert.AreEqual("\"VAL1\"", c2["PROP1"].Value.Formula);
            Assert.IsTrue(c2.ContainsKey("PROP2"));
            Assert.AreEqual("\"VAL 2\"", c2["PROP2"].Value.Formula);

            // Modify the value of the second property
            CustomPropertyHelper.Set(s1, "PROP2", "\"VAL 2 MOD\"");
            var c3 = CustomPropertyHelper.Get(s1);

            Assert.AreEqual(2, c3.Count);
            Assert.IsTrue(c3.ContainsKey("PROP1"));
            Assert.AreEqual("\"VAL1\"", c3["PROP1"].Value.Formula);
            Assert.IsTrue(c3.ContainsKey("PROP2"));
            Assert.AreEqual("\"VAL 2 MOD\"", c3["PROP2"].Value.Formula);

            // Now delete all the custom properties
            foreach (string name in c3.Keys)
            {
                CustomPropertyHelper.Delete(s1, name);
            }
            var c4 = CustomPropertyHelper.Get(s1);

            Assert.AreEqual(0, c4.Count);

            var app = this.GetVisioApplication();
            var doc = app.ActiveDocument;

            if (doc != null)
            {
                doc.Close(true);
            }
        }
コード例 #8
0
        public void CustomProps_PropertyNames()
        {
            var page1 = this.GetNewPage();
            var s1    = page1.DrawRectangle(0, 0, 2, 2);

            int cp_type = 0; // 0 for string

            Assert.AreEqual(0, CustomPropertyHelper.GetCount(s1));
            CustomPropertyHelper.Set(s1, "FOO1", "\"BAR1\"", cp_type);
            Assert.AreEqual(1, CustomPropertyHelper.GetCount(s1));
            CustomPropertyHelper.Set(s1, "FOO1", "\"BAR2\"", cp_type);
            Assert.AreEqual(1, CustomPropertyHelper.GetCount(s1));
            CustomPropertyHelper.Set(s1, "FOO2", "\"BAR3\"", cp_type);

            var names1 = CustomPropertyHelper.GetNames(s1);

            Assert.AreEqual(2, names1.Count);
            Assert.IsTrue(names1.Contains("FOO1"));
            Assert.IsTrue(names1.Contains("FOO2"));

            Assert.AreEqual(2, CustomPropertyHelper.GetCount(s1));
            CustomPropertyHelper.Delete(s1, "FOO1");

            var names2 = CustomPropertyHelper.GetNames(s1);

            Assert.AreEqual(1, names2.Count);
            Assert.IsTrue(names2.Contains("FOO2"));

            CustomPropertyHelper.Set(s1, "FOO3", "\"BAR1\"", cp_type);
            var names3 = CustomPropertyHelper.GetNames(s1);

            Assert.AreEqual(2, names3.Count);
            Assert.IsTrue(names3.Contains("FOO3"));
            Assert.IsTrue(names3.Contains("FOO2"));

            CustomPropertyHelper.Delete(s1, "FOO3");

            Assert.AreEqual(1, CustomPropertyHelper.GetCount(s1));
            CustomPropertyHelper.Delete(s1, "FOO2");

            Assert.AreEqual(0, CustomPropertyHelper.GetCount(s1));
            page1.Delete(0);
        }
コード例 #9
0
        public static void Set_Custom_Property_on_Shape(IVisio.Document doc)
        {
            // Set Custom Property_on_a_shape

            var page = doc.Pages.Add();
            var s1   = page.DrawRectangle(0, 0, 1, 1);
            var cp   = new CustomPropertyCells();

            cp.Value = "Hello World";
            CustomPropertyHelper.Set(s1, "Propname", cp);

            // Retrieve all the Custom properties from a shape

            var props = CustomPropertyHelper.Get(s1);

            // Delete the property from the shape

            CustomPropertyHelper.Delete(s1, "Propname");

            //cleanup
            page.Delete(0);
        }
コード例 #10
0
        public static void SetCustomProperties()
        {
            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            // Draw a shape
            var s1 = page.DrawRectangle(1, 1, 4, 3);

            // Set some properties on it
            CustomPropertyHelper.Set(s1, "FOO1", "BAR1");
            CustomPropertyHelper.Set(s1, "FOO2", "BAR2");
            CustomPropertyHelper.Set(s1, "FOO3", "BAR3");

            // Delete one of those properties
            CustomPropertyHelper.Delete(s1, "FOO2");

            // Set the value of an existing properties
            string formula = Convert.StringToFormulaString("BAR3updated");

            CustomPropertyHelper.Set(s1, "FOO3", formula);

            // retrieve all the properties
            var props = CustomPropertyHelper.Get(s1);
        }