本文整理汇总了C#中MediaFile.IsImage方法的典型用法代码示例。如果您正苦于以下问题:C# MediaFile.IsImage方法的具体用法?C# MediaFile.IsImage怎么用?C# MediaFile.IsImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MediaFile
的用法示例。
在下文中一共展示了MediaFile.IsImage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFile
public MediaFile AddFile(Stream stream, string fileName, string contentType, long contentLength, MediaCategory mediaCategory = null)
{
fileName = Path.GetFileName(fileName);
fileName = fileName.GetTidyFileName();
var mediaFile = new MediaFile
{
FileName = fileName,
ContentType = contentType,
ContentLength = contentLength,
FileExtension = Path.GetExtension(fileName),
};
if (mediaCategory != null)
{
mediaFile.MediaCategory = mediaCategory;
int? max = _session.Query<MediaFile>().Where(x => x.MediaCategory.Id == mediaFile.MediaCategory.Id).Max(x => (int?)x.DisplayOrder);
mediaFile.DisplayOrder = (max.HasValue ? (int)max + 1 : 1);
}
if (mediaFile.IsImage())
{
if (mediaFile.IsJpeg())
{
_imageProcessor.EnforceMaxSize(ref stream, mediaFile, _mediaSettings);
}
_imageProcessor.SetFileDimensions(mediaFile, stream);
}
var fileLocation = GetFileLocation(fileName, mediaCategory);
mediaFile.FileUrl = _fileSystem.SaveFile(stream, fileLocation, contentType);
_session.Transact(session =>
{
session.Save(mediaFile);
if (mediaCategory != null)
{
mediaCategory.Files.Add(mediaFile);
session.SaveOrUpdate(mediaCategory);
}
});
stream.Dispose();
return mediaFile;
}
示例2: GetUrl
public virtual string GetUrl(MediaFile file, Size size)
{
if (!file.IsImage())
return file.FileUrl;
//check to see if the image already exists, if it does simply return it
var requestedImageFileUrl = ImageProcessor.RequestedImageFileUrl(file, size);
// if we've cached the file existing then we're fine
var resizedImages = _session.QueryOver<ResizedImage>().Where(image => image.MediaFile.Id == file.Id).Cacheable().List();
if (resizedImages.Any(image => image.Url == requestedImageFileUrl))
return requestedImageFileUrl;
// if it exists but isn't cached, we should add it to the cache
if (_fileSystem.Exists(requestedImageFileUrl))
{
CacheResizedImage(file, requestedImageFileUrl);
return requestedImageFileUrl;
}
//if we have got this far the image doesn't exist yet so we need to create the image at the requested size
var fileBytes = LoadFile(file);
if (fileBytes.Length == 0)
return "";
_imageProcessor.SaveResizedImage(file, size, fileBytes, requestedImageFileUrl);
// we also need to cache the resized image, to save making a request to find it
CacheResizedImage(file, requestedImageFileUrl);
return requestedImageFileUrl;
}