Example #1
0
 public BlobBufferedIns(GcsReqParmas reqParams)
 {
     this.blob              = GcsService.Instance().GetBlob(reqParams.Bucket, reqParams.Blob);
     this.blobSize          = (long)this.blob.Size;
     this.numOfBlobBtsLeft  = this.blobSize;
     this.fullBlobPath      = reqParams.BlobFullPath;
     this.dwLocalBufferSize = (int)Math.Min(Constants.BLOB_BUFFERED_INS_DOWNLOAD_SIZE * 2, this.blobSize);
 }
Example #2
0
 public BlobBufferedOus(GcsReqParmas reqParams)
 {
     this.blob          = GcsService.Instance().CreateEmptyBlob(reqParams.Bucket, reqParams.Blob);
     this.reqParmas     = reqParams;
     this.fullBlobPath  = reqParams.BlobFullPath;
     this.centralBuffer = new byte[centralBufferSize];
     this.localFileSize = (0 != reqParams.LocalFileSize) ? reqParams.LocalFileSize : 0;
     this.uploadUri     = GcsService.Instance().InitializeResumableUploader(reqParams.Bucket, reqParams.Blob);
 }
Example #3
0
        public void SetGcsProperties()
        {
            GcsService gcsService = GcsService.Instance();

            this.pathType = GcsPathType.INVALID;
            try
            {
                if ("/".Equals(this.FullPath))
                {
                    /*  root directory : /:*/
                    this.pathType = GcsPathType.ROOT;
                    return;
                }
                /* validate the bucket name */
                if (!this.Bucket.Equals("") && Uri.CheckHostName(this.Bucket) == 0)
                {
                    return;
                }
                if (!this.Bucket.Equals("") && this.Blob.Equals(""))
                {
                    /* bucket: /bucket */
                    Bucket bucket = gcsService.GetBucket(this.Bucket);
                    if (null != bucket)
                    {
                        this.pathType = GcsPathType.BUCKET;
                        this.Created  = bucket.TimeCreated;
                        this.Updated  = bucket.Updated;
                        this.Size     = 0L;
                    }
                }
                else if (!this.Bucket.Equals("") && !this.Blob.Equals(""))
                {
                    Google.Apis.Storage.v1.Data.Object blob = gcsService.GetBlob(this.Bucket, this.Blob);
                    if (null != blob && !blob.Name.EndsWith("/"))
                    {
                        /* blob: /container/folder/file1 */
                        this.pathType = GcsPathType.BLOB;
                        this.Created  = blob.TimeCreated;
                        this.Updated  = blob.Updated;
                        this.Size     = blob.Size;
                    }
                    else if (gcsService.SubDirExists(this.Bucket, this.Blob))
                    {
                        /* virtual directory : /container/folder/ */
                        this.pathType = GcsPathType.SUBDIR;
                    }
                }
                //Utils.WriteLine("pathType:" + this.pathType);
            }
            catch (Exception ex)
            {
                Logger.Log(Logger.Level.Error, ex.Message);
            }
        }
Example #4
0
 /// <summary>
 /// Singleton
 /// </summary>
 public static GcsService Instance()
 {
     if (instance == null)
     {
         lock (SyncRoot)
         {
             if (instance == null)
             {
                 instance = new GcsService();
             }
         }
     }
     return(instance);
 }
Example #5
0
        private int UploadBlobChunk(byte[] rawData, int offset, int length)
        {
            int dataUploadedThisChunk = 0;

            try
            {
                byte[] targetData = new byte[length];
                Buffer.BlockCopy(rawData, 0, targetData, 0, length);
                GcsService.Instance().UploadBlobChunk(this.uploadUri, targetData, totalDataUploaded, length);
                /* update the chunk counter */
                chunkNumber++;
                dataUploadedThisChunk = length;
                targetData            = null;
            } catch (Exception ex) {
                String errMessage = "Unexpected exception occurred when uploading to the blob : "
                                    + this.fullBlobPath + ", No. of chunk: " + chunkNumber + "." + ex.Message;
                throw new BlobBufferedOusException(errMessage);
            }
            //Console.WriteLine(String.Format("Uploading to {0} , blockId: {1}, size: {2}", fullBlobPath, chunkNumber, length));
            return(dataUploadedThisChunk);
        }
Example #6
0
        private byte[] DownloadBlobChunk(long offset, int len)
        {
            long bytesDownloaded = 0;

            byte[] dwLocalBuffer;
            if (isBlobEOF)
            {
                return(null);
            }
            /* how much to read (only last chunk may be smaller) */
            len              = Math.Min((int)(blobSize - offset), len);
            dwLocalBuffer    = GcsService.Instance().DownloadByteRange(this.blob.Bucket, this.blob.Name, offset, offset + len - 1);
            bytesDownloaded  = dwLocalBuffer.Length;
            numOfBlobBtsLeft = blobSize - offset - bytesDownloaded;
            blobOffset       = (offset + bytesDownloaded);
            if (numOfBlobBtsLeft <= 0)
            {
                this.isBlobEOF = true;
            }
            Utils.WriteLine(String.Format("Downloaded from {0} , size of this chunk : {1}, " +
                                          "total downloaded size: {2}, TID: {3}",
                                          fullBlobPath, bytesDownloaded, blobOffset, ", TID: " + Thread.CurrentThread.ManagedThreadId));
            return(dwLocalBuffer);
        }