private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Create Visio Application Object
            Visio.Application vsdApp = Application;

            //Make Visio Application Invisible
            vsdApp.Visible = false;

            //Create a document object and load a diagram
            Visio.Document vsdDoc = vsdApp.Documents.Open("Drawing.vsd");

            //Save the VDX diagram
            vsdDoc.SaveAs("Drawing1.vdx");

            //Save as PDF file
            vsdDoc.ExportAsFixedFormat(Visio.VisFixedFormatTypes.visFixedFormatPDF,
                                       "Drawing1.pdf", Visio.VisDocExIntent.visDocExIntentScreen,
                                       Visio.VisPrintOutRange.visPrintAll, 1, vsdDoc.Pages.Count, false, true,
                                       true, true, true, System.Reflection.Missing.Value);

            Visio.Page vsdPage = vsdDoc.Pages[1];

            //Save as JPEG Image
            vsdPage.Export("Drawing1.jpg");

            //Quit Visio Object
            vsdApp.Quit();
        }
        public static void Run()
        {
            // ExStart:SaveDiagramTo_VDX_PDF_JPEG_withVSTO
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_KnowledgeBase();

            // Create Visio Application Object
            Visio.Application vsdApp = new Visio.Application();

            // Make Visio Application Invisible
            vsdApp.Visible = false;

            // Create a document object and load a diagram
            Visio.Document vsdDoc = vsdApp.Documents.Open(dataDir + "Drawing1.vsd");

            // Save the VDX diagram
            vsdDoc.SaveAs(dataDir + "SaveDiagramToVDXwithVSTO_out.vdx");

            // Save as PDF file
            vsdDoc.ExportAsFixedFormat(Visio.VisFixedFormatTypes.visFixedFormatPDF,
                                       dataDir + "SaveDiagramToPDFwithVSTO_out.pdf", Visio.VisDocExIntent.visDocExIntentScreen,
                                       Visio.VisPrintOutRange.visPrintAll, 1, vsdDoc.Pages.Count, false, true,
                                       true, true, true, System.Reflection.Missing.Value);

            Visio.Page vsdPage = vsdDoc.Pages[1];

            // Save as JPEG Image
            vsdPage.Export(dataDir + "SaveDiagramToJPGwithVSTO_out.jpg");

            // Quit Visio Object
            vsdApp.Quit();
            // ExEnd:SaveDiagramTo_VDX_PDF_JPEG_withVSTO
        }
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Visio.Application vsdApp = null;
            Visio.Document    vsdDoc = null;

            //Create Visio Application Object
            vsdApp = Application;

            //Make Visio Application Invisible
            vsdApp.Visible = false;

            //Create a document object and load a diagram
            vsdDoc = vsdApp.Documents.Open("Drawing.vsd");

            //Create page object to get required page
            Visio.Page page = vsdApp.ActivePage;

            //Create shape object to get required shape
            Visio.Shape shape = page.Shapes["Process1"];

            //Set shape text and text style
            shape.Text      = "Hello World";
            shape.TextStyle = "CustomStyle1";

            //Set shape's position
            shape.get_Cells("PinX").ResultIU = 5;
            shape.get_Cells("PinY").ResultIU = 5;

            //Set shape's height and width
            shape.get_Cells("Height").ResultIU = 2;
            shape.get_Cells("Width").ResultIU  = 3;

            //Save file as VDX
            vsdDoc.SaveAs("Drawing1.vdx");
        }
