コード例 #1
0
        public long TryAppend(byte[] buffer, TapeAppendCondition appendCondition = new TapeAppendCondition())
        {
            if (buffer == null)
                throw new ArgumentNullException("buffer");

            if (buffer.Length == 0)
                throw new ArgumentException("Buffer must contain at least one byte.");

            try
            {
                var result = _dictionary.AddOrUpdate(_name, s =>
                {
                    appendCondition.Enforce(0);
                    var records = new List<TapeRecord>();
                    records.Add(new TapeRecord(1, buffer));
                    return records;
                }, (s, list) =>
                {
                    appendCondition.Enforce(list.Count);
                    return list.Concat(new[] {new TapeRecord(list.Count + 1, buffer)}).ToList();
                });

                return result.Count;
            }
            catch (TapeAppendConditionException e)
            {
                return 0;
            }
        }