本文整理汇总了C#中Kooboo.CMS.Content.Models.MediaContent类的典型用法代码示例。如果您正苦于以下问题:C# MediaContent类的具体用法?C# MediaContent怎么用?C# MediaContent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MediaContent类属于Kooboo.CMS.Content.Models命名空间,在下文中一共展示了MediaContent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSimple
public void TestSimple()
{
//var binaryContentProvider = Providers.GetProviderFactory(repository.DBProvider).GetProvider<IContentProvider<BinaryContent>>();
var binaryContent1 = new MediaContent(repository.Name, binaryFolder.Name);
binaryContent1.UserKey = "image1";
binaryContent1.VirtualPath = "~/binary/image1.jpg";
binaryContent1.ContentFile = new ContentFile()
{
Name = "image1.jpg",
FileName = "image1.jpg",
Stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5, 6 })
};
binaryContentProvider.Add(binaryContent1);
var binaryContent2 = new MediaContent(repository.Name, binaryFolder.Name);
binaryContent2.UserKey = "image2";
binaryContent2.VirtualPath = "~/binary/image2.jpg";
binaryContent2.ContentFile = new ContentFile()
{
Name = "image2.jpg",
FileName = "image2.jpg",
Stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5, 6 })
};
binaryContentProvider.Add(binaryContent2);
var query1 = binaryFolder.CreateQuery().WhereEquals("UUID", (string)(binaryContent1.UUID));
Assert.AreEqual(1, query1.Count());
var binaryContentItem1 = query1.First();
Assert.AreEqual(binaryContent1.UUID, binaryContentItem1.UUID);
}
示例2: BlobToMediaContent
public static MediaContent BlobToMediaContent(this CloudBlob blob, MediaContent mediaContent)
{
if (!string.IsNullOrEmpty(blob.Metadata["Published"]))
{
mediaContent.Published = bool.Parse(blob.Metadata["Published"]);
}
if (!string.IsNullOrEmpty(blob.Metadata["Size"]))
{
mediaContent.Size = int.Parse(blob.Metadata["Size"]);
}
mediaContent.FileName = blob.Metadata["FileName"];
mediaContent.UserKey = mediaContent.FileName;
mediaContent.UUID = mediaContent.FileName;
mediaContent.UserId = blob.Metadata["UserId"];
mediaContent.VirtualPath = blob.Uri.ToString();
if (mediaContent.Metadata == null)
{
mediaContent.Metadata = new MediaContentMetadata();
}
mediaContent.Metadata.AlternateText = blob.Metadata["AlternateText"];
mediaContent.Metadata.Description = blob.Metadata["Description"];
mediaContent.Metadata.Title = blob.Metadata["Title"];
return mediaContent;
}
示例3: Update
public virtual MediaContent Update(Repository repository, MediaFolder mediaFolder, string uuid, string fileName, Stream fileStream,
string userid, MediaContentMetadata metadata)
{
IsAllowExtension(fileName, mediaFolder.AllowedExtensions);
var binaryContent = mediaFolder.CreateQuery().WhereEquals("UUID", uuid).First();
var old = new MediaContent(binaryContent);
binaryContent.UserId = userid;
binaryContent.UtcLastModificationDate = DateTime.UtcNow;
binaryContent.FileName = fileName;
binaryContent.UserKey = fileName;
binaryContent.UUID = fileName;
if (fileStream != null)
{
binaryContent.ContentFile = new ContentFile()
{
Name = fileName,
FileName = fileName,
Stream = fileStream
};
Provider.SaveContentStream(old, fileStream);
}
binaryContent.Metadata = metadata;
Provider.Update(binaryContent, old);
return binaryContent;
}
示例4: Test1
public void Test1()
{
MediaContent binaryContent1 = new MediaContent();
binaryContent1.Repository = repository.Name;
binaryContent1.FolderName = binaryFolder.Name;
binaryContent1.FileName = "file1.jpg";
binaryContent1.VirtualPath = "~/file1.jpg";
Providers.DefaultProviderFactory.GetProvider<IMediaContentProvider>().Add(binaryContent1);
MediaContent binaryContent2 = new MediaContent();
binaryContent2.Repository = repository.Name;
binaryContent2.FolderName = binaryFolder.Name;
binaryContent2.FileName = "file2.jpg";
binaryContent2.VirtualPath = "~/file2.jpg";
Providers.DefaultProviderFactory.GetProvider<IMediaContentProvider>().Add(binaryContent2);
var query = binaryFolder.CreateQuery().OrderBy("id");
Assert.AreEqual(2, query.Count());
Assert.AreEqual("file1.jpg", query.First().FileName);
Assert.AreEqual("file2.jpg", query.Last().FileName);
Providers.DefaultProviderFactory.GetProvider<IMediaContentProvider>().Delete(binaryContent1);
Assert.AreEqual(1, query.Count());
}
示例5: Add
public virtual MediaContent Add(Repository repository, MediaFolder mediaFolder, string fileName, Stream fileStream, bool @overrided,
string userId, MediaContentMetadata metadata)
{
fileName = UrlUtility.ToUrlString(Path.GetFileNameWithoutExtension(fileName)) + Path.GetExtension(fileName);
IsAllowExtension(fileName, mediaFolder.AllowedExtensions);
var mediaContent = new MediaContent(repository.Name, mediaFolder.FullName);
mediaContent.UserId = userId;
mediaContent.Published = true;
mediaContent.FileName = fileName;
mediaContent.UserKey = fileName;
mediaContent.UUID = fileName;
mediaContent.ContentFile = new ContentFile()
{
Name = fileName,
FileName = fileName,
Stream = fileStream
};
mediaContent.UtcLastModificationDate = mediaContent.UtcCreationDate = DateTime.UtcNow;
mediaContent.Metadata = metadata;
Provider.Add(mediaContent, @overrided);
return mediaContent;
}
示例6: SaveMetadata
public void SaveMetadata(MediaContent mediaContent)
{
if (mediaContent.Metadata != null)
{
string metadataFile = GetMetadataFilePath(mediaContent);
Kooboo.Runtime.Serialization.DataContractSerializationHelper.Serialize(mediaContent.Metadata, metadataFile);
}
}
示例7: Delete
public void Delete(MediaContent content)
{
var blobClient = CloudStorageAccountHelper.GetStorageAccount().CreateCloudBlobClient();
var contentBlob = blobClient.GetBlobReference(content.GetMediaBlobPath());
contentBlob.DeleteIfExists();
}
示例8: DeleteMetadata
public void DeleteMetadata(MediaContent mediaContent)
{
string metadataFile = GetMetadataFilePath(mediaContent);
if (File.Exists(metadataFile))
{
File.Delete(metadataFile);
}
}
示例9: MoveMetadata
public virtual void MoveMetadata(MediaContent old, MediaContent @new)
{
var oldPath = GetMetadataFilePath(old);
if (File.Exists(oldPath))
{
var newPath = GetMetadataFilePath(@new);
File.Move(oldPath, newPath);
}
}
示例10: FillMetadata
public void FillMetadata(MediaContent mediaContent)
{
string metadataFile = GetMetadataFilePath(mediaContent);
if (File.Exists(metadataFile))
{
var metadata = Kooboo.Runtime.Serialization.DataContractSerializationHelper.Deserialize<MediaContentMetadata>(metadataFile);
mediaContent.Metadata = metadata;
mediaContent["Metadata.Title"] = metadata.Title;
mediaContent["Metadata.AlternateText"] = metadata.AlternateText;
mediaContent["Metadata.Description"] = metadata.Description;
}
}
示例11: Test_Add_Content
public void Test_Add_Content()
{
MediaContent content = new MediaContent(repository.Name, mediaFolder.FullName);
content.Published = true;
content.ContentFile = new ContentFile()
{
FileName = "Test_Add_Content.dat",
Stream = new MemoryStream(new byte[10])
};
provider.Add(content);
Console.WriteLine(content.VirtualPath);
}
示例12: Test_Delete_Content
public void Test_Delete_Content()
{
MediaContent content = new MediaContent(repository.Name, mediaFolder.FullName);
content.Published = true;
content.ContentFile = new ContentFile()
{
FileName = "Test_Delete_Content.zip",
Stream = new MemoryStream(new byte[10])
};
provider.Add(content);
provider.Delete(content);
}
示例13: Add
public void Add(MediaContent content, bool overrided)
{
if (content.ContentFile != null)
{
content.FileName = content.ContentFile.FileName;
content.UserKey = content.FileName;
content.UUID = content.FileName;
RemoteServiceFactory.CreateService<IMediaContentService>().Add(
new MediaContentParameter()
{
MediaContent = content,
FileData = content.ContentFile.Stream.ReadData()
});
}
}
示例14: BlobToMediaContent
public static MediaContent BlobToMediaContent(this CloudBlob blob, MediaContent mediaContent)
{
if (!string.IsNullOrEmpty(blob.Metadata["Published"]))
{
mediaContent.Published = bool.Parse(blob.Metadata["Published"]);
}
if (!string.IsNullOrEmpty(blob.Metadata["Size"]))
{
mediaContent.Size = int.Parse(blob.Metadata["Size"]);
}
mediaContent.FileName = blob.Metadata["FileName"];
mediaContent.UserKey = mediaContent.FileName;
mediaContent.UUID = mediaContent.FileName;
mediaContent.UserId = blob.Metadata["UserId"];
mediaContent.VirtualPath = blob.Uri.ToString();
return mediaContent;
}
示例15: Test_Get_Content
public void Test_Get_Content()
{
MediaContent content = new MediaContent(repository.Name, mediaFolder.FullName);
content.Published = true;
content.UserId = "admin";
content.ContentFile = new ContentFile()
{
FileName = "Test_Get_Content.zip",
Stream = new MemoryStream(new byte[10])
};
provider.Add(content);
var gotContent = mediaFolder.CreateQuery().WhereEquals("FileName", content.FileName).First();
Assert.AreEqual(content.FileName, gotContent.FileName);
Assert.AreEqual(content.UserId, gotContent.UserId);
Assert.AreEqual(content.Published, gotContent.Published);
Console.WriteLine(content.VirtualPath, gotContent.VirtualPath);
}