DO NOT DOWNLOAD. DOWNLOAD LATEST STABLE FROM RELEASE TAB

support for a full cancelable event model on document

[TFS Changeset #56025]
This commit is contained in:
slace
2009-07-06 12:04:51 +00:00
parent b30c526bd3
commit eed74f864e
5 changed files with 164 additions and 43 deletions

View File

@@ -81,6 +81,10 @@ namespace umbraco.cms.businesslogic {
get { return Application.SqlHelper; }
}
public CMSNode()
{
throw new NotSupportedException();
}
/// <summary>
/// Initializes a new instance of the <see cref="CMSNode"/> class.

View File

@@ -32,6 +32,11 @@ namespace umbraco.cms.businesslogic
private bool _propertiesInitialized = false;
private Properties _properties = new Properties();
public Content()
{
throw new NotSupportedException();
}
/// <summary>
///
/// </summary>

View File

@@ -39,5 +39,12 @@ namespace umbraco.cms.businesslogic {
public class RemoveMemberShipUserFromDocumentEventArgs : System.ComponentModel.CancelEventArgs { }
public class AddMembershipUserToDocumentEventArgs : System.ComponentModel.CancelEventArgs { }
//Document Events Arguments
public class DocumentNewingEventArgs : System.ComponentModel.CancelEventArgs
{
public string Text { get; internal set; }
public umbraco.BusinessLogic.User User { get; internal set; }
public umbraco.cms.businesslogic.web.DocumentType DocumentType { get; internal set; }
public int ParentId { get; internal set; }
}
}

View File

@@ -12,6 +12,10 @@ using umbraco.cms.businesslogic.property;
using umbraco.cms.businesslogic.relation;
using umbraco.cms.helpers;
using umbraco.DataLayer;
using System.Collections.Generic;
using umbraco.cms.businesslogic.propertytype;
using System.Linq;
using System.ComponentModel;
namespace umbraco.cms.businesslogic.web
{
@@ -33,6 +37,7 @@ namespace umbraco.cms.businesslogic.web
private XmlNode _xml;
private User _creator;
private User _writer;
private bool _optimizedMode;
// special for passing httpcontext object
private HttpContext _httpContext;
@@ -347,7 +352,11 @@ namespace umbraco.cms.businesslogic.web
setupDocument();
}
public Document(bool OptimizedMode, int id) : base(id, true)
public Document(bool OptimizedMode, int id) : base(id, OptimizedMode)
{
this._optimizedMode = OptimizedMode;
if (OptimizedMode)
{
using (IRecordsReader dr =
SqlHelper.ExecuteReader(
@@ -423,6 +432,12 @@ namespace umbraco.cms.businesslogic.web
}
}
}
}
public Document()
{
}
/// <summary>
/// Used to persist object changes to the database. In Version3.0 it's just a stub for future compatibility
@@ -433,6 +448,20 @@ namespace umbraco.cms.businesslogic.web
FireBeforeSave(e);
if (!e.Cancel) {
if (this._optimizedMode)
{
//I'd like to see this work by making a single SQL query
//all in due time ;)
foreach (var property in this._knownProperties)
{
var pt = property.Key;
pt.Value = property.Value;
}
}
base.Save();
Index(true);
FireAfterSave(e);
@@ -683,13 +712,29 @@ namespace umbraco.cms.businesslogic.web
/// <returns>The newly created document</returns>
public static Document MakeNew(string Name, DocumentType dct, User u, int ParentId)
{
//allows you to cancel a document before anything goes to the DB
var newingArgs = new DocumentNewingEventArgs()
{
Text = Name,
DocumentType = dct,
User = u,
ParentId = ParentId
};
Document.Newing(null, newingArgs);
if (newingArgs.Cancel)
{
return null;
}
Guid newId = Guid.NewGuid();
Document tmp = new Document(newId, true);
// Updated to match level from base node
CMSNode n = new CMSNode(ParentId);
int newLevel = n.Level;
newLevel++;
MakeNew(ParentId, _objectType, u.Id, newLevel, Name, newId);
Document tmp = new Document(newId, true);
tmp.CreateContent(dct);
SqlHelper.ExecuteNonQuery("insert into cmsDocument (newest, nodeId, published, documentUser, versionId, Text) values (1, " +
tmp.Id + ", 0, " +
@@ -1343,6 +1388,16 @@ order by umbracoNode.sortOrder
New(this, e);
}
//TODO: Slace - Document this
public static event EventHandler<DocumentNewingEventArgs> Newing;
protected virtual void OnNewing(DocumentNewingEventArgs e)
{
if (Newing != null)
{
Newing(this, e);
}
}
/// <summary>
/// Occurs when [before delete].
/// </summary>
@@ -1556,6 +1611,48 @@ order by umbracoNode.sortOrder
if (AfterAddToIndex != null)
AfterAddToIndex(this, e);
}
private Dictionary<Property, object> _knownProperties;
private Func<KeyValuePair<Property, object>, string, bool> propertyTypeByAlias = (pt, alias) => pt.Key.PropertyType.Alias == alias;
public object this[string alias]
{
get
{
if (this._optimizedMode)
{
if (this._knownProperties == null) this._knownProperties = new Dictionary<Property, object>();
return this._knownProperties.Single(p => propertyTypeByAlias(p, alias)).Value;
}
else
{
return this.getProperty(alias).Value;
}
}
set
{
if (this._optimizedMode)
{
if (this._knownProperties == null) this._knownProperties = new Dictionary<Property, object>();
if (this._knownProperties.SingleOrDefault(p => propertyTypeByAlias(p, alias)).Key == null)
{
var pt = this.getProperty(alias);
this._knownProperties.Add(pt, pt.Value);
}
else
{
var pt = this._knownProperties.Single(p => propertyTypeByAlias(p, alias)).Key;
this._knownProperties[pt] = value;
}
}
else
{
this.getProperty(alias).Value = value;
}
}
}
}
/// <summary>
@@ -1614,6 +1711,5 @@ order by umbracoNode.sortOrder
_text = Text;
_user = User;
}
}
}

View File

@@ -747,9 +747,18 @@ namespace umbraco
{
cms.businesslogic.web.DocumentType dt = new cms.businesslogic.web.DocumentType(TypeID);
cms.businesslogic.web.Document d = cms.businesslogic.web.Document.MakeNew(Alias, dt, BusinessLogic.User.GetUser(_userID), ParentID);
if (d == null)
{
//TODO: This should do some kind of notification to the user. The Page object would be nice about now! :P
BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.error, "Document Creation", "Document creation was canceled");
return false;
}
else
{
_returnUrl = "editContent.aspx?id=" + d.Id.ToString() + "&isNew=true";
return true;
}
}
public bool Delete()
{