コード例 #1
0
        public DlgUser(EA.Repository rep)
        {
            var sql = new UtilSql(rep);

            InitializeComponent();
            if (rep.IsSecurityEnabled)
            {
                _isSecurityEnabled = true;

                // check if user has the rights to manage users
                if (sql.UserHasPermission(rep.GetCurrentLoginUser(true), 1))
                {
                    _users         = sql.GetUsers();
                    txtStatus.Text = "Security is enabled: Choose user";
                }
                else
                {
                    txtStatus.Text = "Security is enabled: Only person with 'Manage User' are allowed to change users!";

                    MessageBox.Show("User has no 'Manage Users' right", "Insufficient user rights");
                    btnOk.Enabled = false;
                }
            }
            else
            {
                _users         = sql.GetUsers();
                txtStatus.Text = "Security isn't enabled: Choose or enter your desired author name!";
            }


            cmbUser.Text       = _user;
            cmbUser.DataSource = _users;
        }
コード例 #2
0
        protected readonly string[] EaLayoutStyle; // The EA Text Style stored in t_txtref


        protected DiagramGeneralStyle(EA.Repository rep, string type, string style, string property)
        {
            Style    = style.Trim().Replace(",", ";").Replace(";;", ";").TrimEnd(';').Split(';');
            Property = property.Trim().Replace(",", ";").Replace(";;", ";").TrimEnd(';').Split(';');

            type = type.Trim().TrimEnd(';').Replace(";;", ";");
            Type = type.Split(';');
            Rep  = rep;

            // handle EA Layout Styles
            Regex rgx   = new Regex(@"EaLayoutStyle=([^;]*)");
            Match match = rgx.Match(property);

            if (match.Success && match.Groups.Count == 2)
            {
                // handle EA Styles
                string layoutStyleName  = match.Groups[1].Value.Trim();
                string sql              = $@"select Notes as [STYLE] from t_trxtypes  where TRX='{layoutStyleName}'";
                var    layoutStyleValue = UtilSql.GetListOfStringFromSql(Rep, sql, "STYLE");
                if (layoutStyleValue.Count == 0)
                {
                    MessageBox.Show($@"EA Text Style '{layoutStyleName}' not available in EA.", $@"Can't read EA Text Style '{layoutStyleName}'.");
                }
                if (layoutStyleValue.Count > 1)
                {
                    MessageBox.Show(
                        $@"EA Text Style '{EaLayoutStyle}'\r\nCount: {layoutStyleValue.Count}. EA Text styles are a little tricky with names! Check list box of styles in EA!",
                        $@"More than one style with name '{layoutStyleName}'.");
                }
                EaLayoutStyle = layoutStyleValue[0].Split(';');
            }
        }
コード例 #3
0
 /// <summary>
 /// sets the correct wild cards depending on the database type.
 /// changes '%' into '*' if on ms access
 /// and _ into ? on msAccess
 /// </summary>
 /// <param name="sqlQuery">the original query</param>
 /// <returns>the fixed query</returns>
 private string FormatSql(string sqlQuery)
 {
     sqlQuery = UtilSql.ReplaceSqlWildCards(Repository, sqlQuery, RepositoryType);
     sqlQuery = FormatSqlTop(sqlQuery);
     sqlQuery = FormatSqlFunctions(sqlQuery);
     sqlQuery = FormatSqldBspecific(sqlQuery); // DB specifics like #DB=ORACLE#.... #DB=ORACLE#
     return(sqlQuery.Trim());
 }
