Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void CustomProps_GetFromMultipleShapes()
        {
            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);

            int cp_type = 0; // 0 for string

            CustomPropertyHelper.Set(s1, "FOO1", "1", cp_type);
            CustomPropertyHelper.Set(s2, "FOO2", "2", cp_type);
            CustomPropertyHelper.Set(s2, "FOO3", "3", cp_type);
            CustomPropertyHelper.Set(s4, "FOO4", "4", cp_type);
            CustomPropertyHelper.Set(s4, "FOO5", "5", cp_type);
            CustomPropertyHelper.Set(s4, "FOO6", "6", cp_type);

            var shapes   = new[] { s1, s2, s3, s4 };
            var allprops = CustomPropertyHelper.GetCells(page1, shapes, CellValueType.Formula);

            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]["FOO1"].Value.Value);
            Assert.AreEqual("2", allprops[1]["FOO2"].Value.Value);
            Assert.AreEqual("3", allprops[1]["FOO3"].Value.Value);
            Assert.AreEqual("4", allprops[3]["FOO4"].Value.Value);
            Assert.AreEqual("5", allprops[3]["FOO5"].Value.Value);
            Assert.AreEqual("6", allprops[3]["FOO6"].Value.Value);

            page1.Delete(0);
        }
Ejemplo n.º 3
0
        public void CustomProps_InvalidPropName()
        {
            bool caught = false;
            var  page1  = this.GetNewPage();
            var  s1     = page1.DrawRectangle(0, 0, 2, 2);

            Assert.AreEqual(0, CustomPropertyHelper.GetDictionary(s1, CellValueType.Formula).Count);

            int cp_type = 0; // 0 for string

            try
            {
                CustomPropertyHelper.Set(s1, "FOO 1", "BAR1", cp_type);
            }
            catch (System.ArgumentException)
            {
                page1.Delete(0);
                caught = true;
            }

            if (!caught)
            {
                Assert.Fail("Did not catch expected exception");
            }
        }
Ejemplo n.º 4
0
        public void CustomProps_SetSamePropMultipleTimes()
        {
            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));

            int cp_type = 0; // string type

            // Add the same one multiple times Custom Property
            CustomPropertyHelper.Set(s1, "FOO1", "\"BAR1\"", cp_type);
            // 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"));

            // Try to SET the same property again many times
            CustomPropertyHelper.Set(s1, "FOO1", "\"BAR2\"", cp_type);
            CustomPropertyHelper.Set(s1, "FOO1", "\"BAR3\"", cp_type);
            CustomPropertyHelper.Set(s1, "FOO1", "\"BAR4\"", cp_type);

            // 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"));

            page1.Delete(0);
        }
Ejemplo n.º 5
0
        public void Set(TargetShapes targets, string name, CustomPropertyCells customprop)
        {
            this._client.Application.AssertApplicationAvailable();
            this._client.Document.AssertDocumentAvailable();

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

            targets = targets.ResolveShapes(this._client);

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

            using (var undoscope = this._client.Application.NewUndoScope("Set Custom Property"))
            {
                foreach (var shape in targets.Shapes)
                {
                    CustomPropertyHelper.Set(shape, name, customprop);
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
0
        public void CustomProps_GetFromMultipleShapes()
        {
            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);

            CustomPropertyHelper.Set(s1, "FOO1", "1");
            CustomPropertyHelper.Set(s2, "FOO2", "2");
            CustomPropertyHelper.Set(s2, "FOO3", "3");
            CustomPropertyHelper.Set(s4, "FOO4", "4");
            CustomPropertyHelper.Set(s4, "FOO5", "5");
            CustomPropertyHelper.Set(s4, "FOO6", "6");

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

            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]["FOO1"].Value.Formula);
            Assert.AreEqual("\"2\"", allprops[1]["FOO2"].Value.Formula);
            Assert.AreEqual("\"3\"", allprops[1]["FOO3"].Value.Formula);
            Assert.AreEqual("\"4\"", allprops[3]["FOO4"].Value.Formula);
            Assert.AreEqual("\"5\"", allprops[3]["FOO5"].Value.Formula);
            Assert.AreEqual("\"6\"", allprops[3]["FOO6"].Value.Formula);

            page1.Delete(0);
        }
Ejemplo n.º 8
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);
            }
        }
        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"];
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
        private void SetCustomProperties(RenderContext context)
        {
            var shapes_with_custom_props = this._shapes.Where(s => s.CustomProperties != null);

            foreach (var shape in shapes_with_custom_props)
            {
                var vshape = context.GetShape(shape.VisioShapeID);
                foreach (var kv in shape.CustomProperties)
                {
                    string cp_name = kv.Key;
                    CustomPropertyCells cp_cells = kv.Value;
                    CustomPropertyHelper.Set(vshape, cp_name, cp_cells);
                }
            }
        }
