コード例 #1
0
 public Boolean abortDownload(String filePath)
 {
     lock (pendingUploads)
     {
         foreach (String key in pendingUploads.Keys)
         {
             UPLOAD_INFO u = pendingUploads[key];
             if (u.path.Equals(filePath))
             {
                 pendingUploads.Remove(key);
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #2
0
 public void upload(UPLOAD_INFO f, string localpath)
 {
     fileMgr.upload(f, localpath);
 }
コード例 #3
0
        public string getDownloadKey(UPLOAD_INFO f)
        {
            string key;

            lock (pendingUploads)
            {
                while (true)
                {
                    string random1 = Path.GetRandomFileName().Substring(0, 8);
                    string random2 = Path.GetRandomFileName().Substring(0, 8);
                    key = random1 + random2;
                    try
                    {
                        //ADD TIMEOUT NOT SUPPORTED
                        pendingUploads.Add(key, f);
                        break;
                    } catch (ArgumentException) { /* keep trying */ }
                }
            }
            String containerName, blobName, containerAzureName;

            String[] arr = f.path.Split(':');
            containerName = arr[0];
            blobName      = arr[1];

            if (containerName.Equals(f.username))
            {
                containerAzureName = azureLink.findUserId(f.username).ToString();
            }
            else
            {
                int             uid = azureLink.findUserId(f.username);
                IResourceManage r   = new Resource();
                int             rid = r.getContainerID(uid, containerName);
                if (rid == -1)
                {
                    pendingUploads.Remove(key);
                    throw new DBLikeExceptions.CloudContainerNotFoundException();
                }
                if (!r.canWrite(uid, rid))
                {
                    pendingUploads.Remove(key);
                    throw new DBLikeExceptions.UnauthorizedAccessException();
                }
                /* TODO: improve this */
                containerAzureName = new DBManager.ResourceM()
                                     .getResourceById(new DBManager.DBAccess().getDBAccess(), rid)
                                     .getContainerName();
            }
            if (VALIDATE_OLD_HASH)
            {
                try
                {
                    var    blobMgr = new BlobStorageManager.BlobFileHandler();
                    String oldHash = blobMgr.getBlobMD5HashValue(containerAzureName, blobName);
                    if (oldHash != null && !oldHash.Equals(f.prevHash))
                    {
                        throw new DBLikeExceptions.HashConflictException();
                    }
                } catch (DBLikeExceptions.CloudBlobNotFoundException) { /* new file, no old hash */ }
            }
            return(key);
        }