Esempio n. 4
0
        /// <summary>
        /// Draws a TM1 Server in Visio
        /// </summary>
        /// <param name="server">The DocumentationServer instance to draw</param>
        /// <param name="withSystemCubes">true if you want system cubes to be drawn</param>
        /// <param name="withSystemDims">true if you want system dimensions to be drawn</param>
        /// <param name="templatePath">Path to the ADAPT template</param>
        /// <param name="savePath">Save Path</param>
        public static void Draw(DocumentationServer server, bool withSystemCubes, bool withSystemDims, string savePath)
        {
            try
            {
                cubeList = new List <Visio.Shape>();

                // start Visio
                application         = new Visio.Application();
                application.Visible = false;

                // load and set up the ADAPT template
                string filename = @"\Adapt.vst";
                doc         = application.Documents.Add(Environment.CurrentDirectory + filename);
                doc.Creator = @"gmc²";
                doc.Title   = @"Server: " + server.name;
                doc.SaveAs(savePath + server.name + ".vsdx");
                //doc.PaperSize = Visio.VisPaperSizes.visPaperSizeB4;

                // setting up the pages
                adaptPage          = doc.Pages[1];
                adaptPage.Name     = @"gmc² IBM Cognos Documentation Tool";
                adaptPage.AutoSize = true;

                // get the necessary shapes...
                visioCubeMaster = doc.Masters.get_ItemU(@"Cube");

                // ...and draw the cubes
                foreach (DocCube docCube in server.cubes)
                {
                    if (withSystemCubes || !docCube.name.StartsWith("}", StringComparison.OrdinalIgnoreCase))
                    {
                        DrawCube(docCube, withSystemDims);
                    }
                }

                posX = 1.25;
                posY = 1.75;

                foreach (DocCube docCube in server.cubes)
                {
                    if (docCube.nof_look > 0 && (withSystemCubes || !docCube.name.StartsWith("}", StringComparison.OrdinalIgnoreCase)))
                    {
                        DrawLooksConnections(docCube);
                    }

                    if (docCube.nof_fed > 0 && (withSystemCubes || !docCube.name.StartsWith("}", StringComparison.OrdinalIgnoreCase)))
                    {
                        DrawFeedsConnections(docCube);
                    }
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                kill();
            }
        }
        public static void Run()
        {
            // ExStart:CreatingDiagramWithVSTO
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_KnowledgeBase();

            Visio.Application vdxApp = null;
            Visio.Document    vdxDoc = null;
            try
            {
                // Create Visio Application Object
                vdxApp = new Visio.Application();

                // Make Visio Application Invisible
                vdxApp.Visible = false;

                // Create a new diagram
                vdxDoc = vdxApp.Documents.Add("");

                // Load Visio Stencil
                Visio.Documents visioDocs    = vdxApp.Documents;
                Visio.Document  visioStencil = visioDocs.OpenEx("Basic Shapes.vss",
                                                                (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenHidden);

                // Set active page
                Visio.Page visioPage = vdxApp.ActivePage;

                // Add a new rectangle shape
                Visio.Master visioRectMaster = visioStencil.Masters.get_ItemU(@"Rectangle");
                Visio.Shape  visioRectShape  = visioPage.Drop(visioRectMaster, 4.25, 5.5);
                visioRectShape.Text = @"Rectangle text.";

                // Add a new star shape
                Visio.Master visioStarMaster = visioStencil.Masters.get_ItemU(@"Star 7");
                Visio.Shape  visioStarShape  = visioPage.Drop(visioStarMaster, 2.0, 5.5);
                visioStarShape.Text = @"Star text.";

                // Add a new hexagon shape
                Visio.Master visioHexagonMaster = visioStencil.Masters.get_ItemU(@"Hexagon");
                Visio.Shape  visioHexagonShape  = visioPage.Drop(visioHexagonMaster, 7.0, 5.5);
                visioHexagonShape.Text = @"Hexagon text.";


                // Save diagram as VDX
                vdxDoc.SaveAs(dataDir + "CreatingDiagramWithVSTO_Out.vdx");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }

            // ExEnd:CreatingDiagramWithVSTO
        }
Esempio n. 6
0
        public static void Run()
        {
            //ExStart:UpdateShapePropsWithVSTO
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_KnowledgeBase();

            Visio.Application vsdApp = null;
            Visio.Document    vsdDoc = null;
            try
            {
                //Create Visio Application Object
                vsdApp = new Visio.Application();

                //Make Visio Application Invisible
                vsdApp.Visible = false;

                //Create a document object and load a diagram
                vsdDoc = vsdApp.Documents.Open(dataDir + "Drawing1.vsd");

                //Create page object to get required page
                Visio.Page page = vsdApp.ActivePage;

                //Create shape object to get required shape
                Visio.Shape shape = page.Shapes["Process1"];

                //Set shape text and text style
                shape.Text      = "Hello World";
                shape.TextStyle = "CustomStyle1";

                //Set shape's position
                shape.get_Cells("PinX").ResultIU = 5;
                shape.get_Cells("PinY").ResultIU = 5;

                //Set shape's height and width
                shape.get_Cells("Height").ResultIU = 2;
                shape.get_Cells("Width").ResultIU  = 3;

                //Save file as VDX
                vsdDoc.SaveAs(dataDir + "Drawing1.vdx");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
            //ExEnd:UpdateShapePropsWithVSTO
        }
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Visio.Application vdxApp = null;
            Visio.Document    vdxDoc = null;

            //Create Visio Application Object
            vdxApp = Application;

            //Make Visio Application Invisible
            vdxApp.Visible = false;

            //Create a new diagram
            vdxDoc = vdxApp.Documents.Add("Drawing.vsd");

            //Load Visio Stencil
            Visio.Documents visioDocs = vdxApp.Documents;

            Visio.Document visioStencil = visioDocs.OpenEx("sample.vss",
                                                           (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenHidden);

            //Set active page
            Visio.Page visioPage = vdxApp.ActivePage;

            //Add a new rectangle shape
            Visio.Master visioRectMaster = visioStencil.Masters.get_ItemU(@"Rectangle");
            Visio.Shape  visioRectShape  = visioPage.Drop(visioRectMaster, 4.25, 5.5);
            visioRectShape.Text = @"Rectangle text.";

            //Add a new star shape
            Visio.Master visioStarMaster = visioStencil.Masters.get_ItemU(@"Star 7");
            Visio.Shape  visioStarShape  = visioPage.Drop(visioStarMaster, 2.0, 5.5);
            visioStarShape.Text = @"Star text.";

            //Add a new hexagon shape
            Visio.Master visioHexagonMaster = visioStencil.Masters.get_ItemU(@"Hexagon");
            Visio.Shape  visioHexagonShape  = visioPage.Drop(visioHexagonMaster, 7.0, 5.5);
            visioHexagonShape.Text = @"Hexagon text.";


            //Save diagram as VDX
            vdxDoc.SaveAs("Drawing1.vdx");
        }
Esempio n. 8
0
        private static void AutomateVisioImpl()
        {
            try
            {
                // Create an instance of Microsoft Visio and make it invisible.

                Visio.Application oVisio = new Visio.Application();
                oVisio.Visible = false;
                Console.WriteLine("Visio.Application is started");

                // Create a new Document based on no template.

                Visio.Document oDoc = oVisio.Documents.Add("");
                Console.WriteLine("A new document is created");

                // Draw a rectangle and a oval on the first page.

                Console.WriteLine("Draw a rectangle and a oval");
                oDoc.Pages[1].DrawRectangle(0.5, 10.25, 6.25, 7.375);
                oDoc.Pages[1].DrawOval(1.125, 6, 6.875, 2.125);

                // Save the document as a vsd file and close it.

                Console.WriteLine("Save and close the document");
                string fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample2.vsd";
                oDoc.SaveAs(fileName);
                oDoc.Close();

                // Quit the Visio application.

                Console.WriteLine("Quit the Visio application");
                oVisio.Quit();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution2.AutomateVisio throws the error: {0}",
                                  ex.Message);
            }
        }
Esempio n. 9
0
        public static void AutomateVisio()
        {
            Visio.Application oVisio     = null;
            Visio.Documents   oDocs      = null;
            Visio.Document    oDoc       = null;
            Visio.Pages       oPages     = null;
            Visio.Page        oPage      = null;
            Visio.Shape       oRectShape = null;
            Visio.Shape       oOvalShape = null;

            try
            {
                // Create an instance of Microsoft Visio and make it invisible.

                oVisio         = new Visio.Application();
                oVisio.Visible = false;
                Console.WriteLine("Visio.Application is started");

                // Create a new Document based on no template.

                oDocs = oVisio.Documents;
                oDoc  = oDocs.Add("");
                Console.WriteLine("A new document is created");

                // Draw a rectangle and a oval on the first page.

                Console.WriteLine("Draw a rectangle and a oval");

                oPages     = oDoc.Pages;
                oPage      = oPages[1];
                oRectShape = oPage.DrawRectangle(0.5, 10.25, 6.25, 7.375);
                oOvalShape = oPage.DrawOval(1.125, 6, 6.875, 2.125);

                // Save the document as a vsd file and close it.

                Console.WriteLine("Save and close the document");
                string fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample1.vsd";
                oDoc.SaveAs(fileName);
                oDoc.Close();

                // Quit the Visio application.

                Console.WriteLine("Quit the Visio application");
                oVisio.Quit();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution1.AutomateVisio throws the error: {0}",
                                  ex.Message);
            }
            finally
            {
                // Clean up the unmanaged Visio COM resources by explicitly
                // calling Marshal.FinalReleaseComObject on all accessor objects.
                // See http://support.microsoft.com/kb/317109.

                if (oOvalShape != null)
                {
                    Marshal.FinalReleaseComObject(oOvalShape);
                    oOvalShape = null;
                }
                if (oRectShape != null)
                {
                    Marshal.FinalReleaseComObject(oRectShape);
                    oRectShape = null;
                }
                if (oPage != null)
                {
                    Marshal.FinalReleaseComObject(oPage);
                    oPage = null;
                }
                if (oPages != null)
                {
                    Marshal.FinalReleaseComObject(oPages);
                    oPages = null;
                }
                if (oDoc != null)
                {
                    Marshal.FinalReleaseComObject(oDoc);
                    oDoc = null;
                }
                if (oDocs != null)
                {
                    Marshal.FinalReleaseComObject(oDocs);
                    oDocs = null;
                }
                if (oVisio != null)
                {
                    Marshal.FinalReleaseComObject(oVisio);
                    oVisio = null;
                }
            }
        }
Esempio n. 10
0
        public static void DrawModel(DBModel model, bool withViews, bool showVisio, string path, bool physNames, bool allFields)
        {
            if (!System.IO.File.Exists(path + @"Files\SLModel.VSDX"))
            {
                MessageBox.Show("Das Template SLModel.vsdx wurde nicht unter " + path + @"Files\ gefunden. Bitte die README-Datei lesen.");
                return;
            }

            var fokus      = (bool)((MainWindow)Application.Current.MainWindow).Fokus_Aktiv.IsChecked;
            var fokusTable = ((MainWindow)Application.Current.MainWindow).Fokus_Tabelle.Text;

            if (fokus)
            {
                if (fokusTable.Length < 1)
                {
                    MessageBox.Show(@"Bitte Fokus-Tabelle eingeben oder Fokus deaktivieren.");
                    return;
                }
                if (!model.TablesList.Exists(tab => tab.Name.ToLower().Equals(fokusTable.ToLower())))
                {
                    MessageBox.Show(@"Fokus-Tabelle " + fokusTable + " nicht gefunden.");
                    return;
                }
                if (((MainWindow)Application.Current.MainWindow).Fokus_Tiefe.Text.Length < 1)
                {
                    MessageBox.Show(@"Tiefe des Fokus zu kurz.");
                    return;
                }
            }

            try
            {
                var x = -5;
                var y = 11;
                // ToDo: erst berechnen nach Fokus
                var breite  = (int)Math.Sqrt(model.TablesList.Count);
                var hoehe   = 0;
                var counter = 0;

                application         = new Visio.Application();
                application.Visible = showVisio;

                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                doc = application.Documents.Open(path + @"Files\SLModel.VSDX");
                //doc = application.Documents.Open(Environment.CurrentDirectory + @"\Files\SLModel.VSDX");
                doc.SaveAs(path + (fokus ? "Auschnittsfokus_" + fokusTable + "_" : "") + model.serverName + ".vsdx");
                doc.Creator = @"Hicham Ait Ayad";
                doc.Title   = model.serverName;

                page                 = doc.Pages[1];
                page.Name            = @"Scopeland DB Model Builder";
                page.AutoSize        = true;
                visioEntityMaster    = doc.Masters.get_ItemU(@"Entity");
                visioAttributeMaster = doc.Masters.get_ItemU(@"Attribute");
                visioConnectorMaster = doc.Masters.get_ItemU(@"Relationship");

                /***************************************************************************
                * ****************************** FOKUS ************************************
                ***************************************************************************/
                if (fokus)
                {
                    //var fokusTable = ((MainWindow)Application.Current.MainWindow).Fokus_Tabelle.Text.ToLower();
                    var fokusDepth = Int32.Parse(((MainWindow)Application.Current.MainWindow).Fokus_Tiefe.Text);
                    //var mandanten = "t_mandanten";

                    List <Table> TablesToLeaveList = new List <Table>();

                    model.RelationsList.FindAll(rel =>
                                                //!rel.FromField.Table.Name.ToLower().Equals(mandanten) &&
                                                //!rel.ToField.Table.Name.ToLower().Equals(mandanten) &&
                                                (rel.FromField.Table.Name.ToLower().Equals(fokusTable.ToLower()) ||
                                                 rel.ToField.Table.Name.ToLower().Equals(fokusTable.ToLower())))
                    .ForEach(rel =>
                    {
                        TablesToLeaveList.Add(rel.FromField.Table);
                        TablesToLeaveList.Add(rel.ToField.Table);
                    }

                             );

                    for (var i = 0; i < fokusDepth - 1; i++)
                    {
                        List <Table> tablesListTemp = new List <Table>();

                        TablesToLeaveList.ForEach(table => model.RelationsList.FindAll(rel => rel.FromField.Table.Equals(table)).ForEach(rel2 =>
                        {
                            tablesListTemp.Add(rel2.FromField.Table);
                            tablesListTemp.Add(rel2.ToField.Table);
                        }));

                        TablesToLeaveList.AddRange(tablesListTemp);
                    }


                    model.TablesList.RemoveAll(table => !TablesToLeaveList.Contains(table));
                }
                /***************************************************************************/

                /***************************************************************************
                * ****************************** Black/Whitelists ************************************
                ***************************************************************************/
                List <string> tableBlacklist = new List <string>(((MainWindow)Application.Current.MainWindow).Table_Blacklist_Text.Text.Trim().Split(','));
                List <string> tableWhitelist = new List <string>(((MainWindow)Application.Current.MainWindow).Table_Whitelist_Text.Text.Trim().Split(','));

                if (tableBlacklist.Count > 0 && !tableBlacklist[0].Equals(""))
                {
                    model.TablesList.RemoveAll(table => tableBlacklist.Contains(table.Name));
                }

                if (tableWhitelist.Count > 0 && !tableWhitelist[0].Equals(""))
                {
                    model.TablesList.RemoveAll(table => !tableWhitelist.Contains(table.Name));
                }
                /***************************************************************************/

                foreach (Table table in model.TablesList)
                {
                    if (withViews || !table.KindOfObject.Trim().Equals("View"))
                    {
                        if (counter++ % breite == 0)
                        {
                            y    -= hoehe / 2;
                            hoehe = 0;
                            x     = -5;
                        }
                        Visio.Shape entity = page.Drop(visioEntityMaster, x += 5, y);

                        if (allFields && table.Fields.Count > hoehe)
                        {
                            hoehe = table.Fields.Count;
                        }
                        else
                        if (!allFields)
                        {
                            foreach (Field field in table.Fields)
                            {
                                hoehe += model.FieldList.Contains(field) ? 1 : 0;
                            }
                        }


                        Array members = entity.ContainerProperties.GetListMembers();
                        foreach (int member in members)
                        {
                            entity.Shapes.ItemFromID[member].Delete();
                        }
                        //tablesID.Add(table.Name, entity.ID);
                        //printProperties(entity.Shapes);
                        entity.Text = physNames ? table.Name : table.NameD;
                        int i = 1;


                        foreach (Field field in table.Fields)
                        {
                            if (allFields || model.FieldList.Contains(field))
                            {
                                Visio.Shape attribute = page.Drop(visioAttributeMaster, 0, 0);
                                field.ShapeID = attribute.UniqueID[(short)Visio.VisUniqueIDArgs.visGetOrMakeGUID];
                                //fieldsID.Add(field.Table.Name + "_" + field.Name, attribute.ID);
                                attribute.Text = physNames ? field.Name : field.NameD;
                                entity.ContainerProperties.InsertListMember(attribute, i++);
                                //entity.ContainerProperties.AddMember(visioAttributeMaster, Visio.VisMemberAddOptions.visMemberAddUseResizeSetting);
                            }
                        }
                    }
                }
                page.CreateSelection(Visio.VisSelectionTypes.visSelTypeAll).Layout();

                foreach (Relation relation in model.RelationsList)
                {
                    if (relation.FromField.ShapeID != null && relation.ToField.ShapeID != null && relation.TypeFrom != null && relation.TypeTo != null)
                    {
                        int index;
                        if ((relation.TypeFrom.Substring(3).Equals(">>") && relation.TypeTo.Substring(3).Equals("->")) || (relation.TypeFrom.Substring(3).Equals("->") && relation.TypeTo.Substring(3).Equals(">>")))
                        {
                            fromField = relation.TypeFrom.Substring(3).Equals(">>") ? page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID] : page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID];
                            toField   = relation.TypeFrom.Substring(3).Equals(">>") ? page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID] : page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID];
                            index     = 0;
                        }
                        else
                        {
                            if (relation.TypeFrom.Substring(3).Equals(">>") && relation.TypeTo.Substring(3).Equals(">>"))
                            {
                                fromField = page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID];
                                toField   = page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID];
                                index     = 2;
                            }
                            else
                            {
                                fromField = page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID];
                                toField   = page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID];
                                index     = 1;
                            }
                        }
                        ConnectWithDynamicGlueAndConnector(fromField, toField, index);
                    }
                }
                page.AutoSizeDrawing();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                doc.Save();
                if (showVisio)
                {
                    application.Quit();
                }
            }
            MessageBox.Show("All done!");
        }
        public void Generate()
        {
            var builder = this;

            try
            {
                // Load Visio and create a new document.
                // Not showing the UI increases rendering speed
                builder.application = application = new VisioApi.Application
                {
                    Visible        = false,
                    ScreenUpdating = 1,
                    EventsEnabled  = 0,
                    ShowChanges    = false,
                    ShowStatusBar  = 0,
                    AlertResponse  = 0,
                    ShowMenus      = 0,
                    ShowProgress   = 0,
                    ShowToolbar    = 0,
                    UndoEnabled    = false,
                };
                builder.versionName = application.Version;
                builder.document    = document = application.Documents.Add(string.Empty);

                Settings.EntitiesSelected.ToList().ForEach(mainEntities.Enqueue);

                builder.processedRelationships = new List <Guid>();

                if (mainEntities.Count <= 0)
                {
                    OnMessage("No entities passed as argument; fetching all entities ...");
                    GetEntities().ToList().ForEach(entityName => mainEntities.Enqueue(entityName.LogicalName));
                }

                OnMessage(string.Format("Parsing {0} ...",
                                        mainEntities.Aggregate((entity1, entity2) => entity1 + ", " + entity2)));

                depth = Settings.Depth;

                // loop through entities to be drawn
                while (mainEntities.Count > 0 && depth >= 0)
                {
                    if (Cancel)
                    {
                        break;
                    }

                    var tempQueue = new Queue <string>();

                    mainEntities.ToList().ForEach(tempQueue.Enqueue);
                    mainEntities.Clear();
                    builder.Parse(tempQueue);

                    depth--;
                }

                // save the diagram in the current directory without overwriting
                var filename = "CRM_ERD.vsd";
                var index    = 1;
                while (File.Exists(filename))
                {
                    filename = "CRM_ERD_" + (index < 10 ? "0" + index++ : index++.ToString()) + ".vsd";
                }
                document.SaveAs(Directory.GetCurrentDirectory() + "\\" + filename);
                OnMessage(string.Format("\n\nSaved diagrams to {0}.", Directory.GetCurrentDirectory() + "\\" + filename));

                if (!Cancel)
                {
                    Done = true;
                }
                else
                {
                    Cancelled = true;
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                OnMessage("\n\nThe application terminated with an error.");
                OnMessage(string.Format("Timestamp: {0}", ex.Detail.Timestamp));
                OnMessage(string.Format("Code: {0}", ex.Detail.ErrorCode));
                OnMessage(string.Format("Message: {0}", ex.Detail.Message));
                OnMessage(string.Format("Plugin Trace: {0}", ex.Detail.TraceText));
                OnMessage(string.Format(
                              "Inner Fault: {0}",
                              null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"));

                Error = ex;
            }
            catch (TimeoutException ex)
            {
                OnMessage("\n\nThe application terminated with an error.");
                OnMessage(string.Format("Message: {0}", ex.Message));
                OnMessage(string.Format("Stack Trace: {0}", ex.StackTrace));
                OnMessage(string.Format("Inner Fault: {0}",
                                        string.IsNullOrEmpty(ex.InnerException.Message) ? "No Inner Fault" : ex.InnerException.Message));

                Error = ex;
            }
            catch (Exception ex)
            {
                OnMessage("\n\nThe application terminated with an error.");
                OnMessage(string.Format(ex.Message));

                // Display the details of the inner exception.
                if (ex.InnerException != null)
                {
                    OnMessage(string.Format(ex.InnerException.Message));

                    var fe
                        = ex.InnerException
                          as FaultException <OrganizationServiceFault>;
                    if (fe != null)
                    {
                        OnMessage(string.Format("Timestamp: {0}", fe.Detail.Timestamp));
                        OnMessage(string.Format("Code: {0}", fe.Detail.ErrorCode));
                        OnMessage(string.Format("Message: {0}", fe.Detail.Message));
                        OnMessage(string.Format("Plugin Trace: {0}", fe.Detail.TraceText));
                        OnMessage(string.Format(
                                      "Inner Fault: {0}",
                                      null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"));
                    }
                }

                Error = ex;
            }
            // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException,
            // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException.
            finally
            {
                // close the Visio application.
                application.Quit();
            }
        }
Esempio n. 12
0
        public void GenerateVSS()
        {
            visapp         = new IVisio.InvisibleApp();
            visapp.Visible = false;
            foreach (fileListElement fileEl in fileList)
            {
                try
                {
                    string templateFileName = Directory.GetCurrentDirectory() + "\\template.vss";
                    string newFullfileName  = fileEl.filePath + "\\result\\" + fileEl.fileName.Replace(".kml", ".vsd");

                    if (!File.Exists(templateFileName))
                    {
                        throw new Exception("Не найден шаблон выходного файла: " + templateFileName);
                    }

                    Directory.CreateDirectory(fileEl.filePath + "\\result\\");

                    string fileName = fileEl.fileName;
                    string caption  = "Поопорная схема ВЛ 0,4 кВ от ";
                    string firstTmp = "";
                    int    tpPos    = fileName.IndexOf("ТП");
                    if (tpPos >= 0)
                    {
                        firstTmp = fileName.Substring(tpPos, fileName.Length - tpPos).Replace('_', '/').Replace(".kml", "");
                        string secondTmp = fileName.Substring(0, tpPos - 1);
                        fileName = firstTmp + " кВА " + secondTmp;
                    }
                    else
                    {
                        throw new Exception("Не корректное название файла: " + fileName);
                    }
                    caption = caption + fileName + " " + fileEl.city;

                    IVisio.Document doc  = visapp.Documents.Open(templateFileName);// (short)IVisio.VisOpenSaveArgs.visAddHidden + (short)IVisio.VisOpenSaveArgs.visOpenNoWorkspace);
                    IVisio.Page     page = doc.Pages[1];

                    IVisio.Shape visioRectMaster = page.Shapes.get_ItemU("Sheet.1");
                    visioRectMaster.Text = caption;

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.509");
                    visioRectMaster.Text = caption;

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.496");
                    visioRectMaster.Text = fileEl.make;

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.508");
                    visioRectMaster.Text = fileEl.makeDate;

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.495");
                    visioRectMaster.Text = fileEl.check;

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.507");
                    visioRectMaster.Text = fileEl.checkDate;

                    int    pos2 = firstTmp.LastIndexOf('-');
                    int    pos3 = firstTmp.LastIndexOf('/');
                    string tmp2 = "?";
                    if (pos2 != -1 & pos3 != -1 & pos3 > pos2)
                    {
                        tmp2 = firstTmp.Substring(pos2 + 1, pos3 - pos2 - 1);
                    }

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.314");
                    visioRectMaster.Text = "РЛНД - " + tmp2;

                    IVisio.Master aMaster;
                    switch (fileEl.tpType)
                    {
                    case "Столбовая":
                        aMaster         = doc.Masters.get_ItemU(@"СТП");
                        visioRectMaster = page.Drop(aMaster, 6.3400314961, 5.4108622047);
                        //visioRectMaster.tra
                        visioRectMaster.Shapes[2].Text = "С" + firstTmp;
                        break;

                    case "Мачтовая":
                        aMaster         = doc.Masters.get_ItemU(@"МТП");
                        visioRectMaster = page.Drop(aMaster, 6.3976378, 5.4108622047);
                        visioRectMaster.Shapes[2].Text = "М" + firstTmp;
                        break;

                    case "Закрытая":
                        aMaster         = doc.Masters.get_ItemU(@"ЗТП");
                        visioRectMaster = page.Drop(aMaster, 6.313976378, 5.23622);
                        visioRectMaster.Shapes[2].Text = "З" + firstTmp;
                        break;

                    case "Комплектная":
                        aMaster         = doc.Masters.get_ItemU(@"КТП");
                        visioRectMaster = page.Drop(aMaster, 6.4422795276, 5.4108622047);
                        visioRectMaster.Shapes[2].Text = "К" + firstTmp;
                        break;
                    }

                    doc.SaveAs(newFullfileName);
                    doc.Close();
                    //visapp.Quit();
                }
                catch (Exception ex)
                {
                    LogTextEvent(Color.Red, ex.Message);
                }
            }
            foreach (IVisio.Document aDoc in visapp.Documents)
            {
                aDoc.Close();
            }
            visapp.Quit();
        }
Esempio n. 13
0
        public static void DrawModel(Model.DBModel model, bool withViews, bool showVisio, string path, bool physNames, bool allFields)
        {
            if (!System.IO.File.Exists(path + @"Files\SLModel.VSDX"))
            {
                System.Windows.MessageBox.Show("Das Template SLModel.vsdx wurde nicht unter " + path + @"Files\ gefunden. Bitte die README-Datei lesen.");
                return;
            }

            try
            {
                var x       = -5;
                var y       = 11;
                var breite  = (int)Math.Sqrt(model.TablesList.Count);
                var hoehe   = 0;
                var counter = 0;

                application         = new Visio.Application();
                application.Visible = showVisio;

                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                doc = application.Documents.Open(path + @"Files\SLModel.VSDX");
                //doc = application.Documents.Open(Environment.CurrentDirectory + @"\Files\SLModel.VSDX");
                doc.SaveAs(path + model.serverName + ".vsdx");
                doc.Creator = @"Hicham Ait Ayad";
                doc.Title   = model.serverName;

                page                 = doc.Pages[1];
                page.Name            = @"Scopeland DB Model Builder";
                page.AutoSize        = true;
                visioEntityMaster    = doc.Masters.get_ItemU(@"Entity");
                visioAttributeMaster = doc.Masters.get_ItemU(@"Attribute");
                visioConnectorMaster = doc.Masters.get_ItemU(@"Relationship");

                foreach (Model.Table table in model.TablesList)
                {
                    if (withViews || !table.KindOfObject.Trim().Equals("View"))
                    {
                        if (counter++ % breite == 0)
                        {
                            y    -= hoehe / 2;
                            hoehe = 0;
                            x     = -5;
                        }
                        Visio.Shape entity = page.Drop(visioEntityMaster, x += 5, y);

                        if (allFields && table.Fields.Count > hoehe)
                        {
                            hoehe = table.Fields.Count;
                        }
                        else
                        if (!allFields)
                        {
                            foreach (Model.Field field in table.Fields)
                            {
                                hoehe += model.FieldList.Contains(field) ? 1 : 0;
                            }
                        }


                        Array members = entity.ContainerProperties.GetListMembers();
                        foreach (int member in members)
                        {
                            entity.Shapes.ItemFromID[member].Delete();
                        }
                        //tablesID.Add(table.Name, entity.ID);
                        //printProperties(entity.Shapes);
                        entity.Text = physNames ? table.Name : table.NameD;
                        int i = 1;


                        foreach (Model.Field field in table.Fields)
                        {
                            if (allFields || model.FieldList.Contains(field))
                            {
                                Visio.Shape attribute = page.Drop(visioAttributeMaster, 0, 0);
                                field.ShapeID = attribute.UniqueID[(short)Visio.VisUniqueIDArgs.visGetOrMakeGUID];
                                //fieldsID.Add(field.Table.Name + "_" + field.Name, attribute.ID);
                                attribute.Text = physNames ? field.Name : field.NameD;
                                entity.ContainerProperties.InsertListMember(attribute, i++);
                                //entity.ContainerProperties.AddMember(visioAttributeMaster, Visio.VisMemberAddOptions.visMemberAddUseResizeSetting);
                            }
                        }
                    }
                }
                page.CreateSelection(Visio.VisSelectionTypes.visSelTypeAll).Layout();

                foreach (Model.Relation relation in model.RelationsList)
                {
                    if (relation.FromField.ShapeID != null && relation.ToField.ShapeID != null && relation.TypeFrom != null && relation.TypeTo != null)
                    {
                        int index;
                        if ((relation.TypeFrom.Substring(3).Equals(">>") && relation.TypeTo.Substring(3).Equals("->")) || (relation.TypeFrom.Substring(3).Equals("->") && relation.TypeTo.Substring(3).Equals(">>")))
                        {
                            fromField = relation.TypeFrom.Substring(3).Equals(">>") ? page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID] : page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID];
                            toField   = relation.TypeFrom.Substring(3).Equals(">>") ? page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID] : page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID];
                            index     = 0;
                        }
                        else
                        {
                            if (relation.TypeFrom.Substring(3).Equals(">>") && relation.TypeTo.Substring(3).Equals(">>"))
                            {
                                fromField = page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID];
                                toField   = page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID];
                                index     = 2;
                            }
                            else
                            {
                                fromField = page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID];
                                toField   = page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID];
                                index     = 1;
                            }
                        }
                        ConnectWithDynamicGlueAndConnector(fromField, toField, index);
                    }
                }
                page.AutoSizeDrawing();
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.Message);
            }
            finally
            {
                doc.Save();
                if (showVisio)
                {
                    application.Quit();
                }
            }
            System.Windows.MessageBox.Show("All done!");
        }
