本文整理汇总了C#中IMedia.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# IMedia.GetValue方法的具体用法?C# IMedia.GetValue怎么用?C# IMedia.GetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMedia
的用法示例。
在下文中一共展示了IMedia.GetValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UmbracoEventFile
public UmbracoEventFile(IMedia im)
{
Id = im.Id;
File = Kraken.GetImage(im); // Filename
// Read height
var propertyValue = im.GetValue(Constants.UmbracoPropertyAliasHeight);
if (propertyValue != null)
if (propertyValue is int)
_height = (int)propertyValue;
else
int.TryParse(propertyValue as String, out _height);
// Read width
propertyValue = im.GetValue(Constants.UmbracoPropertyAliasWidth);
if (propertyValue != null)
if (propertyValue is int)
_width = (int)propertyValue;
else
int.TryParse(propertyValue as String, out _width);
// Read size
propertyValue = im.GetValue(Constants.UmbracoPropertyAliasSize);
if (propertyValue != null)
if (propertyValue is int)
_size = (int)propertyValue;
else int.TryParse(propertyValue as String, out _size);
}
示例2: HasChanged
public bool HasChanged(IMedia im)
{
if (im != null)
{
// Keep in mind: new media nodes are always 0 in the "saving" event
var uef = _eventFiles.FirstOrDefault(x => x.Id == im.Id);
if (uef != null)
{
// Read height
int height = 0, width = 0, size = 0;
var propertyValue = im.GetValue(Constants.UmbracoPropertyAliasHeight);
if (propertyValue != null)
if (propertyValue is int)
height = (int)propertyValue;
else
int.TryParse(propertyValue as String, out height);
// Read width
propertyValue = im.GetValue(Constants.UmbracoPropertyAliasWidth);
if (propertyValue != null)
if (propertyValue is int)
width = (int)propertyValue;
else
int.TryParse(propertyValue as String, out width);
// Read size
propertyValue = im.GetValue(Constants.UmbracoPropertyAliasSize);
if (propertyValue != null)
if (propertyValue is int)
size = (int)propertyValue;
else int.TryParse(propertyValue as String, out size);
return uef.File != Kraken.GetImage(im) ||
uef.Height != height ||
uef.Width != width ||
uef.Size != size;
}
}
return false;
}
示例3: GetCropUpUrl
/// <summary>
/// Method for getting CropUp url by image
/// </summary>
/// <param name="image">IMedia</param>
/// <param name="cropUpAlias">CropUp alias (optional)</param>
/// <returns>string</returns>
private static string GetCropUpUrl(IMedia image, string cropUpAlias = null)
{
if (string.IsNullOrEmpty(cropUpAlias))
return CropUp.GetUrl(image.GetValue<string>("umbracoFile"));
return CropUp.GetUrl(image.GetValue<string>("umbracoFile"),
new ImageSizeArguments() { CropAlias = cropUpAlias });
}
示例4: ImportMediaFile
public static void ImportMediaFile(Guid guid, IMedia item)
{
string fileroot = IOHelper.MapPath(_mappedFilesRoot);
string folder = Path.Combine(fileroot, guid.ToString());
LogHelper.Debug<FileHelper>("Importing {0}", () => folder);
if (!Directory.Exists(folder))
return;
//
// we look for an existing folder, if it's there we get the
// file info. we only want to import changed files, as it
// creates directories all the time
//
FileInfo currentFile = null;
// some is it already there logic ?
if (item.HasProperty("umbracoFile"))
{
LogHelper.Debug<FileHelper>("Has umbracoFile");
if (item.GetValue("umbracoFile") != null)
{
LogHelper.Debug<FileHelper>("umbracoFile value [{0}]", () => item.GetValue("umbracoFile").ToString() );
string umbracoFile = item.GetValue("umbracoFile").ToString();
// standard uploaded the path is a string .
// for Umbraco 7's image cropper it's all JSON
string path = umbracoFile;
if ( !string.IsNullOrWhiteSpace(umbracoFile))
{
if ( IsJson(umbracoFile))
{
var jsonUmbracoFile = JsonConvert.DeserializeObject<dynamic>(umbracoFile);
path = jsonUmbracoFile.src;
}
}
LogHelper.Debug<FileHelper>("path {0}", () => path);
if (!string.IsNullOrWhiteSpace(path))
{
//
// we check it's in the media folder, because later we delete it and all it's sub folders
// if for some reason it was blank or mallformed we could trash the whole umbraco just here.
//
if (path.StartsWith("/media/"))
{
string f = IOHelper.MapPath(string.Format("~{0}", path));
if (System.IO.File.Exists(f))
{
LogHelper.Debug<FileHelper>("Getting info for {0}", () => f);
currentFile = new FileInfo(f);
}
}
}
}
}
foreach (var file in Directory.GetFiles(folder, "*.*"))
{
LogHelper.Debug<FileHelper>("Import {0}", () => file);
if (currentFile != null)
{
// LogHelper.Debug<FileHelper>("Comparing {0} - {1}", () => currentFile.Name, () => file);
// do some file comparison, we only import if the new file
// is diffrent than the existing one..
if (!FilesAreEqual(currentFile, new FileInfo(file)))
{
LogHelper.Info<FileHelper>("Updating umbracoFile with {0} ", () => file);
string filename = Path.GetFileName(file);
FileStream s = new FileStream(file, FileMode.Open);
item.SetValue("umbracoFile", filename, s); // question this for imagecropper types...
s.Close();
// ok so now we've gone and created a new folder, we need to delete the old on
if (Directory.Exists(currentFile.DirectoryName))
{
LogHelper.Info<FileHelper>("Removing old media folder location {0}", () => currentFile.DirectoryName);
Directory.Delete(currentFile.DirectoryName, true);
}
}
// LogHelper.Debug<FileHelper>("Done comparing {0} - {1}", () => currentFile.Name, () => file);
}
else
{
// if we have no currentfile, that's because it's not been imported first time yet.
LogHelper.Info<FileHelper>("First time import of {0}", () => file);
FileStream s = new FileStream(file, FileMode.Open);
item.SetValue("umbracoFile", Path.GetFileName(file), s);
s.Close();
}
LogHelper.Debug<FileHelper>("<< Done Import {0}", () => file);
//.........这里部分代码省略.........