コード例 #4
0
        /// <summary>
        /// Get the Behavior for an Operation. The behavior is stored in:
        /// .Behavior '{ea_guid}' of classifier which is the behavior
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="method"></param>
        /// <returns>Behavior</returns>
        public static EA.Element GetBehaviorForOperation(Repository repository, Method method)
        {
            EA.Element returnValue = null;
            string     behavior    = method.Behavior;

            if (behavior.StartsWith("{") & behavior.EndsWith("}"))
            {
                // get object according to behavior
                EA.Element el = repository.GetElementByGuid(behavior);
                // Behavior found
                if (el != null)
                {
                    returnValue = el;
                }
                else
                {
                    behavior = "";
                }
            }
            // try to establish link to behavior.
            if (behavior == "")
            {
                string colName = "guid_activity";
                string query   =
                    $@"select ea_guid As [{colName}] from t_object where name = '{method.Name}' and Object_Type = 'Activity'";

                UtilSql       sql           = new UtilSql(repository);
                List <string> lActivityGuid = sql.GetListOfStringFromSql(query, colName);
                if (lActivityGuid.Count == 1)
                {
                    // get Behavior
                    behavior    = lActivityGuid[0];
                    returnValue = repository.GetElementByGuid(behavior);
                    if (returnValue == null)
                    {
                        MessageBox.Show(
                            $"Operation: '{method.Name}' has no possible Activity, can't establish a link from Operation to Activity",
                            "Can't link Activity to operation");
                    }
                    else
                    {
                        method.Behavior = behavior;
                        method.Update();
                    }
                }
                else
                {
                    MessageBox.Show($@"Operation: '{method.Name}' has {lActivityGuid.Count} possible Activities, can't establish a link from Operation to Activity.
This can be because of macros and multiple implementations of the operetion.",
                                    "Can't link Activity to operation, stereotype?");
                }
            }
            return(returnValue);
        }
