Example #1
0
        public void VDX_MultiPageDocument()
        {
            string output_filename = TestGlobals.TestHelper.GetTestMethodOutputFilename(".vdx");

            var template = new VisioAutomation.VDX.Template(); // the default template
            var doc      = new VisioAutomation.VDX.Elements.Drawing(template);

            var Page01 = VDX_Files.GetPage01_Simple_Fill_Format(doc);
            var Page02 = VDX_Files.GetPage02_Locking(doc);
            var Page03 = VDX_Files.GetPage03_Text_Block(doc);
            var Page04 = VDX_Files.GetPage04_Simple_Text(doc);
            var Page05 = VDX_Files.GetPage05_Formatted_Text(doc);
            var Page06 = VDX_Files.GetPage06_All_FillPatterns(doc);
            var Page08 = VDX_Files.GetPage08_Connector_With_Geometry(doc);
            var Page09 = VDX_Files.GetPage09_Layout(doc);
            var Page10 = VDX_Files.GetPage10_layers(doc);
            var Page11 = VDX_Files.GetPage11_Add_color(doc);
            var Page12 = VDX_Files.GetPage12_AdjustToTextSize(doc);
            var Page13 = VDX_Files.GetPage13_MultipleConnectors(doc);
            var Page14 = VDX_Files.GetPage14_Hyperlinks(doc);

            var w1 = new VisioAutomation.VDX.Elements.DocumentWindow();

            w1.ShowGrid             = false;
            w1.ShowGuides           = false;
            w1.ShowConnectionPoints = false;
            w1.ShowPageBreaks       = false;
            w1.Page = Page01.ID; // point to first page we created

            doc.Windows.Add(w1);

            doc.Save(output_filename);

            // Verify this file can be loaded
            this.VerifyDocCanBeLoaded(output_filename);
        }
Example #2
0
        public void VDX_CustomTemplate()
        {
            string input_filename = this.GetTestResultsOutPath(@"datafiles\template_router.vdx");
            string output_filename = TestGlobals.TestHelper.GetTestMethodOutputFilename(".vdx");
            
            // Load the template
            string template_xml = File.ReadAllText(input_filename);

            var template = new VisioAutomation.VDX.Template(template_xml);
            var doc = new VisioAutomation.VDX.Elements.Drawing(template);
            var page = new VisioAutomation.VDX.Elements.Page(8, 4);

            doc.Pages.Add(page);

            // add layers
            var layer0 = page.AddLayer("Layer0", 0);
            var layer1 = page.AddLayer("Layer1", 1);
            var layer2 = page.AddLayer("Layer2", 2);

            // create layout
            var layout = new VisioAutomation.VDX.Sections.Layout();
            layout.ShapeRouteStyle.Result = VisioAutomation.VDX.Enums.RouteStyle.TreeEW;

            // find the id of the master for rounded rectangles
            int shapeMasterNameId = doc.GetMasterMetaData("Router").ID;
            bool shapeMasterNameGroup = doc.GetMasterMetaData("Router").IsGroup;

            // add shape1
            var shape1 = new VisioAutomation.VDX.Elements.Shape(shapeMasterNameId, shapeMasterNameGroup, 1, 3);
            page.Shapes.Add(shape1);
            shape1.Text.Add("Router1");
            shape1.Layout = layout;

            // add shape2
            var shape2 = new VisioAutomation.VDX.Elements.Shape(shapeMasterNameId, shapeMasterNameGroup, 5, 3);
            page.Shapes.Add(shape2);
            shape2.Text.Add("Router2");
            shape2.Layout = shape1.Layout;

            // add shape3 - this is the dynamic connector
            var shape3 = VisioAutomation.VDX.Elements.Shape.CreateDynamicConnector(doc);
            shape3.XForm1D.BeginX.Result = 1;
            shape3.XForm1D.EndX.Result = 5;
            shape3.XForm1D.BeginY.Result = 3;
            shape3.XForm1D.EndY.Result = 3;
            page.Shapes.Add(shape3);
            shape3.Geom = new VisioAutomation.VDX.Sections.Geom();
            shape3.Geom.Rows.Add(new VisioAutomation.VDX.Sections.MoveTo(1, 3));
            shape3.Geom.Rows.Add(new VisioAutomation.VDX.Sections.LineTo(5, 3));

            shape3.Layout = shape1.Layout;
            page.ConnectShapesViaConnector(shape3, shape1, shape2);

            // handle layers
            shape3.LayerMembership = new List<int> {layer0.Index, layer2.Index};
            shape1.LayerMembership = new List<int> {layer1.Index};
            shape2.LayerMembership = new List<int> {layer2.Index};

            // write document to disk as .vdx file

            doc.Save(output_filename);

            this.VerifyDocCanBeLoaded(output_filename);
        }
