Example #1
0
        public IDataModel SaveModel(String source, String command, ExpandoObject data, Object prms = null)
        {
            var dataReader = new DataModelReader(_localizer);
            var dataWriter = new DataModelWriter();

            using var token = _profiler.Start(command);
            var metadataCommand = command.Update2Metadata();

            using var cnn = GetConnection(source);
            using (var cmd = cnn.CreateCommandSP(metadataCommand, CommandTimeout))
            {
                using var rdr = cmd.ExecuteReader();
                do
                {
                    dataWriter.ProcessOneMetadata(rdr);
                }while (rdr.NextResult());
            }
            using (var cmd = cnn.CreateCommandSP(command, CommandTimeout))
            {
                SqlCommandBuilder.DeriveParameters(cmd);
                dataWriter.SetTableParameters(cmd, data, prms);
                using var rdr = cmd.ExecuteReader();
                do
                {
                    // metadata is not needed (exclude aliases)
                    dataReader.ProcessMetadataAliases(rdr);
                    while (rdr.Read())
                    {
                        dataReader.ProcessOneRecord(rdr);
                    }
                }while (rdr.NextResult());
            }
            dataReader.PostProcess();
            return(dataReader.DataModel);
        }
        public async Task <IDataModel> SaveModelAsync(String source, String command, System.Object data, System.Object prms = null, Func <ITableDescription, Object> onSetData = null)
        {
            var dataReader = new DataModelReader(_localizer);
            var dataWriter = new DataModelWriter();

            using (var p = _profiler.Start(command))
            {
                var metadataCommand = command.Update2Metadata();
                using (var cnn = await GetConnectionAsync(source))
                {
                    using (var cmd = cnn.CreateCommandSP(metadataCommand))
                    {
                        using (var rdr = await cmd.ExecuteReaderAsync())
                        {
                            do
                            {
                                dataWriter.ProcessOneMetadata(rdr);
                            }while (await rdr.NextResultAsync());
                        }
                    }
                    if (onSetData != null)
                    {
                        data = onSetData(dataWriter.GetTableDescription());
                    }
                    using (var cmd = cnn.CreateCommandSP(command))
                    {
                        SqlCommandBuilder.DeriveParameters(cmd);
                        dataWriter.SetTableParameters(cmd, data, prms);
                        using (var rdr = await cmd.ExecuteReaderAsync())
                        {
                            do
                            {
                                // metadata is not needed (exclude aliases)
                                dataReader.ProcessMetadataAliases(rdr);
                                while (await rdr.ReadAsync())
                                {
                                    dataReader.ProcessOneRecord(rdr);
                                }
                            }while (await rdr.NextResultAsync());
                        }
                    }
                }
                dataReader.PostProcess();
                return(dataReader.DataModel);
            }
        }
Example #3
0
        public IDataModel LoadModel(String source, String command, System.Object prms = null)
        {
            var modelReader = new DataModelReader(_localizer);

            source          = ResolveSource(source, prms);
            using var token = _profiler.Start(command);
            ReadData(source, command,
                     (prm) =>
            {
                modelReader.SetParameters(prm, prms);
            },
                     (no, rdr) =>
            {
                modelReader.ProcessOneRecord(rdr);
            },
                     (no, rdr) =>
            {
                modelReader.ProcessOneMetadata(rdr);
            });
            modelReader.PostProcess();
            return(modelReader.DataModel);
        }
        public async Task <IDataModel> LoadModelAsync(String source, String command, System.Object prms = null)
        {
            var modelReader = new DataModelReader(_localizer);

            using (var p = _profiler.Start(command))
            {
                await ReadDataAsync(source, command,
                                    (prm) =>
                {
                    modelReader.SetParameters(prm, prms);
                },
                                    (no, rdr) =>
                {
                    modelReader.ProcessOneRecord(rdr);
                },
                                    (no, rdr) =>
                {
                    modelReader.ProcessOneMetadata(rdr);
                });
            }
            modelReader.PostProcess();
            return(modelReader.DataModel);
        }