public GxExternalFileInfo(string storageObjectFullname, string url, ExternalProvider provider, GxFileType fileType = GxFileType.Public)
 {
     _name        = storageObjectFullname;
     _provider    = provider;
     _url         = url;
     _fileTypeAtt = fileType;
 }
    public GxExternalFileInfo(string storageObjectFullname, ExternalProvider provider, GxFileType fileType)
    {
        storageObjectFullname = storageObjectFullname != null?storageObjectFullname.Replace('\\', '/') : storageObjectFullname;

        _name     = storageObjectFullname;
        _provider = provider;
        Uri result;

        if (Uri.TryCreate(storageObjectFullname, UriKind.Absolute, out result) && result.IsAbsoluteUri)
        {
            _url = storageObjectFullname;
        }
        else
        {
            if (fileType.HasFlag(GxFileType.Attribute))             //Attributes multimedia consider Storage Provider Folder
            {
                _url  = provider.GetBaseURL() + storageObjectFullname;
                _name = _url.Replace(provider.StorageUri, string.Empty);
                if (_name.StartsWith("/"))
                {
                    _name = _name.Substring(1, _name.Length - 1);
                }
            }
        }
        _fileTypeAtt = fileType;
    }
示例#3
0
        public void Download(string externalFileName, string localFile, GxFileType fileType)
        {
            string localDirectory = Path.GetDirectoryName(localFile);
            string localFileName  = Path.GetFileName(localFile);

            openstackFilesProvider.GetObjectSaveToFile(GetBucket(fileType), localDirectory, externalFileName, localFileName);
        }
        public long GetLength(string objectName, GxFileType fileType)
        {
            CloudBlockBlob blob = GetCloudBlockBlob(objectName, fileType);

            blob.FetchAttributesAsync().GetAwaiter().GetResult();
            return(blob.Properties.Length);
        }
示例#5
0
 public void Download(string objectName, string localFile, GxFileType fileType)
 {
     using (var fileStream = new System.IO.FileStream(localFile, FileMode.Create))
     {
         Client.DownloadObject(Bucket, objectName, fileStream);
     }
 }
示例#6
0
 public void Delete(string objectName, GxFileType fileType)
 {
     Google.Apis.Storage.v1.Data.Object obj = new Google.Apis.Storage.v1.Data.Object();
     obj.Name   = objectName;
     obj.Bucket = Bucket;
     Client.DeleteObject(obj);
 }
示例#7
0
        public Stream GetStream(string objectName, GxFileType fileType)
        {
            var stream = new MemoryStream();

            Client.DownloadObject(Bucket, objectName, stream);
            return(stream);
        }
        public string Rename(string objectName, string newName, GxFileType fileType)
        {
            string ret = Copy(objectName, fileType, newName, fileType);

            Delete(objectName, fileType);
            return(ret);
        }
示例#9
0
 public Stream GetStream(string objectName, GxFileType fileType)
 {
     using (Stream stream = new MemoryStream())
     {
         openstackFilesProvider.GetObject(GetBucket(fileType), objectName, stream);
         return(stream);
     }
 }
示例#10
0
        public Stream GetStream(string objectName, GxFileType destFileType)
        {
            GetObjectResponse getObjRespone = GetObject(Bucket, objectName);
            MemoryStream      stream        = new MemoryStream();

            getObjRespone.ResponseStream.CopyTo(stream);
            return(stream);
        }
        public Stream GetStream(string objectName, GxFileType fileType)
        {
            CloudBlockBlob blob   = GetCloudBlockBlob(objectName, fileType);
            Stream         stream = new MemoryStream();

            blob.DownloadToStreamAsync(stream).GetAwaiter().GetResult();
            return(stream);
        }
示例#12
0
 private string GetBucket(GxFileType fileType)
 {
     if (fileType.HasFlag(GxFileType.Private))
     {
         return(privateBucketName);
     }
     return(publicBucketName);
 }
示例#13
0
 public string Upload(string localFile, string objectName, GxFileType fileType)
 {
     using (FileStream stream = new FileStream(localFile, FileMode.Open))
     {
         Google.Apis.Storage.v1.Data.Object obj = Client.UploadObject(Bucket, objectName, "application/octet-stream", stream, GetUploadOptions(fileType));
         return(obj.MediaLink);
     }
 }
        public string Copy(string objectName, GxFileType sourceFileType, string newName, GxFileType destFileType)
        {
            CloudBlockBlob sourceBlob = GetCloudBlockBlob(objectName, sourceFileType);
            CloudBlockBlob targetBlob = GetCloudBlockBlob(newName, destFileType);

            targetBlob.StartCopyAsync(sourceBlob).GetAwaiter().GetResult();
            return(GetURL(targetBlob, destFileType));
        }
示例#15
0
 public string Get(string objectName, GxFileType fileType, int urlMinutes)
 {
     if (Exists(objectName, fileType))
     {
         return(GetURL(objectName, fileType, urlMinutes));
     }
     return(string.Empty);
 }
示例#16
0
        public void Delete(string objectName, GxFileType fileType)
        {
            DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest
            {
                BucketName = Bucket,
                Key        = objectName
            };

            DeleteObject(deleteObjectRequest);
        }
        public string Get(string objectName, GxFileType fileType, int urlMinutes)
        {
            CloudBlockBlob blob = GetCloudBlockBlob(objectName, fileType);

            if (blob.ExistsAsync().GetAwaiter().GetResult())
            {
                return(GetURL(blob, fileType, urlMinutes));
            }

            return(string.Empty);
        }
