Пример #1
0
        /// <summary>
        /// Add a new atom to the collection, with name check
        /// </summary>
        /// <param name="atom">The atom to add</param>
        public void AddAtom(AtomData atom)
        {
            if (atom == null)
            {
                throw new ArgumentNullException("atom");
            }

            // Check mixed mode
            if (_atoms.Count == 0)
            {
                // First atom => decide named or unnamed
                _useNames = atom.IsNamed;
            }
            else
            {
                // Check named or unnamed atom vs. current behavior
                if (_useNames != atom.IsNamed)
                {
                    throw new Exception("Mixed mode atoms not allowed in collection");
                }

                // Check atom name if any
                if (_useNames && (this[atom.Name] != null))
                {
                    throw new Exception(
                              $"Atom named '{atom.Name}' already exists in collection");
                }
            }

            _atoms.Add(atom);
        }
Пример #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);
        }