Example #3
0
        public void VDX_CustomProperties()
        {
            string filename = TestGlobals.TestHelper.GetTestMethodOutputFilename(".vdx");

            var template = new VisioAutomation.VDX.Template();
            var doc_node = new VisioAutomation.VDX.Elements.Drawing(template);

            int rect_id = doc_node.GetMasterMetaData("REctAngle").ID;

            var node_page = new VisioAutomation.VDX.Elements.Page(8, 5);
            doc_node.Pages.Add(node_page);

            var node_shape = new VisioAutomation.VDX.Elements.Shape(rect_id, 4, 2, 3, 2);
            node_shape.CustomProps = new VisioAutomation.VDX.Elements.CustomProps();

            var node_custprop0 = new VisioAutomation.VDX.Elements.CustomProp("PROP1");
            node_custprop0.Value = "VALUE1";
            node_shape.CustomProps.Add(node_custprop0);

            var node_custprop1 = new VisioAutomation.VDX.Elements.CustomProp("PROP2");
            node_custprop1.Value = "123";
            node_custprop1.Type.Result = VisioAutomation.VDX.Enums.CustomPropType.String;
            node_shape.CustomProps.Add(node_custprop1);

            var node_custprop2 = new VisioAutomation.VDX.Elements.CustomProp("PROP3");
            node_custprop2.Value = "456";
            node_custprop2.Type.Result = VisioAutomation.VDX.Enums.CustomPropType.Number;
            node_shape.CustomProps.Add(node_custprop2);

            node_page.Shapes.Add(node_shape);

            doc_node.Save(filename);

            var app = new IVisio.Application();
            var docs = app.Documents;
            var doc = docs.Add(filename);

            var page = app.ActivePage;
            var shapes = page.Shapes;
            Assert.AreEqual(1,page.Shapes.Count);

            var shape = page.Shapes[1];
            var customprops = VACUSTPROP.CustomPropertyHelper.Get(shape);

            Assert.IsTrue(customprops.ContainsKey("PROP1"));
            Assert.AreEqual("\"VALUE1\"",customprops["PROP1"].Value.Formula);


            Assert.IsTrue(customprops.ContainsKey("PROP2"));
            Assert.AreEqual("\"123\"", customprops["PROP2"].Value.Formula);
            Assert.AreEqual("0", customprops["PROP2"].Type.Formula);

            Assert.IsTrue(customprops.ContainsKey("PROP3"));
            Assert.AreEqual("\"456\"", customprops["PROP3"].Value.Formula);
            Assert.AreEqual("2", customprops["PROP3"].Type.Formula);

            app.Quit(true);
        }
