예제 #1
0
        private ProcedureModel GetStoredProcedures(string dacpacPath, ProcedureModelFactoryOptions options)
        {
            var result = new List <RevEng.Core.Abstractions.Metadata.Procedure>();
            var errors = new List <string>();

            if (options.FullModel && !options.Procedures.Any())
            {
                return(new ProcedureModel
                {
                    Procedures = result,
                    Errors = errors,
                });
            }

            var consolidator = new DacpacConsolidator();

            dacpacPath = consolidator.Consolidate(dacpacPath);

            var model = new TSqlTypedModel(dacpacPath);

            var procedures = model.GetObjects <TSqlProcedure>(DacQueryScopes.UserDefined)
                             .ToList();

            var filter = new HashSet <string>(options.Procedures);

            foreach (var proc in procedures)
            {
                var procedure = new RevEng.Core.Abstractions.Metadata.Procedure
                {
                    Schema = proc.Name.Parts[0],
                    Name   = proc.Name.Parts[1],
                };

                if (filter.Count == 0 || filter.Contains($"[{procedure.Schema}].[{procedure.Name}]"))
                {
                    if (options.FullModel)
                    {
                        procedure.Parameters = GetStoredProcedureParameters(proc);

                        try
                        {
                            procedure.ResultElements = GetStoredProcedureResultElements(proc);
                        }
                        catch (Exception ex)
                        {
                            errors.Add($"Unable to get result set shape for {procedure.Schema}.{procedure.Name}" + Environment.NewLine + ex.Message);
                            _logger?.Logger.LogWarning(ex, $"Unable to get result set shape for {procedure.Schema}.{procedure.Name}" + Environment.NewLine + ex.Message);
                        }
                    }

                    result.Add(procedure);
                }
            }

            return(new ProcedureModel
            {
                Procedures = result,
                Errors = errors,
            });
        }
        private static RoutineModel GetStoredProcedures(string dacpacPath, ModuleModelFactoryOptions options, bool mergeDacpacs)
        {
            var result = new List <RevEng.Core.Abstractions.Metadata.Procedure>();
            var errors = new List <string>();

            if (mergeDacpacs && dacpacPath != null)
            {
                var consolidator = new DacpacConsolidator();
                dacpacPath = consolidator.Consolidate(dacpacPath);
            }

            using var model = new TSqlTypedModel(dacpacPath);

            var procedures = model.GetObjects <TSqlProcedure>(DacQueryScopes.UserDefined)
                             .ToList();

            var filter = new HashSet <string>(options.Modules);

            foreach (var proc in procedures)
            {
                var procedure = new RevEng.Core.Abstractions.Metadata.Procedure
                {
                    Schema = proc.Name.Parts[0],
                    Name   = proc.Name.Parts[1],
                };

                var key = $"[{procedure.Schema}].[{procedure.Name}]";

                if (filter.Count == 0 || filter.Contains(key))
                {
                    if (options.FullModel)
                    {
                        procedure.Parameters = GetStoredProcedureParameters(proc);

                        if (options.MappedModules?.ContainsKey(key) ?? false)
                        {
                            procedure.MappedType = options.MappedModules[key];
                        }

#pragma warning disable CA1031 // Do not catch general exception types
                        try
                        {
                            procedure.Results.Add(GetStoredProcedureResultElements(proc));
                        }
                        catch (Exception ex)
                        {
                            errors.Add($"Unable to get result set shape for {procedure.Schema}.{procedure.Name}" + Environment.NewLine + ex.ToString());
                        }
#pragma warning restore CA1031 // Do not catch general exception types
                    }

                    result.Add(procedure);
                }
            }

            return(new RoutineModel
            {
                Routines = result.Cast <Routine>().ToList(),
                Errors = errors,
            });
        }