Files
Umbraco-CMS/src/Umbraco.Core/Models/File.cs
Shannon Deminick 52f05612ad Adds another method of distributed cache syncing using a custom json payload. this is necessary for things like ContentType cache
updates especially when deleting one since we require all sorts of Ids from the object but the object will be deleted by the time
the request reaches other servers so instead we create a json payload to send to other servers which contains all information necessary
to refresh/clear the cache on the other servers. This will probably be the preferred way going forward to handle cache refreshing.
With this in place, when removing a conent type cache is removed based on events.
This also adds a 'class' generic argument constraint to the repository base classes to guarantee we can do null checks and then we also
fix a null check on RepositoryBase. Updates the Entity class to properly support tracking properties - this now allows us to determine if
an entity was new, which is now used to ensure we don't re-update all of the content cache when a new content type is created.
Have also changed the deletion and creation of document types to use the new API, this allows for a lot less processing and streamlining how
all cache is invalidated. Fixes the construction of a new Template and Content Type in the v6 api and ensures that default values are set - #U4-1972, #U4-1971
2013-03-21 08:38:18 +06:00

94 lines
2.8 KiB
C#

using System;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents an abstract file which provides basic functionality for a File with an Alias and Name
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
public abstract class File : Entity, IFile
{
private string _path;
private string _content = string.Empty; //initialize to empty string, not null
protected File(string path)
{
_path = path;
}
private static readonly PropertyInfo ContentSelector = ExpressionHelper.GetPropertyInfo<File, string>(x => x.Content);
private static readonly PropertyInfo PathSelector = ExpressionHelper.GetPropertyInfo<File, string>(x => x.Path);
/// <summary>
/// Gets or sets the Name of the File including extension
/// </summary>
[DataMember]
public virtual string Name
{
get
{
return new FileInfo(Path).Name;
}
}
/// <summary>
/// Gets or sets the Alias of the File, which is the name without the extension
/// </summary>
[DataMember]
public virtual string Alias
{
get
{
var fileInfo = new FileInfo(Path);
var name = fileInfo.Name;
int lastIndexOf = name.LastIndexOf(".", StringComparison.InvariantCultureIgnoreCase);
return name.Substring(0, lastIndexOf);
}
}
/// <summary>
/// Gets or sets the Path to the File from the root of the site
/// </summary>
[DataMember]
public virtual string Path
{
get { return _path; }
set
{
SetPropertyValueAndDetectChanges(o =>
{
_path = value;
return _path;
}, _path, PathSelector);
}
}
/// <summary>
/// Gets or sets the Content of a File
/// </summary>
[DataMember]
public virtual string Content
{
get { return _content; }
set
{
SetPropertyValueAndDetectChanges(o =>
{
_content = value;
return _content;
}, _content, ContentSelector);
}
}
/// <summary>
/// Boolean indicating whether the file could be validated
/// </summary>
/// <returns>True if file is valid, otherwise false</returns>
public abstract bool IsValid();
}
}