Example #4
0
        public void VDX_MultiPageDocument()
        {
            string output_filename = TestGlobals.TestHelper.GetTestMethodOutputFilename(".vdx");

            var template = new VisioAutomation.VDX.Template(); // the default template
            var doc = new VisioAutomation.VDX.Elements.Drawing(template);

            var Page01 = VDX_Files.GetPage01_Simple_Fill_Format(doc);
            var Page02 = VDX_Files.GetPage02_Locking(doc);
            var Page03 = VDX_Files.GetPage03_Text_Block(doc);
            var Page04 = VDX_Files.GetPage04_Simple_Text(doc);
            var Page05 = VDX_Files.GetPage05_Formatted_Text(doc);
            var Page06 = VDX_Files.GetPage06_All_FillPatterns(doc);
            var Page08 = VDX_Files.GetPage08_Connector_With_Geometry(doc);
            var Page09 = VDX_Files.GetPage09_Layout(doc);
            var Page10 = VDX_Files.GetPage10_layers(doc);
            var Page11 = VDX_Files.GetPage11_Add_color(doc);
            var Page12 = VDX_Files.GetPage12_AdjustToTextSize(doc);
            var Page13 = VDX_Files.GetPage13_MultipleConnectors(doc);
            var Page14 = VDX_Files.GetPage14_Hyperlinks(doc);

            var w1 = new VisioAutomation.VDX.Elements.DocumentWindow();
            w1.ShowGrid = false;
            w1.ShowGuides = false;
            w1.ShowConnectionPoints = false;
            w1.ShowPageBreaks = false;
            w1.Page = Page01.ID; // point to first page we created
            
            doc.Windows.Add(w1);

            doc.Save(output_filename);
            
            // Verify this file can be loaded
            this.VerifyDocCanBeLoaded(output_filename);
        }
