Exemple #1
0
 /// <summary>
 /// Initialize basic
 /// </summary>
 /// <param name="jsonFilePath"></param>
 /// <param name="rep"></param>
 /// <param name="reqIfLogList"></param>
 public DoorsModule(string jsonFilePath, EA.Repository rep, List <ReqIfLog> reqIfLogList = null)
 {
     _jsonFilePath     = jsonFilePath;
     _rep              = rep;
     _connectionString = LinqUtil.GetConnectionString(_rep, out _provider);
     _reqIfLogList     = reqIfLogList;
     ReadImportSettings();
 }
Exemple #2
0
        /// <summary>
        /// Initialize DoorsModule for usage with package.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="pkg"></param>
        /// <param name="reqIfLogList"></param>
        private void Init(EA.Repository rep, EA.Package pkg, List <ReqIfLog> reqIfLogList = null)
        {
            _pkg = pkg;
            _rep = rep;
            _reqIfDeserialized = null;
            _reqIfLogList      = reqIfLogList;

            // get connection string of repository
            _connectionString = LinqUtil.GetConnectionString(_rep, out _provider);
        }
Exemple #3
0
        /// <summary>
        /// InitializeTable for search results using EA API
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="searchText">Optional: List of packages, EA elements as a comma separated list</param>
        /// <returns></returns>
        private static DataTable AddinSearchObjectsNestedInitTable(EA.Repository rep, string searchText)
        {
            // get connection string of repository
            string connectionString = LinqUtil.GetConnectionString(rep, out var provider);

            _tv = new Dictionary <string, string>();
            DataTable dt = new DataTable();

            dt.Columns.Add("CLASSGUID", typeof(string));
            dt.Columns.Add("CLASSTYPE", typeof(string));
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Alias", typeof(string));
            dt.Columns.Add("Note", typeof(string));
            if (searchText.Trim().StartsWith("{"))
            {
                // handle string
                string[] guidList = GetEaFromCommaSeparatedList(searchText);
                foreach (var guid in guidList)
                {
                    EA.Element el = rep.GetElementByGuid(guid);
                    if (el == null)
                    {
                        continue;
                    }
                    if (el.Type != "Package")
                    {
                        NestedElementsRecursive(connectionString, provider, dt, rep.GetPackageByID(el.PackageID).PackageGUID, el.ElementID);
                    }
                    if (el.Type == "Package")
                    {
                        NestedPackageElementsRecursive(connectionString, provider, dt, guid);
                    }
                }

                EA.Package pkg = rep.GetPackageByGuid(searchText);
                if (pkg != null)
                {
                    NestedPackageElementsRecursive(connectionString, provider, dt, pkg.PackageGUID);
                }
            }
            else
            {
                // handle context element
                rep.GetContextItem(out var item);
                if (item is EA.Element element)
                {
                    NestedElementsRecursive(connectionString, provider, dt, rep.GetPackageByID(element.PackageID).PackageGUID, element.ElementID);
                }
                if (item is EA.Package package)
                {
                    NestedPackageElementsRecursive(connectionString, provider, dt, package.PackageGUID);
                }
            }
            return(dt);
        }
        /// <summary>
        /// Get the object count of all t_object
        /// </summary>
        /// <returns></returns>
        private int GetObjectCount()
        {
            int count;
            // get connection string of repository
            string connectionString = LinqUtil.GetConnectionString(_repository, out var provider);

            using (var db = new DataModels.EaDataModel(provider, connectionString))
            {
                count = (from o in db.t_object
                         select o.Name).Count();
            }

            return(count);
        }
        /// <summary>
        /// Query the EA model and returns the results in the EA Search Window
        /// </summary>
        /// <returns></returns>
        private bool QueryModel()
        {
            // get connection string of repository
            string    connectionString = LinqUtil.GetConnectionString(_repository, out var provider);
            DataTable dt;

            using (var db = new DataModels.EaDataModel(provider, connectionString))
            {
                dt = (from o in db.t_object
                      orderby new { o.Name, o.Object_Type, o.Stereotype }
                      select new { CLASSGUID = o.ea_guid, CLASSTYPE = o.Object_Type, Name = o.Name, Type = o.Object_Type, Stereotype = o.Stereotype }
                      ).Distinct()
                     .ToDataTable();
            }
            // 2. Order, Filter, Join, Format to XML
            string xml = LinqUtil.QueryAndMakeXmlFromTable(dt);

            // 3. Out put to EA
            _repository.RunModelSearch("", "", "", xml);
            return(true);
        }
        /// <summary>
        /// Get the groups for the current user
        /// </summary>
        /// <param name="rep"></param>
        public EaGroup(EA.Repository rep)
        {
            if (!rep.IsSecurityEnabled)
            {
                Groups = new DataTable();
                return;
            }

            string user = rep.GetCurrentLoginUser();
            // get connection string of repository
            string connectionString = LinqUtil.GetConnectionString(rep, out var provider);

            using (var db = new DataModels.EaDataModel(provider, connectionString))
            {
                Groups = (from grp in db.t_secgroup
                          join grpUser in db.t_secusergroup on grp.GroupID equals grpUser.GroupID
                          join cUser in db.t_secuser on grpUser.UserID equals cUser.UserID
                          where cUser.UserLogin == user
                          orderby grp.GroupName
                          select new { Name = grp.GroupName ?? "" }).ToDataTable();
            }
        }
