示例#1
0
        public void Delete(MediaContent content)
        {
            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

            var contentBlob = blobClient.GetBlobReference(content.GetMediaBlobPath());

            contentBlob.DeleteIfExists();
        }
示例#2
0
        public void Add(MediaContent content, bool overrided)
        {
            if (content.ContentFile != null)
            {
                content.FileName = content.ContentFile.FileName;

                content.UserKey = content.FileName;
                content.UUID = content.FileName;

                var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

                var contentBlob = blobClient.GetBlobReference(content.GetMediaBlobPath());
                contentBlob = content.MediaContentToBlob(contentBlob);

                contentBlob.UploadFromStream(content.ContentFile.Stream);

                content.VirtualPath = contentBlob.Uri.ToString();
            }
        }
示例#3
0
        public void Update(MediaContent @new, MediaContent old)
        {
            if ([email protected](old.FileName, StringComparison.OrdinalIgnoreCase))
            {
                MoveContent(old, @new);
            }
            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

            var contentBlob = blobClient.GetBlobReference(@new.GetMediaBlobPath());

            contentBlob = @new.MediaContentToBlob(contentBlob);

            contentBlob.SetMetadata();

            @new.VirtualPath = contentBlob.Uri.ToString();
        }
示例#4
0
        private static void MoveContent(MediaContent oldMediaContent, MediaContent newMediaContent)
        {
            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

            var oldContentBlob = blobClient.GetBlobReference(oldMediaContent.GetMediaBlobPath());
            var newContentBlob = blobClient.GetBlobReference(newMediaContent.GetMediaBlobPath());
            newContentBlob.CopyFromBlob(oldContentBlob);

            oldContentBlob.DeleteIfExists();
        }
示例#5
0
        public void SaveContentStream(MediaContent content, Stream stream)
        {
            if (stream.Length == 0)
            {
                return;
            }
            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();
            var contentBlob = blobClient.GetBlobReference(content.GetMediaBlobPath());

            if (contentBlob.Exists())
            {
                contentBlob.UploadFromStream(stream);
            }
        }
示例#6
0
        public byte[] GetContentStream(MediaContent content)
        {
            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();
            var path = string.Empty;
            if (string.IsNullOrEmpty(content.GetRepository().Name))
            {
                path = content.VirtualPath.Substring(AzureBlobServiceSettings.Instance.Endpoint.Length);
                //path = UrlUtility.Combine(path.Split('/').Select(it => StorageNamesEncoder.EncodeBlobName(it)).ToArray());
            }
            else
            {
                path = content.GetMediaBlobPath();
            }
            var contentBlob = blobClient.GetBlobReference(path);

            byte[] data = null;
            if (contentBlob.Exists())
            {
                data = contentBlob.DownloadByteArray();
            }
            return data;
        }
示例#7
0
        private static void MoveContent(MediaContent oldMediaContent, MediaContent newMediaContent)
        {
            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

            var oldContentBlob = blobClient.GetBlockBlobReference(oldMediaContent.GetMediaBlobPath());
            var newContentBlob = blobClient.GetBlockBlobReference(newMediaContent.GetMediaBlobPath());
            if (oldContentBlob.Exists() && !newContentBlob.Exists())
            {
                try
                {
                    newContentBlob.CopyFromBlob(oldContentBlob);
                }
                catch (Exception e)
                {
                    using (Stream stream = new MemoryStream())
                    {
                        oldContentBlob.DownloadToStream(stream);
                        stream.Position = 0;
                        newContentBlob.UploadFromStream(stream);
                        stream.Dispose();
                    }
                }
                newContentBlob.Metadata["FileName"] = StorageNamesEncoder.EncodeBlobName(newMediaContent.FileName);
                if (!string.IsNullOrEmpty(oldContentBlob.Metadata["UserId"]))
                {
                    newContentBlob.Metadata["UserId"] = oldContentBlob.Metadata["UserId"];
                }
                if (!string.IsNullOrEmpty(oldContentBlob.Metadata["Published"]))
                {
                    newContentBlob.Metadata["Published"] = oldContentBlob.Metadata["Published"];
                }
                if (!string.IsNullOrEmpty(oldContentBlob.Metadata["Size"]))
                {
                    newContentBlob.Metadata["Size"] = oldContentBlob.Metadata["Size"];
                }
                if (oldContentBlob.Metadata.AllKeys.Contains("AlternateText"))
                {
                    newContentBlob.Metadata["AlternateText"] = oldContentBlob.Metadata["AlternateText"];
                }
                if (oldContentBlob.Metadata.AllKeys.Contains("Description"))
                {
                    newContentBlob.Metadata["Description"] = oldContentBlob.Metadata["Description"];
                }
                if (oldContentBlob.Metadata.AllKeys.Contains("Title"))
                {
                    newContentBlob.Metadata["Title"] = oldContentBlob.Metadata["Title"];
                }

                newContentBlob.SetMetadata();
                oldContentBlob.DeleteIfExists();
            }

        }
示例#8
0
        private static void MoveContent(MediaContent oldMediaContent, MediaContent newMediaContent)
        {
            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();

            var oldContentBlob = blobClient.GetBlockBlobReference(oldMediaContent.GetMediaBlobPath());
            var newContentBlob = blobClient.GetBlockBlobReference(newMediaContent.GetMediaBlobPath());
            if (oldContentBlob.Exists() && !newContentBlob.Exists())
            {
                newContentBlob.CopyFromBlob(oldContentBlob);
                newContentBlob.Metadata["FileName"] = newMediaContent.FileName;
                newContentBlob.SetMetadata();
                oldContentBlob.DeleteIfExists();
            }
        }
示例#9
0
        public Stream GetContentStream(MediaContent content)
        {
            var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();
            var path=string.Empty;
            if(string.IsNullOrEmpty(content.GetRepository().Name))
            {
                path = content.VirtualPath.Substring(AzureBlobServiceSettings.Instance.Endpoint.Length);
            }
            else
            {
                path = content.GetMediaBlobPath();
            }
            var contentBlob =  blobClient.GetBlobReference(path);

            var stream = new MemoryStream();
            if (contentBlob.Exists())
            {
                contentBlob.DownloadToStream(stream);
            }
            stream.Position = 0;
            return stream;
        }