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"]; }
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); }
public void CustomProps_InvalidPropName() { bool caught = false; var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 2, 2); Assert.AreEqual(0, CustomPropertyHelper.GetCells(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 IDictionary <IVisio.Shape, CustomPropertyDictionary> Get(VisioScripting.Models.TargetShapes targets) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); var prop_dic = new Dictionary <IVisio.Shape, CustomPropertyDictionary>(); 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_custom_props = CustomPropertyHelper.GetCells(page, targets.Shapes, CellValueType.Formula); for (int i = 0; i < targets.Shapes.Count; i++) { var shape = targets.Shapes[i]; var props = list_custom_props[i]; prop_dic[shape] = props; } return(prop_dic); }
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); }
public void RenderDirectedGraphWithCustomProps() { var d = new DirectedGraphLayout(); var n0 = d.AddShape("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 options = new MsaglLayoutOptions(); options.UseDynamicConnectors = true; var visapp = this.GetVisioApplication(); var doc = this.GetNewDoc(); var page1 = visapp.ActivePage; d.Render(page1, options); Assert.IsNotNull(n0.VisioShape); var props_dic = CustomPropertyHelper.GetCells(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_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.GetCells(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); }
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 = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.String); cp1.Value = "1"; CustomPropertyHelper.Set(s1, "PROP1", cp1); var props1 = CustomPropertyHelper.GetCells(s1, CellValueType.Formula); var cp2 = props1["PROP1"]; Assert.AreEqual("TRUE", cp2.Ask.Value); Assert.AreEqual("0", cp2.Calendar.Value); Assert.AreEqual("\"1\"", cp2.Format.Value); Assert.AreEqual("FALSE", cp2.Invisible.Value); Assert.AreEqual("\"1\"", cp2.Label.Value); Assert.AreEqual("0", cp2.LangID.Value); Assert.AreEqual("\"1\"", cp2.Prompt.Value); Assert.AreEqual("0", cp2.SortKey.Value); Assert.AreEqual("0", cp2.Type.Value); Assert.AreEqual("1", cp2.Value.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 = CustomPropertyCells.CustomPropertyTypeToInt(CustomPropertyType.Boolean); cp3.Value = "2"; CustomPropertyHelper.Set(s1, "PROP1", cp3); var props2 = CustomPropertyHelper.GetCells(s1, CellValueType.Formula); var cp4 = props2["PROP1"]; Assert.AreEqual("FALSE", cp4.Ask.Value); Assert.AreEqual("2", cp4.Calendar.Value); Assert.AreEqual("\"0\"", cp4.Format.Value); Assert.AreEqual("TRUE", cp4.Invisible.Value); Assert.AreEqual("\"3\"", cp4.Label.Value); Assert.AreEqual("2", cp4.LangID.Value); Assert.AreEqual("\"3\"", cp4.Prompt.Value); Assert.AreEqual("2", cp4.SortKey.Value); Assert.AreEqual("3", cp4.Type.Value); Assert.AreEqual("2", cp4.Value.Value); var app = this.GetVisioApplication(); var doc = app.ActiveDocument; if (doc != null) { doc.Close(true); } }
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.GetCells(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.GetCells(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.GetCells(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.GetCells(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.GetCells(s1, CellValueType.Formula); Assert.AreEqual(0, c4.Count); var app = this.GetVisioApplication(); var doc = app.ActiveDocument; if (doc != null) { doc.Close(true); } }