public void RenderDirectedGraphWithCustomProps() { var d = new VA.Models.DirectedGraph.Drawing(); var n0 = d.AddShape("n0", "Untitled Node", "basflo_u.vss", "Decision"); n0.Size = new VA.Drawing.Size(3, 2); n0.CustomProperties = new Dictionary <string, CustomPropertyCells>(); n0.CustomProperties["p1"] = new CustomPropertyCells("v1"); n0.CustomProperties["p2"] = new CustomPropertyCells("v2"); n0.CustomProperties["p3"] = new CustomPropertyCells("v3"); var options = new VA.Models.DirectedGraph.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.Get(n0.VisioShape); Assert.IsTrue(props_dic.Count >= 3); Assert.AreEqual("\"v1\"", props_dic["p1"].Value.Formula); Assert.AreEqual("\"v2\"", props_dic["p2"].Value.Formula); Assert.AreEqual("\"v3\"", props_dic["p3"].Value.Formula); page1.Application.ActiveWindow.ViewFit = (short)IVisio.VisWindowFit.visFitPage; doc.Close(true); }
public IDictionary <IVisio.Shape, CustomPropertyDictionary> Get(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.Get(page, targets.Shapes); 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 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); }
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.Get(s1).Count); // Add the same one multiple times Custom Property CustomPropertyHelper.Set(s1, "FOO1", "BAR1"); // Asset that now we have ONE CustomProperty Assert.AreEqual(1, CustomPropertyHelper.Get(s1).Count); // 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"); CustomPropertyHelper.Set(s1, "FOO1", "BAR3"); CustomPropertyHelper.Set(s1, "FOO1", "BAR4"); // Asset that now we have ONE CustomProperty Assert.AreEqual(1, CustomPropertyHelper.Get(s1).Count); // Check that it is called FOO1 Assert.AreEqual(true, CustomPropertyHelper.Contains(s1, "FOO1")); page1.Delete(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); }
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.Get(s1).Count); // 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.Get(s1).Count); // 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.Get(s1).Count); page1.Delete(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); } }
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.Get(s1); Assert.AreEqual(1, out_cp.Count); page1.Delete(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); }
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"); } }
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 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); } }