Example #1
0
 public void ReplicateTo(IDataFile destFile)
 {
     transaction.CheckValid();
     if (destFile is DbFile)
     {
         DbFile targetFile = (DbFile)destFile;
         parent.ReplicateTo(targetFile.parent);
         targetFile.LogChange();
     }
     else
     {
         parent.ReplicateTo(destFile);
     }
 }
Example #2
0
        public void CopyTo(String name, Directory destination)
        {
            ++destination.directoryVersion;

            StringDictionary pset = new StringDictionary(GetDataFile(propertySetKey));
            long             id   = pset.GetValue <long>(name, -1);

            // Assert the item is stored,
            if (id == -1)
            {
                throw new ApplicationException("Item not found: " + name);
            }

            // Get the source data file item,
            Key       sourceK  = GetItemKey(id);
            IDataFile sourceDf = GetDataFile(sourceK);

            // Get the item from the destination. Throw an error if the item not
            // already found in the destination file set.
            Key destK = destination.GetItem(name);

            if (destK == null)
            {
                throw new ApplicationException("Item not in destination: " + name);
            }

            IDataFile destinationDf = destination.GetDataFile(destK);

            // Copy the data,
            sourceDf.ReplicateTo(destinationDf);
        }
Example #3
0
 private static void CopyFile(IDataFile s, IDataFile d)
 {
     //    d.Delete();
     //    s.Position = 0;
     //    d.Position = 0;
     //    s.CopyTo(d, s.Length);
     s.ReplicateTo(d);
 }
Example #4
0
            public void ReplicateTo(IDataFile destFile)
            {
                // This is a little complex. If 'destFile' is an instance of SubDataFile
                // we use the raw 'ReplicateTo' method on the data files and preserve
                // the header on the target by making a copy of it before the replicateTo
                // function.
                // Otherwise, we use a 'CopyTo' implementation.

                // If replicating to a SubDataFile
                if (destFile is SubDataFile)
                {
                    // Preserve the header of the target
                    SubDataFile targetFile = (SubDataFile)destFile;
                    long        headerSize = targetFile.start;
                    if (headerSize <= 8192)
                    {
                        IDataFile targetDf = targetFile.df;
                        // Make a copy of the header in the target,
                        int    iheadSize = (int)headerSize;
                        byte[] header    = new byte[iheadSize];
                        targetDf.Position = 0;
                        targetDf.Read(header, 0, iheadSize);

                        // Replicate the bases
                        df.ReplicateTo(targetDf);
                        // Now 'target_df' will be a replica of this, so we need to copy
                        // the previous header back on the target.
                        // Remove the replicated header on the target and copy the old one
                        // back.
                        targetDf.Position = start;
                        targetDf.Shift(iheadSize - start);
                        targetDf.Position = 0;
                        targetDf.Write(header, 0, iheadSize);
                        // Set position per spec
                        targetDf.Position = targetDf.Length;
                        // Done.
                        return;
                    }
                }

                // Fall back to a copy-to implementation
                destFile.Delete();
                destFile.Position = 0;
                df.Position       = start;
                df.CopyTo(destFile, df.Length - start);
            }
Example #5
0
            public void ReplicateTo(IDataRange target)
            {
                if (target is DataRange)
                {
                    // If the tree systems are different we fall back
                    DataRange tTarget = (DataRange)target;
                    if (TreeSystem == tTarget.TreeSystem)
                    {
                        // Fail condition (same transaction),
                        if (tTarget.Transaction == Transaction)
                        {
                            throw new ArgumentException("'ReplicateTo' on the same transaction");
                        }

                        // Ok, different transaction, same tree system source, both
                        // TranDataRange objects, so we can do an efficient tree copy.

                        // TODO:
                    }
                }

                // The fallback method,
                // This uses the standard API to replicate all the keys in the target
                // range.
                // Note that if the target can't contain the keys because they fall
                //  outside of its bound then the exception comes from the target.
                target.Delete();
                long sz  = Count;
                long pos = 0;

                while (pos < sz)
                {
                    MoveTo(pos);
                    Key       key      = CurrentKey;
                    IDataFile df       = GetCurrentFile(FileAccess.Read);
                    IDataFile targetDf = target.GetFile(key, FileAccess.Write);
                    df.ReplicateTo(targetDf);
                    pos = MoveToNextKey();
                }
            }