示例#1
0
        /// <summary>
        /// Процедура отображения графа в документе Visio
        /// </summary>
        /// <param name="visioDocs">Документы Visio</param>
        /// <param name="visioPage">Текущая страница в Visio</param>
        public void PresentGraphInVisio(Visio.Documents visioDocs, Visio.Page visioPage)
        {
            PresentNodes(visioDocs, visioPage);
            PresentEdges(visioDocs, visioPage);

            visioPage.Layout();
        }
        public void Apply(IVisio.Page page)
        {
            var page_layout_cells = new VisioAutomation.Pages.PageLayoutCells();

            this.SetPageCells(page_layout_cells);

            var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

            writer.SetValues(page_layout_cells);

            writer.CommitFormulas(page.PageSheet);
            page.Layout();
        }
示例#3
0
        public void Apply(IVisio.Page page)
        {
            var pagecells = new VA.Pages.PageCells();

            this.SetPageCells(pagecells);

            var update = new VA.ShapeSheet.Update();

            update.SetFormulas(pagecells);
            var pagesheet = page.PageSheet;

            update.Execute(pagesheet);
            page.Layout();
        }
示例#4
0
        public void Apply(IVisio.Page page)
        {
            var pagecells = new PageLayoutFormulas();

            this.SetPageCells(pagecells);

            var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageLayoutAvenueSizeX, pagecells.AvenueSizeX);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageLayoutAvenueSizeY, pagecells.AvenueSizeY);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageLayoutLineRouteExt, pagecells.LineRouteExt);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageLayoutRouteStyle, pagecells.RouteStyle);
            writer.SetFormula(VisioAutomation.ShapeSheet.SrcConstants.PageLayoutPlaceStyle, pagecells.PlaceStyle);

            writer.Commit(page.PageSheet);
            page.Layout();
        }
        /// <summary>
        /// Create a new page in a Visio file showing all the direct entity relationships participated in
        /// by the passed-in array of entities.
        /// </summary>
        /// <param name="entities">Core entities for the diagram</param>
        /// <param name="worker">The worker.</param>
        /// <param name="e">The <see cref="DoWorkEventArgs"/> instance containing the event data.</param>
        private void BuildDiagram(List <string> entities, BackgroundWorker worker, DoWorkEventArgs e)
        {
            // Get the default page of our new document
            VisioApi.Page page = _document.Pages[1];
            page.Name = "MSCRMToolKit generated diagram";
            int cptEntititesTreated = 0;

            // Get the metadata for each passed-in entity, draw it, and draw its relationships.
            foreach (string entityName in entities)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                cptEntititesTreated++;
                worker.ReportProgress(cptEntititesTreated);
                EntityMetadata entity = GetEntityMetadata(entityName);

                // Create a Visio rectangle shape.
                VisioApi.Shape rect;

                try
                {
                    // There is no "Get Try", so we have to rely on an exception to tell us it does not exists
                    // We have to skip some entities because they may have already been added by relationships of another entity
                    rect = page.Shapes.get_ItemU(entity.LogicalName);
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    rect = DrawEntityRectangle(page, entity);
                }

                // Draw all relationships TO this entity.
                DrawRelationships(entity, rect, entity.ManyToManyRelationships, false, worker, e);
                DrawRelationships(entity, rect, entity.ManyToOneRelationships, false, worker, e);

                // Draw all relationshipos FROM this entity
                DrawRelationships(entity, rect, entity.OneToManyRelationships, true, worker, e);
            }

            // Arrange the shapes to fit the page.
            page.Layout();
            page.ResizeToFitContents();
        }
