private BulkObject Peek()
        {
            if (!_passedFirstRow)
            {
                var firstRowObject = _bulkObjectReader.ReadNextBulkObject();

                var formatVersion = firstRowObject as FormatVersion;

                if (formatVersion != null)
                {
                    if (formatVersion.Value != "3" && formatVersion.Value != "3.0")
                    {
                        throw new InvalidOperationException(ErrorMessages.FormatVersionIsNotSupported + formatVersion.Value);
                    }
                }
                else
                {
                    _nextObject = firstRowObject;
                }

                _passedFirstRow = true;
            }

            if (_nextObject != null)
            {
                return(_nextObject);
            }

            return(_nextObject = _bulkObjectReader.ReadNextBulkObject());
        }
Пример #2
0
        public void WriteObjectRow(BulkObject bulkObject)
        {
            var values = new RowValues();

            bulkObject.WriteToRowValues(values);

            values[StringTable.Type] = _bulkObjectFactory.GetBulkRowType(bulkObject);

            _streamWriter.WriteLine(_formatter.FormatCsvRow(values.Columns));
        }
Пример #3
0
        public string GetBulkRowType(BulkObject bulkObject)
        {
            if (bulkObject is BulkTargetIdentifier)
            {
                var identifier = (BulkTargetIdentifier)bulkObject;

                return(TargetIdentifierTypeReverseMap[identifier.GetType()][identifier.TargetBidType]);
            }

            return(TypeReverseMap[bulkObject.GetType()]);
        }
Пример #4
0
        /// <summary>
        /// Reads the object only if it matches a predicate
        /// </summary>
        /// <typeparam name="T">Type of the object</typeparam>
        /// <param name="predicate">Predicate that needs to be matched</param>
        /// <param name="result">The next object from the file if the object matches the predicate, null otherwise</param>
        /// <returns>True is object matches the predicate, false otherwise</returns>
        public bool TryRead <T>(Predicate <T> predicate, out T result)
            where T : BulkObject
        {
            var peeked = Peek();

            var instanceOfT = peeked as T;

            if (instanceOfT != null && predicate(instanceOfT))
            {
                _nextObject = null;

                instanceOfT.ReadRelatedDataFromStream(this);

                result = instanceOfT;

                return(true);
            }

            result = null;

            return(false);
        }
        public string GetBulkRowType(BulkObject bulkObject)
        {
            if (bulkObject is BulkTargetIdentifier)
            {
                var identifier = (BulkTargetIdentifier)bulkObject;

                return TargetIdentifierTypeReverseMap[identifier.GetType()][identifier.TargetBidType];
            }

            return TypeReverseMap[bulkObject.GetType()];
        }
Пример #6
0
 public void WriteObjectRow(BulkObject bulkObject)
 {
     WriteObjectRow(bulkObject, false);
 }
 public void WriteObjectRow(BulkObject bulkObject)
 {
     WriteObjectRow(bulkObject, false);
 }
        public void WriteObjectRow(BulkObject bulkObject, bool excludeReadonlyData)
        {            
            var values = new RowValues();

            bulkObject.WriteToRowValues(values, excludeReadonlyData);

            values[StringTable.Type] = _bulkObjectFactory.GetBulkRowType(bulkObject);

            _streamWriter.WriteLine(_formatter.FormatCsvRow(values.Columns));
        }