Exemplo n.º 1
0
        public IFile OpenFile([NotNull] string fileName, bool canWrite)
        {
            Validate.ArgumentNotNull(fileName, "fileName");

            CheckDisposed();

            var vfn = new VirtualFileName(fileName);

            VirtualFile ret;
            // no using clause, since file must remain locked.
            var result = FindNode(vfn, false, canWrite);
            try
            {
                var currentNode = result.File;
                if (currentNode == null)
                {
                    throw new FileNotFoundException("File not found.", fileName);
                }

                ret = new VirtualFile(currentNode, canWrite);
            }
            catch
            {
                result.Dispose();
                throw;
            }

            return ret;
        }
        /// <summary>
        ///         adds a new file to this directory.
        /// </summary>
        /// <param name="fileName">the name of the file to be created.</param>
        /// <returns>the created file.</returns>
        public VirtualFile AddFile(string fileName)
        {
            if (!ValidName(fileName))
                        {
                                throw new ArgumentException("fileName invalid");
                        }

                        if (ReadAllItems().Any(item => item.Name.Equals(fileName)))
                        {
                                throw new ItemNameInUseException(fileName);
                        }

                        var newFile = new VirtualFile(CreateNewFile(), fileName, this, ContainerFile);
                        AddItem(newFile);

                        return newFile;
        }
Exemplo n.º 3
0
        public IFile CreateFile([NotNull] string fileName)
        {
            Validate.ArgumentNotNull(fileName, "fileName");

            CheckDisposed();

            var vfn = new VirtualFileName(fileName);

            VirtualFile ret;
            using (var result = FindNode(vfn, true, true))
            {
                var parentNode = result.Directory;
                if (parentNode == null)
                {
                    throw new DirectoryNotFoundException("Specified path does not reference a directory.");
                }

                var node = _record.CreateFileNode(vfn.Name, parentNode);
                node.LockWrite();
                ret = new VirtualFile(node, true);
            }
            return ret;
        }