示例#6
0
        /// <summary>
        /// Create a new page in a Visio file showing all the direct entity relationships participated in
        /// by the passed-in array of entities.
        /// </summary>
        /// <param name="entities">Core entities for the diagram</param>
        /// <param name="pageTitle">Page title</param>
        private void BuildDiagram(string[] entities, string pageTitle)
        {
            // Get the default page of our new document
            VisioApi.Page page = _document.Pages[1];
            page.Name = pageTitle;
            int i = 1;

            // Get the metadata for each passed-in entity, draw it, and draw its relationships.
            foreach (string entityName in entities)
            {
                Console.Write("Processing entity {1}/{2} {3}: {0}", entityName, i, entities.Length, DateTime.Now.ToLongTimeString());

                EntityMetadata entity = GetEntityMetadata(entityName);

                // Create a Visio rectangle shape.
                VisioApi.Shape rect;

                try
                {
                    // There is no "Get Try", so we have to rely on an exception to tell us it does not exists
                    // We have to skip some entities because they may have already been added by relationships of another entity
                    rect = page.Shapes.get_ItemU(entity.LogicalName);
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    rect = DrawEntityRectangle(page, entity.LogicalName, null == entity.DisplayName.UserLocalizedLabel ? "" : entity.DisplayName.UserLocalizedLabel.Label, entity.OwnershipType.Value);
                    Console.Write('.');                     // Show progress
                }

                // Draw all relationships TO this entity.
                DrawRelationships(entity, rect, entity.ManyToManyRelationships, false);
                Console.Write('.');                 // Show progress
                DrawRelationships(entity, rect, entity.ManyToOneRelationships, false);

                // Draw all relationshipos FROM this entity
                DrawRelationships(entity, rect, entity.OneToManyRelationships, true);
                Console.WriteLine('.');                 // Show progress

                i++;
            }

            // Arrange the shapes to fit the page.
            page.Layout();
            page.ResizeToFitContents();
        }
示例#7
0
        /// <summary>
        /// This is the root of the recursive descent to display the tree on the Visio doc.
        /// The function uses PlaceOneShape() to start the recursive display.
        /// </summary>
        /// <param name="colorMap">Color map to use to render.</param>
        /// <param name="root">Root node to render.</param>
        private static void BuildAndDisplayWithVisio(
            Dictionary <string, string> colorMap,
            TypeTreeNode root)
        {
            Visio.Application app             = null;
            Visio.Document    contentDocument = null;

            try
            {
                app = new Visio.Application();
                app.Settings.EnableAutoConnect = false;
                ////app.Window.WindowState = (int)Visio.VisWindowStates.visWSRestored;
                app.Window.WindowState = (int)Visio.VisWindowStates.visWSMinimized;

                contentDocument = app.Documents.AddEx(
                    string.Empty,
                    Visio.VisMeasurementSystem.visMSUS,
                    (int)Visio.VisOpenSaveArgs.visAddDocked,
                    (int)0);

                contentDocument.PaperSize      = Visio.VisPaperSizes.visPaperSizeE;
                contentDocument.PrintLandscape = true;

                /*
                 * Visio.Document stencilDocument = contentDocument.Application.Documents.OpenEx(
                 *  "Basic_U.vss",
                 *  (short)Visio.VisOpenSaveArgs.visOpenDocked);
                 * Visio.Master shape = stencilDocument.Masters["Rectangle"];
                 */

                Visio.Master shape = contentDocument.Application.Documents.OpenEx(
                    "Basic_U.vss",
                    (short)Visio.VisOpenSaveArgs.visOpenDocked).Masters["Rectangle"];

                Visio.Page targetPage = contentDocument.Pages[1];
                targetPage.Name = "MFx Class Hirearchy";

                BuildHeadersAndFooters(colorMap, contentDocument);

                /*
                 * Program.selectionTree = app.ActiveWindow.Selection;
                 * Program.selectionTree.DeselectAll();
                 */

                double movingYBase = 4.0;
                foreach (TypeTreeNode t in
                         root.Children.Values.OrderBy(t => t.RawType.Namespace).ThenBy(t => t.RawType.Name))
                {
                    movingYBase = PlaceOneShape(
                        colorMap,
                        targetPage,
                        t,
                        shape,
                        null,
                        2.0,
                        movingYBase);
                }

                // now turn the selection into a group, and run the layout code
                // to make the tree look "right"
                ////Program.selectionTree.Group();

                // resize, set the placement, and connector routing styles
                Visio.Cell layoutCell;

                layoutCell = targetPage.PageSheet.get_CellsSRC(
                    (short)Visio.VisSectionIndices.visSectionObject,
                    (short)Visio.VisRowIndices.visRowPageLayout,
                    (short)Visio.VisCellIndices.visPLOResizePage);

                layoutCell.FormulaU = "FALSE";  // don't add more pages to contain the tree, let the user edit

                layoutCell = targetPage.PageSheet.get_CellsSRC(
                    (short)Visio.VisSectionIndices.visSectionObject,
                    (short)Visio.VisRowIndices.visRowPageLayout,
                    (short)Visio.VisCellIndices.visPLOPlaceStyle);

                layoutCell.set_Result(
                    Visio.VisUnitCodes.visPageUnits,
                    (double)Visio.VisCellVals.visPLOPlaceCompactDownRight);

                layoutCell = targetPage.PageSheet.get_CellsSRC(
                    (short)Visio.VisSectionIndices.visSectionObject,
                    (short)Visio.VisRowIndices.visRowPageLayout,
                    (short)Visio.VisCellIndices.visPLORouteStyle);

                layoutCell.set_Result(
                    Visio.VisUnitCodes.visPageUnits,
                    (double)Visio.VisCellVals.visLORouteOrgChartNS);

                targetPage.Layout();
                ////Program.selectionTree.Layout();

                Program.selectionTree.Group();

                Console.WriteLine("Print and save Visio doc if you want, then enter to quit (Visio will close).");
                Console.ReadLine();
            }
            finally
            {
                if (contentDocument != null)
                {
                    contentDocument.Saved = true;   // not really, but we can lie so the close/quit works.
                    contentDocument.Close();
                }

                if (app != null)
                {
                    app.Quit();
                }
            }
        }
