예제 #1
0
        public void DownloadFile(string FilePath, string DirectoryPath)
        {
            FilePath = DropManager.ConvertToDrpPath(FilePath);

            if (System.IO.Directory.Exists(DirectoryPath))
            {
                MetaData metaData = null;
                try
                {
                    metaData = Client.GetMetaData(FilePath, null, false, false);
                }
                catch
                {
                    throw new Exception("File not found (cloud)");
                }
                if (!metaData.Is_Dir)
                {
                    byte[] FileBytes = Client.GetFile(FilePath);
                    System.IO.File.WriteAllBytes(DirectoryPath + metaData.Name, FileBytes);
                }
                else
                {
                    throw new Exception("Cannot download a directory");
                }
            }
            else
            {
                throw new Exception("Directory not found (local)");
            }
        }
예제 #2
0
        public float GetFileSizeInMB(string FilePath)
        {
            FilePath = DropManager.ConvertToDrpPath(FilePath);
            MetaData metaData = null;

            try
            {
                metaData = Client.GetMetaData(FilePath, null, false, false);
            }
            catch
            {
                throw new Exception("File not found (cloud)");
            }
            if (!metaData.Is_Dir)
            {
                if (metaData.Size.Contains("KB"))
                {
                    return(float.Parse(metaData.Size.Remove(metaData.Size.Length - 3)) / 1024);
                }
                else
                {
                    return(float.Parse(metaData.Size.Remove(metaData.Size.Length - 3)));
                }
            }
            else
            {
                throw new Exception("Cannot return size for a folder");
            }
        }
예제 #3
0
        public void UploadFile(string FilePath, string dirPath)
        {
            dirPath = DropManager.ConvertToDrpPath(dirPath);

            if (System.IO.File.Exists(FilePath))
            {
                MetaData metaData = null;
                try
                {
                    metaData = Client.GetMetaData(dirPath, null, false, false);
                }
                catch
                {
                    throw new Exception("Directory not found (cloud)");
                }
                if (metaData.Is_Dir)
                {
                    byte[] FileBytes = System.IO.File.ReadAllBytes(FilePath);
                    Client.UploadFile(dirPath, System.IO.Path.GetFileName(FilePath), FileBytes);
                }
                else
                {
                    throw new Exception("Directory is not a folder (cloud)");
                }
            }
            else
            {
                throw new Exception("File not found (local)");
            }
        }
예제 #4
0
        public string GetFilesList(string directory)
        {
            directory = DropManager.ConvertToDrpPath(directory);

            MetaData metaData = null;

            try
            {
                metaData = Client.GetMetaData(directory, null, false, false);
            }
            catch
            {
                throw new Exception("Directory not found (cloud)");
            }
            StringBuilder sb = new StringBuilder();

            if (metaData.Is_Dir)
            {
                if (metaData.Contents.Count > 0)
                {
                    foreach (MetaData md in metaData.Contents)
                    {
                        if (md.Is_Dir)
                        {
                            sb.AppendLine("-> " + md.Name);
                        }
                        else
                        {
                            sb.AppendLine(md.Name);
                        }
                    }
                }
                else
                {
                    sb.AppendLine("Directory is Empty");
                }
            }
            else
            {
                throw new Exception("Given path is not a directory (cloud)");
            }


            return(sb.ToString());
        }
예제 #5
0
        public void CreateDirectory(string title, string dirPath)
        {
            dirPath = DropManager.ConvertToDrpPath(dirPath);
            MetaData metaData = null;

            try
            {
                metaData = Client.GetMetaData(dirPath, null, false, false);
            }
            catch
            {
                throw new Exception("Directory not found (cloud)");
            }
            if (!dirPath.ElementAt(dirPath.Length - 1).Equals('/'))
            {
                dirPath = dirPath + "/";
            }
            dirPath = dirPath + title;
            Client.CreateFolder(dirPath);
        }
예제 #6
0
        public void DeleteFile(string FilePath)
        {
            FilePath = DropManager.ConvertToDrpPath(FilePath);

            MetaData metaData = null;

            try
            {
                metaData = Client.GetMetaData(FilePath, null, false, false);
            }
            catch
            {
                throw new Exception("File not found (cloud)");
            }
            if (metaData.Is_Dir)
            {
                throw new Exception("Cannot currently delete a folder");
            }
            Client.Delete(FilePath);
        }