本文整理汇总了C#中umbraco.cms.businesslogic.media.Media类的典型用法代码示例。如果您正苦于以下问题:C# Media类的具体用法?C# Media怎么用?C# Media使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Media类属于umbraco.cms.businesslogic.media命名空间,在下文中一共展示了Media类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryFindExistingMedia
public bool TryFindExistingMedia(int parentNodeId, string fileName, out Media existingMedia)
{
var children = parentNodeId == -1 ? Media.GetRootMedias() : new Media(parentNodeId).Children;
foreach (var childMedia in children)
{
if (childMedia.ContentType.Alias == MediaTypeAlias)
{
var prop = childMedia.getProperty(Constants.Conventions.Media.File);
if (prop != null && prop.Value != null)
{
int subfolderId;
var currentValue = prop.Value.ToString();
var subfolder = UmbracoSettings.UploadAllowDirectories
? currentValue.Replace(FileSystem.GetUrl("/"), "").Split('/')[0]
: currentValue.Substring(currentValue.LastIndexOf("/", StringComparison.Ordinal) + 1).Split('-')[0];
if (int.TryParse(subfolder, out subfolderId))
{
var destFilePath = FileSystem.GetRelativePath(subfolderId, fileName);
var destFileUrl = FileSystem.GetUrl(destFilePath);
if (prop.Value.ToString() == destFileUrl)
{
existingMedia = childMedia;
return true;
}
}
}
}
}
existingMedia = null;
return false;
}
示例2: GetOriginalUrl
/// <summary>
/// Gets the image property.
/// </summary>
/// <returns></returns>
internal static string GetOriginalUrl(int nodeId, ImageResizerPrevalueEditor imagePrevalueEditor)
{
Property imageProperty;
var node = new CMSNode(nodeId);
if (node.nodeObjectType == Document._objectType)
{
imageProperty = new Document(nodeId).getProperty(imagePrevalueEditor.PropertyAlias);
}
else if (node.nodeObjectType == Media._objectType)
{
imageProperty = new Media(nodeId).getProperty(imagePrevalueEditor.PropertyAlias);
}
else
{
if (node.nodeObjectType != Member._objectType)
{
throw new Exception("Unsupported Umbraco Node type for Image Resizer (only Document, Media and Members are supported.");
}
imageProperty = new Member(nodeId).getProperty(imagePrevalueEditor.PropertyAlias);
}
try
{
return imageProperty.Value.ToString();
}
catch
{
return string.Empty;
}
}
示例3: Run
public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
{
// Cast to Umbraco worklow instance.
var umbracoWorkflowInstance = (UmbracoWorkflowInstance) workflowInstance;
var count = 0;
var newCmsNodes = new List<int>();
foreach(var nodeId in umbracoWorkflowInstance.CmsNodes)
{
var n = new CMSNode(nodeId);
if(!n.IsMedia()) continue;
var d = new Media(nodeId);
if (!MediaTypes.Contains(d.ContentType.Id)) continue;
newCmsNodes.Add(nodeId);
count++;
}
umbracoWorkflowInstance.CmsNodes = newCmsNodes;
var transition = (count > 0) ? "contains_media" : "does_not_contain_media";
runtime.Transition(workflowInstance, this, transition);
}
示例4: DoHandleMedia
public override void DoHandleMedia(Media media, PostedMediaFile uploadedFile, User user)
{
// Get umbracoFile property
var propertyId = media.getProperty("umbracoFile").Id;
// Get paths
var destFilePath = FileSystem.GetRelativePath(propertyId, uploadedFile.FileName);
var ext = Path.GetExtension(destFilePath).Substring(1);
//var absoluteDestPath = HttpContext.Current.Server.MapPath(destPath);
//var absoluteDestFilePath = HttpContext.Current.Server.MapPath(destFilePath);
// Set media properties
media.getProperty("umbracoFile").Value = FileSystem.GetUrl(destFilePath);
media.getProperty("umbracoBytes").Value = uploadedFile.ContentLength;
if (media.getProperty("umbracoExtension") != null)
media.getProperty("umbracoExtension").Value = ext;
if (media.getProperty("umbracoExtensio") != null)
media.getProperty("umbracoExtensio").Value = ext;
FileSystem.AddFile(destFilePath, uploadedFile.InputStream, uploadedFile.ReplaceExisting);
// Save media
media.Save();
}
示例5: update
public void update(mediaCarrier carrier, string username, string password)
{
Authenticate(username, password);
if (carrier == null) throw new Exception("No carrier specified");
Media m = new Media(carrier.Id);
if (carrier.MediaProperties != null)
{
foreach (mediaProperty updatedproperty in carrier.MediaProperties)
{
if (!(updatedproperty.Key.ToLower().Equals("umbracofile")))
{
Property property = m.getProperty(updatedproperty.Key);
if (property == null)
throw new Exception("property " + updatedproperty.Key + " was not found");
property.Value = updatedproperty.PropertyValue;
}
}
}
m.Save();
}
示例6: TryFindExistingMedia
public bool TryFindExistingMedia(int parentNodeId, string fileName, out Media existingMedia)
{
var children = parentNodeId == -1 ? Media.GetRootMedias() : new Media(parentNodeId).Children;
foreach (var childMedia in children)
{
if (childMedia.ContentType.Alias == MediaTypeAlias)
{
var prop = childMedia.getProperty("umbracoFile");
if (prop != null)
{
var destFilePath = FileSystem.GetRelativePath(prop.Id, fileName);
var destFileUrl = FileSystem.GetUrl(destFilePath);
if (prop.Value.ToString() == destFileUrl)
{
existingMedia = childMedia;
return true;
}
}
}
}
existingMedia = null;
return false;
}
示例7: DoHandleMedia
public override void DoHandleMedia(Media media, PostedMediaFile uploadedFile, User user)
{
// Get umbracoFile property
var propertyId = media.getProperty(Constants.Conventions.Media.File).Id;
// Get paths
var destFilePath = FileSystem.GetRelativePath(propertyId, uploadedFile.FileName);
var ext = Path.GetExtension(destFilePath).Substring(1);
//var absoluteDestPath = HttpContext.Current.Server.MapPath(destPath);
//var absoluteDestFilePath = HttpContext.Current.Server.MapPath(destFilePath);
// Set media properties
media.getProperty(Constants.Conventions.Media.File).Value = FileSystem.GetUrl(destFilePath);
media.getProperty(Constants.Conventions.Media.Bytes).Value = uploadedFile.ContentLength;
if (media.getProperty(Constants.Conventions.Media.Extension) != null)
media.getProperty(Constants.Conventions.Media.Extension).Value = ext;
// Legacy: The 'extensio' typo applied to MySQL (bug in install script, prior to v4.6.x)
if (media.getProperty("umbracoExtensio") != null)
media.getProperty("umbracoExtensio").Value = ext;
FileSystem.AddFile(destFilePath, uploadedFile.InputStream, uploadedFile.ReplaceExisting);
// Save media
media.Save();
}
示例8: Delete
public bool Delete()
{
cms.businesslogic.media.Media d = new cms.businesslogic.media.Media(ParentID);
// Log
BusinessLogic.Log.Add(BusinessLogic.LogTypes.Delete, User.GetCurrent(), d.Id, "");
d.delete();
return true;
}
示例9: Delete
public bool Delete()
{
cms.businesslogic.media.Media d = new cms.businesslogic.media.Media(ParentID);
// Log
LogHelper.Debug<mediaTasks>(string.Format("Delete media item {0} by user {1}", d.Id, User.GetCurrent().Id));
d.delete();
return true;
}
示例10: GetAncestorMedia
/// <summary>
/// Functionally similar to the XPath axis 'ancestor'
/// </summary>
/// <param name="media">an umbraco.cms.businesslogic.media.Media object</param>
/// <returns>Media nodes as IEnumerable</returns>
public static IEnumerable<Media> GetAncestorMedia(this Media media)
{
var ancestor = new Media(media.Parent.Id);
while (ancestor != null)
{
yield return ancestor;
ancestor = new Media(ancestor.Parent.Id);
}
}
示例11: GetSiblingMedia
/// <summary>
/// Gets all sibling Media
/// </summary>
/// <param name="media">an umbraco.cms.businesslogic.media.Media object</param>
/// <returns>Media nodes as IEnumerable</returns>
public static IEnumerable<Media> GetSiblingMedia(this Media media)
{
if (media.Parent != null)
{
var parentMedia = new Media(media.Parent.Id);
foreach (var siblingMedia in parentMedia.GetChildMedia().Where(childMedia => childMedia.Id != media.Id))
{
yield return siblingMedia;
}
}
}
示例12: DoHandleMedia
public override void DoHandleMedia(Media media, PostedMediaFile postedFile, BusinessLogic.User user)
{
// Get Image object, width and height
var image = System.Drawing.Image.FromStream(postedFile.InputStream);
var fileWidth = image.Width;
var fileHeight = image.Height;
// Get umbracoFile property
var propertyId = media.getProperty("umbracoFile").Id;
// Get paths
var destFileName = ConstructDestFileName(propertyId, postedFile.FileName);
var destPath = ConstructDestPath(propertyId);
var destFilePath = VirtualPathUtility.Combine(destPath, destFileName);
var ext = VirtualPathUtility.GetExtension(destFileName).Substring(1);
var absoluteDestPath = HttpContext.Current.Server.MapPath(destPath);
var absoluteDestFilePath = HttpContext.Current.Server.MapPath(destFilePath);
// Set media properties
media.getProperty("umbracoFile").Value = destFilePath;
media.getProperty("umbracoWidth").Value = fileWidth;
media.getProperty("umbracoHeight").Value = fileHeight;
media.getProperty("umbracoBytes").Value = postedFile.ContentLength;
if (media.getProperty("umbracoExtension") != null)
media.getProperty("umbracoExtension").Value = ext;
if (media.getProperty("umbracoExtensio") != null)
media.getProperty("umbracoExtensio").Value = ext;
// Create directory
if (UmbracoSettings.UploadAllowDirectories)
Directory.CreateDirectory(absoluteDestPath);
// Generate thumbnail
var thumbDestFilePath = Path.Combine(absoluteDestPath, Path.GetFileNameWithoutExtension(destFileName) + "_thumb");
GenerateThumbnail(image, 100, fileWidth, fileHeight, thumbDestFilePath + ".jpg");
// Generate additional thumbnails based on PreValues set in DataTypeDefinition uploadField
GenerateAdditionalThumbnails(image, fileWidth, fileHeight, thumbDestFilePath);
image.Dispose();
// Save file
postedFile.SaveAs(absoluteDestFilePath);
// Close stream
postedFile.InputStream.Close();
// Save media
media.Save();
}
示例13: CanHandleMedia
public virtual bool CanHandleMedia(int parentNodeId, PostedMediaFile postedFile, User user)
{
try
{
var parentNode = new Media(parentNodeId);
return parentNodeId <= -1 || user.Applications.Any(app => app.alias.ToLower() == Constants.Applications.Media) && (user.StartMediaId <= 0 || ("," + parentNode.Path + ",").Contains("," + user.StartMediaId + ",")) && parentNode.ContentType.AllowedChildContentTypeIDs.Contains(MediaType.GetByAlias(MediaTypeAlias).Id);
}
catch
{
return false;
}
}
示例14: GetLinkValue
/// <summary>
/// Returns the value for a link in WYSIWYG mode, by default only media items that have a
/// DataTypeUploadField are linkable, however, a custom tree can be created which overrides
/// this method, or another GUID for a custom data type can be added to the LinkableMediaDataTypes
/// list on application startup.
/// </summary>
/// <param name="dd"></param>
/// <param name="nodeLink"></param>
/// <returns></returns>
public virtual string GetLinkValue(Media dd, string nodeLink)
{
var props = dd.getProperties;
foreach (Property p in props)
{
Guid currId = p.PropertyType.DataTypeDefinition.DataType.Id;
if (LinkableMediaDataTypes.Contains(currId) && !String.IsNullOrEmpty(p.Value.ToString()))
{
return p.Value.ToString();
}
}
return "";
}
示例15: GetProperty
public System.Xml.Linq.XElement GetProperty(umbraco.cms.businesslogic.property.Property prop)
{
//get access to media item based on some path.
try
{
var mediaItem = new Media(int.Parse(prop.Value.ToString()));
return new XElement(prop.PropertyType.Alias, mediaItem.ConfigPath());
}
catch { }
return new XElement(prop.PropertyType.Alias, "");
}