Exemple #7
0
        /// <summary>
        /// Called when user makes a selection in the menu.
        /// This is your main exit point to the rest of your Add-in
        /// </summary>
        /// <param name="repository">the repository</param>
        /// <param name="location">the location of the menu</param>
        /// <param name="menuName">the name of the menu</param>
        /// <param name="itemName">the name of the selected menu item</param>
        public override void EA_MenuClick(EA.Repository repository, string location, string menuName, string itemName)
        {
            string    xml;
            DataTable dt;

            // for LINQ to SQL
            IDataProvider provider;         // the provider to connect to database like Access, ..
            string        connectionString; // The connection string to connect to database
            string        parametersToPassToQuery;
            string        linqQueryFileName;
            string        linqQueryFilePath;
            bool          result;
            LinqPad       linqPad;
            DataTable     dtHtml;

            switch (itemName)
            {
            // user has clicked the menuHello menu option
            case MenuHello:
                this.SayHello();
                break;

            // user has clicked the menuGoodbye menu option
            case MenuGoodbye:
                this.SayGoodbye();
                break;


            case MenuOpenProperties:
                this.TestPropertiesDialog(repository);
                break;

            // Test the Search and output the results to EA Search Window
            case MenuRunDemoSearch:
                // 1. Collect data
                dt = SetTable();
                // 2. Order, Filter, Join, Format to XML
                xml = QueryAndMakeXmlFromTable(dt);
                // 3. Out put to EA
                repository.RunModelSearch("", "", "", xml);
                break;

            case MenuRunDemoPackageContent:
                // 1. Collect data into a data table
                dt = SetTableFromContext(repository);
                // 2. Order, Filter, Join, Format to XML
                xml = QueryAndMakeXmlFromTable(dt);
                // 3. Out put to EA
                repository.RunModelSearch("", "", "", xml);
                break;

            // Example to run SQL, convert to DataTable and output in EA Search Window
            case MenuRunDemoSqlToDataTable:
                // 1. Run SQL
                string sql = "select ea_guid AS CLASSGUID, object_type AS CLASSTYPE, name, stereotype, object_type from t_object order by name";
                xml = repository.SQLQuery(sql);
                // 2. Convert to DataTable
                dt = Xml.MakeDataTableFromSqlXml(xml);
                // 2. Order, Filter, Join, Format to XML
                xml = QueryAndMakeXmlFromTable(dt);
                // 3. Out put to EA
                repository.RunModelSearch("", "", "", xml);
                break;


            // Read connection string from EA and try an ADODB Connection
            // Copy connection string to clipboard
            case MenuShowConnectionString:
                string eaConnectionString = repository.ConnectionString;
                if (eaConnectionString != null)
                {
                    connectionString = LinqUtil.GetConnectionString(repository, out provider);

                    string lConnectionString = $"{eaConnectionString}\r\n\r\nProvider for Linq for SQL:\r\n'{provider}\r\n{connectionString}";
                    Clipboard.SetText(lConnectionString);
                    MessageBox.Show($@"{lConnectionString}", @"Connection string (EA+LINQ + SQL) copied to clipboard");
                    if (connectionString == "")
                    {
                        return;
                    }


                    ADODB.Connection conn = new ADODB.Connection();
                    try
                    {
                        conn.Open(connectionString, "", "", -1);      // connection Open synchronously

                        //conn.Open(connectionString, "", "", -1);  // connection Open synchronously
                        MessageBox.Show($@"EA ConnectionString:    '{eaConnectionString}'
ConnectionString:
- '{connectionString}'
Provider:
-  '{provider}'
Mode:             
- '{conn.Mode}' 
State:
- '{conn.State}'", @"ODBC Connection established ");
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show($@"EA ConnectionString:    '{eaConnectionString}'
ConnectionString:
- '{connectionString}'
Mode:             
- '{conn.Mode}' 
State:
- '{conn.State}'

{ e}", @"ODBC Connection error ");
                    }
                }
                break;

            // Basis LINQ to SQL example
            case MenuShowRunLinq2Db:
                // get connection string of repository
                connectionString = LinqUtil.GetConnectionString(repository, out provider);

                // Run LINQ query to dataTable
                dt = LinqUtil.RunLinq2Db(provider, connectionString);
                // Make EA xml
                OrderedEnumerableRowCollection <DataRow> rows = from row in dt.AsEnumerable()
                                                                orderby row.Field <string>(dt.Columns[0].Caption)
                                                                select row;

                xml = Xml.MakeXml(dt, rows);

                // Output to EA
                repository.RunModelSearch("", "", "", xml);
                break;

            // Advanced LINQ to SQL example
            case MenuShowRunLinq2DbAdvanced:
                // get connection string of repository
                connectionString = LinqUtil.GetConnectionString(repository, out provider);

                // Run LINQ query to dataTable
                dt = LinqUtil.RunLinq2DbAdvanced(provider, connectionString);

                // Make EA xml
                xml = Xml.MakeXmlFromDataTable(dt);
                // Output to EA
                repository.RunModelSearch("", "", "", xml);
                break;

            // run LINQPad query to HTML,csv, text (uses lprun.exe)
            // - !!!!You need a LINQPad license to run!!!!!!
            // - lprun installed at standard location (c:\Program Files (x86)\LINQPad5\lprun.exe)
            // - output to 'c:\temp\EaBasicQuery.html'
            // - EA standard installation (used for EAExample database)
            case MenuShowRunLinqPadToHtml:
                // Run query with lprun.exe
                parametersToPassToQuery = @"""Test query EaBasicQuery.linq""";
                linqQueryFileName       = "EaBasicQuery.linq";
                linqQueryFilePath       = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\" + linqQueryFileName;

                linqPad = new LinqPad(repository);
                // Output as html with read back table and out put to EA Search Window
                result = linqPad.Run(linqQueryFilePath, @"html", parametersToPassToQuery);
                if (!result)
                {
                    return;
                }
                dtHtml = linqPad.ReadHtml();

                // Make EA xml
                xml = Xml.MakeXmlFromDataTable(dtHtml);
                // Output to EA
                repository.RunModelSearch("", "", "", xml);
                linqPad.Show();
                // csv
                result = linqPad.Run(linqQueryFilePath, @"csv", parametersToPassToQuery);
                if (!result)
                {
                    return;
                }
                linqPad.Show();
                // text
                result = linqPad.Run(linqQueryFilePath, @"text", parametersToPassToQuery);
                if (!result)
                {
                    return;
                }
                linqPad.Show();
                break;

            // Run LINQPad and output EA context information
            case MenuShowRunLinqPadEaContext:
                linqQueryFileName = "TestCallLinqWithParameter.linq";
                linqQueryFilePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\" + linqQueryFileName;

                linqPad = new LinqPad(repository);
                // Output as html with read back table and out put to EA Search Window
                result = linqPad.Run(linqQueryFilePath, @"html", linqPad.GetArg(repository, "mySearchTerm"));
                if (!result)
                {
                    return;
                }
                dtHtml = linqPad.ReadHtml();

                // Make EA xml
                xml = Xml.MakeXmlFromDataTable(dtHtml);
                // Output to EA
                repository.RunModelSearch("", "", "", xml);
                linqPad.Show();
                break;


            // run LINQ XML query for own EA queries which are stored in *.xml
            case MenuShowRunLinqXml:
                // Make DataTable with LINQ Search/Query
                dt = EaSearches();

                // Make
                xml = Xml.MakeXmlFromDataTable(dt);

                // Output to EA
                repository.RunModelSearch("", "", "", xml);
                //linqPad.Show();
                break;

            case MenuShowShowLinqPadConnections:
                linqQueryFileName = "LinqPadConnections.linq";
                linqQueryFilePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\" + linqQueryFileName;

                linqPad = new LinqPad(repository);
                // Output as html with read back table and out put to EA Search Window, don't use a connection
                result = linqPad.Run(linqQueryFilePath, @"html", linqPad.GetArg(repository, ""), noConnection: true);
                if (!result)
                {
                    return;
                }
                dtHtml = linqPad.ReadHtml();

                // Make EA xml
                xml = Xml.MakeXmlFromDataTable(dtHtml);
                // Output to EA
                repository.RunModelSearch("", "", "", xml);
                linqPad.Show();
                break;

            // run LINQ XML query for own EA queries which are stored in *.xml
            case MenuAbout:

                // get product version
                Assembly        assembly        = Assembly.GetExecutingAssembly();
                FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);

                // Get file-version of dll
                string pathRoot = Assembly.GetExecutingAssembly().Location;
                pathRoot = Path.GetDirectoryName(pathRoot);

                string productVersion         = $"{fileVersionInfo.ProductVersion}{Environment.NewLine}";
                string pathAddInSimpleVersion = Path.Combine(new[] { pathRoot, "AddInSimple.dll" });
                string pathHoLinqToSql        = Path.Combine(new[] { pathRoot, "hoLinqToSql.dll" });
                string pathLinq2Db            = Path.Combine(new[] { pathRoot, "linq2db.dll" });

                MessageBox.Show($@"Product version: {productVersion}
AddInSimple.dll  {FileVersionInfo.GetVersionInfo(pathAddInSimpleVersion).FileVersion}
hoLinqToSql.dll   {FileVersionInfo.GetVersionInfo(pathHoLinqToSql).FileVersion}
linq2db.dll           {FileVersionInfo.GetVersionInfo(pathLinq2Db).FileVersion}

hoTools
[email protected]
+49 172 51 79 16 7
", @"AddInSimple, the example Add-In");
                break;
            }
        }
Exemple #8
0
        public bool ShowFunctions(string folderPathCSourceCode)
        {
            // get connection string of repository
            // the provider to connect to database like Access, ..
            _folderRoot = folderPathCSourceCode;
            string connectionString = LinqUtil.GetConnectionString(folderPathCSourceCode, out IDataProvider provider, withErrorMessage: true);

            if (connectionString == "")
            {
                return(false);
            }
            using (BROWSEVCDB db = new BROWSEVCDB(provider, connectionString))
            {
                folderPathCSourceCode = folderPathCSourceCode.ToUpper();

                // Get all functions of implementation
                // store it to list to avoid SQL with something not possible via SQL
                // Currently there is a bug in VC-Code which ignores some c-files because of lacking #include files.
                var allFunctionsImpl1 = (from f in db.CodeItems
                                         join file in db.Files on f.FileId equals file.Id
                                         where f.Kind == 22 && (f.Name != "TASK" && f.Name != "ISR") &&
                                         file.Name.Contains(folderPathCSourceCode) &&
                                         (
                                             file.LeafName.EndsWith(".C") || file.LeafName.EndsWith(".CPP") ||
                                             file.LeafName.EndsWith(".H") || file.LeafName.EndsWith(".HPP")
                                         )
                                         select new ImplFunctionItem("", f.Name, file.Name, (int)f.StartLine, (int)f.StartColumn, (int)f.EndLine, (int)f.EndColumn)).ToList()

                                        .Union(
                    (from f in db.CodeItems
                     join param in db.CodeItems on f.Id equals param.ParentId
                     join file in db.Files on f.FileId equals file.Id
                     where f.Kind == 22 && (f.Name == "TASK" || f.Name == "ISR") &&
                     (f.EndLine - f.StartLine) > 2 &&                   // filter out extern.....
                     file.Name.Contains(folderPathCSourceCode) &&
                     (
                         file.LeafName.EndsWith(".C") || file.LeafName.EndsWith(".CPP") ||
                         file.LeafName.EndsWith(".H") || file.LeafName.EndsWith(".HPP")
                     )
                     select new ImplFunctionItem("", $"{f.Name}({param.Type})", file.Name, (int)f.StartLine, (int)f.StartColumn, (int)f.EndLine,
                                                 (int)f.EndColumn,
                                                 (int)f.Id)).ToList());
                ;
                // Filter multiple function names
                var allFunctionsImpl = (from f in allFunctionsImpl1
                                        orderby f.Implementation, f.FileName
                                        group f by new
                {
                    a = f.Implementation,
                    b = f.FileName.Substring(0, f.FileName.Length - 3)
                }
                                        into gs
                                        select gs.First()).ToList();



                // get all implementations (C_Functions)
                // - Macro with Implementation
                // - Implementation without Macro
                // - Macro without implementation
                IEnumerable <ImplFunctionItem> allImplementations = (
                    // Implemented Interfaces (Macro with Interface and implementation with different name)
                    from m in _macros
                    join f in allFunctionsImpl on m.Key equals f.Implementation
                    select new ImplFunctionItem(m.Value, m.Key, f.FilePath, f.LineStart, f.ColumnStart, f.LineEnd, f.ColumnEnd, true))
                                                                    .Union
                                                                        (from f in allFunctionsImpl
                                                                        where _macros.All(m => m.Key != f.Implementation)
                                                                        select new ImplFunctionItem(f.Implementation, "", f.FilePath.Substring(_folderRoot.Length), f.LineStart, f.ColumnStart, f.LineEnd, f.ColumnEnd, false))
                                                                    .Union
                                                                    // macros without implementation
                                                                        (from m in _macros
                                                                        where allFunctionsImpl.All(f => m.Key != f.Implementation)
                                                                        select new ImplFunctionItem(m.Value, m.Key, "", 0, 0, 0, 0, true));

                string[] ignoreList = { @"_" };
                _dtFunctions = (from f in allImplementations
                                where ignoreList.All(l => !f.Interface.StartsWith(l)) // handle ignore list
                                orderby(f.Interface)
                                select f)
                               .ToDataTable();



                // new component
                if (_frmFunctions == null || _frmFunctions.IsDisposed)
                {
                    _frmFunctions = new FrmFunctions();
                }
                _frmFunctions.ChangeFolder(connectionString, folderPathCSourceCode, _dtFunctions);
                _frmFunctions.Show();
            }


            return(true);
        }
        /// <summary>
        /// Inventory Macros like '#define AMM_MyFuntion AMM_MyImplementation'
        /// </summary>
        /// <param name="backgroundWorker">Background worker to update progress or null</param>
        /// <param name="folderPathCSourceCode">The C/C++ root folder</param>
        /// <param name="pathRoot">The path of the root folder to inventory</param>
        /// <returns></returns>
        public bool InventoryMacros(System.ComponentModel.BackgroundWorker backgroundWorker, string folderPathCSourceCode, string pathRoot = "")
        {
            // get connection string of repository
            _folderRoot = folderPathCSourceCode;
            string connectionString = LinqUtil.GetConnectionString(_folderRoot, out var provider, withErrorMessage: true);

            if (connectionString == "")
            {
                return(false);
            }
            using (var db = new DataModels.VcSymbols.BROWSEVCDB(provider, connectionString))
            {
                // Estimates macros which concerns functions
                var macros = (from m in db.CodeItems
                              join file in db.Files on m.FileId equals file.Id
                              where m.Kind == 33 && file.Name.Contains(pathRoot) && (file.LeafName.EndsWith(".h") || file.LeafName.EndsWith(".hpp")) &&
                              !(m.Name.StartsWith("_") || m.Name.EndsWith("_H") || m.Name.Contains("_SEC_"))
                              orderby file.Name
                              select new { MacroName = m.Name, FilePath = file.Name, FileName = file.LeafName, m.StartLine, m.StartColumn, m.EndLine, m.EndColumn }).Distinct();

                int step  = 1;
                int count = 0;
                if (backgroundWorker != null)
                {
                    step  = macros.Count() / 50;
                    count = step;
                    backgroundWorker.ReportProgress(2);
                }
                _macros.Clear();
                string   fileLast = "";
                string[] code     = { "" };

                // capture the following macros
                // #define <<interface>> <<implementation>>
                // #define <<interface>> &<<implementation>>
                Regex rxIsFunctioName = new Regex(@"^[&A-Z_a-z]\w*$");
                foreach (var m in macros)
                {
                    if (backgroundWorker != null)
                    {
                        count += 1;
                        if (count % step == 0)
                        {
                            backgroundWorker.ReportProgress(count / step);
                        }
                    }
                    // get file content if file changed
                    if (fileLast != m.FilePath)
                    {
                        fileLast = m.FilePath;
                        code     = File.ReadAllLines(m.FilePath);
                    }
                    string   text  = code[m.StartLine - 1].Substring((int)m.StartColumn - 1);
                    string[] lText = text.Split(' ');
                    if (lText.Count() == 3)
                    {
                        // check if functionName
                        if (rxIsFunctioName.IsMatch(lText[2].Trim()))
                        {
                            // delete pointer
                            if (lText[2].StartsWith("&"))
                            {
                                text = "5";
                            }
                            string key = lText[2].Replace("&", "");
                            // add macro value as key
                            if (!_macros.ContainsKey(key))
                            {
                                _macros.Add(key, m.MacroName);
                            }
                        }
                    }
                }
            }
            return(true);
        }
        /// <summary>
        /// Show all interfaces (provided/required) for this Component/Class
        /// - Provided (declaration on in header file
        /// -- Defined functions which start with Component-Name
        /// -- Defined functions per macro (#define NAME_functionname implName)
        /// - Required
        /// -- Called functions defined outside the component
        /// -- Takes macros in account
        /// </summary>
        /// <param name="el"></param>
        /// <param name="folderRoot">Root folder patch of C/C++ source code</param>
        /// <param name="fileFolderToAnalyze"></param>
        /// <returns></returns>
        public bool ShowInterfacesOfElement(EA.Element el, string folderRoot, string fileFolderToAnalyze = "")
        {
            // get connection string of repository
            // the provider to connect to database like Access, ..
            _folderRoot = folderRoot;
            string connectionString = LinqUtil.GetConnectionString(folderRoot, out IDataProvider provider);

            using (BROWSEVCDB db = new BROWSEVCDB(provider, connectionString))
            {
                // Estimate file name of component
                if (el == null && fileFolderToAnalyze == "")
                {
                    MessageBox.Show("You should select Element or a file/folder", "Nothing selected");
                    return(false);
                }
                string modName = "xxxxxx";
                if (el != null)
                {
                    modName = $"{el.Name.ToLower()}_";
                }
                var folderNameOfClass = fileFolderToAnalyze != ""
                    ? fileFolderToAnalyze
                    : GetSourceOfComponent(el, db);
                if (folderNameOfClass == "")
                {
                    return(false);
                }

                // estimate file names of component
                // Component and Module implementation file names beneath folder
                IQueryable <string> fileNamesOfClassTree = from f in db.Files
                                                           where f.Name.StartsWith(folderNameOfClass) && (f.LeafName.EndsWith(".c") || f.LeafName.ToLower().EndsWith(".cpp"))
                                                           select f.Name;

                // Get all functions of implementation
                // store it to list to avoid SQL with something not possible via SQL
                var allFunctionsImpl1 = (from f in db.CodeItems
                                         join file in db.Files on f.FileId equals file.Id
                                         where f.Kind == 22 && (f.Name != "TASK" && f.Name != "ISR") &&
                                         (f.EndLine - f.StartLine) > 2 && // filter out extern.....
                                         file.Name.ToLower().Contains(folderRoot) &&
                                         (
                                             file.LeafName.ToLower().EndsWith(".c") || file.LeafName.ToLower().EndsWith(".cpp") ||
                                             file.LeafName.ToLower().EndsWith(".h") || file.LeafName.ToLower().EndsWith(".hpp")
                                         )
                                         select new ImplFunctionItem("", f.Name, file.Name, (int)f.StartLine, (int)f.StartColumn, (int)f.EndLine,
                                                                     (int)f.EndColumn,
                                                                     (int)f.Id)).ToList()

                                        // Task and ISR
                                        .Union(
                    (from f in db.CodeItems
                     join param in db.CodeItems on f.Id equals param.ParentId
                     join file in db.Files on f.FileId equals file.Id
                     where f.Kind == 22 && (f.Name == "TASK" || f.Name == "ISR") &&
                     (f.EndLine - f.StartLine) > 2 &&               // filter out extern.....
                     file.Name.ToLower().Contains(folderRoot) &&
                     (
                         file.LeafName.ToLower().EndsWith(".c") || file.LeafName.ToLower().EndsWith(".cpp") ||
                         file.LeafName.ToLower().EndsWith(".h") || file.LeafName.ToLower().EndsWith(".hpp")
                     )
                     select new ImplFunctionItem("", $"{f.Name}({param.Type})", file.Name, (int)f.StartLine, (int)f.StartColumn, (int)f.EndLine,
                                                 (int)f.EndColumn,
                                                 (int)f.Id)).ToList()


                    );

                // Filter multiple function names
                // If #includes aren't correct VS Code has some issues.
                var allFunctionsImpl = (from f in allFunctionsImpl1
                                        orderby f.Implementation, f.FileName
                                        group f by new
                {
                    a = f.Implementation,
                    b = f.FileName.Substring(0, f.FileName.Length - 3)
                }
                                        into gs
                                        select gs.First()).ToList();

                // Check macros
                //DataTable tMacro = _macros.OrderBy(x=>x.Key).ToDataTable();
                //DataTable tx = (
                //    // Implemented Interfaces (Macro with Interface and implementation with different name)
                //    from m in _macros
                //    join f in allFunctionsImpl on m.Key equals f.Implementation
                //    where f.FilePath.StartsWith(folderNameOfClass)
                //    //where m.Value.ToLower().StartsWith(modName)
                //    select new ImplFunctionItem(m.Value, m.Key, f.FilePath, f.LineStart, f.ColumnStart, f.LineEnd,
                //        f.ColumnEnd)).ToDataTable();


                IEnumerable <ImplFunctionItem> allCompImplementations = (
                    // Implemented Interfaces (Macro with Interface and implementation with different name)
                    from m in _macros
                    join f in allFunctionsImpl on m.Key equals f.Implementation
                    where f.FilePath.StartsWith(folderNameOfClass)
                    //where m.Value.ToLower().StartsWith(modName)
                    select new ImplFunctionItem(m.Value, m.Key, f.FilePath, f.LineStart, f.ColumnStart, f.LineEnd, f.ColumnEnd))

                                                                        .Union
                                                                        // all C-Implementations
                                                                            (from f in allFunctionsImpl
                                                                            where f.FilePath.StartsWith(folderNameOfClass)
                                                                            where _macros.All(m => m.Key != f.Implementation)
                                                                            select new ImplFunctionItem(f.Implementation, f.Implementation, f.FilePath, f.LineStart, f.ColumnStart, f.LineEnd, f.ColumnEnd))


                                                                        .Union
                                                                        // macros without implementation, no link to path macro definition available
                                                                            (from m in _macros
                                                                            where m.Value.ToLower().StartsWith(modName) &&
                                                                            allFunctionsImpl.All(f => m.Key != f.Implementation)
                                                                            select new ImplFunctionItem(m.Value, m.Key, "", 0, 0, 0, 0));

                // get all implementations (C_Functions)
                // - Macro with Implementation
                // - Implementation without Macro
                // - Macro without implementation
                IEnumerable <ImplFunctionItem> allImplementations = (
                    // Implemented Interfaces (Macro with Interface and implementation with different name)
                    from m in _macros
                    join f in allFunctionsImpl on m.Key equals f.Implementation
                    select new ImplFunctionItem(m.Value, m.Key, f.FilePath, f.LineStart, f.ColumnStart, f.LineEnd, f.ColumnEnd))

                                                                    .Union( // Implementation without macros
                    (from f in allFunctionsImpl
                     where _macros.All(m => m.Key != f.Implementation)
                     select new ImplFunctionItem(f.Implementation, f.Implementation, f.FilePath, f.LineStart, f.ColumnStart, f.LineEnd, f.ColumnEnd))
                    )

                                                                    .Union
                                                                    // macros without implementation
                                                                        (from m in _macros
                                                                        where allFunctionsImpl.All(f => m.Key != f.Implementation)
                                                                        select new ImplFunctionItem(m.Value, m.Key, "", 0, 0, 0, 0));

                // Test purposes
                //DataTable dt = allCompImplementations.ToDataTable();
                //-----------------------------------------

                DataTable dtProvidedInterface = ShowProvidedInterface(db, folderNameOfClass, fileNamesOfClassTree, allCompImplementations);
                DataTable dtRequiredInterface = ShowRequiredInterface(db, folderNameOfClass, fileNamesOfClassTree, allImplementations);



                // new component
                if (_frm == null || _frm.IsDisposed)
                {
                    _frm = new FrmComponentFunctions(connectionString, Rep, el, folderRoot, folderNameOfClass, dtProvidedInterface, dtRequiredInterface);
                    _frm.Show();
                }
                else
                {
                    _frm.ChangeComponent(connectionString, Rep, el, _folderRoot, folderNameOfClass, dtProvidedInterface, dtRequiredInterface);
                    _frm.Show();
                    _frm.BringToFront();
                }

                return(true);
            }
        }
 public SymbolDb(Settings.Settings settings, LanguageClient client)
 {
     _settings         = settings;
     _client           = client;
     _connectionString = LinqUtil.GetConnectionString(_settings.SettingsItem.SqLiteDatabasePath, out _dbProvider);
 }