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"); } }
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.GetDictionary(s1, VASS.CellValueType.Formula); var cp_foo1 = props["FOO1"]; // var cp_foo2 = props["FOO2"]; // there is not prop called FOO2 var cp_foo3 = props["FOO3"]; }
public List <CustomPropertyDictionary> GetCustomProperties(TargetShapes targetshapes, VASS.CellValueType type) { targetshapes = targetshapes.ResolveToShapes(this._client); if (targetshapes.Shapes.Count < 1) { return(new List <CustomPropertyDictionary>(0)); } var page = targetshapes.Shapes[0].ContainingPage; var shapeidpairs = targetshapes.ToShapeIDPairs(); var listof_cpdic = CustomPropertyHelper.GetDictionary(page, shapeidpairs, type); return(listof_cpdic); }
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.GetDictionary(s1, CellValueType.Formula); Assert.AreEqual(1, out_cp.Count); page1.Delete(0); }
public void RenderDirectedGraphWithCustomProps() { var d = new VADG.DirectedGraphLayout(); var n0 = d.AddNode("n0", "Untitled Node", "basflo_u.vss", "Decision"); n0.Size = new VA.Geometry.Size(3, 2); n0.CustomProperties = new CustomPropertyDictionary(); n0.CustomProperties["p1"] = new CustomPropertyCells("\"v1\""); n0.CustomProperties["p2"] = new CustomPropertyCells("\"v2\""); n0.CustomProperties["p3"] = new CustomPropertyCells("\"v3\""); var visapp = this.GetVisioApplication(); var doc = this.GetNewDoc(); var page1 = visapp.ActivePage; var renderer = new VADG.MsaglRenderer(); renderer.LayoutOptions.UseDynamicConnectors = true; renderer.Render(page1, d); Assert.IsNotNull(n0.VisioShape); var props_dic = CustomPropertyHelper.GetDictionary(n0.VisioShape, CellValueType.Formula); Assert.IsTrue(props_dic.Count >= 3); Assert.AreEqual("\"v1\"", props_dic["p1"].Value.Value); Assert.AreEqual("\"v2\"", props_dic["p2"].Value.Value); Assert.AreEqual("\"v3\"", props_dic["p3"].Value.Value); page1.Application.ActiveWindow.ViewFit = (short)IVisio.VisWindowFit.visFitPage; string output_filename = TestGlobals.TestHelper.GetOutputFilename(nameof(RenderDirectedGraphWithCustomProps), ".vsd"); doc.SaveAs(output_filename); doc.Close(); }
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 shapeidpairs = ShapeIDPairs.FromShapes(shapes); var allprops = CustomPropertyHelper.GetDictionary(page1, shapeidpairs, 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); }
public void CustomProps_CRUD() { 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.GetDictionary(s1, CellValueType.Formula); Assert.AreEqual(0, c0.Count); int cp_type = 0; // 0 for string // Set one property // Notice that the properties some back double-quoted CustomPropertyHelper.Set(s1, "PROP1", "\"VAL1\"", cp_type); var c1 = CustomPropertyHelper.GetDictionary(s1, CellValueType.Formula); Assert.AreEqual(1, c1.Count); Assert.IsTrue(c1.ContainsKey("PROP1")); Assert.AreEqual("\"VAL1\"", c1["PROP1"].Value.Value); // Add another property CustomPropertyHelper.Set(s1, "PROP2", "\"VAL 2\"", cp_type); var c2 = CustomPropertyHelper.GetDictionary(s1, CellValueType.Formula); Assert.AreEqual(2, c2.Count); Assert.IsTrue(c2.ContainsKey("PROP1")); Assert.AreEqual("\"VAL1\"", c2["PROP1"].Value.Value); Assert.IsTrue(c2.ContainsKey("PROP2")); Assert.AreEqual("\"VAL 2\"", c2["PROP2"].Value.Value); // Modify the value of the second property CustomPropertyHelper.Set(s1, "PROP2", "\"VAL 2 MOD\"", cp_type); var c3 = CustomPropertyHelper.GetDictionary(s1, CellValueType.Formula); Assert.AreEqual(2, c3.Count); Assert.IsTrue(c3.ContainsKey("PROP1")); Assert.AreEqual("\"VAL1\"", c3["PROP1"].Value.Value); Assert.IsTrue(c3.ContainsKey("PROP2")); Assert.AreEqual("\"VAL 2 MOD\"", c3["PROP2"].Value.Value); // Now delete all the custom properties foreach (string name in c3.Keys) { CustomPropertyHelper.Delete(s1, name); } var c4 = CustomPropertyHelper.GetDictionary(s1, CellValueType.Formula); Assert.AreEqual(0, c4.Count); var app = this.GetVisioApplication(); var doc = app.ActiveDocument; if (doc != null) { doc.Close(true); } }
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); } }
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); }