public void Delete(VisioScripting.Models.TargetShapes targets, string name)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

            targets = targets.ResolveShapes(this._client);

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

            if (name == null)
            {
                throw new System.ArgumentNullException("name cannot be null", "name");
            }

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

            using (var undoscope = this._client.Application.NewUndoScope("Delete User-Defined Cell"))
            {
                foreach (var shape in targets.Shapes)
                {
                    UserDefinedCellHelper.Delete(shape, name);
                }
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public void UserDefinedCells_GetNames()
        {
            var page1 = this.GetNewPage();
            var s1    = page1.DrawRectangle(0, 0, 2, 2);

            Assert.AreEqual(0, UserDefinedCellHelper.GetCount(s1));
            UserDefinedCellHelper.Set(s1, "FOO1", "BAR1", null);
            Assert.AreEqual(1, UserDefinedCellHelper.GetCount(s1));
            UserDefinedCellHelper.Set(s1, "FOO1", "BAR2", null);
            Assert.AreEqual(1, UserDefinedCellHelper.GetCount(s1));
            UserDefinedCellHelper.Set(s1, "FOO2", "BAR3", null);

            var names1 = UserDefinedCellHelper.GetNames(s1);

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

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

            var names2 = UserDefinedCellHelper.GetNames(s1);

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

            UserDefinedCellHelper.Set(s1, "FOO3", "BAR1", null);
            var names3 = UserDefinedCellHelper.GetNames(s1);

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

            UserDefinedCellHelper.Delete(s1, "FOO3");

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

            Assert.AreEqual(0, UserDefinedCellHelper.GetCount(s1));

            page1.Delete(0);
        }