Example #1
0
 public void CopyTo(IDataFile destFile, long size)
 {
     transaction.CheckValid();
     if (destFile is DbFile)
     {
         DbFile targetFile = (DbFile)destFile;
         parent.CopyTo(targetFile.parent, size);
         targetFile.LogChange();
     }
     else
     {
         parent.CopyTo(destFile, size);
     }
 }
Example #2
0
 public void CopyTo(IDataFile destFile, long size)
 {
     df.CopyTo(destFile, size);
 }
        public void EnumeratorCheck()
        {
            IDataFile        df1         = Transaction.GetFile(new Key(1, 0, 5), FileAccess.ReadWrite);
            IDataFile        df2         = Transaction.GetFile(new Key(2, 0, 5), FileAccess.ReadWrite);
            BinaryCollection collection1 = new BinaryCollection(df1);

            Random rnd = new Random(5);

            // Add some data,
            byte[] buf = new byte[300];
            {
                for (int i = 0; i < 100; ++i)
                {
                    ByteBuffer.WriteInt8(i, buf, 0);
                    ByteBuffer.WriteInt8((10 - i), buf, 8);
                    // Add random sized records
                    collection1.Add(new Binary(buf, 0, 16 + rnd.Next(284)));
                }
            }

            // Copy the data from df1,
            df1.CopyTo(df2, df1.Length);
            BinaryCollection collection2 = new BinaryCollection(df2);

            // Basic iterate over the set,
            {
                IEnumerator <Binary> i = collection1.GetEnumerator();
                long ci = 0;
                while (i.MoveNext())
                {
                    Binary       barr = i.Current;
                    BinaryReader din  = new BinaryReader(barr.GetInputStream());
                    long         inI  = din.ReadInt64();
                    Assert.AreEqual(inI, ci);
                    ++ci;
                }
            }

            {
                IInteractiveEnumerator <Binary> i;
                // Iterate over the set and remove index 1, 3, 5, 7, etc
                i = (IInteractiveEnumerator <Binary>)collection1.GetEnumerator();
                long ci = 0;
                while (i.MoveNext())
                {
                    if ((ci % 2) == 1)
                    {
                        i.Remove();
                    }
                    ++ci;
                }
                // And check,
                i  = (IInteractiveEnumerator <Binary>)collection1.GetEnumerator();
                ci = 0;
                while (i.MoveNext())
                {
                    Binary       barr = i.Current;
                    BinaryReader din  = new BinaryReader(barr.GetInputStream());
                    long         inI  = din.ReadInt64();
                    Assert.AreEqual(inI, ci);
                    ci += 2;
                }
            }

            // Operations on set_2 (the copy)
            {
                IInteractiveEnumerator <Binary> i;
                // Iterate over the set and remove index 0, 2, 4, 6, etc
                i = (IInteractiveEnumerator <Binary>)collection2.GetEnumerator();
                long ci = 0;
                while (i.MoveNext())
                {
                    if ((ci % 2) == 0)
                    {
                        i.Remove();
                    }
                    ++ci;
                }
                // And check,
                i  = (IInteractiveEnumerator <Binary>)collection2.GetEnumerator();
                ci = 1;
                while (i.MoveNext())
                {
                    Binary       barr = i.Current;
                    BinaryReader din  = new BinaryReader(barr.GetInputStream());
                    long         inI  = din.ReadInt64();
                    Assert.AreEqual(inI, ci);
                    ci += 2;
                }
            }
        }