/// <summary>
		/// Prepares an insert query.
		/// </summary>
		/// <param name="context"></param>
		/// <param name="connection">The connection.</param>
		/// <param name="transaction">The transaction.</param>
		/// <param name="sourceNode"></param>
		/// <param name="targetParentNode"></param>
		/// <returns></returns>
		public void Prepare(IMansionContext context, SqlConnection connection, SqlTransaction transaction, Node sourceNode, Node targetParentNode)
		{
			// validate arguments
			if (connection == null)
				throw new ArgumentNullException("connection");
			if (transaction == null)
				throw new ArgumentNullException("transaction");
			if (sourceNode == null)
				throw new ArgumentNullException("sourceNode");
			if (targetParentNode == null)
				throw new ArgumentNullException("targetParentNode");

			// get the properties of the new node
			var newProperties = new PropertyBag(sourceNode);

			// if the target pointer is the same as the parent of the source node, generate a new name to distinguish between the two.
			if (sourceNode.Pointer.Parent == targetParentNode.Pointer)
			{
				// get the name of the node
				var name = sourceNode.Get<string>(context, "name");

				// change the name to indicate the copied node
				newProperties.Set("name", name + CopyPostfix);
			}

			// create an insert query
			command = context.Nucleus.CreateInstance<InsertNodeCommand>();
			command.Prepare(context, connection, transaction, targetParentNode.Pointer, newProperties);
		}
		/// <summary>
		/// Creates an <see cref="AssetEntry"/> instance from <paramref name="node"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="folder">The <see cref="AssetFolder"/>.</param>
		/// <param name="node">The <see cref="Node"/>.</param>
		/// <returns>Returns the created <see cref="AssetEntry"/> instance.</returns>
		public static AssetEntry Create(IMansionContext context, AssetFolder folder, Node node)
		{
			//validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (folder == null)
				throw new ArgumentNullException("folder");
			if (node == null)
				throw new ArgumentNullException("node");

			return new AssetEntry
			       {
			       	AssetFolder = folder,
			       	Name = node.Pointer.Name,
			       	Size = node.Get<long>(context, "size", 0),
			       	ModificationDate = node.Get(context, "modified", DateTime.MinValue)
			       };
		}
		/// <summary>
		/// Creates a new node in this repository.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="parent">The parent node.</param>
		/// <param name="newProperties">The properties of the node which to create.</param>
		/// <returns>Returns the created nodes.</returns>
		public Node CreateNode(IMansionContext context, Node parent, IPropertyBag newProperties)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (parent == null)
				throw new ArgumentNullException("parent");
			if (newProperties == null)
				throw new ArgumentNullException("newProperties");
			CheckDisposed();

			// if no allowedRoleGuids are specified, copy the parens
			if (!newProperties.Contains("allowedRoleGuids"))
				newProperties.Set("allowedRoleGuids", parent.Get(context, "allowedRoleGuids", string.Empty));

			// invoke template method
			return DoCreateNode(context, parent, newProperties);
		}
 /// <summary>
 /// Retrieves a <see cref="Nodeset"/> containing the groups to which <paramref name="userNode"/> belongs.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="userNode"></param>
 /// <param name="repository"></param>
 /// <returns></returns>
 private Nodeset RetrieveUserGroupNodes(IMansionContext context, Node userNode, IRepository repository)
 {
     return repository.RetrieveNodeset(context, new PropertyBag
                                                {
                                                	{"baseType", "UserGroup"},
                                                	{"userGuids", userNode.Get<string>(context, "guid")},
                                                	{"bypassAuthorization", true},
                                                	{StorageOnlyQueryComponent.PropertyKey, true}
                                                });
 }
        /// <summary>
        /// Maps a <paramref name="roleNode"/> to <see cref="Role"/>.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="roleNode"></param>
        /// <returns></returns>
        private Role MapRole(IMansionContext context, Node roleNode)
        {
            // create the role
            var role = new Role(roleNode.PermanentId);

            // find all the properties ending with _granted
            foreach (var property in roleNode.Where(x => x.Key.EndsWith(GrantedPostfix, StringComparison.OrdinalIgnoreCase)))
            {
                // get the resourceId and operationId
                var permissionParts = property.Key.Substring(0, property.Key.Length - GrantedPostfix.Length).Split(new[] {'_'}, StringSplitOptions.RemoveEmptyEntries);
                if (permissionParts.Length != 2)
                    throw new InvalidOperationException(string.Format("Invalid permission '{0}' found in role '{1}'", property.Key, roleNode.Pointer.PathString));
                var resourceId = permissionParts[0];
                var operationId = permissionParts[1];
                var permissionPrefix = resourceId + "_" + operationId + "_";

                // create the operation
                var operation = ProtectedOperation.Create(context, resourceId, operationId);

                // create the permission
                var permission = new Permission
                                 {
                                 	Granted = roleNode.Get(context, permissionPrefix + "granted", false),
                                 	Operation = operation,
                                 	Priority = roleNode.Get(context, permissionPrefix + "priority", 5)
                                 };

                // add the permission to the role
                role.Add(permission);
            }

            // return the role
            return role;
        }
        private UserState CreateUserState(IMansionContext context, Node userNode)
        {
            // create the user state
            var userState = new UserState(userNode.Get<Guid>(context, "guid"), this);

            // merge the user properties
            userState.Properties.Merge(userNode);

            return userState;
        }