Example #5
0
        static void Main(string[] args)
        {
            string left_font = "Calibri";

            var template = new VDX.Template();
            var doc = new VDX.Elements.Drawing(template);
            var page = new VDX.Elements.Page(10,10);
            doc.Pages.Add(page);
            var faces = doc.Faces;

            var left_face = Helpers.GetFontSafe(doc.Faces, left_font);

            double face_size = 32.0;
            int rect_id = doc.GetMasterMetaData("REctAngle").ID;

            string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string letters2 = "abcdefghijklmnopqrstuvwxyz";
            string numbers = "01234567890";
            string punctuation = "!@#$%^&*()_+-=<>,.[]{}\\|``/?;:'\"";

            var text = letters + letters2 + numbers + punctuation;

            int count = text.Length;
            int cols = (int) System.Math.Ceiling(System.Math.Sqrt(count));
            double face_size_inches = face_size / 72.0;

            double box_size = face_size_inches*2.0;
            double box_sep = box_size/8.0;

            double grid_delta = box_size + box_sep;

            page.PageProperties.PageWidth.Formula = (cols*grid_delta).ToString();
            page.PageProperties.PageHeight.Formula = (cols * grid_delta).ToString();

            int n = 0;
            foreach (int row in Enumerable.Range(0, cols))
            {
                foreach (int col in Enumerable.Range(0,cols))
                {
                    if (n >= count)
                    {
                        break;
                    }


                    var pinx = col* grid_delta;
                    var piny = (cols*grid_delta) - (row * grid_delta);

                    var shape = new VDX.Elements.Shape(rect_id,pinx, piny, box_size, box_size);
                    page.Shapes.Add(shape);

                    string s = text[n].ToString();
                    shape.Text.Add(s);

                    shape.CharFormats = new List<VDX.Sections.Char>();

                    var charfmt = new VDX.Sections.Char();
                    charfmt.Font.Formula = left_face.ID.ToString();
                    charfmt.Size.Formula = face_size.ToString()+"pt"; 

                    shape.CharFormats.Add(charfmt);

                    shape.Fill = new VDX.Sections.Fill();
                    shape.Fill.Pattern.Formula = "0";
                    shape.Fill.ForegroundColor.Formula = "rgb(255,255,255)";
                    shape.Fill.ForegroundTransparency.Formula = "1.0";

                    shape.Line  = new VDX.Sections.Line();
                    shape.Line.Pattern.Formula = "0";
                    shape.Line.Weight.Formula = "0";
                    shape.Line.Color.Formula = "rgb(240,240,240)";
                    n++;
                }

            }

            doc.Save("D:\\specimen.vdx");
        }
        private void GenerateVisio(string drawingOutputPath)
        {
            var pageWidth                = 16.53543307086614;
            var pageHeight               = 11.69291338582677;
            var left                     = 0.1;
            var processWidth             = 1.5;
            var processHeight            = 1.0;
            var processPaddingHorizontal = 0.4;
            var processPaddingVertical   = 1.4;
            var maxProcessCountPerRow    = 10;
            var activityPos              = 1;
            var activityYPos             = 0;
            var addToHorizontal          = 1;
            var shapes                   = new List <VisioShape>();

            // Clean up the template and remove the existing pages
            var templateXml = XDocument.Load("DrawingTemplate.vdx");
            //VisioTemplate.CleanUpTemplate(templateXml);

            var template = new VisioTemplate(templateXml.ToString());
            var document = new VisioDrawing(template);

            document.DocumentProperties.Creator     = "Automation Studio";
            document.DocumentProperties.TimeCreated = DateTime.Now;

            // Configure the page
            var runbooks     = _backendContext.Runbooks;
            var runbooksList = new List <RunbookModelProxy>();

            foreach (var runbook in runbooks)
            {
                runbooksList.Add((runbook.Tag as RunbookModelProxy));
            }

            var languageContext = new LanguageContext();

            foreach (var runbook in runbooks)
            {
                if (!(runbook.Tag as RunbookModelProxy).PublishedRunbookVersionID.HasValue)
                {
                    continue;
                }

                var runbookProxy = (runbook.Tag as RunbookModelProxy);
                _statusManager.SetText("Generating visio drawing for " + runbookProxy.RunbookName);
                var viewModel = (runbook.Tag as RunbookModelProxy).GetViewModel <RunbookViewModel>();

                var page = ConfigureVisioPage(viewModel.Runbook.RunbookName, pageWidth, pageHeight);
                document.Pages.Add(page);

                var publishedContent = viewModel.GetContent(RunbookType.Published, true);
                languageContext.Parse(publishedContent);

                var references = languageContext.GetReferences(runbooksList);

                if (references.Count == 0)
                {
                    continue;
                }

                var totalRows = (double)(runbooksList.Count / maxProcessCountPerRow);

                if (runbooksList.Count <= maxProcessCountPerRow)
                {
                    totalRows = 2.0;
                }

                var y  = (pageHeight / totalRows) + (totalRows * ((processHeight + processPaddingVertical)) / totalRows);
                var x  = (pageWidth / (maxProcessCountPerRow - 1)) + ((processWidth + processPaddingHorizontal) * activityPos);
                var ay = y - ((processHeight + processPaddingVertical) * activityYPos);

                // Add the current runbook as the start activity
                var processId     = document.GetMasterMetaData("Process").ID;
                var visioActivity = new VisioShape(processId, x, ay, processWidth, processHeight);

                var charFormat = new VisioAutomation.VDX.Sections.Char();
                charFormat.Size.Result = 12;

                visioActivity.CharFormats = new List <VisioAutomation.VDX.Sections.Char>();
                visioActivity.CharFormats.Add(charFormat);
                visioActivity.Text.Add(runbookProxy.RunbookName);

                page.Shapes.Add(visioActivity);
                shapes.Add(visioActivity);

                activityPos += addToHorizontal;

                foreach (var reference in references)
                {
                    x  = (pageWidth / (maxProcessCountPerRow - 1)) + ((processWidth + processPaddingHorizontal) * activityPos);
                    ay = y - ((processHeight + processPaddingVertical) * activityYPos);

                    // Add all references
                    processId     = document.GetMasterMetaData("Process").ID;
                    visioActivity = new VisioShape(processId, x, ay, processWidth, processHeight);

                    visioActivity.CharFormats = new List <VisioAutomation.VDX.Sections.Char>();
                    visioActivity.CharFormats.Add(charFormat);
                    visioActivity.Text.Add(reference.RunbookName);

                    page.Shapes.Add(visioActivity);
                    shapes.Add(visioActivity);

                    /*//if (!String.IsNullOrEmpty(activity.Description))
                     * {
                     *  int shapeID = visioActivity.ID;
                     *
                     *  var callOut = new VisioShape(26, x + 0.3, ay + 1.0);
                     *  //callOut.Text.Add(activity.Description);
                     *  callOut.Geom = new VisioAutomation.VDX.Sections.Geom();
                     *
                     *  page.Shapes.Add(callOut);
                     * }*/

                    activityPos++;

                    if (activityPos >= maxProcessCountPerRow)
                    {
                        addToHorizontal = -1;
                        activityPos    += addToHorizontal;
                        activityYPos++;
                    }
                    else
                    {
                        addToHorizontal = 1;
                        activityPos    += addToHorizontal;
                        activityYPos++;
                    }
                }

                // Add connectors between the activities
                for (int i = 0; i < shapes.Count; i++)
                {
                    // We only add connectors up until the latest process object
                    if ((i + 1) >= shapes.Count)
                    {
                        break;
                    }

                    VisioShape a1 = shapes[i];
                    VisioShape a2 = shapes[i + 1];

                    var line = VisioShape.CreateDynamicConnector(document);
                    line.XForm1D.EndY.Result = 0;

                    line.Line = new VisioLine();
                    line.Line.EndArrow.Result = 2;

                    page.Shapes.Add(line);
                    page.ConnectShapesViaConnector(line, a1, a2);
                }

                shapes.Clear();
                languageContext.ClearCache();
            }

            document.Save(drawingOutputPath);
        }
        private void GenerateVisio(string drawingOutputPath)
        {
            var pageWidth = 16.53543307086614;
            var pageHeight = 11.69291338582677;
            var left = 0.1;
            var processWidth = 1.5;
            var processHeight = 1.0;
            var processPaddingHorizontal = 0.4;
            var processPaddingVertical = 1.4;
            var maxProcessCountPerRow = 10;
            var activityPos = 1;
            var activityYPos = 0;
            var addToHorizontal = 1;
            var shapes = new List<VisioShape>();

            // Clean up the template and remove the existing pages
            var templateXml = XDocument.Load("DrawingTemplate.vdx");
            //VisioTemplate.CleanUpTemplate(templateXml);

            var template = new VisioTemplate(templateXml.ToString());
            var document = new VisioDrawing(template);
            document.DocumentProperties.Creator = "Automation Studio";
            document.DocumentProperties.TimeCreated = DateTime.Now;

            // Configure the page
            var runbooks = _backendContext.Runbooks;
            var runbooksList = new List<RunbookModelProxy>();
            foreach (var runbook in runbooks)
                runbooksList.Add((runbook.Tag as RunbookModelProxy));

            var languageContext = new LanguageContext();

            foreach (var runbook in runbooks)
            {
                if (!(runbook.Tag as RunbookModelProxy).PublishedRunbookVersionID.HasValue)
                    continue;

                var runbookProxy = (runbook.Tag as RunbookModelProxy);
                _statusManager.SetText("Generating visio drawing for " + runbookProxy.RunbookName);
                var viewModel = (runbook.Tag as RunbookModelProxy).GetViewModel<RunbookViewModel>();

                var page = ConfigureVisioPage(viewModel.Runbook.RunbookName, pageWidth, pageHeight);
                document.Pages.Add(page);

                var publishedContent = viewModel.GetContent(RunbookType.Published, true);
                languageContext.Parse(publishedContent);

                var references = languageContext.GetReferences(runbooksList);

                if (references.Count == 0)
                    continue;

                var totalRows = (double)(runbooksList.Count / maxProcessCountPerRow);

                if (runbooksList.Count <= maxProcessCountPerRow)
                    totalRows = 2.0;

                var y = (pageHeight / totalRows) + (totalRows * ((processHeight + processPaddingVertical)) / totalRows);
                var x = (pageWidth / (maxProcessCountPerRow - 1)) + ((processWidth + processPaddingHorizontal) * activityPos);
                var ay = y - ((processHeight + processPaddingVertical) * activityYPos);

                // Add the current runbook as the start activity
                var processId = document.GetMasterMetaData("Process").ID;
                var visioActivity = new VisioShape(processId, x, ay, processWidth, processHeight);

                var charFormat = new VisioAutomation.VDX.Sections.Char();
                charFormat.Size.Result = 12;

                visioActivity.CharFormats = new List<VisioAutomation.VDX.Sections.Char>();
                visioActivity.CharFormats.Add(charFormat);
                visioActivity.Text.Add(runbookProxy.RunbookName);

                page.Shapes.Add(visioActivity);
                shapes.Add(visioActivity);

                activityPos += addToHorizontal;

                foreach (var reference in references)
                {
                    x = (pageWidth / (maxProcessCountPerRow - 1)) + ((processWidth + processPaddingHorizontal) * activityPos);
                    ay = y - ((processHeight + processPaddingVertical) * activityYPos);

                    // Add all references
                    processId = document.GetMasterMetaData("Process").ID;
                    visioActivity = new VisioShape(processId, x, ay, processWidth, processHeight);

                    visioActivity.CharFormats = new List<VisioAutomation.VDX.Sections.Char>();
                    visioActivity.CharFormats.Add(charFormat);
                    visioActivity.Text.Add(reference.RunbookName);

                    page.Shapes.Add(visioActivity);
                    shapes.Add(visioActivity);

                    /*//if (!String.IsNullOrEmpty(activity.Description))
                    {
                        int shapeID = visioActivity.ID;

                        var callOut = new VisioShape(26, x + 0.3, ay + 1.0);
                        //callOut.Text.Add(activity.Description);
                        callOut.Geom = new VisioAutomation.VDX.Sections.Geom();

                        page.Shapes.Add(callOut);
                    }*/

                    activityPos++;

                    if (activityPos >= maxProcessCountPerRow)
                    {
                        addToHorizontal = -1;
                        activityPos += addToHorizontal;
                        activityYPos++;
                    }
                    else
                    {
                        addToHorizontal = 1;
                        activityPos += addToHorizontal;
                        activityYPos++;
                    }
                }

                // Add connectors between the activities
                for (int i = 0; i < shapes.Count; i++)
                {
                    // We only add connectors up until the latest process object
                    if ((i + 1) >= shapes.Count)
                        break;

                    VisioShape a1 = shapes[i];
                    VisioShape a2 = shapes[i + 1];

                    var line = VisioShape.CreateDynamicConnector(document);
                    line.XForm1D.EndY.Result = 0;

                    line.Line = new VisioLine();
                    line.Line.EndArrow.Result = 2;

                    page.Shapes.Add(line);
                    page.ConnectShapesViaConnector(line, a1, a2);
                }

                shapes.Clear();
                languageContext.ClearCache();
            }

            document.Save(drawingOutputPath);
        }
