Beispiel #1
0
 private FileInfoModel SumToModel(OssObjectSummary obj)
 {
     return(new FileInfoModel()
     {
         FileName = Path.GetFileName(obj.Key),
         Path = obj.Key,
         Isdir = obj.Size == 0 && obj.Key.EndsWith("/"),
         Modification_time = obj.LastModified.ToFileTimeUtc(),
         Size = obj.Size
     });
 }
Beispiel #2
0
        public override ObjectListing Deserialize(ServiceResponse xmlStream)
        {
            var    listBucketResult = ContentDeserializer.Deserialize(xmlStream.Content);
            string encodeType       = listBucketResult.EncodingType == null ?
                                      string.Empty : listBucketResult.EncodingType.ToLowerInvariant();

            var objectList = new ObjectListing(listBucketResult.Name)
            {
                Delimiter   = Decode(listBucketResult.Delimiter, encodeType),
                IsTruncated = listBucketResult.IsTruncated,
                Marker      = Decode(listBucketResult.Marker, encodeType),
                MaxKeys     = listBucketResult.MaxKeys,
                NextMarker  = Decode(listBucketResult.NextMarker, encodeType),
                Prefix      = Decode(listBucketResult.Prefix, encodeType)
            };

            if (listBucketResult.Contents != null)
            {
                foreach (var contents in listBucketResult.Contents)
                {
                    var summary = new OssObjectSummary
                    {
                        BucketName                                 = listBucketResult.Name,
                        Key                                        = Decode(contents.Key, encodeType),
                        LastModified                               = contents.LastModified,
                        ETag                                       = contents.ETag != null?OssUtils.TrimQuotes(contents.ETag) : string.Empty,
                                                      Size         = contents.Size,
                                                      StorageClass = contents.StorageClass,
                                                      Owner        = contents.Owner != null ?
                                                                     new Owner(contents.Owner.Id, contents.Owner.DisplayName) : null
                    };

                    objectList.AddObjectSummary(summary);
                }
            }

            if (listBucketResult.CommonPrefixes != null)
            {
                foreach (var commonPrefixes in listBucketResult.CommonPrefixes)
                {
                    if (commonPrefixes.Prefix != null)
                    {
                        foreach (var prefix in commonPrefixes.Prefix)
                        {
                            objectList.AddCommonPrefix(Decode(prefix, encodeType));
                        }
                    }
                }
            }

            DeserializeGeneric(xmlStream, objectList);

            return(objectList);
        }
Beispiel #3
0
        /// <summary>
        /// Create a <see cref="S3ToAzureTransferJob"/> representing a download-to-local-and-upload copy from one S3 object to Azure blob.
        /// </summary>
        /// <param name="sourceObject">S3 object used to create the job.</param>
        /// <returns>A job representing a download-to-local-and-upload copy from one S3 object to Azure blob.</returns>
        private static AliyunToAzureTransferJob CreateTransferJob(OssObjectSummary objectSummary)
        {
            // Download the source object to a temporary file
            GetObjectRequest getObjectRequest = new GetObjectRequest(PocConfig.SourceBucket, objectSummary.Key);



            using (OssObject ossObject = ossClient.GetObject(getObjectRequest))
            {
                string tempFile = Path.Combine(tempFolder, Guid.NewGuid().ToString());
                string md5;
                string sha256;
                string relativeName = PocUtil.GetRelativeName(ossObject.Key, PocConfig.SourceDir);

                // Check if the destination blob already exists.
                CloudBlobContainer container = azureClient.GetContainerReference(PocConfig.DestContainer);
                CloudBlockBlob     destBlob  = container.GetBlockBlobReference(PocUtil.GetFullName(relativeName, PocConfig.DestDir));

                try
                {
                    if (destBlob.Exists(PocConstant.DefaultBlobRequestOptions))
                    {
                        Console.WriteLine("Dest already exist {0}", destBlob.Uri.ToString());
                        pocManifest.AddFailed(relativeName, PocErrorString.DestAlreadyExist);
                        return(null);
                    }

                    PocUtil.DownloadOssObject2File(ossObject, tempFile, out md5, out sha256);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("Fail to download from aliyun {0}. Error: {1}", objectSummary.Key, e.ToString());
                    pocManifest.AddFailed(relativeName, PocErrorString.DownloadFailed);
                    return(null);
                }

                if (!VerifyDownloadSHA(relativeName, sha256))
                {
                    Console.Error.WriteLine("Download content miss match {0}. SHA: {1}", objectSummary.Key, sha256);
                    pocManifest.AddFailed(relativeName, PocErrorString.DownloadContentMissMatch);
                    return(null);
                }

                AliyunToAzureTransferJob job = new AliyunToAzureTransferJob()
                {
                    Source     = tempFile,
                    Name       = relativeName,
                    ContentMD5 = md5,
                };

                return(job);
            }
        }
        private async Task createFolder(string bucketName, string key) //key is the parent
        {
            MemoryStream     s             = new MemoryStream();
            ObjectMetadata   oMetaData     = new ObjectMetadata();
            OssObjectSummary ossObjSummary = new OssObjectSummary();

            ossObjSummary.BucketName = bucketName;

            ossObjSummary.Key = key;

            await clientService.ossClient.PutObject(ossObjSummary.BucketName, ossObjSummary.Key, s, oMetaData);

            s.Dispose();
        }
Beispiel #5
0
        public async override Task <ObjectListing> Deserialize(HttpResponseMessage response)
        {
            ListBucketResult listBucketResult = base.ContentDeserializer.Deserialize(await response.Content.ReadAsStreamAsync());
            ObjectListing    objectList       = new ObjectListing(listBucketResult.Name)
            {
                Delimiter  = listBucketResult.Delimiter,
                IsTrunked  = listBucketResult.IsTruncated,
                Marker     = listBucketResult.Marker,
                MaxKeys    = listBucketResult.MaxKeys,
                NextMarker = listBucketResult.NextMarker,
                Prefix     = listBucketResult.Prefix
            };

            if (listBucketResult.Contents != null)
            {
                foreach (ListBucketResultContents contents in listBucketResult.Contents)
                {
                    OssObjectSummary summary = new OssObjectSummary
                    {
                        BucketName   = listBucketResult.Name,
                        Key          = contents.Key,
                        LastModified = contents.LastModified,
                        ETag         = (contents.ETag != null) ? contents.ETag.Trim(new char[] { '"' }) : string.Empty,
                        Size         = contents.Size,
                        StorageClass = contents.StorageClass,
                        Owner        = (contents.Owner != null) ? new Owner(contents.Owner.Id, contents.Owner.DisplayName) : null
                    };
                    objectList.AddObjectSummary(summary);
                }
            }
            if (listBucketResult.CommonPrefixes != null)
            {
                foreach (ListBucketResultCommonPrefixes commonPrefixes in listBucketResult.CommonPrefixes)
                {
                    if (commonPrefixes.Prefix != null)
                    {
                        foreach (string prefix in commonPrefixes.Prefix)
                        {
                            objectList.AddCommonPrefix(prefix);
                        }
                    }
                }
            }
            return(objectList);
        }
Beispiel #6
0
 public void Delete(OssObjectSummary ossObject)
 {
     logger.LogInformation($"delete the object {ossObject.Key} from bucket {_bucketName}");
     Client.DeleteObject(_bucketName, ossObject.Key);
 }