Ejemplo n.º 1
0
        //Accept button
        private void accept_Click(object sender, EventArgs e)
        {
            String localFileName = "";

            try
            {
                disableAllButtons();
                if (application is Word.Document)
                {
                    Word.Document activeDocument = ((Word.Document)application);
                    activeDocument.Save(); // Saves the document
                    localFileName = activeDocument.FullName;
                }
                else if (application is Excel.Workbook)
                {
                    Excel.Workbook actitiveWorkBook = ((Excel.Workbook)application);
                    actitiveWorkBook.Save(); // Saves the document;
                    localFileName = actitiveWorkBook.FullName;
                }
                else if (application is PowerPoint.Presentation)
                {
                    PowerPoint.Presentation activePresentation = ((PowerPoint.Presentation)application);
                    activePresentation.Save(); // Saves the document
                    localFileName = activePresentation.FullName;
                }
                else if (application is Visio.Document)
                {
                    Visio.Document activeDocument = ((Visio.Document)application);
                    activeDocument.Save(); // Saves the document
                    localFileName = activeDocument.FullName;
                }
                else if (application is String)
                {
                    localFileName = (String)application;
                }

                String docPath = Util.getOpenKMPath(localFileName, (MSOpenKMCore.ws.folder)actualNode.Tag);
                // Must save a temporary file to be uploaded
                File.Copy(localFileName, localFileName + "_TEMP");
                localFileName = localFileName + "_TEMP";
                DocumentLogic.create(localFileName, docPath, configXML.getHost(), configXML.getUser(), configXML.getPassword());
                File.Delete(localFileName); // Deletes temporary file
                MessageBox.Show(resources.GetString("uploaded"));
            }
            catch (Exception ex)
            {
                // Ensure temporary file is deleted
                if (!localFileName.Equals("") && File.Exists(localFileName))
                {
                    File.Delete(localFileName); // Deletes temporary file
                }
                String errorMsg = "TreeForm - (accept_Click)\n" + ex.Message + "\n\n" + ex.StackTrace;
                MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                Hide();
            }
        }
Ejemplo n.º 2
0
        public static void ImportVBA(Visio.Document doc, string folder, Settings settings, bool save)
        {
            if (doc.Type != Visio.VisDocumentTypes.visTypeDrawing &&
                doc.Type != Visio.VisDocumentTypes.visTypeTemplate &&
                doc.Type != Visio.VisDocumentTypes.visTypeStencil)
            {
                return;
            }

            VBA.ImportOneDocumentVBA(doc.VBProject, folder, settings);

            if (save)
            {
                doc.Save();
            }

            if (!settings.IncludeStencils)
            {
                return;
            }

            if (doc.Type != Visio.VisDocumentTypes.visTypeDrawing &&
                doc.Type != Visio.VisDocumentTypes.visTypeTemplate)
            {
                return;
            }

            var app = doc.Application;

            var window = FindDocumentWindow(app, doc.ID);

            if (window == null)
            {
                return;
            }

            Array stencilNames;

            window.DockedStencils(out stencilNames);
            foreach (string stencilName in stencilNames)
            {
                var stencilDoc = app.Documents[stencilName];

                var readOnly = stencilDoc.ReadOnly != 0;
                if (readOnly)
                {
                    stencilDoc.Close();
                    short flags = (short)Visio.VisOpenSaveArgs.visOpenDocked | (short)Visio.VisOpenSaveArgs.visOpenRW;

                    stencilDoc = app.Documents.OpenEx(stencilName, flags);
                }

                VBA.ImportOneDocumentVBA(stencilDoc.VBProject, Path.Combine(folder, stencilDoc.Name), settings);
                if (save)
                {
                    stencilDoc.Save();
                }
            }
        }
Ejemplo n.º 3
0
 private static void kill()
 {
     doc.Save();
     application.Quit();
 }