Example #8
0
        static void Main(string[] args)
        {
            string left_font = "Calibri";

            var template = new VDX.Template();
            var doc      = new VDX.Elements.Drawing(template);
            var page     = new VDX.Elements.Page(10, 10);

            doc.Pages.Add(page);
            var faces = doc.Faces;

            var left_face = Helpers.GetFontSafe(doc.Faces, left_font);

            double face_size = 32.0;
            int    rect_id   = doc.GetMasterMetaData("REctAngle").ID;

            string letters     = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string letters2    = "abcdefghijklmnopqrstuvwxyz";
            string numbers     = "01234567890";
            string punctuation = "!@#$%^&*()_+-=<>,.[]{}\\|``/?;:'\"";

            var text = letters + letters2 + numbers + punctuation;

            int    count            = text.Length;
            int    cols             = (int)System.Math.Ceiling(System.Math.Sqrt(count));
            double face_size_inches = face_size / 72.0;

            double box_size = face_size_inches * 2.0;
            double box_sep  = box_size / 8.0;

            double grid_delta = box_size + box_sep;

            page.PageProperties.PageWidth.Formula  = (cols * grid_delta).ToString();
            page.PageProperties.PageHeight.Formula = (cols * grid_delta).ToString();

            int n = 0;

            foreach (int row in Enumerable.Range(0, cols))
            {
                foreach (int col in Enumerable.Range(0, cols))
                {
                    if (n >= count)
                    {
                        break;
                    }


                    var pinx = col * grid_delta;
                    var piny = (cols * grid_delta) - (row * grid_delta);

                    var shape = new VDX.Elements.Shape(rect_id, pinx, piny, box_size, box_size);
                    page.Shapes.Add(shape);

                    string s = text[n].ToString();
                    shape.Text.Add(s);

                    shape.CharFormats = new List <VDX.Sections.Char>();

                    var charfmt = new VDX.Sections.Char();
                    charfmt.Font.Formula = left_face.ID.ToString();
                    charfmt.Size.Formula = face_size.ToString() + "pt";

                    shape.CharFormats.Add(charfmt);

                    shape.Fill = new VDX.Sections.Fill();
                    shape.Fill.Pattern.Formula                = "0";
                    shape.Fill.ForegroundColor.Formula        = "rgb(255,255,255)";
                    shape.Fill.ForegroundTransparency.Formula = "1.0";

                    shape.Line = new VDX.Sections.Line();
                    shape.Line.Pattern.Formula = "0";
                    shape.Line.Weight.Formula  = "0";
                    shape.Line.Color.Formula   = "rgb(240,240,240)";
                    n++;
                }
            }

            doc.Save("D:\\specimen.vdx");
        }
