[Nmailserver-commits] SF.net SVN: nmailserver: [183] NMail/trunk/NMail
Brought to you by:
dframpton-oss,
tmyroadctfig
|
From: <tmy...@us...> - 2007-04-18 13:02:58
|
Revision: 183
http://svn.sourceforge.net/nmailserver/?rev=183&view=rev
Author: tmyroadctfig
Date: 2007-04-18 06:02:58 -0700 (Wed, 18 Apr 2007)
Log Message:
-----------
More work on NHibernate local store and unit tests.
Modified Paths:
--------------
NMail/trunk/NMail/DataTypes/Calendar/Calendar.cs
NMail/trunk/NMail/DataTypes/Calendar/EventEntry.cs
NMail/trunk/NMail/DataTypes/LocalStore/ILocalStore.cs
NMail/trunk/NMail/DataTypes/LocalStore/ILocalStoreData.cs
NMail/trunk/NMail.Administration.Console/Command/AddMailDomainCommand.cs
NMail/trunk/NMail.Administration.Console/Command/ListMailDomainsCommand.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.Server.Console/NMail.config
NMail/trunk/NMail.UnitTests/LocalStoreData/CreateEventEntryTest1.cs
NMail/trunk/NMail.UnitTests/NMail.UnitTests.csproj
Added Paths:
-----------
NMail/trunk/NMail.LocalStoreData.NHibernate/FolderSubscription.cs
NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.FolderSubsciption.hbm.xml
NMail/trunk/NMail.UnitTests/LocalStoreData/CreateMailDomainTest1.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/CreateMailDomainTest2.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/DeleteMailDomainTest1.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/MoveStoreFolderTest1.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/MoveStoreFolderTest2.cs
NMail/trunk/NMail.UnitTests/LocalStoreData/MySqlLocalStoreTests.cs
Modified: NMail/trunk/NMail/DataTypes/Calendar/Calendar.cs
===================================================================
--- NMail/trunk/NMail/DataTypes/Calendar/Calendar.cs 2007-04-11 04:58:48 UTC (rev 182)
+++ NMail/trunk/NMail/DataTypes/Calendar/Calendar.cs 2007-04-18 13:02:58 UTC (rev 183)
@@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Text;
namespace NMail.DataTypes.Calendar {
/// <summary>
/// Represents a calendar in the system.
/// </summary>
+ [Serializable]
+ [DebuggerDisplay("Calendar: {Name} Id:{CalendarId}")]
public class Calendar {
private string name;
Modified: NMail/trunk/NMail/DataTypes/Calendar/EventEntry.cs
===================================================================
--- NMail/trunk/NMail/DataTypes/Calendar/EventEntry.cs 2007-04-11 04:58:48 UTC (rev 182)
+++ NMail/trunk/NMail/DataTypes/Calendar/EventEntry.cs 2007-04-18 13:02:58 UTC (rev 183)
@@ -17,9 +17,12 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Text;
namespace NMail.DataTypes.Calendar {
+ [Serializable]
+ [DebuggerDisplay("EventEntry: {Summary} Id:{EntryId}")]
public class EventEntry : CalendarEntry {
// TODO: alarm list
// TODO: GeographicPosition
Modified: NMail/trunk/NMail/DataTypes/LocalStore/ILocalStore.cs
===================================================================
--- NMail/trunk/NMail/DataTypes/LocalStore/ILocalStore.cs 2007-04-11 04:58:48 UTC (rev 182)
+++ NMail/trunk/NMail/DataTypes/LocalStore/ILocalStore.cs 2007-04-18 13:02:58 UTC (rev 183)
@@ -463,31 +463,36 @@
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <returns>The list of groups.</returns>
- LocalStoreGroup[] GetGroups(IAuthenticationToken authToken);
+ IList<LocalStoreGroup> GetGroups(IAuthenticationToken authToken);
/// <summary>
/// Creates a new group in the local store.
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
- /// <param name="name">The name of the new group.</param>
- /// <returns>The result of the attemp to create a new group.</returns>
- LocalStoreGroupResult CreateGroup(IAuthenticationToken authToken, string name);
+ /// <param name="group">The new group.</param>
+ /// <exception cref="System.Data.DuplicateNameException">If a group with the same name already exists.</exception>
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The group is invalid.</exception>
+ void CreateGroup(IAuthenticationToken authToken, LocalStoreGroup group);
/// <summary>
/// Removes a group from the local store.
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <param name="groupId">The Id of the group to delete.</param>
- /// <returns>The result of the attempt to delete a group.</returns>
- LocalStoreGroupResult DeleteGroup(IAuthenticationToken authToken, int groupId);
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The user is invalid.</exception>
+ void DeleteGroup(IAuthenticationToken authToken, int groupId);
/// <summary>
/// Updates the group.
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
- /// <param name="group">The group to update.</param>
- /// <returns>The result of the attempt to update the group.</returns>
- LocalStoreGroupResult UpdateGroup(IAuthenticationToken authToken, LocalStoreGroup group);
+ /// <param name="group">The group to update.</param>
+ /// <exception cref="System.Data.DuplicateNameException">If a group with the same name already exists.</exception>
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The group is invalid.</exception>
+ void UpdateGroup(IAuthenticationToken authToken, LocalStoreGroup group);
#endregion
#region Mail Domain Management
@@ -496,31 +501,28 @@
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <returns>The mail domains.</returns>
- MailDomain[] GetMailDomains(IAuthenticationToken authToken);
+ IList<MailDomain> GetMailDomains(IAuthenticationToken authToken);
/// <summary>
/// Creates a new mail domain for the given host.
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
- /// <param name="host">The primary host for the mail domain.</param>
- /// <returns>The result of the attempt to add the mail domain.</returns>
- LocalStoreMailDomainResult CreateMailDomain(IAuthenticationToken authToken, Host host);
+ /// <param name="mailDomain">The mail domain.</param>
+ void CreateMailDomain(IAuthenticationToken authToken, MailDomain mailDomain);
/// <summary>
/// Deletes a mail domain from the local store.
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <param name="mailDomainId">The Id of the mail domain to delete.</param>
- /// <returns>The result of the attempt to delete the domain.</returns>
- LocalStoreMailDomainResult DeleteMailDomain(IAuthenticationToken authToken, int mailDomainId);
+ void DeleteMailDomain(IAuthenticationToken authToken, int mailDomainId);
/// <summary>
/// Updates a mail domain.
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <param name="mailDomain">The mail domain to update.</param>
- /// <returns>The result of the attempt to update the mail domain.</returns>
- LocalStoreMailDomainResult UpdateMailDomain(IAuthenticationToken authToken, MailDomain mailDomain);
+ void UpdateMailDomain(IAuthenticationToken authToken, MailDomain mailDomain);
#endregion
#region System ACL
Modified: NMail/trunk/NMail/DataTypes/LocalStore/ILocalStoreData.cs
===================================================================
--- NMail/trunk/NMail/DataTypes/LocalStore/ILocalStoreData.cs 2007-04-11 04:58:48 UTC (rev 182)
+++ NMail/trunk/NMail/DataTypes/LocalStore/ILocalStoreData.cs 2007-04-18 13:02:58 UTC (rev 183)
@@ -126,23 +126,23 @@
/// <summary>
/// Gets a list of subscribed folders that match the query folder.
/// </summary>
- /// <param name="userName">The username to get the list of subscribed folders for.</param>
+ /// <param name="userId">The Id of the user to get the list of subscribed folders for.</param>
/// <returns>The list of folders.</returns>
- IList<StoreFolder> GetSubscribedFolders(string userName);
+ IList<StoreFolder> GetSubscribedFolders(int userId);
/// <summary>
/// Subscribes to a folder.
/// </summary>
- /// <param name="userName">The username to subscribe for.</param>
+ /// <param name="userId">The Id of the user to subscribe for.</param>
/// <param name="folder">The folder to subscribe to.</param>
- void Subscribe(string userName, StoreFolder folder);
+ void Subscribe(int userId, StoreFolder folder);
/// <summary>
/// Un-subscribes from a folder.
/// </summary>
- /// <param name="userName">The username to unsubscribe for.</param>
+ /// <param name="userId">The Id of the user to unsubscribe for.</param>
/// <param name="folder">The folder to unsubscribe from.</param>
- void UnSubscribe(string userName, StoreFolder folder);
+ void UnSubscribe(int userId, StoreFolder folder);
#endregion
#region Message Id and Offset
@@ -291,16 +291,16 @@
/// Sets the privileges on the folder. If no ACE exists for the associated
/// identifier one is added.
/// </summary>
- /// <param name="folder">The folder to set the ACE on.</param>
+ /// <param name="folder">The Id of the folder to set the ACE on.</param>
/// <param name="ace">The privileges and the identifier to put.</param>
- void SetStoreFolderAce(StoreFolder folder, GenericAce<StoreFolderPrivilege> ace);
+ void SetStoreFolderAce(int folderId, GenericAce<StoreFolderPrivilege> ace);
/// <summary>
/// Removes any ACE associated with the given user.
/// </summary>
- /// <param name="folder">The folder to remove the ACE from.</param>
+ /// <param name="folderId">The Id of the folder to remove the ACE from.</param>
/// <param name="identifier">The identifier to remove from the ACL.</param>
- void RemoveStoreFolderAce(StoreFolder folder, string identifier);
+ void RemoveStoreFolderAce(int folderId, string identifier);
/// <summary>
/// Gets the ACL for the given folder.
@@ -344,7 +344,6 @@
/// Removes a user from the local store.
/// </summary>
/// <param name="userId">The Id of the user to delete.</param>
- /// <exception cref="System.Data.DuplicateNameException">If a user with the same name already exists.</exception>
/// <exception cref="System.InvalidOperationException">Changes to the user are not permitted.</exception>
/// <exception cref="System.ArgumentException">The user is invalid.</exception>
/// <exception cref="System.Data.ConstraintException">User still has folders.</exception>
@@ -386,28 +385,33 @@
/// Gets the list of groups that currently exist in the local store.
/// </summary>
/// <returns>The list of groups.</returns>
- LocalStoreGroup[] GetGroups();
+ IList<LocalStoreGroup> GetGroups();
/// <summary>
- /// Creates a new group in the local store.
- /// </summary>
- /// <param name="name">The name of the new group.</param>
- /// <returns>The result of the attemp to create a new group.</returns>
- LocalStoreGroupResult CreateGroup(string name);
-
+ /// Creates a new group in the local store.
+ /// </summary>
+ /// <param name="group">The group to create.</param>
+ /// <exception cref="System.Data.DuplicateNameException">If a group with the same name already exists.</exception>
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The group is invalid.</exception>
+ void CreateGroup(LocalStoreGroup group);
+
/// <summary>
/// Removes a group from the local store.
/// </summary>
/// <param name="groupId">The Id of the group to delete.</param>
- /// <returns>The result of the attempt to delete a group.</returns>
- LocalStoreGroupResult DeleteGroup(int groupId);
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The user is invalid.</exception>
+ void DeleteGroup(int groupId);
/// <summary>
/// Updates the group.
- /// </summary>
- /// <param name="group">The updated group.</param>
- /// <returns>The result of the attempt to update the group.</returns>
- LocalStoreGroupResult UpdateGroup(LocalStoreGroup group);
+ /// </summary>
+ /// <param name="user">The group details to update.</param>
+ /// <exception cref="System.Data.DuplicateNameException">If a group with the same name already exists.</exception>
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The group is invalid.</exception>
+ void UpdateGroup(LocalStoreGroup group);
#endregion
#region Mail Domain Management
@@ -415,28 +419,25 @@
/// Gets all mail domains associated with this local store.
/// </summary>
/// <returns>The mail domains.</returns>
- MailDomain[] GetMailDomains();
+ IList<MailDomain> GetMailDomains();
/// <summary>
/// Creates a new mail domain for the given host.
- /// </summary>
- /// <param name="host">The primary host for the mail domain.</param>
- /// <returns>The result of the attempt to add the mail domain.</returns>
- LocalStoreMailDomainResult CreateMailDomain(Host host);
+ /// </summary>
+ /// <param name="mailDomain">The mail domain to create.</param>
+ void CreateMailDomain(MailDomain mailDomain);
/// <summary>
/// Deletes a mail domain from the local store.
/// </summary>
/// <param name="mailDomainId">The Id of the mail domain to delete.</param>
- /// <returns>The result of the attempt to delete the domain.</returns>
- LocalStoreMailDomainResult DeleteMailDomain(int mailDomainId);
+ void DeleteMailDomain(int mailDomainId);
/// <summary>
/// Updates a mail domain.
/// </summary>
/// <param name="mailDomain">The updated mail domain.</param>
- /// <returns>The result of the attempt to update the mail domain.</returns>
- LocalStoreMailDomainResult UpdateMailDomain(MailDomain mailDomain);
+ void UpdateMailDomain(MailDomain mailDomain);
#endregion
#region System ACL
Modified: NMail/trunk/NMail.Administration.Console/Command/AddMailDomainCommand.cs
===================================================================
--- NMail/trunk/NMail.Administration.Console/Command/AddMailDomainCommand.cs 2007-04-11 04:58:48 UTC (rev 182)
+++ NMail/trunk/NMail.Administration.Console/Command/AddMailDomainCommand.cs 2007-04-18 13:02:58 UTC (rev 183)
@@ -81,12 +81,16 @@
return;
}
- LocalStoreMailDomainResult result = this.localStore.CreateMailDomain(this.authToken, host);
+ try {
+ MailDomain md = new MailDomain();
+ md.PrimaryHost = host;
- if (result == LocalStoreMailDomainResult.OkSuccessful) {
+ this.localStore.CreateMailDomain(this.authToken, md);
+
System.Console.WriteLine("Added new mail domain.");
- } else {
- System.Console.WriteLine("Error adding mail domain.");
+
+ } catch (Exception ex) {
+ System.Console.WriteLine("Error adding mail domain: {0}.", ex.Message);
}
System.Console.WriteLine();
}
Modified: NMail/trunk/NMail.Administration.Console/Command/ListMailDomainsCommand.cs
===================================================================
--- NMail/trunk/NMail.Administration.Console/Command/ListMailDomainsCommand.cs 2007-04-11 04:58:48 UTC (rev 182)
+++ NMail/trunk/NMail.Administration.Console/Command/ListMailDomainsCommand.cs 2007-04-18 13:02:58 UTC (rev 183)
@@ -55,7 +55,7 @@
}
public void Process(string[] commandTokens) {
- MailDomain[] domains = this.localStore.GetMailDomains(this.authToken);
+ IList<MailDomain> domains = this.localStore.GetMailDomains(this.authToken);
System.Console.WriteLine();
Modified: NMail/trunk/NMail.LocalStore/LocalStore.cs
===================================================================
--- NMail/trunk/NMail.LocalStore/LocalStore.cs 2007-04-11 04:58:48 UTC (rev 182)
+++ NMail/trunk/NMail.LocalStore/LocalStore.cs 2007-04-18 13:02:58 UTC (rev 183)
@@ -231,7 +231,7 @@
#endregion
private MailDomain ResolveMailDomain(Host host) {
- MailDomain[] mailDomains = this.LocalStoreData.GetMailDomains();
+ IList<MailDomain> mailDomains = this.LocalStoreData.GetMailDomains();
// First check primary hosts
foreach (MailDomain mailDomain in mailDomains) {
@@ -373,7 +373,7 @@
// Create an ACL for the folder
GenericAce<StoreFolderPrivilege> ace = new GenericAce<StoreFolderPrivilege>(authToken.Username, StoreFolderPrivilegeHelper.AllPrivileges, AcePrivilegeType.Allow);
- LocalStoreData.SetStoreFolderAce(createdFolder, ace);
+ LocalStoreData.SetStoreFolderAce(createdFolder.FolderId, ace);
return LocalStoreFolderResult.OkSuccessful;
@@ -552,7 +552,8 @@
// Filter out unsubscribed folders from the list
IList<StoreFolder> result = new List<StoreFolder>();
- IList<StoreFolder> subscribedFolders = LocalStoreData.GetSubscribedFolders(authToken.Username);
+ LocalStoreUser user = LocalStoreData.GetUser(authToken.Username);
+ IList<StoreFolder> subscribedFolders = LocalStoreData.GetSubscribedFolders(user.UserId);
foreach (StoreFolder currentFolder in subscribedFolders) {
if (matchMode == MatchMode.Single) {
if (currentFolder == folder) {
@@ -590,7 +591,8 @@
if (hasFolderPrivilege(authToken.Username, folder.FolderId, StoreFolderPrivilege.Lookup)) {
// Subscribe to the folder
- LocalStoreData.Subscribe(authToken.Username, folder);
+ LocalStoreUser user = LocalStoreData.GetUser(authToken.Username);
+ LocalStoreData.Subscribe(user.UserId, folder);
return LocalStoreFolderResult.OkSuccessful;
} else {
@@ -607,7 +609,8 @@
/// <param name="folder">The folder to unsubscribe from.</param>
public void UnSubscribe(IAuthenticationToken authToken, StoreFolder folder) {
// Un-subscribe from the folder
- LocalStoreData.UnSubscribe(authToken.Username, folder);
+ LocalStoreUser user = LocalStoreData.GetUser(authToken.Username);
+ LocalStoreData.UnSubscribe(user.UserId, folder);
}
#endregion
#endregion
@@ -1034,7 +1037,7 @@
public IList<EmailAddress> GetUserAddresses(IAuthenticationToken authToken, int userId) {
List<EmailAddress> result = new List<EmailAddress>();
- MailDomain[] mailDomains = LocalStoreData.GetMailDomains();
+ IList<MailDomain> mailDomains = LocalStoreData.GetMailDomains();
LocalStoreUser user = LocalStoreData.GetUser(userId);
if (user != null) {
@@ -1091,7 +1094,7 @@
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <returns>The list of groups.</returns>
- public LocalStoreGroup[] GetGroups(IAuthenticationToken authToken) {
+ public IList<LocalStoreGroup> GetGroups(IAuthenticationToken authToken) {
return LocalStoreData.GetGroups();
}
@@ -1099,10 +1102,12 @@
/// Creates a new group in the local store.
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
- /// <param name="name">The name of the new group.</param>
- /// <returns>The result of the attemp to create a new group.</returns>
- public LocalStoreGroupResult CreateGroup(IAuthenticationToken authToken, string name) {
- return LocalStoreData.CreateGroup(name);
+ /// <param name="group">The new group.</param>
+ /// <exception cref="System.Data.DuplicateNameException">If a group with the same name already exists.</exception>
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The group is invalid.</exception>
+ public void CreateGroup(IAuthenticationToken authToken, LocalStoreGroup group) {
+ LocalStoreData.CreateGroup(group);
}
/// <summary>
@@ -1110,9 +1115,10 @@
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <param name="groupId">The Id of the group to delete.</param>
- /// <returns>The result of the attempt to delete a group.</returns>
- public LocalStoreGroupResult DeleteGroup(IAuthenticationToken authToken, int groupId) {
- return LocalStoreData.DeleteGroup(groupId);
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The user is invalid.</exception>
+ public void DeleteGroup(IAuthenticationToken authToken, int groupId) {
+ LocalStoreData.DeleteGroup(groupId);
}
/// <summary>
@@ -1120,9 +1126,11 @@
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <param name="group">The group to update.</param>
- /// <returns>The result of the attempt to update the group.</returns>
- public LocalStoreGroupResult UpdateGroup(IAuthenticationToken authToken, LocalStoreGroup group) {
- return LocalStoreData.UpdateGroup(group);
+ /// <exception cref="System.Data.DuplicateNameException">If a group with the same name already exists.</exception>
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The group is invalid.</exception>
+ public void UpdateGroup(IAuthenticationToken authToken, LocalStoreGroup group) {
+ LocalStoreData.UpdateGroup(group);
}
#endregion
@@ -1133,7 +1141,7 @@
if (hasFolderPrivilege(authToken.Username, folder.FolderId, StoreFolderPrivilege.Admin)
|| hasSystemPrivilege(authToken.Username, SystemPrivilege.EditAllAcls)) {
// Set the ACE
- LocalStoreData.SetStoreFolderAce(folder, ace);
+ LocalStoreData.SetStoreFolderAce(folder.FolderId, ace);
}
}
@@ -1143,7 +1151,7 @@
if (hasFolderPrivilege(authToken.Username, folder.FolderId, StoreFolderPrivilege.Admin)
|| hasSystemPrivilege(authToken.Username, SystemPrivilege.EditAllAcls)) {
// Remove the ACE
- LocalStoreData.RemoveStoreFolderAce(folder, identifier);
+ LocalStoreData.RemoveStoreFolderAce(folder.FolderId, identifier);
}
}
@@ -1168,7 +1176,7 @@
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <returns>The mail domains.</returns>
- public MailDomain[] GetMailDomains(IAuthenticationToken authToken) {
+ public IList<MailDomain> GetMailDomains(IAuthenticationToken authToken) {
// TODO: check acls
return this.LocalStoreData.GetMailDomains();
@@ -1177,12 +1185,11 @@
/// Creates a new mail domain for the given host.
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
- /// <param name="host">The primary host for the mail domain.</param>
- /// <returns>The result of the attempt to add the mail domain.</returns>
- public LocalStoreMailDomainResult CreateMailDomain(IAuthenticationToken authToken, Host host) {
+ /// <param name="mailDomain">The mail domain to create.</param>
+ public void CreateMailDomain(IAuthenticationToken authToken, MailDomain mailDomain) {
// TODO: check ACLs
- return this.LocalStoreData.CreateMailDomain(host);
+ this.LocalStoreData.CreateMailDomain(mailDomain);
}
/// <summary>
@@ -1190,11 +1197,10 @@
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <param name="mailDomainId">The Id of the mail domain to delete.</param>
- /// <returns>The result of the attempt to delete the domain.</returns>
- public LocalStoreMailDomainResult DeleteMailDomain(IAuthenticationToken authToken, int mailDomainId) {
+ public void DeleteMailDomain(IAuthenticationToken authToken, int mailDomainId) {
// TODO: check acls
- return this.LocalStoreData.DeleteMailDomain(mailDomainId);
+ this.LocalStoreData.DeleteMailDomain(mailDomainId);
}
/// <summary>
@@ -1202,11 +1208,10 @@
/// </summary>
/// <param name="authToken">The authentication credentials.</param>
/// <param name="mailDomain">The mail domain to update.</param>
- /// <returns>The result of the attempt to update the mail domain.</returns>
- public LocalStoreMailDomainResult UpdateMailDomain(IAuthenticationToken authToken, MailDomain mailDomain) {
+ public void UpdateMailDomain(IAuthenticationToken authToken, MailDomain mailDomain) {
// TODO: check acls
- return this.LocalStoreData.UpdateMailDomain(mailDomain);
+ this.LocalStoreData.UpdateMailDomain(mailDomain);
}
#endregion
Modified: NMail/trunk/NMail.LocalStoreData.MySql/MySqlLocalStoreData.cs
===================================================================
--- NMail/trunk/NMail.LocalStoreData.MySql/MySqlLocalStoreData.cs 2007-04-11 04:58:48 UTC (rev 182)
+++ NMail/trunk/NMail.LocalStoreData.MySql/MySqlLocalStoreData.cs 2007-04-18 13:02:58 UTC (rev 183)
@@ -412,11 +412,11 @@
#region Folder Subscription
#region GetSubscribedFolders
- public IList<StoreFolder> GetSubscribedFolders(string userName) {
+ public IList<StoreFolder> GetSubscribedFolders(int userId) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
- cmd.CommandText = "SELECT s.FolderId AS FolderId FROM User u, Subscription s WHERE s.UserId = u.UserId AND u.UserName = ?UserName";
- cmd.Parameters.Add("?UserName", userName);
+ cmd.CommandText = "SELECT s.FolderId AS FolderId FROM User u, Subscription s WHERE s.UserId = ?UserId";
+ cmd.Parameters.Add("?UserId", userId);
using (MySqlDataReader reader = cmd.ExecuteReader()) {
List<int> subscribedIds = new List<int>();
@@ -453,13 +453,9 @@
}
}
- public void Subscribe(string userName, StoreFolder folder) {
+ public void Subscribe(int userId, StoreFolder folder) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
- cmd.CommandText = "SELECT UserId FROM User WHERE UserName = ?UserName";
- cmd.Parameters.Add("?UserName", userName);
- int userId = (int) cmd.ExecuteScalar();
-
if (!folderSubscribed(userId, folder.FolderId)) {
cmd.CommandText = "INSERT INTO Subscription (UserId, FolderId) VALUES(?UserId, ?FolderId)";
cmd.Parameters.Add("?FolderId", folder.FolderId);
@@ -475,13 +471,9 @@
#endregion
#region UnSubscribe
- public void UnSubscribe(string userName, StoreFolder folder) {
+ public void UnSubscribe(int userId, StoreFolder folder) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
- cmd.CommandText = "SELECT UserId FROM User WHERE Username = ?Username";
- cmd.Parameters.Add("?Username", userName);
- int userId = (int)cmd.ExecuteScalar();
-
cmd.CommandText = "DELETE FROM Subscription WHERE UserId = ?UserId AND FolderId = ?FolderId";
cmd.Parameters.Add("?UserId", userId);
cmd.Parameters.Add("?FolderId", folder.FolderId);
@@ -1281,7 +1273,7 @@
/// Gets the list of groups that currently exist in the local store.
/// </summary>
/// <returns>The list of groups.</returns>
- public LocalStoreGroup[] GetGroups() {
+ public IList<LocalStoreGroup> GetGroups() {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
MySqlTransaction transaction = cnn.BeginTransaction();
@@ -1304,7 +1296,7 @@
}
transaction.Commit();
- return groups.ToArray();
+ return groups;
} catch (Exception ex) {
if (transaction != null) {
@@ -1323,12 +1315,12 @@
/// </summary>
/// <param name="name">The name of the new group.</param>
/// <returns>The result of the attemp to create a new group.</returns>
- public LocalStoreGroupResult CreateGroup(string name) {
+ public void CreateGroup(LocalStoreGroup group) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "CreateGroup";
- cmd.Parameters.Add("?Name", name);
+ cmd.Parameters.Add("?Name", group.Name);
cmd.Parameters.Add("?GroupId", MySqlDbType.Int32);
cmd.Parameters["GroupId"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("?Result", MySqlDbType.Int32);
@@ -1336,9 +1328,13 @@
cmd.ExecuteNonQuery();
- int result = (int) cmd.Parameters["Result"].Value;
+ LocalStoreGroupResult result = (LocalStoreGroupResult)((int) cmd.Parameters["Result"].Value);
- return (LocalStoreGroupResult) result;
+ if (result == LocalStoreGroupResult.AlreadyExists) {
+ throw new DuplicateNameException();
+ } else if (result == LocalStoreGroupResult.NotPermitted) {
+ throw new InvalidOperationException();
+ }
}
}
}
@@ -1350,7 +1346,7 @@
/// </summary>
/// <param name="groupId">The Id of the group to delete.</param>
/// <returns>The result of the attempt to delete a group.</returns>
- public LocalStoreGroupResult DeleteGroup(int groupId) {
+ public void DeleteGroup(int groupId) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
cmd.CommandType = CommandType.StoredProcedure;
@@ -1361,9 +1357,13 @@
cmd.ExecuteNonQuery();
- int result = (int) cmd.Parameters["Result"].Value;
+ LocalStoreGroupResult result = (LocalStoreGroupResult) ((int) cmd.Parameters["Result"].Value);
- return (LocalStoreGroupResult) result;
+ if (result == LocalStoreGroupResult.NoSuchGroup) {
+ throw new ArgumentException();
+ } else if (result == LocalStoreGroupResult.NotPermitted) {
+ throw new InvalidOperationException();
+ }
}
}
}
@@ -1375,7 +1375,7 @@
/// </summary>
/// <param name="group">The updated group.</param>
/// <returns>The result of the attempt to update the group.</returns>
- public LocalStoreGroupResult UpdateGroup(LocalStoreGroup group) {
+ public void UpdateGroup(LocalStoreGroup group) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
cmd.CommandType = CommandType.StoredProcedure;
@@ -1388,9 +1388,15 @@
cmd.ExecuteNonQuery();
- int result = (int) cmd.Parameters["Result"].Value;
+ LocalStoreGroupResult result = (LocalStoreGroupResult) ((int) cmd.Parameters["Result"].Value);
- return (LocalStoreGroupResult) result;
+ if (result == LocalStoreGroupResult.AlreadyExists) {
+ throw new DuplicateNameException();
+ } else if (result == LocalStoreGroupResult.NoSuchGroup) {
+ throw new ArgumentException();
+ } else if (result == LocalStoreGroupResult.NotPermitted) {
+ throw new InvalidOperationException();
+ }
}
}
}
@@ -1399,16 +1405,16 @@
#region Folder ACLs
#region Set StoreFolder ACE
- public void SetStoreFolderAce(StoreFolder folder, GenericAce<StoreFolderPrivilege> ace) {
+ public void SetStoreFolderAce(int folderId, GenericAce<StoreFolderPrivilege> ace) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- setStoreFolderAce(folder, ace, cnn, null);
+ setStoreFolderAce(folderId, ace, cnn, null);
}
}
- private void setStoreFolderAce(StoreFolder folder, GenericAce<StoreFolderPrivilege> ace, MySqlConnection cnn, MySqlTransaction transaction) {
+ private void setStoreFolderAce(int folderId, GenericAce<StoreFolderPrivilege> ace, MySqlConnection cnn, MySqlTransaction transaction) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
cmd.CommandText = "REPLACE FolderAcl (FolderId, Identifier, Allow, Privilege) VALUES (?FolderId, ?Identifier, ?Allow, ?Privilege)";
- cmd.Parameters.Add("?FolderId", folder.FolderId);
+ cmd.Parameters.Add("?FolderId", folderId);
cmd.Parameters.Add("?Identifier", ace.Identifier);
cmd.Parameters.Add("?Privilege", Convert.ToUInt32(ace.Privilege));
cmd.Parameters.Add("?Allow", (ace.AceType == AcePrivilegeType.Allow));
@@ -1422,11 +1428,11 @@
#endregion
#region Remove StoreFolder ACE
- public void RemoveStoreFolderAce(StoreFolder folder, string identifier) {
+ public void RemoveStoreFolderAce(int folderId, string identifier) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
cmd.CommandText = "DELETE FROM FolderAcl WHERE FolderId = ?FolderId AND Identifier = ?Identifier";
- cmd.Parameters.Add("?FolderId", folder.FolderId);
+ cmd.Parameters.Add("?FolderId", folderId);
cmd.Parameters.Add("?Identifier", identifier);
if (cmd.ExecuteNonQuery() != 1) {
@@ -1493,7 +1499,7 @@
/// Gets all mail domains associated with this local store.
/// </summary>
/// <returns>The mail domains.</returns>
- public MailDomain[] GetMailDomains() {
+ public IList<MailDomain> GetMailDomains() {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
MySqlTransaction transaction = cnn.BeginTransaction();
@@ -1517,7 +1523,7 @@
}
transaction.Commit();
- return mailDomains.ToArray();
+ return mailDomains;
} catch (Exception ex) {
if (transaction != null) {
@@ -1536,11 +1542,9 @@
/// </summary>
/// <param name="host">The primary host for the mail domain.</param>
/// <returns>The result of the attempt to add the mail domain.</returns>
- public LocalStoreMailDomainResult CreateMailDomain(Host host) {
+ public void CreateMailDomain(MailDomain mailDomain) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
- MailDomain mailDomain = new MailDomain(-1, host);
-
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "AddMailDomain";
cmd.Parameters.Add("?PrimaryHost", mailDomain.PrimaryHost.ToString());
@@ -1552,9 +1556,13 @@
cmd.ExecuteNonQuery();
- int result = (int) cmd.Parameters["Result"].Value;
+ LocalStoreMailDomainResult result = (LocalStoreMailDomainResult) ((int) cmd.Parameters["Result"].Value);
- return (LocalStoreMailDomainResult) result;
+ if (result == LocalStoreMailDomainResult.AlreadyExists) {
+ throw new DuplicateNameException();
+ } else if (result == LocalStoreMailDomainResult.NotPermitted) {
+ throw new InvalidOperationException();
+ }
}
}
}
@@ -1566,7 +1574,7 @@
/// </summary>
/// <param name="mailDomainId">The Id of the mail domain to delete.</param>
/// <returns>The result of the attempt to delete the domain.</returns>
- public LocalStoreMailDomainResult DeleteMailDomain(int mailDomainId) {
+ public void DeleteMailDomain(int mailDomainId) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
cmd.CommandType = CommandType.StoredProcedure;
@@ -1577,9 +1585,15 @@
cmd.ExecuteNonQuery();
- int result = (int) cmd.Parameters["Result"].Value;
+ LocalStoreMailDomainResult result = (LocalStoreMailDomainResult) ((int) cmd.Parameters["Result"].Value);
- return (LocalStoreMailDomainResult) result;
+ if (result == LocalStoreMailDomainResult.AlreadyExists) {
+ throw new DuplicateNameException();
+ } else if (result == LocalStoreMailDomainResult.NoSuchMailDomain) {
+ throw new ArgumentException();
+ } else if (result == LocalStoreMailDomainResult.NotPermitted) {
+ throw new InvalidOperationException();
+ }
}
}
}
@@ -1591,7 +1605,7 @@
/// </summary>
/// <param name="updatedMailDomain">The updated mail domain.</param>
/// <returns>The result of the attempt to update the mail domain.</returns>
- public LocalStoreMailDomainResult UpdateMailDomain(MailDomain updatedMailDomain) {
+ public void UpdateMailDomain(MailDomain updatedMailDomain) {
using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
using (MySqlCommand cmd = cnn.CreateCommand()) {
cmd.CommandType = CommandType.StoredProcedure;
@@ -1604,9 +1618,15 @@
cmd.ExecuteNonQuery();
- int result = (int) cmd.Parameters["Result"].Value;
+ LocalStoreMailDomainResult result = (LocalStoreMailDomainResult) ((int) cmd.Parameters["Result"].Value);
- return (LocalStoreMailDomainResult) result;
+ if (result == LocalStoreMailDomainResult.AlreadyExists) {
+ throw new DuplicateNameException();
+ } else if (result == LocalStoreMailDomainResult.NoSuchMailDomain) {
+ throw new ArgumentException();
+ } else if (result == LocalStoreMailDomainResult.NotPermitted) {
+ throw new InvalidOperationException();
+ }
}
}
}
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/FolderSubscription.cs
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/FolderSubscription.cs (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/FolderSubscription.cs 2007-04-18 13:02:58 UTC (rev 183)
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace NMail.LocalStoreData.NHibernate {
+ /// <summary>
+ /// A simple class for storing folder subscriptions.
+ /// </summary>
+ internal class FolderSubscription {
+
+ private int subscriptionId;
+
+ /// <summary>
+ /// The Id of the folder subscription.
+ /// </summary>
+ public int SubscriptionId {
+ get { return subscriptionId; }
+ set { subscriptionId = value; }
+ }
+
+ private int userId;
+
+ /// <summary>
+ /// The user subscribing to a folder.
+ /// </summary>
+ public int UserId {
+ get { return userId; }
+ set { userId = value; }
+ }
+
+ private int folderId;
+
+ /// <summary>
+ /// The folder subscribed to.
+ /// </summary>
+ public int FolderId {
+ get { return folderId; }
+ set { folderId = value; }
+ }
+ }
+}
Added: NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.FolderSubsciption.hbm.xml
===================================================================
--- NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.FolderSubsciption.hbm.xml (rev 0)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/Mappings/NMail.LocalStoreData.NHibernate.FolderSubsciption.hbm.xml 2007-04-18 13:02:58 UTC (rev 183)
@@ -0,0 +1,17 @@
+<?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.FolderSubscription" table="FolderSubscription">
+ <id name="SubscriptionId" type="Int32" unsaved-value="0">
+ <column name="SubscriptionId" not-null="true"/>
+ <generator class="native" />
+ </id>
+
+ <!-- TODO: ideally this would be a many-to-one relationship with StoreFolder -->
+ <property name="FolderId" not-null="true" />
+
+ <!-- TODO: ideally this would be a many-to-one relationship with LocalStoreUser -->
+ <property name="UserId" not-null="true" />
+ </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-11 04:58:48 UTC (rev 182)
+++ NMail/trunk/NMail.LocalStoreData.NHibernate/NHibernateLocalStoreData.cs 2007-04-18 13:02:58 UTC (rev 183)
@@ -16,7 +16,6 @@
*/
using System;
-using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Security.Cryptography;
@@ -318,6 +317,8 @@
DeleteChildrenWithoutUpdate(folder, session);
+ // TODO: delete ACLs
+ // TODO: delete folder subscriptions
session.Delete(folder);
// Remove the folder from the parent's list of children if present
@@ -352,7 +353,9 @@
// Recurse down
DeleteChildrenWithoutUpdate(child, session);
- // Delete the child at the current leve
+ // Delete the child at the current level
+ // TODO: remove child ACLs
+ // TODO: delete folder subscriptions
session.Delete(child);
}
}
@@ -384,18 +387,29 @@
StoreFolder newFolder;
StoreFolder currentParent;
StoreFolder newParentFolder = null;
+
+ if (parentId.HasValue) {
+ newParentFolder = session.Load<StoreFolder>(parentId.Value);
+ }
if (currentFolder.ParentId.HasValue) {
currentParent = session.Load<StoreFolder>(currentFolder.ParentId.Value);
}
- if (parentId.HasValue) {
- newParentFolder = session.Load<StoreFolder>(parentId.Value);
- }
-
// Setup the new folder
if (newParentFolder != null) {
newFolder = new StoreFolder(newParentFolder, newFolderName);
+
+ // Check for any folders with the same name
+ IList<StoreFolder> matching = session.CreateCriteria(typeof(StoreFolder))
+ .Add(Expression.Like("FullFolderName", newFolder.FullFolderName))
+ .Add(Expression.Eq("ParentId", parentId))
+ .List<StoreFolder>();
+
+ if (matching.Count > 0) {
+ throw new DuplicateNameException("Folder with the same name already exists.");
+ }
+
} else {
newFolder = new StoreFolder(currentFolder.NameSpace, newFolderName);
}
@@ -487,88 +501,87 @@
#region Folder Subscription
#region GetSubscribedFolders
- public IList<StoreFolder> GetSubscribedFolders(string userName) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.CommandText = "SELECT s.FolderId AS FolderId FROM User u, Subscription s WHERE s.UserId = u.UserId AND u.UserName = ?UserName";
- // cmd.Parameters.Add("?UserName", userName);
-
- // using (MySqlDataReader reader = cmd.ExecuteReader()) {
- // List<int> subscribedIds = new List<int>();
+ /// <summary>
+ /// Gets a list of subscribed folders that match the query folder.
+ /// </summary>
+ /// <param name="userId">The Id of the user to get the list of subscribed folders for.</param>
+ /// <returns>The list of folders.</returns>
+ public IList<StoreFolder> GetSubscribedFolders(int userId) {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ using (ITransaction tx = session.BeginTransaction()) {
+ IList<FolderSubscription> subscriptionList = session.CreateCriteria(typeof(FolderSubscription))
+ .Add(Expression.Eq("UserId", userId))
+ .List<FolderSubscription>();
- // while (reader.Read()) {
- // int currentId = (int) reader["FolderId"];
+ int[] folderIds = new int[subscriptionList.Count];
+ for (int i = 0; i < subscriptionList.Count; i++) {
+ folderIds[i] = subscriptionList[i].FolderId;
+ }
- // subscribedIds.Add(currentId);
- // }
- // reader.Close();
+ IList<StoreFolder> subscribed = session.CreateCriteria(typeof(StoreFolder))
+ .Add(Expression.In("FolderId", folderIds))
+ .List<StoreFolder>();
- // List<StoreFolder> subscribedFolders = new List<StoreFolder>();
- // foreach (int currentId in subscribedIds) {
- // subscribedFolders.Add(GetStoreFolder(currentId));
- // }
- // return subscribedFolders.ToArray();
- // }
- // }
- //}
- throw new NotImplementedException();
+ tx.Commit();
+ session.Close();
+
+ return subscribed;
+ }
+ }
}
#endregion
#region Subscribe
- //private bool folderSubscribed(int userId, int folderId) {
- // using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.CommandText = "SELECT COUNT(*) FROM Subscription WHERE UserId = ?UserId AND FolderId = ?FolderId";
- // cmd.Parameters.Add("?UserId", userId);
- // cmd.Parameters.Add("?FolderId", folderId);
- // long count = (long) cmd.ExecuteScalar();
-
- // return (count > 0);
- // }
- // }
- //}
+ /// <summary>
+ /// Subscribes to a folder.
+ /// </summary>
+ /// <param name="userId">The Id of the user to subscribe for.</param>
+ /// <param name="folder">The folder to subscribe to.</param>
+ public void Subscribe(int userId, StoreFolder folder) {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ using (ITransaction tx = session.BeginTransaction()) {
+ IList<FolderSubscription> current = session.CreateCriteria(typeof(FolderSubscription))
+ .Add(Expression.Eq("UserId", userId))
+ .Add(Expression.Eq("FolderId", folder.FolderId))
+ .List<FolderSubscription>();
- public void Subscribe(string userName, StoreFolder folder) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.CommandText = "SELECT UserId FROM User WHERE UserName = ?UserName";
- // cmd.Parameters.Add("?UserName", userName);
- // int userId = (int) cmd.ExecuteScalar();
+ if (current.Count == 0) {
+ FolderSubscription subscription = new FolderSubscription();
+ subscription.FolderId = folder.FolderId;
+ subscription.UserId = userId;
- // if (!folderSubscribed(userId, folder.FolderId)) {
- // cmd.CommandText = "INSERT INTO Subscription (UserId, FolderId) VALUES(?UserId, ?FolderId)";
- // cmd.Parameters.Add("?FolderId", folder.FolderId);
- // cmd.Parameters.Add("?UserId", userId);
-
- // if (cmd.ExecuteNonQuery() != 1) {
- // throw new System.Data.DataException("Error updating subscription.");
- // }
- // }
- // }
- //}
- throw new NotImplementedException();
+ session.Save(subscription);
+ }
+
+ tx.Commit();
+ session.Close();
+ }
+ }
}
#endregion
#region UnSubscribe
- public void UnSubscribe(string userName, StoreFolder folder) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.CommandText = "SELECT UserId FROM User WHERE Username = ?Username";
- // cmd.Parameters.Add("?Username", userName);
- // int userId = (int)cmd.ExecuteScalar();
+ /// <summary>
+ /// Un-subscribes from a folder.
+ /// </summary>
+ /// <param name="userId">The Id of the user to unsubscribe for.</param>
+ /// <param name="folder">The folder to unsubscribe from.</param>
+ public void UnSubscribe(int userId, StoreFolder folder) {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ using (ITransaction tx = session.BeginTransaction()) {
+ IList<FolderSubscription> current = session.CreateCriteria(typeof(FolderSubscription))
+ .Add(Expression.Eq("UserId", userId))
+ .Add(Expression.Eq("FolderId", folder.FolderId))
+ .List<FolderSubscription>();
- // cmd.CommandText = "DELETE FROM Subscription WHERE UserId = ?UserId AND FolderId = ?FolderId";
- // cmd.Parameters.Add("?UserId", userId);
- // cmd.Parameters.Add("?FolderId", folder.FolderId);
+ if (current.Count != 0) {
+ session.Delete(current[0].SubscriptionId);
+ }
- // if (cmd.ExecuteNonQuery() != 1) {
- // throw new System.Data.DataException("Error updating subscription.");
- // }
- // }
- //}
- throw new NotImplementedException();
+ tx.Commit();
+ session.Close();
+ }
+ }
}
#endregion
@@ -1016,9 +1029,9 @@
}
// Check if any other user with the same name exists in the system
- IList existing = session.CreateCriteria(typeof(LocalStoreUser))
+ IList<LocalStoreUser> existing = session.CreateCriteria(typeof(LocalStoreUser))
.Add(Expression.Like("Username", user.Username))
- .List();
+ .List<LocalStoreUser>();
if (existing.Count > 0) {
throw new DuplicateNameException("User with the same name already exists in the system.");
@@ -1059,7 +1072,6 @@
/// Removes a user from the local store.
/// </summary>
/// <param name="userId">The Id of the user to delete.</param>
- /// <returns>The result of the attempt to delete a user.</returns>
public void DeleteUser(int userId) {
using (ISession session = this.hibernateFactory.OpenSession()) {
using (ITransaction tx = session.BeginTransaction()) {
@@ -1087,9 +1099,9 @@
using (ISession session = this.hibernateFactory.OpenSession()) {
using (ITransaction tx = session.BeginTransaction()) {
// Check if any other user with the same name exists in the system
- IList existing = session.CreateCriteria(typeof(LocalStoreUser))
+ IList<LocalStoreUser> existing = session.CreateCriteria(typeof(LocalStoreUser))
.Add(Expression.Like("Username", user.Username))
- .List();
+ .List<LocalStoreUser>();
if (existing.Count > 0) {
throw new DuplicateNameException("User with the same name already exists in the system.");
@@ -1138,109 +1150,25 @@
/// <param name="name">The name to look up.</param>
/// <returns>The matching group or null if non is found.</returns>
public LocalStoreGroup GetGroup(string name) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // return getGroup(name, cnn, null);
- //}
- throw new NotImplementedException();
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ return session.CreateCriteria(typeof(LocalStoreGroup))
+ .Add(Expression.Like("Name", name))
+ .UniqueResult<LocalStoreGroup>();
+ }
}
- //private LocalStoreGroup getGroup(string name, MySqlConnection cnn, MySqlTransaction transaction) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.Transaction = transaction;
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "GetGroupFromName";
- // cmd.Parameters.Add("?Name", name);
- // cmd.Parameters.Add("?GroupId", MySqlDbType.Int32);
- // cmd.Parameters["GroupId"].Direction = ParameterDirection.Output;
- // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
- // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
-
- // DataSet groupData = new DataSet();
- // MySqlDataAdapter da = new MySqlDataAdapter(cmd);
- // da.Fill(groupData);
-
- // int resultValue = (int) cmd.Parameters["Result"].Value;
- // LocalStoreUserResult result = (LocalStoreUserResult) resultValue;
-
- // // Check if the lookup succeeded
- // if (result != LocalStoreUserResult.OkSuccessful) {
- // return null;
- // }
-
- // int groupId = (int) cmd.Parameters["GroupId"].Value;
-
- // // Get the group's sub-group Ids
- // List<int> groupIds = new List<int>();
- // DataTable groupGroupTable = groupData.Tables[0];
- // foreach (DataRow row in groupGroupTable.Rows) {
- // groupIds.Add((int) row[0]);
- // }
-
- // // The the group's user Ids
- // List<int> userIds = new List<int>();
- // DataTable userGroupTable = groupData.Tables[1];
- // foreach (DataRow row in userGroupTable.Rows) {
- // userIds.Add((int) row[0]);
- // }
-
- // return new LocalStoreGroup(name, groupId, userIds.ToArray(), groupIds.ToArray());
- // }
- //}
-
/// <summary>
/// Gets the group for the given user Id.
/// </summary>
/// <param name="groupId">The Id of the group to look up.</param>
/// <returns>The matching group or null if non is found.</returns>
public LocalStoreGroup GetGroup(int groupId) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // return getGroup(groupId, cnn, null);
- //}
- throw new NotImplementedException();
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ return session.CreateCriteria(typeof(LocalStoreGroup))
+ .Add(Expression.Like("GroupId", groupId))
+ .UniqueResult<LocalStoreGroup>();
+ }
}
-
- //private LocalStoreGroup getGroup(int groupId, MySqlConnection cnn, MySqlTransaction transaction) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.Transaction = transaction;
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "GetGroupFromId";
- // cmd.Parameters.Add("?GroupId", groupId);
- // cmd.Parameters.Add("?Name", MySqlDbType.VarChar);
- // cmd.Parameters["Name"].Direction = ParameterDirection.Output;
- // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
- // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
-
- // DataSet groupData = new DataSet();
- // MySqlDataAdapter da = new MySqlDataAdapter(cmd);
- // da.Fill(groupData);
-
- // int resultValue = (int) cmd.Parameters["Result"].Value;
- // LocalStoreUserResult result = (LocalStoreUserResult) resultValue;
-
- // // Check if the lookup succeeded
- // if (result != LocalStoreUserResult.OkSuccessful) {
- // return null;
- // }
-
- // string name = (string) cmd.Parameters["Name"].Value;
-
- // // Get the group's sub-group Ids
- // List<int> groupIds = new List<int>();
- // DataTable groupGroupTable = groupData.Tables[0];
- // foreach (DataRow row in groupGroupTable.Rows) {
- // groupIds.Add((int) row[0]);
- // }
-
- // // The the group's user Ids
- // List<int> userIds = new List<int>();
- // DataTable userGroupTable = groupData.Tables[1];
- // foreach (DataRow row in userGroupTable.Rows) {
- // userIds.Add((int) row[0]);
- // }
-
- // return new LocalStoreGroup(name, groupId, userIds.ToArray(), groupIds.ToArray());
- // }
- //}
#endregion
#region GetGroups
@@ -1248,68 +1176,43 @@
/// Gets the list of groups that currently exist in the local store.
/// </summary>
/// <returns>The list of groups.</returns>
- public LocalStoreGroup[] GetGroups() {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // MySqlTransaction transaction = cnn.BeginTransaction();
-
- // try {
- // MySqlCommand cmd = cnn.CreateCommand();
- // cmd.Transaction = transaction;
-
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "GetGroupIds";
- // MySqlDataReader reader = cmd.ExecuteReader();
- // List<int> groupIds = new List<int>();
-
- // while (reader.NextResult()) {
- // int groupId = (int) reader["GroupId"];
- // }
-
- // List<LocalStoreGroup> groups = new List<LocalStoreGroup>();
- // foreach (int groupId in groupIds) {
- // groups.Add(getGroup(groupId, cnn, transaction));
- // }
-
- // transaction.Commit();
- // return groups.ToArray();
-
- // } catch (Exception ex) {
- // if (transaction != null) {
- // transaction.Rollback();
- // }
-
- // throw ex;
- // }
- //}
- throw new NotImplementedException();
+ public IList<LocalStoreGroup> GetGroups() {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ return session.CreateCriteria(typeof(LocalStoreGroup)).List<LocalStoreGroup>();
+ }
}
#endregion
#region CreateGroup
/// <summary>
- /// Creates a new group in the local store.
- /// </summary>
- /// <param name="name">The name of the new group.</param>
- /// <returns>The result of the attemp to create a new group.</returns>
- public LocalStoreGroupResult CreateGroup(string name) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "CreateGroup";
- // cmd.Parameters.Add("?Name", name);
- // cmd.Parameters.Add("?GroupId", MySqlDbType.Int32);
- // cmd.Parameters["GroupId"].Direction = ParameterDirection.Output;
- // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
- // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+ /// Creates a new group in the local store.
+ /// </summary>
+ /// <param name="group">The group to create.</param>
+ /// <exception cref="System.Data.DuplicateNameException">If a group with the same name already exists.</exception>
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The group is invalid.</exception>
+ public void CreateGroup(LocalStoreGroup group) {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ using (ITransaction tx = session.BeginTransaction()) {
+ if (group.GroupId != 0) {
+ throw new InvalidOperationException("Can't save an existing group with this method.");
+ }
- // cmd.ExecuteNonQuery();
+ // Check if any other user with the same name exists in the system
+ IList<LocalStoreUser> existing = session.CreateCriteria(typeof(LocalStoreGroup))
+ .Add(Expression.Like("Name", group.Name))
+ .List<LocalStoreUser>();
- // int result = (int) cmd.Parameters["Result"].Value;
+ if (existing.Count > 0) {
+ throw new DuplicateNameException("Group with the same name already exists in the system.");
+ }
- // return (LocalStoreGroupResult) result;
- // }
- //}
- throw new NotImplementedException();
+ session.Save(group);
+
+ tx.Commit();
+ session.Close();
+ }
+ }
}
#endregion
@@ -1318,24 +1221,18 @@
/// Removes a group from the local store.
/// </summary>
/// <param name="groupId">The Id of the group to delete.</param>
- /// <returns>The result of the attempt to delete a group.</returns>
- public LocalStoreGroupResult DeleteGroup(int groupId) {
- //using (MySqlConnection cnn = MySqlHelper.GetConnection()) {
- // using (MySqlCommand cmd = cnn.CreateCommand()) {
- // cmd.CommandType = CommandType.StoredProcedure;
- // cmd.CommandText = "DeleteGroup";
- // cmd.Parameters.Add("?DeleteGroupId", groupId);
- // cmd.Parameters.Add("?Result", MySqlDbType.Int32);
- // cmd.Parameters["Result"].Direction = ParameterDirection.Output;
+ /// <exception cref="System.InvalidOperationException">Changes to the group are not permitted.</exception>
+ /// <exception cref="System.ArgumentException">The user is invalid.</exception>
+ public void DeleteGroup(int groupId) {
+ using (ISession session = this.hibernateFactory.OpenSession()) {
+ using (ITransaction tx = session.BeginTransaction()) {
+ LocalStoreGroup group = session.Load<LocalStoreGroup>(groupId);
+ session.Delete(group);
- // cmd.ExecuteNonQuery();
-
- // int result = (int) cmd.Parameters["Result"].Value;
-
- // return (LocalStoreGroupResult) result;
- // }
- //}
- throw new NotImplementedException();
+ tx.Commit();
+ }
+ session.Close();
+ }
}
#endregion
@@ -1345,163 +1242,136 @@
/// </summary>
/// <param name="group">The updated group.</param>
/// <returns>The result of the attempt to update the group.</returns>
- public LocalStoreGroupResult UpdateGroup(LocalStoreGroup gro...
[truncated message content] |