Ejemplo n.º 12
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);

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

            var query = new ShapeSheetQuery();

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

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

            var data = query.GetFormulasAndResults(page1, 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);
        }
Ejemplo n.º 13
0
        public static void Counting_properties(IVisio.Document doc)
        {
            // Set Custom Property_on_a_shape

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

            var cp1 = new CustomPropertyCells();

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

            int num_custom_props  = CustomPropertyHelper.GetCount(s1);
            var custom_prop_names = CustomPropertyHelper.GetNames(s1);

            //cleanup
            page.Delete(0);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        public void CustomProps_VerifyCustomPropAttributes()
        {
            var page1 = this.GetNewPage();
            var s1    = page1.DrawRectangle(0, 0, 2, 2);

            var in_cp = new CustomPropertyCells();

            in_cp.Label     = "\"The Foo property\"";
            in_cp.Value     = "\"Some value\"";
            in_cp.Prompt    = "\"Some Prompt\"";
            in_cp.LangID    = 1034;
            in_cp.Type      = 0; // 0 = string. see: http://msdn.microsoft.com/en-us/library/aa200980(v=office.10).aspx
            in_cp.Calendar  = (int)IVisio.VisCellVals.visCalWestern;
            in_cp.Invisible = 0;
            CustomPropertyHelper.Set(s1, "foo", in_cp);
            var out_cp = CustomPropertyHelper.GetCells(s1, CellValueType.Formula);

            Assert.AreEqual(1, out_cp.Count);
            page1.Delete(0);
        }
Ejemplo n.º 16
0
        public void CustomProps_TryAllTypes()
        {
            var page1 = this.GetNewPage();

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

            // string
            var cp_string = new CustomPropertyCells();

            cp_string.Value = "Hello World";
            cp_string.Type  = 0;

            var cp_int = new CustomPropertyCells();

            cp_int.Value = 1024;
            cp_int.Type  = 2;

            var cp_dt = new CustomPropertyCells();

            cp_dt.Value = "DATETIME(\"03/31/1979\")";
            cp_dt.Type  = 5;

            var cp_bool = new CustomPropertyCells();

            cp_bool.Value = "TRUE";
            cp_bool.Type  = 2;

            var cp_float = new CustomPropertyCells();

            cp_float.Value = 3.14;
            cp_float.Type  = 2;

            CustomPropertyHelper.Set(s1, "PropertyString", cp_string);
            CustomPropertyHelper.Set(s1, "PropertyInt", cp_int);
            CustomPropertyHelper.Set(s1, "PropertyFloat", cp_float);
            CustomPropertyHelper.Set(s1, "PropertyDateTime", cp_dt);
            CustomPropertyHelper.Set(s1, "PropertyBool", cp_bool);

            page1.Delete(0);
        }
Ejemplo n.º 17
0
        public void CustomProps_InvalidPropName()
        {
            bool caught = false;
            var  page1  = this.GetNewPage();
            var  s1     = page1.DrawRectangle(0, 0, 2, 2);

            Assert.AreEqual(0, CustomPropertyHelper.Get(s1).Count);
            try
            {
                CustomPropertyHelper.Set(s1, "FOO 1", "BAR1");
            }
            catch (System.ArgumentException)
            {
                page1.Delete(0);
                caught = true;
            }

            if (!caught)
            {
                Assert.Fail("Did not catch expected exception");
            }
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
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);
        }
        public void SetCustomProperty(TargetShapes targetshapes, string name, CustomPropertyCells customprop)
        {
            if (customprop == null)
            {
                throw new System.ArgumentNullException(nameof(customprop));
            }

            targetshapes = targetshapes.ResolveToShapes(this._client);

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

            customprop.EncodeValues();

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetCustomProperty)))
            {
                foreach (var shape in targetshapes.Shapes)
                {
                    CustomPropertyHelper.Set(shape, name, customprop);
                }
            }
        }
