private
void
CreateImageNativeAPI(Guid masterImageId, Guid parentAlbumId,
string
imageTitle, Stream imageStream,
string
imageExtension)
{
LibrariesManager librariesManager = LibrariesManager.GetManager();
Image image = librariesManager.GetImages().Where(i => i.Id == masterImageId).FirstOrDefault();
if
(image ==
null
)
{
//The album post is created as master. The masterImageId is assigned to the master version.
image = librariesManager.CreateImage(masterImageId);
//Set the parent album.
Album album = librariesManager.GetAlbums().Where(i => i.Id == parentAlbumId).SingleOrDefault();
image.Parent = album;
//Set the properties of the album post.
image.Title = imageTitle;
image.DateCreated = DateTime.UtcNow;
image.PublicationDate = DateTime.UtcNow;
image.LastModified = DateTime.UtcNow;
image.UrlName = Regex.Replace(imageTitle.ToLower(), @
"[^\w\-\!\$\'\(\)\=\@\d_]+"
,
"-"
);
//Upload the image file.
librariesManager.Upload(image, imageStream, imageExtension);
//Save the changes.
librariesManager.SaveChanges();
//Publish the Albums item. The live version acquires new ID.
var bag =
new
Dictionary<
string
,
string
>();
bag.Add(
"ContentType"
,
typeof
(Image).FullName);
WorkflowManager.MessageWorkflow(masterImageId,
typeof
(Image),
null
,
"Publish"
,
false
, bag);
}
}