Example #9
0
        public void VDX_CustomTemplate()
        {
            string input_filename  = this.GetTestResultsOutPath(@"datafiles\template_router.vdx");
            string output_filename = TestGlobals.TestHelper.GetTestMethodOutputFilename(".vdx");

            // Load the template
            string template_xml = File.ReadAllText(input_filename);

            var template = new VisioAutomation.VDX.Template(template_xml);
            var doc      = new VisioAutomation.VDX.Elements.Drawing(template);
            var page     = new VisioAutomation.VDX.Elements.Page(8, 4);

            doc.Pages.Add(page);

            // add layers
            var layer0 = page.AddLayer("Layer0", 0);
            var layer1 = page.AddLayer("Layer1", 1);
            var layer2 = page.AddLayer("Layer2", 2);

            // create layout
            var layout = new VisioAutomation.VDX.Sections.Layout();

            layout.ShapeRouteStyle.Result = VisioAutomation.VDX.Enums.RouteStyle.TreeEW;

            // find the id of the master for rounded rectangles
            int  shapeMasterNameId    = doc.GetMasterMetaData("Router").ID;
            bool shapeMasterNameGroup = doc.GetMasterMetaData("Router").IsGroup;

            // add shape1
            var shape1 = new VisioAutomation.VDX.Elements.Shape(shapeMasterNameId, shapeMasterNameGroup, 1, 3);

            page.Shapes.Add(shape1);
            shape1.Text.Add("Router1");
            shape1.Layout = layout;

            // add shape2
            var shape2 = new VisioAutomation.VDX.Elements.Shape(shapeMasterNameId, shapeMasterNameGroup, 5, 3);

            page.Shapes.Add(shape2);
            shape2.Text.Add("Router2");
            shape2.Layout = shape1.Layout;

            // add shape3 - this is the dynamic connector
            var shape3 = VisioAutomation.VDX.Elements.Shape.CreateDynamicConnector(doc);

            shape3.XForm1D.BeginX.Result = 1;
            shape3.XForm1D.EndX.Result   = 5;
            shape3.XForm1D.BeginY.Result = 3;
            shape3.XForm1D.EndY.Result   = 3;
            page.Shapes.Add(shape3);
            shape3.Geom = new VisioAutomation.VDX.Sections.Geom();
            shape3.Geom.Rows.Add(new VisioAutomation.VDX.Sections.MoveTo(1, 3));
            shape3.Geom.Rows.Add(new VisioAutomation.VDX.Sections.LineTo(5, 3));

            shape3.Layout = shape1.Layout;
            page.ConnectShapesViaConnector(shape3, shape1, shape2);

            // handle layers
            shape3.LayerMembership = new List <int> {
                layer0.Index, layer2.Index
            };
            shape1.LayerMembership = new List <int> {
                layer1.Index
            };
            shape2.LayerMembership = new List <int> {
                layer2.Index
            };

            // write document to disk as .vdx file

            doc.Save(output_filename);

            this.VerifyDocCanBeLoaded(output_filename);
        }
