Exemplo n.º 1
0
        public void Delete(string origin, string route, IEnumerable <KeyValuePair <string, string> > nameValuePairs)
        {
            FileSystemObject obj = Query(origin, route, nameValuePairs);

            if (!obj.Exists)
            {
                return;
            }

            if (obj is FileObject)
            {
                File.Delete(obj.GetPhysicalPath());
            }
            else if (obj is DirectoryObject)
            {
                if ((obj as DirectoryObject).IsDrive)
                {
                    throw new InvalidOperationException("Drive is not allowed to delete.");
                }

                //
                string recursive = nameValuePairs.GetValue("recursive");
                Directory.Delete(obj.GetPhysicalPath(), recursive == "true" || recursive == "True");
            }
        }
Exemplo n.º 2
0
        // if the directory does not exist, create it.
        private void Update(FileSystemObject obj, IEnumerable <KeyValuePair <string, string> > nameValuePairs)
        {
            if (!obj.Exists)
            {
                if (obj is DirectoryObject)
                {
                    // Create Directory
                    DirectoryInfo info = new DirectoryInfo(obj.GetPhysicalPath());
                    info.Create();
                    SetFileSystemInfo(info, nameValuePairs);
                }
            }

            if (obj is FileObject)
            {
                FileInfo info = new FileInfo(obj.GetPhysicalPath());
                SetFileInfo(info, nameValuePairs);
            }
            else if (obj is DirectoryObject)
            {
                if ((obj as DirectoryObject).IsDrive)
                {
                    throw new InvalidOperationException("Drive is not allowed to update.");
                }

                DirectoryInfo info = new DirectoryInfo(obj.GetPhysicalPath());
                SetDirectoryInfo(info, nameValuePairs);
            }
        }
Exemplo n.º 3
0
        private void MoveTo(FileSystemObject obj, string destPath)
        {
            if (!obj.Exists)
            {
                if (obj is DirectoryObject)
                {
                    throw new DirectoryNotFoundException(string.Format("Source directory: {0} was not found.", obj.Path));
                }
                else
                {
                    Debug.Assert(obj is FileObject);

                    throw new FileNotFoundException(string.Format("Source file: {0} was not found.", obj.Path));
                }
            }

            //
            string destPhysicalPath = DriveObject.Drives.GetDirectory(obj.Route);

            destPhysicalPath += destPath.Replace('/', System.IO.Path.DirectorySeparatorChar);

            if (obj is DirectoryObject)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(obj.GetPhysicalPath());
                dirInfo.MoveTo(destPhysicalPath);
            }
            else
            {
                Debug.Assert(obj is FileObject);

                string directory = Path.GetDirectoryName(destPhysicalPath);
                Directory.CreateDirectory(directory);

                FileInfo fileInfo = new FileInfo(obj.GetPhysicalPath());
                fileInfo.MoveTo(destPhysicalPath);
            }
        }
Exemplo n.º 4
0
        private void CopyTo(FileSystemObject obj, string destPath, bool overwrite)
        {
            if (obj is DirectoryObject)
            {
                throw new ArgumentException(string.Format("Source file: {0} specifies a directory.", obj.Path));
            }
            if (!obj.Exists)
            {
                throw new FileNotFoundException(string.Format("Source file: {0} was not found.", obj.Path));
            }

            string destPhysicalPath = DriveObject.Drives.GetDirectory(obj.Route);

            destPhysicalPath += destPath.Replace('/', System.IO.Path.DirectorySeparatorChar);

            string directory = Path.GetDirectoryName(destPhysicalPath);

            Directory.CreateDirectory(directory);

            FileInfo fileInfo = new FileInfo(obj.GetPhysicalPath());

            fileInfo.CopyTo(destPhysicalPath, overwrite);
        }