コード例 #5
0
        public void ConnectPortsOf2Classes(Element srcEl, Element trgtEl)
        {
            foreach (Element srcPort in srcEl.EmbeddedElements)
            {
                foreach (Element trgtPort in trgtEl.EmbeddedElements)
                {
                    // don't connect to itself
                    if (srcPort.Name == trgtPort.Name && srcPort.ElementID != trgtPort.ElementID)
                    {
                        //if (srcPort.Stereotype != trgtEl.Stereotype)
                        //{
                        //    // only connect:
                        //    // sender to receiver
                        //    // client to server
                        //    // check if connection already exists
                        //    if (srcPort.Stereotype == "Sender")
                        //        if (trgtPort.Stereotype != "Receiver") continue;
                        //    if (srcPort.Stereotype == "Receiver")
                        //        if (trgtPort.Stereotype != "Sender") continue;
                        //    if (srcPort.Stereotype == "Client")
                        //        if (trgtPort.Stereotype != "Server") continue;
                        //    if (srcPort.Stereotype == "Server")
                        //        if (trgtPort.Stereotype != "Client") continue;

                        var sql = new UtilSql(_rep);
                        if (sql.IsConnectionAvailable(srcPort, trgtPort) == false)
                        {
                            // direction of connector
                            if (srcPort.Stereotype == "Sender" | srcPort.Stereotype == "Client")
                            {
                                var con = (Connector)srcPort.Connectors.AddNew("", "Connector");
                                srcPort.Connectors.Refresh();
                                con.SupplierID = trgtPort.ElementID;
                                con.Update();
                                _count += 1;
                            }
                            else
                            {
                                var con = (Connector)trgtPort.Connectors.AddNew("", "Connector");
                                trgtPort.Connectors.Refresh();
                                con.SupplierID = srcPort.ElementID;
                                con.Update();
                                _count += 1;
                            }
                        }
                        //}
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Dialog to ask and enter a user. Enter a user is only possible if the user has the rights.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="changeScope"></param>
        /// <param name="lToDelete"></param>
        public DlgAuthor(Repository rep, ChangeScope changeScope, List <string> lToDelete)
        {
            _rep = rep;
            var sql = new UtilSql(rep);

            InitializeComponent();
            _listChanged.DataSource = lToDelete;
            switch (changeScope)
            {
            case ChangeScope.Item:
                Text = _items;
                break;

            case ChangeScope.Package:
                Text = _packages;
                break;

            case ChangeScope.PackageRecursive:
                Text = _packagesRecursive;
                break;
            }
            if (rep.IsSecurityEnabled)
            {
                _isSecurityEnabled = true;

                // check if user has the rights to manage users
                if (sql.UserHasPermission(rep.GetCurrentLoginUser(true)))
                {
                    _users         = sql.GetUsers();
                    txtStatus.Text = "Security is enabled: Choose user";
                }
                else
                {
                    txtStatus.Text = "Security is enabled: Only person with 'Manage User' are allowed to change users!";

                    MessageBox.Show("User has no 'Manage Users' right", "Insufficient user rights");
                    btnOk.Enabled = false;
                }
            }
            else
            {
                _users         = sql.GetUsers();
                txtStatus.Text = "Security isn't enabled: Choose or enter your desired author name!";
            }


            cmbUser.Text       = _user;
            cmbUser.DataSource = _users;
        }
コード例 #7
0
        /// <summary>
        /// Format DB specific by removing unnecessary DB specific string parts.
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        //#DB=Asa#                DB specif SQL for Asa
        //#DB=FIREBIRD#           DB specif SQL for FIREBIRD
        //#DB=JET#                DB specif SQL for JET
        //#DB=MySql#              DB specif SQL for My SQL
        //#DB=ACCESS2007#         DB specif SQL for ACCESS2007
        //#DB=ORACLE#             DB specif SQL for Oracle
        //#DB=POSTGRES#           DB specif SQL for POSTGRES
        //#DB=SqlSvr#             DB specif SQL for SQL Server
        string FormatSqldBspecific(string sql)
        {
            // available DBs
            var dbs = new Dictionary <UtilSql.RepositoryType, string>()
            {
                { UtilSql.RepositoryType.Access2007, "#DB=ACCESS2007#" },
                { UtilSql.RepositoryType.Asa, "#DB=Asa#" },
                { UtilSql.RepositoryType.Firebird, "#DB=FIREBIRD#" },
                { UtilSql.RepositoryType.AdoJet, "#DB=JET#" },
                { UtilSql.RepositoryType.MySql, "#DB=MySql#" },
                { UtilSql.RepositoryType.Oracle, "#DB=ORACLE#" },
                { UtilSql.RepositoryType.Postgres, "#DB=POSTGRES#" },
                { UtilSql.RepositoryType.SqlSvr, "#DB=SqlSvr#" },
            };

            UtilSql.RepositoryType dbType = UtilSql.GetRepositoryType(Repository);
            string s = sql;

            foreach (var curDb in dbs)
            {
                if (curDb.Key != dbType)
                {   // delete not used DBs
                    string delete = $"{curDb.Value}.*?{curDb.Value}";
                    s = Regex.Replace(s, delete, "", RegexOptions.Multiline | RegexOptions.IgnoreCase);
                }
            }
            // delete remaining DB identifying string
            s = Regex.Replace(s, @"#DB=(Asa|FIREBIRD|JET|MySql|ORACLE|ACCESS2007|POSTGRES|SqlSvr)#", "", RegexOptions.Multiline | RegexOptions.IgnoreCase);

            // delete multiple empty lines
            for (int i = 0; i < 4; i++)
            {
                s = Regex.Replace(s, "\r\n\r\n", "", RegexOptions.Multiline | RegexOptions.IgnoreCase);
            }
            return(s);
        }
コード例 #8
0
        /// <summary>
        /// Runs the search (hoTools SQL file, EA search or LINQ Search). It handles the exceptions.
        /// It converts wild cards of the &lt;Search Term>.
        /// - First search for SQL-File
        /// - Search the LINQ Search if LINQ is supported
        /// - If no SQL file found run EA Search
        /// </summary>
        /// <param name="searchName">EA Search name or SQL file name (uses path to find absolute path)</param>
        /// <param name="searchTerm"></param>
        /// <param name="exportToExcel"></param>
        public string SearchRun(string searchName, string searchTerm, bool exportToExcel = false)
        {
            searchName = searchName.Trim();
            if (searchName == "")
            {
                return("");
            }


            // SQL file?
            string sqlFile = _globalCfg.GetSqlFileName(searchName);

            if (sqlFile != "")

            {
                // ---------------------SQL Search----------------------------
                string sqlString = _globalCfg.ReadSqlFile(searchName);

                // run sql search
                searchTerm = UtilSql.ReplaceSqlWildCards(Repository, searchTerm, RepositoryType);
                return(SqlRun(searchName, sqlString, searchTerm, exportToExcel));
            }
            // LINQPad
            string linqPadFile = _globalCfg.GetLinqPadQueryFileName(searchName);

            if (linqPadFile != "")
            {
                LinqPad linqPad = new LinqPad(Repository, _globalCfg.LprunPath, _globalCfg.TempFolder, @"html",
                                              _globalCfg.UseLinqPadConnection)
                {
                    UseLinqPadConnections = _globalCfg.UseLinqPadConnection,
                    LinqPadConnections    = _globalCfg.LinqPadConnectionPath
                };

                Boolean result = linqPad.Run(linqPadFile, @"html", linqPad.GetArg(Repository, searchTerm));
                if (!result)
                {
                    return("");
                }

                // output target to browser
                if (_globalCfg.LinqPadOutputHtml)
                {
                    Process.Start(linqPad.TargetFile);
                }
                // HTML to DataTable
                System.Data.DataTable dtHtml = linqPad.ReadHtml();

                if (exportToExcel)
                {
                    // DataTable to Excel
                    string excelFile = Path.Combine(_globalCfg.TempFolder,
                                                    $"{Path.GetFileNameWithoutExtension(linqPadFile)}");
                    Excel.SaveTableToExcel(ref excelFile, dtHtml);
                }

                // Make EA xml
                string xml = Xml.MakeXmlFromDataTable(dtHtml);
                // Output to EA
                Repository.RunModelSearch("", "", "", xml);
                return("");
            }
            else
            {
                // EA Search
                try
                {
                    // run SQL search and display in Search Window
                    Repository.RunModelSearch(searchName, searchTerm, "", "");
                    return("");
                }
                catch (Exception e)
                {
                    MessageBox.Show($@"Can't find search!{Environment.NewLine}{Environment.NewLine}- MDG hoTools.. enabled?{Environment.NewLine}- SQL path in Settings correct?{Environment.NewLine}- LINQPad support enabled (Settings General)? :{Environment.NewLine}'{searchName}' '{searchTerm}'{Environment.NewLine}- *.sql in path '{_globalCfg.GetSqlPaths()}'{Environment.NewLine}- *.linq in path '{_globalCfg.GetLinqPaths()}'{Environment.NewLine}- EA Search{Environment.NewLine}{Environment.NewLine}Note:{Environment.NewLine}- Define path in File, Settings{Environment.NewLine}- LINQPad needs a license and has to be installed!{Environment.NewLine}{Environment.NewLine}{e}",
                                    $@"Error start search.");
                    return("");
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Handle Diagram Properties like: Orientation=L/P, Scale=100 (100%) which are independent of the general styles in PDATA, StyleEX.
        /// Sequence:!!
        /// 1 Non SQL Diagram Properties
        /// 2.SQL Diagram Properties
        ///
        /// Rational: It looks as if the EA Update process overwrites SQL changes if not separated!
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="dia"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="withSql">false non SQL, true with SQL</param>
        private static void SetDiagramProperty(Repository rep, EA.Diagram dia, string name, string value, bool withSql = false)
        {
            if (!withSql)
            {
                switch (name.ToLower().Trim())
                {
                case "orientation":
                    dia.Orientation = value.Trim();
                    break;

                case "scale":
                    int scale;
                    if (Int32.TryParse(value.Trim(), out scale))
                    {
                        dia.Scale = scale;
                    }
                    else
                    {
                        MessageBox.Show($"Invalid Diagram Style 'Scale={value};' in Settings.json");
                    }
                    break;

                case @"cx":
                    int cx;
                    if (Int32.TryParse(value.Trim(), out cx))
                    {
                        dia.cx = cx;
                    }
                    else
                    {
                        MessageBox.Show("Should be Integer",
                                        $"Invalid Diagram Style 'cx={value};' in Settings.json");
                    }
                    break;

                case @"cy":
                    int cy;
                    if (Int32.TryParse(value.Trim(), out cy))
                    {
                        dia.cy = cy;
                    }
                    else
                    {
                        MessageBox.Show("Should be Integer",
                                        $"Invalid Diagram Style 'cy={value};' in Settings.json");
                    }
                    break;

                case @"showdetails":
                    int showDetails;
                    if (Int32.TryParse(value.Trim(), out showDetails))
                    {
                        dia.ShowDetails = showDetails;
                    }
                    else
                    {
                        MessageBox.Show("Should be 0=Hide/1=Show",
                                        $"Invalid Diagram Style 'ShowDetails={value};' in Settings.json");
                    }
                    break;

                case @"showpublic":
                    bool showPublic;
                    if (Boolean.TryParse(value.Trim(), out showPublic))
                    {
                        dia.ShowPublic = showPublic;
                    }
                    else
                    {
                        MessageBox.Show("Should be 'true' or 'false'",
                                        $"Invalid Diagram Style 'ShowPublic={value};' in Settings.json");
                    }
                    break;

                case @"showprivate":
                    bool showPrivate;
                    if (Boolean.TryParse(value.Trim(), out showPrivate))
                    {
                        dia.ShowPrivate = showPrivate;
                    }
                    else
                    {
                        MessageBox.Show("Should be 'true' or 'false'",
                                        $"Invalid Diagram Style 'ShowPrivate={value};' in Settings.json");
                    }
                    break;

                case @"showprotected":
                    bool showProtected;
                    if (Boolean.TryParse(value.Trim(), out showProtected))
                    {
                        dia.ShowProtected = showProtected;
                    }
                    else
                    {
                        MessageBox.Show("Should be 'true' or 'false'",
                                        $"Invalid Diagram Style 'ShowProtected={value};' in Settings.json");
                    }
                    break;

                case @"showpackagecontents":
                    bool showPackageContents;
                    if (Boolean.TryParse(value.Trim(), out showPackageContents))
                    {
                        dia.ShowPackageContents = showPackageContents;
                    }
                    else
                    {
                        MessageBox.Show("Should be 'true' or 'false'",
                                        $"Invalid Diagram Style 'ShowPackageContents={value};' in Settings.json");
                    }
                    break;

                case @"highlightimports":
                    bool highLightImports;
                    if (Boolean.TryParse(value.Trim(), out highLightImports))
                    {
                        dia.HighlightImports = highLightImports;
                    }
                    else
                    {
                        MessageBox.Show("Should be 'true' or 'false'",
                                        $"Invalid Diagram Style 'HighLightImports={value};' in Settings.json");
                    }
                    break;
                }
            }
            else
            {   // with SQL
                switch (name.ToLower().Trim())
                {
                case @"showforeign":
                    //dia.Update();
                    //rep.ReloadDiagram(dia.DiagramID);
                    bool showForeign;
                    if (Boolean.TryParse(value.Trim(), out showForeign))
                    {
                        string updateStr = $@"update t_diagram set ShowForeign = {value.Trim()} 
                                                                          where Diagram_ID = {dia.DiagramID}";
                        UtilSql.SqlUpdate(rep, updateStr);
                        //rep.ReloadDiagram(dia.DiagramID);
                        //var schowForeign = rep.GetStringsBySql($@"select ShowForeign from t_diagram where Diagram_ID = {dia.DiagramID}");
                    }
                    else
                    {
                        MessageBox.Show("Should be 'true' or 'false'",
                                        $"Invalid Diagram Style 'ShowForeign={value};' in Settings.json");
                    }
                    break;

                case @"showborder":
                    //dia.Update();
                    //rep.ReloadDiagram(dia.DiagramID);
                    bool showBorder;
                    if (Boolean.TryParse(value.Trim(), out showBorder))
                    {
                        string updateStr = $@"update t_diagram set ShowBorder = {value.Trim()} 
                                                                          where Diagram_ID = {dia.DiagramID}";
                        UtilSql.SqlUpdate(rep, updateStr);
                        //rep.ReloadDiagram(dia.DiagramID);
                        //var schowForeign = rep.GetStringsBySql($@"select ShowForeign from t_diagram where Diagram_ID = {dia.DiagramID}");
                    }
                    else
                    {
                        MessageBox.Show("Should be 'true' or 'false'",
                                        $"Invalid Diagram Style 'ShowBorder={value};' in Settings.json");
                    }
                    break;
                }
            }
        }