public void selectShpLayer(string layerName) { int i = 0; int[] lngRowIDs; Array lngRowIDArray; //this selects the shapes of the selected layer LayerSelection = acPage.CreateSelection(Microsoft.Office.Interop.Visio.VisSelectionTypes.visSelTypeByLayer, Microsoft.Office.Interop.Visio.VisSelectMode.visSelModeSkipSuper, layerName); LayerSelection.GetIDs(out lngRowIDArray); lngRowIDs = (int[])lngRowIDArray; for (i = 0; i < lngRowIDs.Length; i++) { Debug.Write("Object ID: " + lngRowIDs[i].ToString() + "\n"); } }
public void addSequanceDiagram(ref Word.Document doc) { try { Visio.Document sequenceVisio; string sequenceDiagramPath = Directory.GetCurrentDirectory() + "\\Templates\\" + Constants.ServiceFlow + "\\ServiceSequanceDiagram.vsdx"; sequenceVisio = visioApp.Documents.Open(sequenceDiagramPath); Visio.Page sequencePage = sequenceVisio.Pages[1]; foreach (Visio.Shape shp in sequencePage.Shapes) { if (shp.Name != "Watermark Title" && shp.Text != "") { shp.Text = shp.Text.Replace("ServiceCanonicalName", Constants.ServiceCanonicalName); shp.Text = shp.Text.Replace("Subject", Constants.Subject); shp.Text = shp.Text.Replace("Backend", Constants.BackendName); } } Visio.Selection sequenceDiagram = sequencePage.CreateSelection(Visio.VisSelectionTypes.visSelTypeAll); sequenceDiagram.Copy(); //rollback foreach (Visio.Shape shp in sequencePage.Shapes) { if (shp.Name != "Watermark Title" && shp.Text != "") { shp.Text = shp.Text.Replace(Constants.ServiceCanonicalName, "ServiceCanonicalName"); shp.Text = shp.Text.Replace(Constants.Subject, "Subject"); shp.Text = shp.Text.Replace(Constants.BackendName, "Backend"); } } sequenceVisio.Saved = true; Word.Bookmark sequenceDiagBM = doc.Bookmarks["SequenceDiagram"]; Word.Range sequenceDiagRng = sequenceDiagBM.Range; sequenceDiagRng.PasteAndFormat(Word.WdRecoveryType.wdFormatOriginalFormatting); Console.WriteLine("Sequance Diagram Added"); } catch (Exception ex) { throw ex; } }
public void addRequestFlowDiagram(ref Word.Document doc) { try { Visio.Document requestVisio; string RequestDiagramPath = Directory.GetCurrentDirectory() + "\\Templates\\" + Constants.ServiceFlow + "\\ServiceRequestFlow.vsdx"; requestVisio = visioApp.Documents.Open(RequestDiagramPath); Visio.Page requestPage = requestVisio.Pages[1]; foreach (Visio.Shape shp in requestPage.Shapes) { if (shp.Name != "Watermark Title" && shp.Text != "") { shp.Text = shp.Text.Replace("ServiceCanonicalName", Constants.ServiceCanonicalName); } } Visio.Selection requestDiagram = requestPage.CreateSelection(Visio.VisSelectionTypes.visSelTypeAll); requestDiagram.Copy(); //rollback foreach (Visio.Shape shp in requestPage.Shapes) { if (shp.Name != "Watermark Title" && shp.Text != "") { shp.Text = shp.Text.Replace(Constants.ServiceCanonicalName, "ServiceCanonicalName"); } } requestVisio.Saved = true; Word.Bookmark requestDiagBM = doc.Bookmarks["RequestFlow"]; Word.Range requestDiagRng = requestDiagBM.Range; requestDiagRng.PasteAndFormat(Word.WdRecoveryType.wdFormatOriginalFormatting); Console.WriteLine("Request flow Added"); } catch (Exception ex) { throw ex; } }
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 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!"); }