本文整理汇总了C#中ILocalizationService.GetResourceString方法的典型用法代码示例。如果您正苦于以下问题:C# ILocalizationService.GetResourceString方法的具体用法?C# ILocalizationService.GetResourceString怎么用?C# ILocalizationService.GetResourceString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILocalizationService
的用法示例。
在下文中一共展示了ILocalizationService.GetResourceString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadFile
public static UploadFileResult UploadFile(HttpPostedFileBase file, string uploadFolderPath, ILocalizationService localizationService, bool onlyImages = false)
{
var upResult = new UploadFileResult { UploadSuccessful = true };
const string imageExtensions = "jpg,jpeg,png,gif";
var fileName = Path.GetFileName(file.FileName);
if (fileName != null)
{
// Lower case
fileName = fileName.ToLower();
// Get the file extension
var fileExtension = Path.GetExtension(fileName.ToLower());
//Before we do anything, check file size
if (file.ContentLength > Convert.ToInt32(SiteConstants.FileUploadMaximumFileSizeInBytes))
{
//File is too big
upResult.UploadSuccessful = false;
upResult.ErrorMessage = localizationService.GetResourceString("Post.UploadFileTooBig");
return upResult;
}
// now check allowed extensions
var allowedFileExtensions = SiteConstants.FileUploadAllowedExtensions;
if (onlyImages)
{
allowedFileExtensions = imageExtensions;
}
if (!string.IsNullOrEmpty(allowedFileExtensions))
{
// Turn into a list and strip unwanted commas as we don't trust users!
var allowedFileExtensionsList = allowedFileExtensions.ToLower().Trim()
.TrimStart(',').TrimEnd(',').Split(',').ToList();
// If can't work out extension then just error
if (string.IsNullOrEmpty(fileExtension))
{
upResult.UploadSuccessful = false;
upResult.ErrorMessage = localizationService.GetResourceString("Errors.GenericMessage");
return upResult;
}
// Remove the dot then check against the extensions in the web.config settings
fileExtension = fileExtension.TrimStart('.');
if (!allowedFileExtensionsList.Contains(fileExtension))
{
upResult.UploadSuccessful = false;
upResult.ErrorMessage = localizationService.GetResourceString("Post.UploadBannedFileExtension");
return upResult;
}
}
// Store these here as we may change the values within the image manipulation
var newFileName = string.Empty;
var path = string.Empty;
if (imageExtensions.Split(',').ToList().Contains(fileExtension))
{
// Rotate image if wrong want around
using (var sourceimage = Image.FromStream(file.InputStream))
{
if (sourceimage.PropertyIdList.Contains(0x0112))
{
int rotationValue = sourceimage.GetPropertyItem(0x0112).Value[0];
switch (rotationValue)
{
case 1: // landscape, do nothing
break;
case 8: // rotated 90 right
// de-rotate:
sourceimage.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
case 3: // bottoms up
sourceimage.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case 6: // rotated 90 left
sourceimage.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
}
}
using (var stream = new MemoryStream())
{
// Save the image as a Jpeg only
sourceimage.Save(stream, ImageFormat.Jpeg);
stream.Position = 0;
// Change the extension to jpg as that's what we are saving it as
fileName = fileName.Replace(fileExtension, "");
fileName = string.Concat(fileName, "jpg");
file = new MemoryFile(stream, "image/jpeg", fileName);
// Sort the file name
//.........这里部分代码省略.........
示例2: UploadFile
public static UploadFileResult UploadFile(HttpPostedFileBase file, string uploadFolderPath, ILocalizationService localizationService, bool onlyImages = false)
{
var upResult = new UploadFileResult { UploadSuccessful = true };
var fileName = Path.GetFileName(file.FileName);
if (fileName != null)
{
//Before we do anything, check file size
if (file.ContentLength > Convert.ToInt32(ConfigUtils.GetAppSetting("FileUploadMaximumFileSizeInBytes")))
{
//File is too big
upResult.UploadSuccessful = false;
upResult.ErrorMessage = localizationService.GetResourceString("Post.UploadFileTooBig");
return upResult;
}
// now check allowed extensions
var allowedFileExtensions = ConfigUtils.GetAppSetting("FileUploadAllowedExtensions");
if (onlyImages)
{
allowedFileExtensions = "jpg,jpeg,png,gif";
}
if (!string.IsNullOrEmpty(allowedFileExtensions))
{
// Turn into a list and strip unwanted commas as we don't trust users!
var allowedFileExtensionsList = allowedFileExtensions.ToLower().Trim()
.TrimStart(',').TrimEnd(',').Split(',').ToList();
// Get the file extension
var fileExtension = Path.GetExtension(fileName.ToLower());
// If can't work out extension then just error
if (string.IsNullOrEmpty(fileExtension))
{
upResult.UploadSuccessful = false;
upResult.ErrorMessage = localizationService.GetResourceString("Errors.GenericMessage");
return upResult;
}
// Remove the dot then check against the extensions in the web.config settings
fileExtension = fileExtension.TrimStart('.');
if (!allowedFileExtensionsList.Contains(fileExtension))
{
upResult.UploadSuccessful = false;
upResult.ErrorMessage = localizationService.GetResourceString("Post.UploadBannedFileExtension");
return upResult;
}
}
// Sort the file name
var newFileName = string.Format("{0}_{1}", GuidComb.GenerateComb(), fileName.Trim(' ').Replace("_", "-").Replace(" ", "-").ToLower());
var path = Path.Combine(uploadFolderPath, newFileName);
// Save the file to disk
file.SaveAs(path);
var hostingRoot = HostingEnvironment.MapPath("~/") ?? "";
var fileUrl = path.Substring(hostingRoot.Length).Replace('\\', '/').Insert(0, "/");
upResult.UploadedFileName = newFileName;
upResult.UploadedFileUrl = fileUrl;
}
return upResult;
}