Ejemplo n.º 21
0
        public void CustomProps_GetSet2()
        {
            var page1 = this.GetNewPage();

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

            s1.Text = "Checking for Custom Properties";


            var cp1 = new CustomPropertyCells();

            cp1.Ask       = "1";
            cp1.Calendar  = "0";
            cp1.Format    = "1";
            cp1.Invisible = "0";
            cp1.Label     = "1";
            cp1.LangID    = "0";
            cp1.Prompt    = "1";
            cp1.SortKey   = "0";
            cp1.Type      = "0";
            cp1.Value     = "1";

            CustomPropertyHelper.Set(s1, "PROP1", cp1);

            var props1 = CustomPropertyHelper.Get(s1);

            var cp2 = props1["PROP1"];

            Assert.AreEqual("TRUE", cp2.Ask.Formula.Value);
            Assert.AreEqual("0", cp2.Calendar.Formula.Value);
            Assert.AreEqual("\"1\"", cp2.Format.Formula.Value);
            Assert.AreEqual("FALSE", cp2.Invisible.Formula.Value);
            Assert.AreEqual("\"1\"", cp2.Label.Formula.Value);

            Assert.AreEqual("0", cp2.LangID.Formula.Value);
            Assert.AreEqual("\"1\"", cp2.Prompt.Formula.Value);
            Assert.AreEqual("0", cp2.SortKey.Formula.Value);
            Assert.AreEqual("0", cp2.Type.Formula.Value);

            Assert.AreEqual("\"1\"", cp2.Value.Formula.Value);

            var cp3 = new CustomPropertyCells();

            cp3.Ask       = "0";
            cp3.Calendar  = "2";
            cp3.Format    = "0";
            cp3.Invisible = "TRUE";
            cp3.Label     = "3";
            cp3.LangID    = "2";
            cp3.Prompt    = "3";
            cp3.SortKey   = "2";
            cp3.Type      = "3";
            cp3.Value     = "2";

            CustomPropertyHelper.Set(s1, "PROP1", cp3);
            var props2 = CustomPropertyHelper.Get(s1);

            var cp4 = props2["PROP1"];

            Assert.AreEqual("FALSE", cp4.Ask.Formula.Value);
            Assert.AreEqual("2", cp4.Calendar.Formula.Value);
            Assert.AreEqual("\"0\"", cp4.Format.Formula.Value);
            Assert.AreEqual("TRUE", cp4.Invisible.Formula.Value);
            Assert.AreEqual("\"3\"", cp4.Label.Formula.Value);

            Assert.AreEqual("2", cp4.LangID.Formula.Value);
            Assert.AreEqual("\"3\"", cp4.Prompt.Formula.Value);
            Assert.AreEqual("2", cp4.SortKey.Formula.Value);
            Assert.AreEqual("3", cp4.Type.Formula.Value);

            Assert.AreEqual("2", cp4.Value.Formula.Value);

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

            if (doc != null)
            {
                doc.Close(true);
            }
        }