Example #10
0
        public void VDX_CustomProperties()
        {
            string filename = TestGlobals.TestHelper.GetTestMethodOutputFilename(".vdx");

            var template = new VisioAutomation.VDX.Template();
            var doc_node = new VisioAutomation.VDX.Elements.Drawing(template);

            int rect_id = doc_node.GetMasterMetaData("REctAngle").ID;

            var node_page = new VisioAutomation.VDX.Elements.Page(8, 5);

            doc_node.Pages.Add(node_page);

            var node_shape = new VisioAutomation.VDX.Elements.Shape(rect_id, 4, 2, 3, 2);

            node_shape.CustomProps = new VisioAutomation.VDX.Elements.CustomProps();

            var node_custprop0 = new VisioAutomation.VDX.Elements.CustomProp("PROP1");

            node_custprop0.Value = "VALUE1";
            node_shape.CustomProps.Add(node_custprop0);

            var node_custprop1 = new VisioAutomation.VDX.Elements.CustomProp("PROP2");

            node_custprop1.Value       = "123";
            node_custprop1.Type.Result = VisioAutomation.VDX.Enums.CustomPropType.String;
            node_shape.CustomProps.Add(node_custprop1);

            var node_custprop2 = new VisioAutomation.VDX.Elements.CustomProp("PROP3");

            node_custprop2.Value       = "456";
            node_custprop2.Type.Result = VisioAutomation.VDX.Enums.CustomPropType.Number;
            node_shape.CustomProps.Add(node_custprop2);

            node_page.Shapes.Add(node_shape);

            doc_node.Save(filename);

            var app  = new IVisio.Application();
            var docs = app.Documents;
            var doc  = docs.Add(filename);

            var page   = app.ActivePage;
            var shapes = page.Shapes;

            Assert.AreEqual(1, page.Shapes.Count);

            var shape       = page.Shapes[1];
            var customprops = VACUSTPROP.CustomPropertyHelper.Get(shape);

            Assert.IsTrue(customprops.ContainsKey("PROP1"));
            Assert.AreEqual("\"VALUE1\"", customprops["PROP1"].Value.Formula);


            Assert.IsTrue(customprops.ContainsKey("PROP2"));
            Assert.AreEqual("\"123\"", customprops["PROP2"].Value.Formula);
            Assert.AreEqual("0", customprops["PROP2"].Type.Formula);

            Assert.IsTrue(customprops.ContainsKey("PROP3"));
            Assert.AreEqual("\"456\"", customprops["PROP3"].Value.Formula);
            Assert.AreEqual("2", customprops["PROP3"].Type.Formula);

            app.Quit(true);
        }