示例#18
0
 public long GetLength(string objectName, GxFileType fileType)
 {
     foreach (ContainerObject obj in openstackFilesProvider.ListObjects(GetBucket(fileType)))
     {
         if (obj.Name.Equals(objectName))
         {
             return(obj.Bytes);
         }
     }
     return(0);
 }
示例#19
0
 private string GetURL(string objectName, GxFileType fileType, int urlMinutes = 60 * 24 * 7)
 {
     if (fileType.HasFlag(GxFileType.Private))
     {
         return(Signer.Sign(Bucket, StorageUtils.EncodeUrl(objectName), TimeSpan.FromMinutes(urlMinutes), HttpMethod.Get));
     }
     else
     {
         return(StorageUri + StorageUtils.EncodeUrl(objectName));
     }
 }
示例#20
0
 public DateTime GetLastModified(string objectName, GxFileType fileType)
 {
     foreach (ContainerObject obj in openstackFilesProvider.ListObjects(GetBucket(fileType)))
     {
         if (obj.Name.Equals(objectName))
         {
             return(obj.LastModified.UtcDateTime);
         }
     }
     return(new DateTime());
 }
示例#21
0
 public bool Exists(string objectName, GxFileType fileType)
 {
     try
     {
         openstackFilesProvider.GetObjectMetaData(GetBucket(fileType), objectName);
         return(true);
     }
     catch (ItemNotFoundException)
     {
         return(false);
     }
 }
示例#22
0
        public void Download(string objectName, string localFile, GxFileType fileType)
        {
            GetObjectRequest request = new GetObjectRequest
            {
                BucketName = Bucket,
                Key        = objectName,
            };

            GetObjectResponse response = GetObject(request);

            WriteResponseStreamToFile(response, localFile);
        }
示例#23
0
 public GxFile(string baseDirectory, string fileName, GxFileType fileType = GxFileType.Public)
     : this(baseDirectory)
 {
     fileName = fileName.Trim();
     if ((GXServices.Instance != null && GXServices.Instance.Get(GXServices.STORAGE_SERVICE) != null) && !Path.IsPathRooted(fileName))
     {
         _file = new GxExternalFileInfo(fileName, ServiceFactory.GetExternalProvider(), fileType);
     }
     else
     {
         _file = new GxFileInfo(fileName, baseDirectory);
     }
 }
示例#24
0
        public string Upload(string localFile, string objectName, GxFileType fileType)
        {
            PutObjectRequest objectRequest = new PutObjectRequest()
            {
                BucketName = Bucket,
                Key        = objectName,
                FilePath   = localFile,
                CannedACL  = GetCannedACL(fileType)
            };
            PutObjectResponse result = PutObject(objectRequest);

            return(Get(objectName, fileType));
        }
        private string GetURL(CloudBlockBlob blob, GxFileType fileType, int urlMinutes = 0)
        {
            string url = StorageUri + StorageUtils.DELIMITER + blob.Container.Name + StorageUtils.DELIMITER + StorageUtils.EncodeUrl(blob.Name);

            if (IsPrivateFile(fileType))
            {
                SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
                sasConstraints.SharedAccessStartTime  = DateTime.UtcNow;
                sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes((urlMinutes > 0) ? urlMinutes : 60 * 24 * 7);
                sasConstraints.Permissions            = SharedAccessBlobPermissions.Read;
                url += blob.GetSharedAccessSignature(sasConstraints);
            }
            return(url);
        }
示例#26
0
        private static UploadObjectOptions GetUploadOptions(GxFileType fileType)
        {
            UploadObjectOptions options = new UploadObjectOptions();

            if (fileType.HasFlag(GxFileType.Private))
            {
                options.PredefinedAcl = PredefinedObjectAcl.ProjectPrivate;
            }
            else
            {
                options.PredefinedAcl = PredefinedObjectAcl.PublicRead;
            }
            return(options);
        }
示例#27
0
        //https://github.com/aws/aws-sdk-net/blob/master/sdk/src/Services/S3/Custom/_bcl/IO/S3FileInfo.cs
        public bool Exists(string objectName, GxFileType fileType)
        {
            bool exists = true;

            try
            {
                exists = new S3FileInfo(Client, Bucket, objectName).Exists;
            }
            catch (Exception)
            {
                exists = false;
            }
            return(exists);
        }
示例#28
0
        public string Copy(string objectName, GxFileType sourceFileType, string newName, GxFileType destFileType)
        {
            CopyObjectRequest request = new CopyObjectRequest
            {
                SourceBucket      = Bucket,
                SourceKey         = objectName,
                DestinationBucket = Bucket,
                DestinationKey    = newName,
                CannedACL         = GetCannedACL(destFileType)
            };

            CopyObject(request);
            return(StorageUri + StorageUtils.EncodeUrl(newName));
        }
示例#29
0
        private static CopyObjectOptions GetCopyOptions(GxFileType fileType)
        {
            CopyObjectOptions options = new CopyObjectOptions();

            if (fileType.HasFlag(GxFileType.Private))
            {
                options.DestinationPredefinedAcl = PredefinedObjectAcl.ProjectPrivate;
            }
            else
            {
                options.DestinationPredefinedAcl = PredefinedObjectAcl.PublicRead;
            }
            return(options);
        }
        private CloudBlockBlob GetCloudBlockBlob(string externalFileName, GxFileType fileType)
        {
            CloudBlockBlob blob;

            if (fileType.HasFlag(GxFileType.Private))
            {
                blob = PrivateContainer.GetBlockBlobReference(externalFileName);
            }
            else
            {
                blob = PublicContainer.GetBlockBlobReference(externalFileName);
            }

            return(blob);
        }