Exemplo n.º 1
0
        /// <summary>
        /// Execute the underlying stored procedure and returns a result.
        /// </summary>
        /// <param name="arguments">The arguments to execute the stored procedure</param>
        /// <returns>The data resulting from the stored procedure</returns>
        public RowSetCollectionData Execute(AtomCollectionData arguments)
        {
            if (Database == null)
            {
                throw new InvalidOperationException("Missing database connection");
            }
            if (OperationName == null)
            {
                throw new InvalidOperationException("Missing operation name");
            }
            if (MetadataBuilder == null)
            {
                throw new InvalidOperationException("Missing metadata builder");
            }

            Database.Open();
            using (var cmd = Database.CreateCommand())
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = OperationName;
                SetupArguments(cmd, arguments);

                var result = new RowSetCollectionData();
                using (var reader = cmd.ExecuteReader())
                {
                    return(ProcessData(reader));
                }
            }
        }
Exemplo n.º 2
0
        private RowSetCollectionData ProcessData(IDataReader reader)
        {
            var result = new RowSetCollectionData();

            do
            {
                MetadataBuilder.Build(reader);
                var rowset = new RowSetData();
                while (reader.Read())
                {
                    var row     = new AtomCollectionData();
                    var columns = MetadataBuilder.Columns.OrderBy(c => c.Ordinal);
                    foreach (var column in columns)
                    {
                        try
                        {
                            var atom = new AtomData();
                            atom.Name  = column.Name;
                            atom.Value = reader.GetValue(column.Ordinal);
                            row.AddAtom(atom);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception($"Error reading column {column.Ordinal} ({column.Name})", ex);
                        }
                    }
                    rowset.AddRow(row);
                }
                result.AddRowSet(rowset);
            }while (reader.NextResult());
            return(result);
        }
Exemplo n.º 3
0
        private RowSetCollectionData InternalProcess(AtomCollectionData arguments)
        {
            var setup            = new WebApplicationSetup();
            var dbFactory        = new SoftTypedDbFactory(setup);
            var operationHandler = new DbStoredProcedureHandler();

            operationHandler.MetadataBuilder = new MetadataBuilder();
            operationHandler.OperationName   = GetOperationName();

            using (var db = dbFactory.GetConnection("db"))
            {
                operationHandler.Database = db;
                return(operationHandler.Execute(arguments));
            }
        }
Exemplo n.º 4
0
 private void SetupArguments(IDbCommand cmd, AtomCollectionData arguments)
 {
     foreach (var argument in arguments.Atoms)
     {
         try
         {
             var sqlParameter = cmd.CreateParameter();
             sqlParameter.ParameterName = argument.Name;
             sqlParameter.Value         = argument.Value;
             cmd.Parameters.Add(sqlParameter);
         }
         catch (Exception ex)
         {
             throw new Exception($"Error setting parameter '{argument.Name}'", ex);
         }
     }
 }
Exemplo n.º 5
0
 public ParseContext(IValueSource additionalInfo)
 {
     _additionalInfo = additionalInfo;
     _result         = new AtomCollectionData();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Add a new row to the row set.
 /// </summary>
 /// <param name="row">The row to add</param>
 public void AddRow(AtomCollectionData row)
 {
     _rows.Add(row);
 }