Esempio n. 14
0
        private void generateVisio(Connection treeNode)
        {
            visapp = new IVisio.InvisibleApp();
            visapp.AlertResponse = 7; //autoAnswer NO on any alert
            visapp.Visible       = false;
            bool errorCatch = false;

            try
            {
                string _fileName = fileName.Text.Split('\\').Last();
                string _filePath = fileName.Text.Replace(_fileName, "");

                string templateFileName = Directory.GetCurrentDirectory() + "\\template.vss";
                string shapesFileName   = Directory.GetCurrentDirectory() + "\\shapes.vss";
                string newFullfileName  = _filePath + "\\result\\" + _fileName.Replace(".kml", ".vsd");

                if (!File.Exists(templateFileName))
                {
                    throw new Exception("Не найден шаблон выходного файла: " + templateFileName);
                }

                Directory.CreateDirectory(_filePath + "\\result\\");

                string caption  = "Поопорная схема ВЛ 0,4 кВ от ";
                string firstTmp = "";
                int    tpPos    = _fileName.IndexOf("ТП");
                if (tpPos >= 0)
                {
                    firstTmp = _fileName.Substring(tpPos, _fileName.Length - tpPos).Replace('_', '/').Replace(".kml", "");
                    string secondTmp = _fileName.Substring(0, tpPos - 1);
                    _fileName = firstTmp + " кВА " + secondTmp;
                }
                else
                {
                    throw new Exception("Не корректное название файла: " + fileName);
                }
                caption = caption + _fileName + " " + city.Text;

                IVisio.Document doc       = visapp.Documents.Open(templateFileName); // (short)IVisio.VisOpenSaveArgs.visAddHidden + (short)IVisio.VisOpenSaveArgs.visOpenNoWorkspace);
                IVisio.Document shapesDoc = visapp.Documents.Open(shapesFileName);   // (short)IVisio.VisOpenSaveArgs.visAddHidden + (short)IVisio.VisOpenSaveArgs.visOpenNoWorkspace);
                IVisio.Page     page      = doc.Pages[1];

                IVisio.Shape visioRectMaster = page.Shapes.get_ItemU("Sheet.1");
                visioRectMaster.Text = caption;

                visioRectMaster      = page.Shapes.get_ItemU("Sheet.509");
                visioRectMaster.Text = caption;

                visioRectMaster      = page.Shapes.get_ItemU("Sheet.496");
                visioRectMaster.Text = make.Text;

                visioRectMaster      = page.Shapes.get_ItemU("Sheet.508");
                visioRectMaster.Text = makeDate.Text;

                visioRectMaster      = page.Shapes.get_ItemU("Sheet.495");
                visioRectMaster.Text = chekedM.Text;

                visioRectMaster      = page.Shapes.get_ItemU("Sheet.507");
                visioRectMaster.Text = chekedDate.Text;

                int    pos2 = firstTmp.LastIndexOf('-');
                int    pos3 = firstTmp.LastIndexOf('/');
                string tmp2 = "?";
                if (pos2 != -1 & pos3 != -1 & pos3 > pos2)
                {
                    tmp2 = firstTmp.Substring(pos2 + 1, pos3 - pos2 - 1);
                }

                //visioRectMaster = page.Shapes.get_ItemU("Sheet.314");
                //visioRectMaster.Text = "РЛНД - " + tmp2;

                double newX = 5.9;
                double newY = 6.85;

                GenerateShapes(shapesDoc.Masters, ref page, mainNode, 0, newX, newY, firstTmp);

                doc.SaveAs(newFullfileName);
                doc.Close();
            }
            catch (Exception ex)
            {
                LogTextEvent(System.Drawing.Color.Red, ex.Message);
                errorCatch = true;
            }

            foreach (IVisio.Document aDoc in visapp.Documents)
            {
                aDoc.Close();
            }
            visapp.Quit();
            if (errorCatch)
            {
                throw new Exception("Ошибка формирвания выходного файла");
            }
        }