Ejemplo n.º 4
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 static void Main(string[] args)
        {
            Console.WriteLine("Process models mining started...");

            string[] models = Directory.GetFiles(MODELS_PATH, "*.vsd", SearchOption.AllDirectories);

            foreach (string model in models)
            {
                Console.WriteLine(model);

                Visio.Application visioApp = new Visio.Application();
                Visio.Document    document = visioApp.Documents.Open(model);

                visioApp.Visible = true;

                VBA.VBComponent codeModule = document.VBProject.VBComponents.Add(VBA.vbext_ComponentType.vbext_ct_StdModule);

                string vbaCode = @"
                Sub ExtractProcessModel()
                    Set file = CreateObject(""Scripting.FileSystemObject"").CreateTextFile(""${models_path}"" & ActiveDocument.Name & "".java"", True, True)
    
                    file.Write (""/* "" & ActiveDocument.Name & "" */ {"" & vbNewLine)
                    file.Write (""Process process = repository.createProcess("""""" & ActiveDocument.Name & """""");"" & vbNewLine)
    
                    For i = 1 To ActivePage.Shapes.Count
                        'For native Visio-based EPC diagrams
                        If InStr(ActivePage.Shapes(i).NameU, ""Dynamic connector"") <> 0 Then
                            FromShape = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(1).ToSheet.Text
                            ToShape = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(2).ToSheet.Text
            
                            FromShapeID = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(1).ToSheet.ID
                            ToShapeID = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(2).ToSheet.ID
            
                            FromShapeName = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(1).ToSheet.NameU
                            ToShapeName = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(2).ToSheet.NameU
            
                            If InStr(FromShapeName, ""Organizational unit"") <> 0 Then
                                file.Write (""repository.createResourceFlow("")
                            ElseIf InStr(FromShapeName, ""Information/ Material"") <> 0 Then
                                file.Write (""repository.createInputFlow("")
                            ElseIf InStr(ToShapeName, ""Information/ Material"") <> 0 Then
                                file.Write (""repository.createOutputFlow("")
                            Else
                                file.Write (""repository.createControlFlow("")
                            End If
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                CurrentShapeName = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.NameU
            
                                ResText = Null
                                ResID = Null
                
                                If j = 1 Then
                                    ResText = FromShape
                                    ResID = FromShapeID
                                Else
                                    ResText = ToShape
                                    ResID = ToShapeID
                                End If
            
                                If InStr(CurrentShapeName, ""Event"") <> 0 Then
                                    file.Write (""repository.createEvent("""""" & ResText & """""", process)"")
                                End If
                
                                If InStr(CurrentShapeName, ""Function"") <> 0 Then
                                    file.Write (""repository.createFunction("""""" & ResText & """""", process)"")
                                End If
                
                                If InStr(CurrentShapeName, ""XOR"") <> 0 Then
                                    file.Write (""repository.createXOrGateway("""""" & ResID & """""", process)"")
                                ElseIf InStr(CurrentShapeName, ""OR"") <> 0 Then
                                    file.Write (""repository.createOrGateway("""""" & ResID & """""", process)"")
                                End If
                
                                If InStr(CurrentShapeName, ""AND"") <> 0 Then
                                    file.Write (""repository.createAndGateway("""""" & ResID & """""", process)"")
                                End If
                
                                If InStr(CurrentShapeName, ""Process path"") <> 0 Then
                                    file.Write (""repository.createProcessInterface("""""" & ResText & """""", process)"")
                                End If
                
                                If InStr(CurrentShapeName, ""Organizational unit"") <> 0 Then
                                    file.Write (""repository.createOrganizationalUnit("""""" & ResText & """""")"")
                                End If
                
                                If InStr(CurrentShapeName, ""Information/ Material"") <> 0 Then
                                    file.Write (""repository.createBusinessObject("""""" & ResText & """""")"")
                                End If
                
                                If j = 1 Then
                                    file.Write ("", "")
                                Else
                                    file.Write ("");"" & vbNewLine)
                                End If
                            Next
                        End If

                        'For custom ARIS stencil-based diagrams
                        If InStr(ActivePage.Shapes(i).Name, ""IsPredecessorOfARIS"") <> 0 Then
                            Subj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(1).ToSheet.Text
                            Obj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(2).ToSheet.Text
            
                            file.Write (""repository.createControlFlow("")
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                ResName = Null
                
                                If j = 1 Then
                                    ResName = Subj
                                Else
                                    ResName = Obj
                                End If
                
                                ValID = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.ID
                
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""EventARIS"") <> 0 Then
                                    file.Write (""repository.createEvent("""""" & ResName & """""", process)"")
                                End If
                
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""FunctionARIS"") <> 0 Then
                                    file.Write (""repository.createFunction("""""" & ResName & """""", process)"")
                                End If
                
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""ProcessInterfaceARIS"") <> 0 Then
                                    file.Write (""repository.createProcessInterface("""""" & ResName & """""", process)"")
                                End If
                
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""ANDruleARIS"") <> 0 Then
                                    file.Write (""repository.createAndGateway("""""" & ValID & """""", process)"")
                                End If
                
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""XORruleARIS"") <> 0 Then
                                    file.Write (""repository.createXOrGateway("""""" & ValID & """""", process)"")
                                ElseIf InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""ORruleARIS"") <> 0 Then
                                    file.Write (""repository.createOrGateway("""""" & ValID & """""", process)"")
                                End If
                
                                If j = 1 Then
                                    file.Write ("", "")
                                Else
                                    file.Write ("");"" & vbNewLine)
                                End If
                            Next
                        End If
    
                        If InStr(ActivePage.Shapes(i).Name, ""RoleInProcessARIS"") <> 0 Then
                            Subj = Null
                            Obj = Null
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""FunctionARIS"") <> 0 Then
                                    Subj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                Else
                                    Obj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                End If
                            Next
            
                            file.Write (""repository.assignOrganizationalUnits(repository.createFunction("""""" & Subj & """""", process), repository.createOrganizationalUnit("""""" & Obj & """"""));"" & vbNewLine)
                        End If
        
                        If InStr(ActivePage.Shapes(i).Name, ""SoftwareRoleARIS"") <> 0 Then
                            Subj = Null
                            Obj = Null
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""FunctionARIS"") <> 0 Then
                                    Subj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                Else
                                    Obj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                End If
                            Next
            
                            file.Write (""repository.assignApplicationSystems(repository.createFunction("""""" & Subj & """""", process), repository.createApplicationSystem("""""" & Obj & """"""));"" & vbNewLine)
                        End If
        
                        If InStr(ActivePage.Shapes(i).Name, ""InputObjectARIS"") <> 0 Then
                            Subj = Null
                            Obj = Null
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""FunctionARIS"") <> 0 Then
                                    Subj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                Else
                                    Obj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                End If
                            Next
            
                            file.Write (""repository.assignInputs(repository.createFunction("""""" & Subj & """""", process), repository.createBusinessObject("""""" & Obj & """"""));"" & vbNewLine)
                        End If
        
                        If InStr(ActivePage.Shapes(i).Name, ""OutputObjectARIS"") <> 0 Then
                            Subj = Null
                            Obj = Null
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""FunctionARIS"") <> 0 Then
                                    Subj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                Else
                                    Obj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                End If
                            Next
            
                            file.Write (""repository.assignOutputs(repository.createFunction("""""" & Subj & """""", process), repository.createBusinessObject("""""" & Obj & """"""));"" & vbNewLine)
                        End If
                    Next
    
                    file.Write (""repository.store();"" & vbNewLine)
                    file.Write (""}"")
    
                    file.Close
                End Sub";

                vbaCode = vbaCode.Replace("${models_path}", MODELS_PATH);

                codeModule.CodeModule.AddFromString(vbaCode);

                document.ExecuteLine("ExtractProcessModel");

                document.VBProject.VBComponents.Remove(codeModule);

                document.Save();
                document.Close();

                visioApp.Quit();
            }

            string[] files = Directory.GetFiles(MODELS_PATH, "*.java", SearchOption.AllDirectories);

            string modelsCollection = @"
            package main.resources.repository;

            import edu.kopp.phd.ProcessModelRepositoryApplication;
            import edu.kopp.phd.model.flow.Process;
            import edu.kopp.phd.repository.RDFRepository;

            import org.junit.Test;

            public class PortalProcessModelsCollection {
            public RDFRepository repository = RDFRepository.getInstance();
            ";

            foreach (string file in files)
            {
                modelsCollection += File.ReadAllText(file) + "\n";

                File.Delete(file);
            }

            modelsCollection += @"
                @Test
                public void deploy() {
                    ProcessModelRepositoryApplication.run();
                }
            }";

            File.WriteAllText(PORTAL_COLLECTION_PATH, modelsCollection);

            string[] pages = Directory.GetFiles(PAGES_PATH, "*.html", SearchOption.AllDirectories);

            foreach (string page in pages)
            {
                File.Delete(page);
            }

            Console.WriteLine("Done!");
        }
