public static bool Move(IItemNode nodemove, IItemNode newparent, string newname = null) { if (nodemove.GetRoot.RootType.Email != newparent.GetRoot.RootType.Email || nodemove.GetRoot.RootType.Type != newparent.GetRoot.RootType.Type) { throw new Exception("Cloud not match."); } DropboxRequestAPIv2 client = GetAPIv2(nodemove.GetRoot.RootType.Email); IDropbox_Response_MetaData metadata = client.move( new Dropbox_Request_MoveCopy(nodemove.GetFullPathString(false), newparent.GetFullPathString(false) + "/" + newname == null ? nodemove.Info.Name : newname )); return(newparent.GetFullPathString(false) == metadata.path_display); }
public static IItemNode GetListFileFolder(IItemNode node) { string path = node.GetFullPathString(); node.Childs.Clear(); foreach (string item in Directory.GetDirectories(path)) { DirectoryInfo info = new DirectoryInfo(item); if (CheckAttribute(info.Attributes, FileAttributes.System) | CheckAttribute(info.Attributes, FileAttributes.Offline)) { continue; } IItemNode f = new ItemNode(); f.Info.Name = info.Name; f.Info.Size = -1; f.Info.DateMod = info.LastWriteTime; node.AddChild(f); } foreach (string item in Directory.GetFiles(path)) { FileInfo info = new FileInfo(item); if (CheckAttribute(info.Attributes, FileAttributes.System) | CheckAttribute(info.Attributes, FileAttributes.Offline)) { continue; } IItemNode f = new ItemNode(); f.Info.Name = info.Name; f.Info.Size = info.Length; f.Info.DateMod = info.LastWriteTime; node.AddChild(f); } return(node); }
public static void CreateFolder(IItemNode node) { DirectoryInfo dinfo = new DirectoryInfo(node.GetFullPathString()); if (!dinfo.Exists) { dinfo.Create(); } }
public static IItemNode GetMetaData(IItemNode node) { DropboxRequestAPIv2 client = GetAPIv2(node.GetRoot.RootType.Email); IDropbox_Response_MetaData metadata = client.GetMetadata( new Dropbox_Request_Metadata(string.IsNullOrEmpty(node.Info.ID) ? node.GetFullPathString(false, true) : "id:" + node.Info.ID)); node.Info.Name = metadata.name; node.Info.DateMod = DateTime.Parse(metadata.server_modified); node.Info.Size = metadata.size; return(node); }
public static IItemNode GetFileInfo(IItemNode node) { FileInfo info = new FileInfo(node.GetFullPathString()); if (info.Exists) { node.Info.Size = info.Length; node.Info.DateMod = info.LastWriteTimeUtc; node.Info.permission = info.IsReadOnly ? Permission.Read : Permission.Owner; } return(node); }
void AddFile(IItemNode item, IItemNode fromfolder, IItemNode savefolder, bool AreCut) { TransferItem ud_item = new TransferItem(); ud_item.From.node = item; ud_item.SizeString = UnitConventer.ConvertSize(item.Info.Size, 2, UnitConventer.unit_size); ud_item.status = StatusTransfer.Waiting; //To ud_item.To.node = item.MakeNodeTo(fromfolder, savefolder); ud_item.DataSource.From = item.GetFullPathString(); ud_item.DataSource.To = ud_item.To.node.GetFullPathString(); ud_item.DataSource.Status = ud_item.status.ToString(); ItemsTransfer.ItemsBlinding.Add(ud_item); }
public static bool Delete(IItemNode node, bool PernamentDelete) { DropboxRequestAPIv2 dropbox_client = GetAPIv2(node.GetRoot.RootType.Email); string path = node.GetFullPathString(false); if (PernamentDelete) { dropbox_client.permanently_delete(new Dropbox_path(path)); return(true); } else { IDropbox_Response_MetaData metadata = dropbox_client.delete(new Dropbox_path(path)); return(true); } }
public static Stream GetFileSteam(IItemNode node, bool GetfileForUpload, long Startpos = 0) { string path = node.GetFullPathString(); FileInfo info = new FileInfo(path); FileStream fs; if (GetfileForUpload) { if (!info.Exists) { throw new FileNotFoundException("File not found", path); } if (info.Length == 0) { throw new Exception("File size = 0"); } fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); if (Startpos >= 0) { fs.Seek(Startpos, SeekOrigin.Begin); } return(fs); } else if (!info.Exists) { List <IItemNode> nodelist = node.GetFullPath(); DirectoryInfo dinfo; for (int i = 1; i < nodelist.Count - 1; i++) { dinfo = new DirectoryInfo(nodelist[i].GetFullPathString()); if (!dinfo.Exists) { dinfo.Create(); } } } fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write); if (Startpos >= 0) { fs.Seek(Startpos, SeekOrigin.Begin); } return(fs); }
public static bool Move(IItemNode node, IItemNode newparent, string newname = null) { if (node.GetRoot.RootType.Type != CloudType.LocalDisk && newparent.GetRoot.RootType.Type != CloudType.LocalDisk) { throw new Exception("CloudType is != LocalDisk."); } string path_from = node.GetFullPathString(); string path_to = newparent.GetFullPathString() + "\\" + newname == null ? node.Info.Name : newname; FileInfo info = new FileInfo(path_from); if (info.Exists) { info.MoveTo(path_to); return(true); } DirectoryInfo dinfo = new DirectoryInfo(path_from); if (dinfo.Exists) { dinfo.MoveTo(path_to); return(true); } return(false); }
public static void CreateFolder(IItemNode node) { if (node == node.GetRoot) { throw new Exception("Node is root."); } DropboxRequestAPIv2 client = GetAPIv2(node.GetRoot.RootType.Email); IDropbox_Response_MetaData metadata = client.create_folder(new Dropbox_path(node.GetFullPathString(false))); node.Info.ID = metadata.id; }
public static Stream GetFileStream(IItemNode node, long Startpos = -1, long endpos = -1) { DropboxRequestAPIv2 client = GetAPIv2(node.GetRoot.RootType.Email); return(client.Download(new Dropbox_path(node.GetFullPathString(false)), Startpos, endpos)); }
public static IItemNode GetListFileFolder(IItemNode node) { DropboxRequestAPIv2 client = GetAPIv2(node.GetRoot.RootType.Email); IDropbox_Response_ListFolder response = client.ListFolder(new Dropbox_Request_ListFolder(node.GetFullPathString(false))); node.Childs.Clear(); foreach (IDropbox_Response_MetaData metadata in response.entries) { if (metadata.tag == "folder") { new ItemNode( new NodeInfo() { Name = metadata.name, Size = -1, ID = metadata.id }, node); } } foreach (IDropbox_Response_MetaData metadata in response.entries) { if (metadata.tag == "file") { new ItemNode( new NodeInfo() { Name = metadata.name, Size = metadata.size, ID = metadata.id, DateMod = DateTime.Parse(metadata.client_modified) }, node); } } return(node); }