Esempio n. 1
0
        /// <summary>
        /// Get the List of all of the Stored Procedures in the Database.
        /// </summary>
        /// <param name="getParameters">Indicates if the Parameters of each Stored Procedure will be returned.
        /// False by Default, because it requires extra calculation and time.</param>
        /// <returns>List of all of the Stored Procedures in the Database.</returns>
        public virtual async Task <List <StoredProcedureDTO> > GetAllStoredProcedures(bool getParameters = false, bool getTables = false)
        {
            var storedProcedureDTOs = await Repository.GetAllStoredProcedures(getParameters);

            if (getTables)
            {
                var message = await GetText("SearchingStoredProceduresTables", "", typeof(BaseManager).FullName);

                SetViewIsBusy(message);
                await DelayTask();

                var sqlParser = new SQLParser();

                foreach (var storedProcedureDTO in storedProcedureDTOs)
                {
                    try
                    {
                        //Get all of the Statements of the Stored Procedure.
                        var statements = sqlParser.GetStatements(storedProcedureDTO.Content, PermissionTypeEnum.AllCRUD);

                        //Check all of the Statements of the Stored Procedure.
                        foreach (var statement in statements)
                        {
                            var tables = sqlParser.GetTablesInStatement(statement, storedProcedureDTO.Name);

                            var sqlStatement = new SQLStatementDTO
                            {
                                Content = statement,
                                Tables  = tables
                            };

                            storedProcedureDTO.SQLStatements.Add(sqlStatement);
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }

            return(storedProcedureDTOs);
        }