[Nmailserver-commits] SF.net SVN: nmailserver: [185] NMail/trunk/NMail
Brought to you by:
dframpton-oss,
tmyroadctfig
|
From: <tmy...@us...> - 2007-04-24 12:45:08
|
Revision: 185
http://svn.sourceforge.net/nmailserver/?rev=185&view=rev
Author: tmyroadctfig
Date: 2007-04-24 05:45:08 -0700 (Tue, 24 Apr 2007)
Log Message:
-----------
Further work on local store data and unit tests.
Modified Paths:
--------------
NMail/trunk/NMail/DataTypes/LocalStore/ILocalStoreData.cs
NMail/trunk/NMail.LocalStore/LocalStore.cs
NMail/trunk/NMail.LocalStoreData.MySql/MySqlLocalStoreData.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.csproj
NMail/trunk/NMail.UnitTests/NMail.UnitTests.csproj
Added Paths:
-----------
NMail/trunk/NMail.LocalStoreData.NHibernate/InternalMessage.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/InternalStoreFolder.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/InternalStoreFolderAcl.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalMessage.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalStoreFolder.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalStoreFolderAcl.hbm.xml
NMail/trunk/NMail.UnitTests/LocalStoreData/CreateGroupTest1.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/CreateGroupTest2.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/DeleteGroupTest1.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderChildrenTest1.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderTest1.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderTest2.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/RemoveStoreFolderAceTest1.cs
Removed Paths:
-------------
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.ACLs.StoreFolderAcl.hbm.xml
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.StoreFolder.hbm.xml
Modified: NMail/trunk/NMail/DataTypes/LocalStore/ILocalStoreData.cs
===================================================================
--- NMail/trunk/NMail/DataTypes/LocalStore/ILocalStoreData.cs 2007-04-19 12:09:29 UTC (rev 184)
+++ NMail/trunk/NMail/DataTypes/LocalStore/ILocalStoreData.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -46,8 +46,8 @@
/// Delivers the message into the given folder.
/// </summary>
/// <param name="message">The message data.</param>
- /// <param name="folder">The folder to deliver into.</param>
- void DeliverMessage(Message message, StoreFolder folder);
+ /// <param name="folder">The Id of the folder to deliver into.</param>
+ void DeliverMessage(Message message, int folderId);
#endregion
#region Folder Retrieval and Manipulation
Modified: NMail/trunk/NMail.LocalStore/LocalStore.cs
===================================================================
--- NMail/trunk/NMail.LocalStore/LocalStore.cs 2007-04-19 12:09:29 UTC (rev 184)
+++ NMail/trunk/NMail.LocalStore/LocalStore.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -204,7 +204,7 @@
/// <returns>The result of the delivery.</returns>
public DeliveryResult DeliverMessage(IAuthenticationToken authToken, Message message, StoreFolder folder) {
- LocalStoreData.DeliverMessage(message, folder);
+ LocalStoreData.DeliverMessage(message, folder.FolderId);
return new DeliveryResult(DeliveryResultType.Success, null);
// TODO: lookup a maildomain or a system wide delivery chain to process the message
Modified: NMail/trunk/NMail.LocalStoreData.MySql/MySqlLocalStoreData.cs
===================================================================
--- NMail/trunk/NMail.LocalStoreData.MySql/MySqlLocalStoreData.cs 2007-04-19 12:09:29 UTC (rev 184)
+++ NMail/trunk/NMail.LocalStoreData.MySql/MySqlLocalStoreData.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -63,14 +63,14 @@
// TODO: update quotas?
public void DeliverMessage(LocalStoreDelivery message) {
- DeliverMessage(message.Message, GetStoreFolder(message.TargetFolder));
+ DeliverMessage(message.Message, GetStoreFolder(message.TargetFolder).FolderId);
foreach (StoreFolder folder in message.AdditionalFolders) {
- DeliverMessage(message.Message, GetStoreFolder(folder));
+ DeliverMessage(message.Message, GetStoreFolder(folder).FolderId);
}
}
- public void DeliverMessage(Message message, StoreFolder folder) {
+ public void DeliverMessage(Message message, int folderId) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
MySqlTransaction transaction = null;
@@ -83,7 +83,7 @@
// Get the next folder message id
cmd.CommandText = "SELECT NextMessageId FROM Folder WHERE FolderId=?FolderId";
- cmd.Parameters.Add("?FolderId", folder.FolderId);
+ cmd.Parameters.Add("?FolderId", folderId);
int folderMessageId = (int)cmd.ExecuteScalar();
// Update the next message id
@@ -91,7 +91,7 @@
cmd.Transaction = transaction;
cmd.Connection = cnn;
cmd.CommandText = "UPDATE Folder SET NextMessageId=?NextMessageId WHERE FolderId=?FolderId";
- cmd.Parameters.Add("?FolderId", folder.FolderId);
+ cmd.Parameters.Add("?FolderId", folderId);
cmd.Parameters.Add("?NextMessageId", folderMessageId + 1);
int count = cmd.ExecuteNonQuery();
if (count == 1) {
@@ -101,7 +101,7 @@
cmd.Connection = cnn;
cmd.CommandText = "INSERT INTO Message (FolderId, FolderMessageId, MimeMessage, Headers, Preamble, Postamble, MessageFlags, Size, InternalDate) " +
"VALUES (?FolderId, ?FolderMessageId, ?MimeMessage, ?Headers, ?Preamble, ?Postamble, ?MessageFlags, ?Size, ?InternalDate)";
- cmd.Parameters.Add("?FolderId", folder.FolderId);
+ cmd.Parameters.Add("?FolderId", folderId);
cmd.Parameters.Add("?FolderMessageId", folderMessageId);
cmd.Parameters.Add("?MimeMessage", message.MultipartBody);
cmd.Parameters.Add("?Headers", message.Headers.Data.Bytes);
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/InternalMessage.cs
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/InternalMessage.cs (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/InternalMessage.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,104 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NMail.DataTypes;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.LocalStoreData.NHibernate {
+
+ internal class InternalMessage {
+
+ internal InternalMessage() { }
+
+ internal InternalMessage(Message message) {
+ this.mimeMessage = message.MultipartBody;
+ this.headers = message.Headers;
+ this.preamble = message.Preamble;
+ this.postamble = message.Postamble;
+
+ if (this.mimeMessage) {
+ this.mimeParts = message.MimeParts;
+ } else {
+ this.simpleBody = message.BodyData;
+ }
+ }
+
+ private long messageId;
+
+ internal long MessageId {
+ get { return messageId; }
+ set { messageId = value; }
+ }
+
+ private int folderMessageId;
+
+ internal int FolderMessageId {
+ get { return folderMessageId; }
+ set { folderMessageId = value; }
+ }
+
+ private int folderId;
+
+ internal int FolderId {
+ get { return folderId; }
+ set { folderId = value; }
+ }
+
+ private bool mimeMessage;
+
+ internal bool MimeMessage {
+ get { return this.mimeMessage; }
+ set { this.mimeMessage = value; }
+ }
+
+ private MessageHeaders headers;
+
+ internal MessageHeaders Headers {
+ get { return headers; }
+ set { headers = value; }
+ }
+
+ private IMessagePart preamble;
+
+ internal IMessagePart Preamble {
+ get { return preamble; }
+ set { preamble = value; }
+ }
+
+ private IMessagePart postamble;
+
+ internal IMessagePart Postamble {
+ get { return postamble; }
+ set { postamble = value; }
+ }
+
+ private StoreMessageFlags messageFlags;
+
+ internal StoreMessageFlags MessageFlags {
+ get { return messageFlags; }
+ set { messageFlags = value; }
+ }
+
+ private DateTime internalDate;
+
+ internal DateTime InternalDate {
+ get { return internalDate; }
+ set { internalDate = value; }
+ }
+
+ private ByteString simpleBody;
+
+ internal ByteString SimpleBody {
+ get { return simpleBody; }
+ set { simpleBody = value; }
+ }
+
+ private IList<IMessageBodyPart> mimeParts;
+
+ internal IList<IMessageBodyPart> MimeParts {
+ get { return mimeParts; }
+ set { mimeParts = value; }
+ }
+ }
+}
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/InternalStoreFolder.cs
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/InternalStoreFolder.cs (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/InternalStoreFolder.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NMail.DataTypes;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.LocalStoreData.NHibernate {
+ [Serializable]
+ internal class InternalStoreFolder : StoreFolder {
+
+ internal InternalStoreFolder() { }
+
+ /// <summary>
+ /// Creates a new store folder.
+ /// </summary>
+ /// <param name="newFolder">The folder name.</param>
+ internal InternalStoreFolder(string newFolder) : base(newFolder) { }
+
+ /// <summary>
+ /// Creates a new store folder.
+ /// </summary>
+ /// <param name="newNameSpace">The namespace the folder belongs to.</param>
+ /// <param name="newFolder">The folder name.</param>
+ internal InternalStoreFolder(string newNameSpace, string newFolder) : base(newNameSpace, newFolder) { }
+
+ /// <summary>
+ /// Creates a new store folder.
+ /// </summary>
+ /// <param name="parent">The parent folder.</param>
+ /// <param name="childName">The name of this folder.</param>
+ internal InternalStoreFolder(Folder parent, string childName) : base(parent, childName) { }
+
+ internal InternalStoreFolder(StoreFolder f) {
+ this.ChildIds = f.ChildIds;
+ this.FolderId = f.FolderId;
+ this.FullFolderName = f.FullFolderName;
+ this.HasChildren = f.HasChildren;
+ this.NameSpace = f.NameSpace;
+ this.OwnerUserId = f.OwnerUserId;
+ this.ParentId = f.ParentId;
+ }
+
+ private int nextMessageId;
+
+ public int NextMessageId {
+ get { return nextMessageId; }
+ set { nextMessageId = value; }
+ }
+ }
+}
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/InternalStoreFolderAcl.cs
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/InternalStoreFolderAcl.cs (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/InternalStoreFolderAcl.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NMail.DataTypes.ACLs;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.LocalStoreData.NHibernate {
+
+ internal class InternalStoreFolderAcl : GenericAcl<StoreFolderPrivilege> {
+
+ internal InternalStoreFolderAcl() { }
+
+ internal InternalStoreFolderAcl(StoreFolder folder) : base() {
+ this.folder = new InternalStoreFolder(folder);
+ }
+
+ internal InternalStoreFolderAcl(StoreFolderAcl acl) : base() {
+ this.folder = new InternalStoreFolder(acl.Folder);
+ this.aclId = acl.AclId;
+ }
+
+ internal StoreFolderAcl CreateStoreFolderAcl() {
+ StoreFolderAcl result = new StoreFolderAcl(this.folder);
+ result.AclId = this.aclId;
+
+ IEnumerator<KeyValuePair<string, GenericAce<StoreFolderPrivilege>>> e = this.entries.GetEnumerator();
+ while (e.MoveNext()) {
+ result.SetAce(e.Current.Value);
+ }
+
+ return result;
+ }
+
+ private int aclId;
+
+ /// <summary>
+ /// The Id of this store folder ACL.
+ /// </summary>
+ public int AclId {
+ get { return aclId; }
+ set { aclId = value; }
+ }
+
+ private InternalStoreFolder folder;
+
+ /// <summary>
+ /// The folder associated with this ACL.
+ /// </summary>
+ public InternalStoreFolder Folder {
+ get {
+ return this.folder;
+ }
+ set {
+ this.folder = value;
+ }
+ }
+ }
+}
Deleted: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.ACLs.StoreFolderAcl.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.ACLs.StoreFolderAcl.hbm.xml 2007-04-19 12:09:29 UTC (rev 184)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.ACLs.StoreFolderAcl.hbm.xml 2007-04-24 12:45:08 UTC (rev 185)
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
-
- <class name="NMail.DataTypes.ACLs.StoreFolderAcl" table="StoreFolderAcl">
- <id name="AclId" type="Int32" unsaved-value="0">
- <column name="AclId" not-null="true"/>
- <generator class="native" />
- </id>
-
- <many-to-one name="Folder" cascade="all" class="NMail.DataTypes.LocalStore.StoreFolder" not-null="true"/>
-
- <map name="entries" access="field" table="StoreFolderAclEntries">
- <key column="IdentifierId" />
- <index column="Identifier" type="String" />
- <element column="StoreFolderPrivilege" type="Serializable" />
- </map>
- </class>
-
-</hibernate-mapping>
\ No newline at end of file
Deleted: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.StoreFolder.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.StoreFolder.hbm.xml 2007-04-19 12:09:29 UTC (rev 184)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.DataTypes.LocalStore.StoreFolder.hbm.xml 2007-04-24 12:45:08 UTC (rev 185)
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail" assembly="NMail" default-lazy="false">
-
- <class name="NMail.DataTypes.LocalStore.StoreFolder" table="Folder">
- <id name="FolderId" type="Int32" unsaved-value="0">
- <column name="FolderId" not-null="true"/>
- <generator class="native" />
- </id>
-
- <property name="FullFolderName" not-null="true"/>
-
- <property name="NameSpace" not-null="true" />
-
- <!-- TODO: ideally this would be a many-to-one relationship with StoreFolder -->
- <property name="ParentId" type="System.Int32" />
-
- <!-- TODO: ideally this would be a many-to-one relationship with LocalStoreUser -->
- <property name="OwnerUserId" not-null="true" />
-
- <list name="ChildIds" cascade="all" table="FolderChildren">
- <key column="FolderId" />
- <index column="ChildIndex" type="Int32" />
- <element column="ChildId" type="Int32" />
- </list>
- </class>
-
-</hibernate-mapping>
\ No newline at end of file
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalMessage.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalMessage.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalMessage.hbm.xml 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail.LocalStoreData.NHibernate" assembly="NMail.LocalStoreData.NHibernate" default-lazy="false">
+
+ <class name="NMail.LocalStoreData.NHibernate.InternalMessage" table="InternalMessage">
+ <id name="MessageId" type="Int64" unsaved-value="0">
+ <column name="MessageId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <property name="FolderMessageId" not-null="true"/>
+
+ <property name="FolderId" not-null="true"/>
+
+ <property name="MimeMessage" not-null="true"/>
+
+ <property name="Headers" not-null="true"/>
+
+ <property name="Preamble" not-null="true" type="Serializable"/>
+
+ <property name="Postamble" not-null="true" type="Serializable"/>
+
+ <property name="MessageFlags" not-null="true"/>
+
+ <property name="InternalDate" not-null="true"/>
+
+ <property name="SimpleBody" type="Serializable"/>
+
+ <list name="MimeParts" table="InternalMessageMimeParts" cascade="all">
+ <key column="MimePartId" />
+ <index column="PartNumber" type="Int32" />
+ <element column="Part" type="Serializable"/>
+ </list>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalStoreFolder.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalStoreFolder.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalStoreFolder.hbm.xml 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail.LocalStoreData.NHibernate" assembly="NMail.LocalStoreData.NHibernate" default-lazy="false">
+
+ <class name="NMail.LocalStoreData.NHibernate.InternalStoreFolder" table="Folder">
+ <id name="FolderId" type="Int32" unsaved-value="0">
+ <column name="FolderId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <property name="FullFolderName" not-null="true"/>
+
+ <property name="NameSpace" not-null="true" />
+
+ <!-- TODO: ideally this would be a many-to-one relationship with StoreFolder -->
+ <property name="ParentId" type="System.Int32" />
+
+ <!-- TODO: ideally this would be a many-to-one relationship with LocalStoreUser -->
+ <property name="OwnerUserId" not-null="true" />
+
+ <list name="ChildIds" cascade="all" table="FolderChildren">
+ <key column="FolderId" />
+ <index column="ChildIndex" type="Int32" />
+ <element column="ChildId" type="Int32" />
+ </list>
+
+ <property name="NextMessageId" not-null="true"/>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalStoreFolderAcl.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalStoreFolderAcl.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.InternalStoreFolderAcl.hbm.xml 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NMail.LocalStoreData.NHibernate" assembly="NMail.LocalStoreData.NHibernate" default-lazy="false">
+
+ <class name="NMail.LocalStoreData.NHibernate.InternalStoreFolderAcl" table="StoreFolderAcl">
+ <id name="AclId" type="Int32" unsaved-value="0">
+ <column name="AclId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <many-to-one name="Folder" cascade="all" class="NMail.LocalStoreData.NHibernate.InternalStoreFolder" not-null="true"/>
+
+ <map name="entries" access="field" table="StoreFolderAclEntries">
+ <key column="IdentifierId" />
+ <index column="Identifier" type="String" />
+ <element column="StoreFolderPrivilege" type="Serializable" />
+ </map>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Modified: NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs 2007-04-19 12:09:29 UTC (rev 184)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -55,120 +55,46 @@
#region ILocalStoreData Members
#region Message Delivery
-
- // TODO: update quotas?
+ /// <summary>
+ /// Delivers the message into the given folder.
+ /// </summary>
+ /// <param name="message">The details of the delivery.</param>
public void DeliverMessage(LocalStoreDelivery message) {
- DeliverMessage(message.Message, GetStoreFolder(message.TargetFolder));
+ DeliverMessage(message.Message, GetStoreFolder(message.TargetFolder).FolderId);
foreach (StoreFolder folder in message.AdditionalFolders) {
- DeliverMessage(message.Message, GetStoreFolder(folder));
+ DeliverMessage(message.Message, GetStoreFolder(folder).FolderId);
}
}
- public void DeliverMessage(Message message, StoreFolder folder) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // MySqlTransaction transaction = null;
+ /// <summary>
+ /// Delivers the message into the given folder.
+ /// </summary>
+ /// <param name="message">The message data.</param>
+ /// <param name="folder">The Id of the folder to deliver into.</param>
+ public void DeliverMessage(Message message, int folderId) {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ using (ITransaction tx = session.BeginTransaction()) {
+ // Get the next folder message id
+ InternalStoreFolder folder = session.Load<InternalStoreFolder>(folderId);
+ int nextFolderMessageId = folder.NextMessageId;
- // try {
- // transaction = cnn.BeginTransaction();
+ // Update the next message id
+ folder.NextMessageId++;
+ session.Update(folder);
- // MySqlCommand cmd = cnn.CreateCommand();
- // cmd.Transaction = transaction;
- // cmd.Connection = cnn;
+ // Save the message details and data
+ InternalMessage internalMessage = new InternalMessage(message);
+ internalMessage.FolderId = folderId;
+ internalMessage.FolderMessageId = nextFolderMessageId;
+ internalMessage.InternalDate = DateTime.Now;
+ internalMessage.MessageFlags = StoreMessageFlags.Recent;
+ session.Save(internalMessage);
- // // Get the next folder message id
- // cmd.CommandText = "SELECT NextMessageId FROM Folder WHERE FolderId=?FolderId";
- // cmd.Parameters.Add("?FolderId", folder.FolderId);
- // int folderMessageId = (int)cmd.ExecuteScalar();
-
- // // Update the next message id
- // cmd = cnn.CreateCommand();
- // cmd.Transaction = transaction;
- // cmd.Connection = cnn;
- // cmd.CommandText = "UPDATE Folder SET NextMessageId=?NextMessageId WHERE FolderId=?FolderId";
- // cmd.Parameters.Add("?FolderId", folder.FolderId);
- // cmd.Parameters.Add("?NextMessageId", folderMessageId + 1);
- // int count = cmd.ExecuteNonQuery();
- // if (count == 1) {
- // // Insert the message body
- // cmd = cnn.CreateCommand();
- // cmd.Transaction = transaction;
- // cmd.Connection = cnn;
- // cmd.CommandText = "INSERT INTO Message (FolderId, FolderMessageId, MimeMessage, Headers, Preamble, Postamble, MessageFlags, Size, InternalDate) " +
- // "VALUES (?FolderId, ?FolderMessageId, ?MimeMessage, ?Headers, ?Preamble, ?Postamble, ?MessageFlags, ?Size, ?InternalDate)";
- // cmd.Parameters.Add("?FolderId", folder.FolderId);
- // cmd.Parameters.Add("?FolderMessageId", folderMessageId);
- // cmd.Parameters.Add("?MimeMessage", message.MultipartBody);
- // cmd.Parameters.Add("?Headers", message.Headers.Data.Bytes);
- // cmd.Parameters.Add("?Preamble", (message.Preamble != null) ? message.Preamble.Data.Bytes : null);
- // cmd.Parameters.Add("?Postamble", (message.Postamble != null) ? message.Postamble.Data.Bytes : null);
- // cmd.Parameters.Add("?MessageFlags", StoreMessageFlags.Recent);
- // cmd.Parameters.Add("?Size", message.Size);
- // cmd.Parameters.Add("?InternalDate", DateTime.Now);
- // count = cmd.ExecuteNonQuery();
-
- // if (count == 1) {
- // // Get the message Id
- // cmd = cnn.CreateCommand();
- // cmd.Transaction = transaction;
- // cmd.Connection = cnn;
- // cmd.CommandText = "SELECT LAST_INSERT_ID()";
- // long messageId = (long)cmd.ExecuteScalar(); ;
-
- // if (message.MultipartBody) {
- // // Insert each part of the message
- // for (int i = 0; i < message.MimeParts.Count; i++) {
- // // Insert the current part
- // cmd = cnn.CreateCommand();
- // cmd.Transaction = transaction;
- // cmd.Connection = cnn;
- // cmd.CommandText = "INSERT INTO MessageData (MessageId, Part, Data) " +
- // "VALUES (?MessageId, ?Part, ?Data)";
- // cmd.Parameters.Add("?MessageId", messageId);
- // cmd.Parameters.Add("?Part", i + 1); // Count from 1
- // cmd.Parameters.Add("?Data", message.MimeParts[i].Data.Bytes);
- // count = cmd.ExecuteNonQuery();
-
- // if (count != 1) {
- // // Insert failed, rollback
- // throw new System.Data.DataException("Error inserting message part.");
- // }
- // }
- // } else {
- // // Insert the body data
- // cmd = cnn.CreateCommand();
- // cmd.Transaction = transaction;
- // cmd.Connection = cnn;
-
- // cmd.CommandText = "INSERT INTO MessageData (MessageId, Part, Data) " +
- // "VALUES (?MessageId, 1, ?Data)";
- // cmd.Parameters.Add("?MessageId", messageId);
- // cmd.Parameters.Add("?Data", message.BodyData.Bytes);
- // count = cmd.ExecuteNonQuery();
-
- // if (count != 1) {
- // // Insert failed, rollback
- // throw new System.Data.DataException("Error inserting message body.");
- // }
- // }
- // } else {
- // throw new System.Data.DataException("Error inserting message details.");
- // }
- // } else {
- // throw new System.Data.DataException("Error updating next message id.");
- // }
-
- // transaction.Commit();
-
- // } catch (Exception e) {
- // if (transaction != null) {
- // transaction.Rollback();
- // }
-
- // throw e;
- // }
- //}
- throw new NotImplementedException();
+ tx.Commit();
+ session.Close();
+ }
+ }
}
#endregion
@@ -182,10 +108,10 @@
/// <returns>The store folder or null if the folder name is invalid.</returns>
public StoreFolder GetStoreFolder(Folder folder) {
using (ISession session = this.hibernateFactory.OpenSession()) {
- return session.CreateCriteria(typeof(StoreFolder))
+ return session.CreateCriteria(typeof(InternalStoreFolder))
.Add(Expression.Like("NameSpace", folder.NameSpace))
.Add(Expression.Like("FullFolderName", folder.FullFolderName))
- .UniqueResult<StoreFolder>();
+ .UniqueResult<InternalStoreFolder>();
}
}
@@ -196,7 +122,7 @@
/// <returns>The store folder or null if the folder Id is invalid.</returns>
public StoreFolder GetStoreFolder(int folderId) {
using (ISession session = this.hibernateFactory.OpenSession()) {
- return session.Load<StoreFolder>(folderId);
+ return session.Load<InternalStoreFolder>(folderId);
}
}
#endregion
@@ -241,9 +167,9 @@
// Validate parent details
if (newFolder.Parent != null) {
// Lookup the parent Id
- parentByName = session.CreateCriteria(typeof(StoreFolder))
+ parentByName = session.CreateCriteria(typeof(InternalStoreFolder))
.Add(Expression.Like("FullFolderName", newFolder.Parent.FullFolderName))
- .UniqueResult<StoreFolder>();
+ .UniqueResult<InternalStoreFolder>();
if (parentByName == null) {
throw new InvalidOperationException("Can't find a valid parent folder.");
@@ -268,21 +194,23 @@
}
// Check for any folders with the same name
- ICriteria criteria = session.CreateCriteria(typeof(StoreFolder))
+ ICriteria criteria = session.CreateCriteria(typeof(InternalStoreFolder))
.Add(Expression.Like("FullFolderName", newFolder.FullFolderName));
if (newFolder.ParentId.HasValue) {
criteria = criteria.Add(Expression.Eq("ParentId", newFolder.ParentId));
- }
+ }
- IList<StoreFolder> matching = criteria.List<StoreFolder>();
+ IList<InternalStoreFolder> matching = criteria.List<InternalStoreFolder>();
if (matching.Count > 0) {
throw new DuplicateNameException("Folder with the same name already exists.");
}
// Checks done, save!
- session.Save(newFolder);
+ InternalStoreFolder internalNewFolder = new InternalStoreFolder(newFolder);
+ session.Save(internalNewFolder);
+ newFolder.FolderId = internalNewFolder.FolderId;
// Add an ACL to the folder
GenericAce<StoreFolderPrivilege> ace = new GenericAce<StoreFolderPrivilege>(user.Username, StoreFolderPrivilege.Admin, AcePrivilegeType.Allow);
@@ -309,7 +237,7 @@
public void DeleteFolder(int folderId, bool deleteChildren) {
using (ISession session = this.hibernateFactory.OpenSession()) {
using (ITransaction tx = session.BeginTransaction()) {
- StoreFolder folder = session.Get<StoreFolder>(folderId);
+ InternalStoreFolder folder = session.Get<InternalStoreFolder>(folderId);
if (folder == null) {
throw new ArgumentException("Invalid folder Id.", "folderId");
@@ -321,14 +249,14 @@
DeleteChildrenWithoutUpdate(folder, session);
- DeleteStoreFolderAcl(folderId);
- DeleteSubscriptions(folderId);
+ DeleteStoreFolderAcl(folderId, session);
+ DeleteSubscriptions(folderId, session);
session.Delete(folder);
// Remove the folder from the parent's list of children if present
if (folder.ParentId != null) {
- StoreFolder parent = session.Load<StoreFolder>(folder.ParentId);
+ InternalStoreFolder parent = session.Load<InternalStoreFolder>(folder.ParentId);
parent.ChildIds.Remove(folderId);
session.Update(parent);
}
@@ -345,7 +273,7 @@
/// </summary>
/// <param name="folder">The folder to delete the children from.</param>
/// <param name="session">The session to use.</param>
- protected void DeleteChildrenWithoutUpdate(StoreFolder folder, ISession session) {
+ internal void DeleteChildrenWithoutUpdate(InternalStoreFolder folder, ISession session) {
// Ensure session has started a transaction
if (!session.Transaction.IsActive) {
throw new InvalidOperationException("A transaction is required for this operation.");
@@ -353,14 +281,14 @@
// Delete each child and sub-children
foreach (int childId in folder.ChildIds) {
- StoreFolder child = session.Load<StoreFolder>(childId);
+ InternalStoreFolder child = session.Load<InternalStoreFolder>(childId);
// Recurse down
DeleteChildrenWithoutUpdate(child, session);
// Delete the child at the current level
- DeleteStoreFolderAcl(childId);
- DeleteSubscriptions(childId);
+ DeleteStoreFolderAcl(childId, session);
+ DeleteSubscriptions(childId, session);
session.Delete(child);
}
}
@@ -388,42 +316,42 @@
public void MoveFolder(int folderId, int? parentId, string newFolderName) {
using (ISession session = this.hibernateFactory.OpenSession()) {
using (ITransaction tx = session.BeginTransaction()) {
- StoreFolder currentFolder = session.Load<StoreFolder>(folderId);
- StoreFolder newFolder;
- StoreFolder currentParent;
- StoreFolder newParentFolder = null;
+ InternalStoreFolder currentFolder = session.Load<InternalStoreFolder>(folderId);
+ InternalStoreFolder newFolder;
+ InternalStoreFolder currentParent;
+ InternalStoreFolder newParentFolder = null;
if (parentId.HasValue) {
- newParentFolder = session.Load<StoreFolder>(parentId.Value);
+ newParentFolder = session.Load<InternalStoreFolder>(parentId.Value);
}
if (currentFolder.ParentId.HasValue) {
- currentParent = session.Load<StoreFolder>(currentFolder.ParentId.Value);
+ currentParent = session.Load<InternalStoreFolder>(currentFolder.ParentId.Value);
}
// Setup the new folder
if (newParentFolder != null) {
- newFolder = new StoreFolder(newParentFolder, newFolderName);
+ newFolder = new InternalStoreFolder(newParentFolder, newFolderName);
// Check for any folders with the same name
- IList<StoreFolder> matching = session.CreateCriteria(typeof(StoreFolder))
+ IList<InternalStoreFolder> matching = session.CreateCriteria(typeof(InternalStoreFolder))
.Add(Expression.Like("FullFolderName", newFolder.FullFolderName))
.Add(Expression.Eq("ParentId", parentId))
- .List<StoreFolder>();
+ .List<InternalStoreFolder>();
if (matching.Count > 0) {
throw new DuplicateNameException("Folder with the same name already exists.");
}
} else {
- newFolder = new StoreFolder(currentFolder.NameSpace, newFolderName);
+ newFolder = new InternalStoreFolder(currentFolder.NameSpace, newFolderName);
}
newFolder.ParentId = parentId;
newFolder.OwnerUserId = currentFolder.OwnerUserId;
session.Save(newFolder);
- MoveStoreFolderAcl(folderId, newFolder.FolderId);
- MoveSubscriptions(folderId, newFolder.FolderId);
+ MoveStoreFolderAcl(folderId, newFolder.FolderId, session);
+ MoveSubscriptions(folderId, newFolder.FolderId, session);
// Adjust the details of the child folders and move them across
MoveChildren(newFolder, currentFolder, session);
@@ -440,7 +368,7 @@
/// <param name="newParent">The new parent folder.</param>
/// <param name="oldParent">The old parent folder.</param>
/// <param name="session">The session to use.</param>
- protected void MoveChildren(StoreFolder newParent, StoreFolder oldParent, ISession session) {
+ internal void MoveChildren(InternalStoreFolder newParent, InternalStoreFolder oldParent, ISession session) {
// Ensure session has started a transaction
if (!session.Transaction.IsActive) {
throw new InvalidOperationException("A transaction is required for this operation.");
@@ -448,16 +376,16 @@
// Update each child recursively
foreach (int childId in oldParent.ChildIds) {
- StoreFolder currentChild = session.Load<StoreFolder>(childId);
+ InternalStoreFolder currentChild = session.Load<InternalStoreFolder>(childId);
// Make a new child folder
- StoreFolder newChild = new StoreFolder(newParent, currentChild.FolderName);
+ InternalStoreFolder newChild = new InternalStoreFolder(newParent, currentChild.FolderName);
newChild.ParentId = newParent.FolderId;
newChild.OwnerUserId = currentChild.OwnerUserId;
session.Save(newChild);
- MoveStoreFolderAcl(childId, newChild.FolderId);
- MoveSubscriptions(childId, newChild.FolderId);
+ MoveStoreFolderAcl(childId, newChild.FolderId, session);
+ MoveSubscriptions(childId, newChild.FolderId, session);
// Add the to parent
newParent.ChildIds.Add(newChild.FolderId);
@@ -480,9 +408,9 @@
public IList<StoreFolder> GetChildren(int parentId) {
using (ISession session = this.hibernateFactory.OpenSession()) {
using (ITransaction tx = session.BeginTransaction()) {
- StoreFolder folder = session.Load<StoreFolder>(parentId);
+ InternalStoreFolder folder = session.Load<InternalStoreFolder>(parentId);
- IList<StoreFolder> result = session.CreateCriteria(typeof(StoreFolder))
+ IList<StoreFolder> result = session.CreateCriteria(typeof(InternalStoreFolder))
.Add(Expression.Eq("ParentId", parentId))
.List<StoreFolder>();
@@ -501,7 +429,7 @@
/// <returns>The list of folders.</returns>
public IList<StoreFolder> GetFolders() {
using (ISession session = this.hibernateFactory.OpenSession()) {
- return session.CreateCriteria(typeof(StoreFolder)).List<StoreFolder>();
+ return session.CreateCriteria(typeof(InternalStoreFolder)).List<StoreFolder>();
}
}
#endregion
@@ -513,20 +441,19 @@
/// Deletes all subscriptions from a folder.
/// </summary>
/// <param name="folderId">The Id of the folder to delete the subscriptions from.</param>
- protected void DeleteSubscriptions(int folderId) {
- using (ISession session = this.hibernateFactory.OpenSession()) {
- using (ITransaction tx = session.BeginTransaction()) {
- IList<FolderSubscription> current = session.CreateCriteria(typeof(FolderSubscription))
- .Add(Expression.Eq("FolderId", folderId))
- .List<FolderSubscription>();
+ /// <param name="session">The session to use.</param>
+ protected void DeleteSubscriptions(int folderId, ISession session) {
+ // Ensure session has started a transaction
+ if (!session.Transaction.IsActive) {
+ throw new InvalidOperationException("A transaction is required for this operation.");
+ }
- for (int i = 0; i < current.Count; i++) {
- session.Delete(current[i]);
- }
+ IList<FolderSubscription> current = session.CreateCriteria(typeof(FolderSubscription))
+ .Add(Expression.Eq("FolderId", folderId))
+ .List<FolderSubscription>();
- tx.Commit();
- session.Close();
- }
+ for (int i = 0; i < current.Count; i++) {
+ session.Delete(current[i]);
}
}
#endregion
@@ -537,21 +464,19 @@
/// </summary>
/// <param name="currentFolderId">The current folder Id.</param>
/// <param name="newFolderId">The new folder Id.</param>
- protected void MoveSubscriptions(int currentFolderId, int newFolderId) {
- using (ISession session = this.hibernateFactory.OpenSession()) {
- using (ITransaction tx = session.BeginTransaction()) {
- IList<FolderSubscription> current = session.CreateCriteria(typeof(FolderSubscription))
- .Add(Expression.Eq("FolderId", currentFolderId))
- .List<FolderSubscription>();
+ protected void MoveSubscriptions(int currentFolderId, int newFolderId, ISession session) {
+ // Ensure session has started a transaction
+ if (!session.Transaction.IsActive) {
+ throw new InvalidOperationException("A transaction is required for this operation.");
+ }
+
+ IList<FolderSubscription> current = session.CreateCriteria(typeof(FolderSubscription))
+ .Add(Expression.Eq("FolderId", currentFolderId))
+ .List<FolderSubscription>();
- for (int i = 0; i < current.Count; i++) {
- current[i].FolderId = newFolderId;
- session.Update(current[i]);
- }
-
- tx.Commit();
- session.Close();
- }
+ for (int i = 0; i < current.Count; i++) {
+ current[i].FolderId = newFolderId;
+ session.Update(current[i]);
}
}
#endregion
@@ -574,7 +499,7 @@
folderIds[i] = subscriptionList[i].FolderId;
}
- IList<StoreFolder> subscribed = session.CreateCriteria(typeof(StoreFolder))
+ IList<StoreFolder> subscribed = session.CreateCriteria(typeof(InternalStoreFolder))
.Add(Expression.In("FolderId", folderIds))
.List<StoreFolder>();
@@ -1110,8 +1035,6 @@
inboxFolder.OwnerUserId = user.UserId;
CreateFolder(inboxFolder, session);
- // TODO: ACLs
-
// Set the user's folder Id
user.UserFolderId = userFolder.FolderId;
session.Update(user);
@@ -1191,7 +1114,7 @@
/// <param name="session">The session to use.</param>
/// <returns>The list of folders or null if the user Id is invalid.</returns>
protected IList<StoreFolder> GetUserFolders(int userId, ISession session) {
- return session.CreateCriteria(typeof(StoreFolder))
+ return session.CreateCriteria(typeof(InternalStoreFolder))
.Add(Expression.Eq("OwnerUserId", userId))
.List<StoreFolder>();
}
@@ -1255,9 +1178,9 @@
}
// Check if any other user with the same name exists in the system
- IList<LocalStoreUser> existing = session.CreateCriteria(typeof(LocalStoreGroup))
+ IList<LocalStoreGroup> existing = session.CreateCriteria(typeof(LocalStoreGroup))
.Add(Expression.Like("Name", group.Name))
- .List<LocalStoreUser>();
+ .List<LocalStoreGroup>();
if (existing.Count > 0) {
throw new DuplicateNameException("Group with the same name already exists in the system.");
@@ -1327,27 +1250,26 @@
/// Completely deletes a store folder's ACL.
/// </summary>
/// <param name="folderId">The Id of the folder to delete the ACL for.</param>
- protected void DeleteStoreFolderAcl(int folderId) {
- using (ISession session = this.hibernateFactory.OpenSession()) {
- using (ITransaction tx = session.BeginTransaction()) {
- IList<StoreFolderAcl> current = session.CreateCriteria(typeof(StoreFolderAcl))
- .CreateCriteria("Folder")
- .Add(Expression.Eq("FolderId", folderId))
- .List<StoreFolderAcl>();
+ /// <param name="session">The session to use.</param>
+ protected void DeleteStoreFolderAcl(int folderId, ISession session) {
+ // Ensure session has started a transaction
+ if (!session.Transaction.IsActive) {
+ throw new InvalidOperationException("A transaction is required for this operation.");
+ }
- if (current.Count == 0) {
- // No such ACL
- throw new ArgumentException("Invalid folder Id.");
+ IList<InternalStoreFolderAcl> current = session.CreateCriteria(typeof(InternalStoreFolderAcl))
+ .CreateCriteria("Folder")
+ .Add(Expression.Eq("FolderId", folderId))
+ .List<InternalStoreFolderAcl>();
- } else {
- // Update the current ACL
- StoreFolderAcl acl = current[0];
- session.Delete(acl);
- }
+ if (current.Count == 0) {
+ // No such ACL
+ throw new ArgumentException("Invalid folder Id.");
- tx.Commit();
- session.Close();
- }
+ } else {
+ // Update the current ACL
+ InternalStoreFolderAcl acl = current[0];
+ session.Delete(acl);
}
}
#endregion
@@ -1358,28 +1280,26 @@
/// </summary>
/// <param name="currentFolderId">The Id of the current folder.</param>
/// <param name="newFolderId">The Id of the new folder.</param>
- protected void MoveStoreFolderAcl(int currentFolderId, int newFolderId) {
- using (ISession session = this.hibernateFactory.OpenSession()) {
- using (ITransaction tx = session.BeginTransaction()) {
- IList<StoreFolderAcl> current = session.CreateCriteria(typeof(StoreFolderAcl))
- .CreateCriteria("Folder")
- .Add(Expression.Eq("FolderId", currentFolderId))
- .List<StoreFolderAcl>();
+ protected void MoveStoreFolderAcl(int currentFolderId, int newFolderId, ISession session) {
+ // Ensure session has started a transaction
+ if (!session.Transaction.IsActive) {
+ throw new InvalidOperationException("A transaction is required for this operation.");
+ }
- if (current.Count == 0) {
- // No such ACL
- throw new ArgumentException("Invalid folder Id.");
+ IList<InternalStoreFolderAcl> current = session.CreateCriteria(typeof(InternalStoreFolderAcl))
+ .CreateCriteria("Folder")
+ .Add(Expression.Eq("FolderId", currentFolderId))
+ .List<InternalStoreFolderAcl>();
- } else {
- // Update the current ACL
- StoreFolderAcl acl = current[0];
- acl.Folder = session.Load<StoreFolder>(newFolderId);
- session.Update(acl);
- }
+ if (current.Count == 0) {
+ // No such ACL
+ throw new ArgumentException("Invalid folder Id.");
- tx.Commit();
- session.Close();
- }
+ } else {
+ // Update the current ACL
+ InternalStoreFolderAcl acl = current[0];
+ acl.Folder = session.Load<InternalStoreFolder>(newFolderId);
+ session.Update(acl);
}
}
#endregion
@@ -1408,22 +1328,22 @@
throw new InvalidOperationException("A transaction is required for this operation.");
}
- IList<StoreFolderAcl> current = session.CreateCriteria(typeof(StoreFolderAcl))
+ IList<InternalStoreFolderAcl> current = session.CreateCriteria(typeof(InternalStoreFolderAcl))
.CreateCriteria("Folder")
.Add(Expression.Eq("FolderId", folderId))
- .List<StoreFolderAcl>();
+ .List<InternalStoreFolderAcl>();
if (current.Count == 0) {
// Create a new ACL
- StoreFolder folder = session.Load<StoreFolder>(folderId);
- StoreFolderAcl acl = new StoreFolderAcl(folder);
+ InternalStoreFolder folder = session.Load<InternalStoreFolder>(folderId);
+ InternalStoreFolderAcl acl = new InternalStoreFolderAcl(folder);
acl[ace.Identifier] = ace;
- session.Save(acl);
+ session.SaveOrUpdateCopy(acl);
} else {
// Update the current ACL
- StoreFolderAcl acl = current[0];
+ InternalStoreFolderAcl acl = current[0];
acl[ace.Identifier] = ace;
session.Update(acl);
@@ -1440,10 +1360,10 @@
public void RemoveStoreFolderAce(int folderId, string identifier) {
using (ISession session = this.hibernateFactory.OpenSession()) {
using (ITransaction tx = session.BeginTransaction()) {
- IList<StoreFolderAcl> current = session.CreateCriteria(typeof(StoreFolderAcl))
+ IList<InternalStoreFolderAcl> current = session.CreateCriteria(typeof(InternalStoreFolderAcl))
.CreateCriteria("Folder")
.Add(Expression.Eq("FolderId", folderId))
- .List<StoreFolderAcl>();
+ .List<InternalStoreFolderAcl>();
if (current.Count == 0) {
// No such ACL
@@ -1451,7 +1371,7 @@
} else {
// Update the current ACL
- StoreFolderAcl acl = current[0];
+ InternalStoreFolderAcl acl = current[0];
acl.RemoveAce(identifier);
session.Update(acl);
@@ -1472,10 +1392,10 @@
/// <returns>The folder ACL.</returns>
public StoreFolderAcl GetStoreFolderAcl(int folderId) {
using (ISession session = this.hibernateFactory.OpenSession()) {
- IList<StoreFolderAcl> current = session.CreateCriteria(typeof(StoreFolderAcl))
+ IList<InternalStoreFolderAcl> current = session.CreateCriteria(typeof(InternalStoreFolderAcl))
.CreateCriteria("Folder")
.Add(Expression.Eq("FolderId", folderId))
- .List<StoreFolderAcl>();
+ .List<InternalStoreFolderAcl>();
if (current.Count == 0) {
// No such ACL
@@ -1483,7 +1403,7 @@
}
- return current[0];
+ return current[0].CreateStoreFolderAcl();
}
}
#endregion
Modified: NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.csproj
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.csproj 2007-04-19 12:09:29 UTC (rev 184)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/NMail.LocalStoreData.NHibernate.csproj 2007-04-24 12:45:08 UTC (rev 185)
@@ -48,6 +48,8 @@
<ItemGroup>
<Compile Include="FolderSubscription.cs" />
<Compile Include="InternalMessage.cs" />
+ <Compile Include="InternalStoreFolder.cs" />
+ <Compile Include="InternalStoreFolderAcl.cs" />
<Compile Include="NHibernateAuthProvider.cs" />
<Compile Include="NHibernateLocalStoreData.cs" />
<Compile Include="NHibernateUserMap.cs" />
@@ -64,7 +66,7 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Mappings\NMail.DataTypes.LocalStore.LocalStoreUser.hbm.xml" />
- <EmbeddedResource Include="Mappings\NMail.DataTypes.LocalStore.StoreFolder.hbm.xml" />
+ <EmbeddedResource Include="Mappings\NMail.LocalStoreData.NHibernate.InternalStoreFolder.hbm.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Mappings\NMail.DataTypes.LocalStore.LocalStoreGroup.hbm.xml" />
@@ -82,11 +84,14 @@
<EmbeddedResource Include="Mappings\NMail.DataTypes.LocalStore.MailDomain.hbm.xml" />
</ItemGroup>
<ItemGroup>
- <EmbeddedResource Include="Mappings\NMail.DataTypes.ACLs.StoreFolderAcl.hbm.xml" />
+ <EmbeddedResource Include="Mappings\NMail.LocalStoreData.NHibernate.InternalStoreFolderAcl.hbm.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Mappings\NMail.LocalStoreData.NHibernate.FolderSubsciption.hbm.xml" />
</ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Mappings\NMail.LocalStoreData.NHibernate.InternalMessage.hbm.xml" />
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Added: NMail/trunk/NMail.UnitTests/LocalStoreData/CreateGroupTest1.cs
===================================================================
--- NMail/trunk/NMail.UnitTests/LocalStoreData/CreateGroupTest1.cs (rev 0)
+++ NMail/trunk/NMail.UnitTests/LocalStoreData/CreateGroupTest1.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NUnit.Framework;
+
+using NMail.Configuration;
+using NMail.DataTypes.Calendar;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.UnitTests.LocalStoreData {
+ /// <summary>
+ /// Tests creating a group.
+ /// </summary>
+ [TestFixture]
+ public class CreateGroupTest1 : BaseLocalStoreDataTest {
+
+ [Test]
+ public void TestCreateGroup() {
+ LocalStoreGroup group = new LocalStoreGroup();
+ group.Name = "Test";
+ this.localStoreData.CreateGroup(group);
+
+ Assert.IsTrue(group.GroupId > 0, "Valid group Id.");
+ }
+ }
+}
Added: NMail/trunk/NMail.UnitTests/LocalStoreData/CreateGroupTest2.cs
===================================================================
--- NMail/trunk/NMail.UnitTests/LocalStoreData/CreateGroupTest2.cs (rev 0)
+++ NMail/trunk/NMail.UnitTests/LocalStoreData/CreateGroupTest2.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Text;
+
+using NUnit.Framework;
+
+using NMail.Configuration;
+using NMail.DataTypes.Calendar;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.UnitTests.LocalStoreData {
+ /// <summary>
+ /// Tests creating a group.
+ /// </summary>
+ [TestFixture]
+ public class CreateGroupTest2 : BaseLocalStoreDataTest {
+
+ [ExpectedException(typeof(DuplicateNameException))]
+ [Test]
+ public void TestCreateGroup() {
+ LocalStoreGroup group1 = new LocalStoreGroup();
+ group1.Name = "Test";
+ this.localStoreData.CreateGroup(group1);
+
+ Assert.IsTrue(group1.GroupId > 0, "Valid group Id.");
+
+ LocalStoreGroup group2 = new LocalStoreGroup();
+ group2.Name = "Test";
+ this.localStoreData.CreateGroup(group2);
+
+ Assert.Fail("Allowed duplicate user names.");
+ }
+ }
+}
Added: NMail/trunk/NMail.UnitTests/LocalStoreData/DeleteGroupTest1.cs
===================================================================
--- NMail/trunk/NMail.UnitTests/LocalStoreData/DeleteGroupTest1.cs (rev 0)
+++ NMail/trunk/NMail.UnitTests/LocalStoreData/DeleteGroupTest1.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NUnit.Framework;
+
+using NMail.Configuration;
+using NMail.DataTypes.Calendar;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.UnitTests.LocalStoreData {
+ /// <summary>
+ /// Tests deleting a group.
+ /// </summary>
+ [TestFixture]
+ public class DeleteGroupTest1 : BaseLocalStoreDataTest {
+
+ [Test]
+ public void TestDeleteGroup() {
+ LocalStoreGroup group = new LocalStoreGroup();
+ group.Name = "Test";
+ this.localStoreData.CreateGroup(group);
+
+ Assert.IsTrue(group.GroupId > 0, "Valid group Id.");
+
+ this.localStoreData.DeleteGroup(group.GroupId);
+
+ Assert.IsNull(this.localStoreData.GetGroup("Test"), "No group.");
+ }
+ }
+}
Added: NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderChildrenTest1.cs
===================================================================
--- NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderChildrenTest1.cs (rev 0)
+++ NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderChildrenTest1.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NUnit.Framework;
+
+using NMail.Configuration;
+using NMail.DataTypes.Calendar;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.UnitTests.LocalStoreData {
+ /// <summary>
+ /// Tests getting a store folder's children.
+ /// </summary>
+ [TestFixture]
+ public class GetStoreFolderChildrenTest1 : BaseLocalStoreDataTest {
+
+ [Test]
+ public void TestGetStoreFolderChildren() {
+ LocalStoreUser user1 = new LocalStoreUser();
+ user1.Username = "Test";
+ this.localStoreData.CreateUser(user1);
+
+ Assert.IsTrue(user1.UserId > 0, "Valid user Id.");
+ Assert.IsTrue(user1.UserFolderId > 0, "Valid user folder Id.");
+
+ IList<StoreFolder> children = this.localStoreData.GetChildren(user1.UserFolderId);
+
+ Assert.IsTrue(children.Count > 0, "Children exist.");
+ }
+ }
+}
Added: NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderTest1.cs
===================================================================
--- NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderTest1.cs (rev 0)
+++ NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderTest1.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NUnit.Framework;
+
+using NMail.Configuration;
+using NMail.DataTypes.Calendar;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.UnitTests.LocalStoreData {
+ /// <summary>
+ /// Tests getting a store folder.
+ /// </summary>
+ [TestFixture]
+ public class GetStoreFolderTest1 : BaseLocalStoreDataTest {
+
+ [Test]
+ public void TestGetStoreFolder() {
+ LocalStoreUser user1 = new LocalStoreUser();
+ user1.Username = "Test";
+ this.localStoreData.CreateUser(user1);
+
+ Assert.IsTrue(user1.UserId > 0, "Valid user Id.");
+ Assert.IsTrue(user1.UserFolderId > 0, "Valid user folder Id.");
+
+ StoreFolder f = this.localStoreData.GetStoreFolder(user1.UserFolderId);
+
+ Assert.IsTrue(f.FolderId > 0, "Valid folder Id.");
+ Assert.AreEqual(user1.UserId, f.OwnerUserId, "Valid owner user Id.");
+ }
+ }
+}
Added: NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderTest2.cs
===================================================================
--- NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderTest2.cs (rev 0)
+++ NMail/trunk/NMail.UnitTests/LocalStoreData/GetStoreFolderTest2.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NUnit.Framework;
+
+using NMail.Configuration;
+using NMail.DataTypes;
+using NMail.DataTypes.Calendar;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.UnitTests.LocalStoreData {
+ /// <summary>
+ /// Tests getting a store folder.
+ /// </summary>
+ [TestFixture]
+ public class GetStoreFolderTest2 : BaseLocalStoreDataTest {
+
+ [Test]
+ public void TestGetStoreFolder() {
+ LocalStoreUser user1 = new LocalStoreUser();
+ user1.Username = "Test";
+ this.localStoreData.CreateUser(user1);
+
+ Assert.IsTrue(user1.UserId > 0, "Valid user Id.");
+ Assert.IsTrue(user1.UserFolderId > 0, "Valid user folder Id.");
+
+ StoreFolder f1 = this.localStoreData.GetStoreFolder(user1.UserFolderId);
+
+ Assert.IsTrue(f1.FolderId > 0, "Valid folder Id.");
+ Assert.AreEqual(user1.UserId, f1.OwnerUserId, "Valid owner user Id.");
+
+ StoreFolder f2 = this.localStoreData.GetStoreFolder(new Folder(f1.NameSpace, f1.FullFolderName));
+
+ Assert.IsTrue(f2.FolderId > 0, "Valid folder Id.");
+ Assert.AreEqual(user1.UserId, f2.OwnerUserId, "Valid owner user Id.");
+ }
+ }
+}
Added: NMail/trunk/NMail.UnitTests/LocalStoreData/RemoveStoreFolderAceTest1.cs
===================================================================
--- NMail/trunk/NMail.UnitTests/LocalStoreData/RemoveStoreFolderAceTest1.cs (rev 0)
+++ NMail/trunk/NMail.UnitTests/LocalStoreData/RemoveStoreFolderAceTest1.cs 2007-04-24 12:45:08 UTC (rev 185)
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NUnit.Framework;
+
+using NMail.Configuration;
+using NMail.DataTypes.ACLs;
+using NMail.DataTypes.LocalStore;
+
+namespace NMail.UnitTests.LocalStoreData {
+ /// <summary>
+ /// Tests for removing a store folder ACE
+ /// </summary>
+ [TestFixture]
+ public class RemoveStoreFolderAceTest1 : BaseLocalStoreDataTest {
+
+ [Test]
+ public void TestSetAce() {
+ // Create a user
+ LocalStoreUser u1 = new LocalStoreUser();
+ u1.Username = "Test1";
+ this.localStoreData.CreateUser(u1);
+ Assert.IsTrue(u1.UserFolderId > 0, "Valid user folder Id.");
+ Assert.IsTrue(u1.UserId > 0, "Valid user Id.");
+
+ // Create a user
+ LocalStoreUser u2 = new LocalStoreUser();
+ u2.Username = "Test2";
+ this.localStoreData.CreateUser(u2);
+ Assert.IsTrue(u2.UserId > 0, "Valid user Id.");
+
+ // Check ACL
+ StoreFolderAcl acl1 = this.localStoreData.GetStoreFolderAcl(u1.UserFolderId);
+ Assert.IsNull(acl1[u2.Username], "No ACE for user 2.");
+
+ // Add ACE
+ GenericAce<StoreFolderPrivilege> ace1 = new GenericAce<StoreFolderPrivilege>(u2.Username, StoreFolderPrivilege.Admin, AcePrivilegeType.Allow);
+ this.localStoreData.SetStoreFolderAce(u1.UserFolderId, ace1);
+
+ // Check ACL
+ StoreFolderAcl acl2 = this.localStoreData.GetStoreFolderAcl(u1.UserFolderId);
+ Assert.IsNotNull(acl2[u2.Username], "Valid ACE for user 2.");
+ Assert.AreEqual(StoreFolderPrivilege.Admin, acl2[u2.Username].Privilege, "Correct ACE privilege.");
+ Assert.AreEqual(AcePrivilegeType.Allow, acl2[u2.Username].AceType, "Correct ACE type.");
+
+ // Remove ACE
+ this.localStoreData.RemoveStoreFolderAce(u1.UserFolderId, u2.Username);
+
+ // Check ACL
+ StoreFolderAcl acl3 = this.localStoreData.GetStoreFolderAcl(u1.UserFolderId);
+ Assert.IsNull(acl3[u2.Username], "No ACE for user 2.");
+ }
+ }
+}
Modified: NMail/trunk/NMail.UnitTests/NMail.UnitTests.csproj
===================================================================
--- NMail/trunk/NMail.UnitTests/NMail.UnitTests.csproj 2007-04-19 12:09:29 UTC (rev 184)
+++ NMail/trunk/NMail.UnitTests/NMail.UnitTests.csproj 2007-04-24 12:45:08 UTC (rev 185)
@@ -52,6 +52,13 @@
<Compile Include="DataTypes\Helper\MimeHelperTests.cs" />
<Compile Include="DataTypes\Helper\StringTokenizerTests.cs" />
<Compile Include="LocalStoreData\BaseLocalStoreDataTest.cs" />
+ <Compile Include="LocalStoreData\GetStoreFolderChildrenTest1.cs" />
+ <Compile Include="LocalStoreData\GetStoreFolderTest2.cs" />
+ <Compile Include="LocalStoreData\GetStoreFolderTest1.cs" />
+ <Compile Include="LocalStoreData\DeleteGroupTest1.cs" />
+ <Compile Include="LocalStoreData\CreateGroupTest2.cs" />
+ <Compile Include="LocalStoreData\CreateGroupTest1.cs" />
+ <Compile Include="LocalStoreData\RemoveStoreFolderAceTest1.cs" />
<Compile Include="LocalStoreData\SetStoreFolderAceTest1.cs" />
<Compile Include="LocalStoreData\DeleteMailDomainTest1.cs" />
<Compile Include="LocalStoreData\CreateMailDomainTest2.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|