示例#8
0
        public void AddShapes()
        {
            Visio.Application visio     = this.Application;
            Visio.Documents   documents = this.Application.Documents;

            Visio.Page     page     = visio.ActivePage;
            Visio.Document document = visio.ActiveDocument;
            if (document == null)
            {
                document = visio.Documents.Add("");
            }

            if (page == null)
            {
                page = document.Pages.Add();
            }

            List <Service> services = null;

            try
            {
                ServicesApi api = new ServicesApi();
                services = api.getServices(true, "");
            }
            catch (ApiException e)
            {
                System.Windows.Forms.MessageBox.Show("Error calling the LeanIX API: " + e.Message);
                return;
            }
            catch (System.Net.WebException)
            {
                System.Windows.Forms.MessageBox.Show("Please check your internet connection");
                return;
            }

            if (services == null || services.Count == 0)
            {
                System.Windows.Forms.MessageBox.Show("No data received from API");
                return;
            }

            Dictionary <String, Visio.Shape> placedShapes = new Dictionary <String, Visio.Shape>();

            //add shapes
            foreach (Service s in services)
            {
                if (s.serviceHasInterfaces == null || s.serviceHasInterfaces.Count == 0)
                {
                    continue;
                }

                Visio.Document stencil = documents.OpenEx("Basic Shapes.vss",
                                                          (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);
                Visio.Master visioRectMaster = stencil.Masters.get_ItemU(@"Rounded Rectangle");

                Visio.Shape visioRectShape = page.Drop(visioRectMaster, 0, 0);
                visioRectShape.Text = s.name;
                placedShapes.Add(s.ID, visioRectShape);
            }

            //connect shapes
            foreach (Service s in services)
            {
                foreach (ServiceHasInterface si in s.serviceHasInterfaces)
                {
                    Visio.Shape sourceShape = placedShapes[s.ID];
                    Visio.Shape targetShape = placedShapes[si.serviceRefID];
                    if (targetShape != null)
                    {
                        sourceShape.AutoConnect(targetShape, Visio.VisAutoConnectDir.visAutoConnectDirLeft);
                    }
                }
            }

            //set the layout and resize the page
            page.PageSheet.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowPageLayout,
                (short)Visio.VisCellIndices.visPLOPlaceStyle).ResultIU = 6;

            page.PageSheet.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowPageLayout,
                (short)Visio.VisCellIndices.visPLORouteStyle).ResultIU = 1;

            page.PageSheet.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowPageLayout,
                (short)Visio.VisCellIndices.visPLOSplit).ResultIU = 1;

            page.Layout();
            page.ResizeToFitContents();
        }