Beispiel #1
0
        public FileUploadResult UploadCloudFile(string filePath, string destinationDirectoryId)
        {
            FileUploadResult result = new FileUploadResult();
            FileInfo         info   = new FileInfo(filePath);

            FileBlock file = new FileBlock()
            {
                id     = "",
                Parent = new List <string> {
                    destinationDirectoryId
                },
                path     = filePath,
                mimeType = GetMimeType(info),
            };

            cloudService.UploadCloudFile(file);
            result.status = true;
            return(result);
        }
Beispiel #2
0
 public void Traverse()
 {
     if (queue.Count == 0)
     {
         return;
     }
     while (queue.Count > 0)
     {
         DirectoryBlock          currentDirectory     = queue.Dequeue();
         System.IO.DirectoryInfo currentDirectoryInfo = new DirectoryInfo(currentDirectory.path);
         FileSystemInfo[]        files = currentDirectoryInfo.GetFileSystemInfos();
         List <Task>             tasks = new List <Task>();
         foreach (var file in files)
         {
             if (file.GetType() == typeof(System.IO.DirectoryInfo))
             {
                 string         DirectoryId = cloudService.CreateDirectory(destinationDirectoryId, file.Name);
                 DirectoryBlock directory   = new DirectoryBlock()
                 {
                     id   = DirectoryId,
                     Name = file.Name,
                     path = file.FullName,
                 };
                 queue.Enqueue(directory);
             }
             if (file.GetType() == typeof(System.IO.FileInfo))
             {
                 FileBlock newFile = new FileBlock()
                 {
                     Name   = file.Name,
                     Parent = new List <string> {
                         currentDirectory.id
                     }
                 };
                 cloudService.UploadCloudFile(newFile, file.FullName);
             }
         }
         Task.WaitAll(tasks.ToArray());
         Traverse();
     }
 }