Exemplo n.º 1
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);
        }
Exemplo n.º 2
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.º 3
0
        public void Put(string origin, string route, IEnumerable <KeyValuePair <string, string> > nameValuePairs)
        {
            FileSystemObject obj    = Query(origin, route, nameValuePairs);
            string           copyto = nameValuePairs.GetValue("copyto");

            if (!string.IsNullOrWhiteSpace(copyto))
            {
                string overwrite = nameValuePairs.GetValue("overwrite");
                CopyTo(obj, copyto, overwrite == "true" || overwrite == "True");
                return;
            }

            //
            string moveto = nameValuePairs.GetValue("moveto");

            if (!string.IsNullOrWhiteSpace(moveto))
            {
                MoveTo(obj, moveto);
                return;
            }

            //
            Update(obj, nameValuePairs);
        }