Ejemplo n.º 6
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!");
        }
Ejemplo n.º 7
0
        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.Error.WriteLine("Invalid number of arguments.");
                Usage();
                return(3);
            }

            FileInfo sourceFileInfo = new FileInfo(args[0]);

            if (!sourceFileInfo.Exists)
            {
                Console.Error.WriteLine("Source file \"{0}\"doesn't exist.", sourceFileInfo.FullName);
                Usage();
                return(3);
            }

            string[] validExtensions = new string[] { ".vst", ".vsd" };
            if (!validExtensions.Contains(sourceFileInfo.Extension, StringComparer.InvariantCultureIgnoreCase))
            {
                Console.Error.WriteLine(String.Format("Source file extension must be one of: {0}", String.Join(", ", validExtensions)));
                Usage();
                return(3);
            }

            string referencePageNames = args[1];

            FileInfo targetFileInfo = new FileInfo(args[2]);

            if (targetFileInfo.Exists && targetFileInfo.IsReadOnly)
            {
                Console.Error.WriteLine("Target file exists and is readonly.");
                Usage();
                return(3);
            }
            if (!targetFileInfo.Directory.Exists)
            {
                Console.Error.WriteLine("Target file directory doesn't exist.");
                Usage();
                return(3);
            }
            if (!validExtensions.Contains(targetFileInfo.Extension, StringComparer.InvariantCultureIgnoreCase))
            {
                Console.Error.WriteLine(String.Format("Target file extension must be one of: {0}", String.Join(", ", validExtensions)));
                Usage();
                return(3);
            }
            if (String.Compare(sourceFileInfo.FullName, targetFileInfo.FullName, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                Console.Error.WriteLine("Source and targer file are identical.");
                Usage();
                return(3);
            }

            string targetFile = targetFileInfo.FullName;

            File.Copy(sourceFileInfo.FullName, targetFile, true);
            File.SetAttributes(targetFile, FileAttributes.Normal);
            //Visio.Application visioApp = new Visio.Application(); // Visible Application
            Visio.InvisibleApp visioApp            = new Visio.InvisibleApp();
            Visio.Document     visioTargetDocument = visioApp.Documents.OpenEx(targetFile, (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visAddMacrosDisabled);

            Array pageNameArray;

            visioTargetDocument.Pages.GetNames(out pageNameArray);
            IList <string> pageNames = pageNameArray.Cast <string>().ToList();

            foreach (string referencePageName in referencePageNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                bool referencePageContained = pageNames.Remove(referencePageName);
                if (!referencePageContained)
                {
                    visioApp.Quit();
                    File.Delete(targetFile);
                    Console.Error.WriteLine(String.Format("ReferencePageName \"{0}\" not found in \"{1}\".", referencePageName, sourceFileInfo.FullName));
                    Usage();
                    return(3);
                }
            }

            foreach (string pageName in pageNames)
            {
                Visio.Page page = visioTargetDocument.Pages[pageName];
                page.Delete(1);
            }

            visioTargetDocument.Save();

            if (referencePageNames != "Template")
            {
                foreach (Visio.Page page in visioTargetDocument.Pages)
                {
                    foreach (Visio.Shape shape in page.Shapes)
                    {
                        if (shape.get_CellExists("User.StateChartType", (short)0) != 0)
                        {
                            string stateChartType = shape.Cells["User.StateChartType"].FormulaU;
                            if (stateChartType == "GUARD(0)")
                            {
                                Console.WriteLine("Name={0} NameID={1} NameU={2}", shape.Name, shape.NameID, shape.NameU);

                                shape.get_Cells("Prop.TargetFile").FormulaU = "";

                                Console.WriteLine("Prop.TargetFile Formula={0} Value={1}", shape.get_Cells("Prop.TargetFile").FormulaU, shape.get_Cells("Prop.TargetFile").get_ResultStrU((short)Visio.VisToParts.visNone));
                            }
                        }
                    }
                }
            }

            visioTargetDocument.Save();

            visioTargetDocument.Close();

            visioApp.Quit();

            Console.WriteLine(String.Format("File written to \"{0}\"", targetFileInfo.FullName));

            return(0);
        }