public INode Create(string path, Type defaultType, StreamOptions flags)
 {
     return(root.CreateChild(path, defaultType, flags));
 }
Esempio n. 2
0
        public INode CopyTo([NotNull] INode n)
        {
            lock (SyncRoot)
            {
                AssertNotDisposed();

                // Must ensure from the same db and other checks.
                ManagedNode dest = n as ManagedNode;


                // We check if we are not moving to child of our node.
                string pathTo   = dest.Path;
                string pathFrom = Path;

                if (pathTo.Length > pathFrom.Length && pathTo.Substring(0, pathFrom.Length) == pathFrom)
                {
                    throw new InvalidOperationException(string.Format("Moving from path {0} to " +
                                                                      "path {1} which is a child of path {0}", pathFrom, pathTo));
                }

                // We create it with default type.
                INode myCopy;
                using (ITypedStream defaultTS = OpenDefaultStream(OpenMode.Read))
                {
                    myCopy = dest.CreateChild(Name, defaultTS.StreamType, defaultTS.Flags);

                    // Copy data.
                    using (ITypedStream defaultCopyTS = myCopy.OpenDefaultStream(OpenMode.Write))
                    {
                        defaultTS.CopyTo(defaultCopyTS);
                    }
                }

                // All typed streams.
                foreach (Type t in TypedStreams)
                {
                    // Default type already handled.
                    if (t == DefaultType)
                    {
                        continue;
                    }

                    using (ITypedStream ts = GetTypedStream(OpenMode.Read, t))
                    {
                        // Copy data.
                        myCopy.AddTypedStream(ts.StreamType, ts.Flags);

                        using (ITypedStream tsCopy = myCopy.GetTypedStream(OpenMode.Write, ts.StreamType))
                        {
                            ts.CopyTo(tsCopy);
                        }
                    }
                }


                // And all children at last.
                foreach (string s in Children)
                {
                    INode child = this.Find(s);
                    child.CopyTo(myCopy);
                }

                return(myCopy);
            }
        }