Ejemplo n.º 22
0
        public void CustomProps_AllTypes()
        {
            var page1 = this.GetNewPage();
            var s1    = page1.DrawRectangle(0, 0, 1, 1);

            s1.Text = "Checking for Custom Properties";

            // String Custom Property
            var prop_string_in = new CustomPropertyCells();

            prop_string_in.Format = "\"Format\"";
            prop_string_in.Label  = "\"Label\"";
            prop_string_in.Prompt = "\"Prompt\"";
            prop_string_in.Type   = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.String);
            prop_string_in.Value  = "1";

            // Boolean
            var prop_bool_in = new CustomPropertyCells();

            prop_bool_in.Format = "\"Format\"";
            prop_bool_in.Label  = "\"Label\"";
            prop_bool_in.Prompt = "\"Prompt\"";
            prop_bool_in.Type   = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Boolean);
            prop_bool_in.Value  = true;

            // Date
            var dt           = new System.DateTime(2017, 3, 31, 14, 5, 6);
            var st           = dt.ToString(CultureInfo.InvariantCulture);
            var prop_date_in = new CustomPropertyCells();

            prop_date_in.Format = "\"Format\"";
            prop_date_in.Label  = "\"Label\"";
            prop_date_in.Prompt = "\"Prompt\"";
            prop_date_in.Type   = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Date);
            prop_date_in.Value  = string.Format("DATETIME(\"{0}\")", st);;

            // Boolean
            var prop_number_in = new CustomPropertyCells();

            prop_number_in.Format = "\"Format\"";
            prop_number_in.Label  = "\"Label\"";
            prop_number_in.Prompt = "\"Prompt\"";
            prop_number_in.Type   = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Number);
            prop_number_in.Value  = "3.14";

            CustomPropertyHelper.Set(s1, "PROP_STRING", prop_string_in);
            CustomPropertyHelper.Set(s1, "PROP_BOOLEAN", prop_bool_in);
            CustomPropertyHelper.Set(s1, "PROP_DATE", prop_date_in);
            CustomPropertyHelper.Set(s1, "PROP_NUMBER", prop_number_in);

            var props_dic = CustomPropertyHelper.GetDictionary(s1, CellValueType.Formula);


            var prop_string_out = props_dic["PROP_STRING"];

            Assert.AreEqual("\"Format\"", prop_string_out.Format.Value);
            Assert.AreEqual("\"Label\"", prop_string_out.Label.Value);
            Assert.AreEqual("\"Prompt\"", prop_string_out.Prompt.Value);
            Assert.AreEqual("0", prop_string_out.Type.Value);
            Assert.AreEqual("1", prop_string_out.Value.Value);

            var prop_bool_out = props_dic["PROP_BOOLEAN"];

            Assert.AreEqual("\"Format\"", prop_bool_out.Format.Value);
            Assert.AreEqual("\"Label\"", prop_bool_out.Label.Value);
            Assert.AreEqual("\"Prompt\"", prop_bool_out.Prompt.Value);
            Assert.AreEqual("3", prop_bool_out.Type.Value);
            Assert.AreEqual("TRUE", prop_bool_out.Value.Value);

            var prop_date_out = props_dic["PROP_DATE"];

            Assert.AreEqual("\"Format\"", prop_date_out.Format.Value);
            Assert.AreEqual("\"Label\"", prop_date_out.Label.Value);
            Assert.AreEqual("\"Prompt\"", prop_date_out.Prompt.Value);
            Assert.AreEqual("5", prop_date_out.Type.Value);
            Assert.AreEqual("DATETIME(\"03/31/2017 14:05:06\")", prop_date_out.Value.Value);

            var prop_number_out = props_dic["PROP_NUMBER"];

            Assert.AreEqual("\"Format\"", prop_number_out.Format.Value);
            Assert.AreEqual("\"Label\"", prop_number_out.Label.Value);
            Assert.AreEqual("\"Prompt\"", prop_number_out.Prompt.Value);
            Assert.AreEqual("2", prop_number_out.Type.Value);
            Assert.AreEqual("3.14", prop_number_out.Value.Value);

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

            if (doc != null)
            {
                doc.Close(true);
            }
        }
Ejemplo n.º 23
0
        public void CustomProps_TryAllTypes()
        {
            var page1 = this.GetNewPage();

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

            // string
            var cp_string = new CustomPropertyCells();

            cp_string.Value = "\"Hello World\"";
            cp_string.Type  = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.String);

            var cp_int = new CustomPropertyCells();

            cp_int.Value = 1024;
            cp_int.Type  = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Number);

            var cp_dt = new CustomPropertyCells();

            cp_dt.Value = "DATETIME(\"03/31/1979\")";
            cp_dt.Type  = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Date);

            var cp_bool = new CustomPropertyCells();

            cp_bool.Value = "TRUE";
            cp_bool.Type  = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Boolean);

            var cp_float = new CustomPropertyCells();

            cp_float.Value = 3.14;
            cp_float.Type  = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Number);

            CustomPropertyHelper.Set(s1, "PropertyString", cp_string);
            CustomPropertyHelper.Set(s1, "PropertyInt", cp_int);
            CustomPropertyHelper.Set(s1, "PropertyFloat", cp_float);
            CustomPropertyHelper.Set(s1, "PropertyDateTime", cp_dt);
            CustomPropertyHelper.Set(s1, "PropertyBool", cp_bool);

            var cpdic = CustomPropertyHelper.GetDictionary(s1, CellValueType.Formula);

            var out_cpstring   = cpdic["PropertyString"];
            var out_cpint      = cpdic["PropertyInt"];
            var out_cpfloat    = cpdic["PropertyFloat"];
            var out_cpdatetime = cpdic["PropertyDateTime"];
            var out_cpbool     = cpdic["PropertyBool"];

            Assert.AreEqual("\"Hello World\"", out_cpstring.Value.Value);
            Assert.AreEqual("0", out_cpstring.Type.Value);

            Assert.AreEqual("1024", out_cpint.Value.Value);
            Assert.AreEqual("2", out_cpint.Type.Value);

            Assert.AreEqual("3.14", out_cpfloat.Value.Value);
            Assert.AreEqual("2", out_cpfloat.Type.Value);

            Assert.AreEqual("DATETIME(\"03/31/1979\")", out_cpdatetime.Value.Value);
            Assert.AreEqual("5", out_cpdatetime.Type.Value);

            Assert.AreEqual("TRUE", out_cpbool.Value.Value);
            Assert.AreEqual("3", out_cpbool.Type.Value);

            page1.Delete(0);
        }