public static TrashBag BagThis(GenericContent node)
{
var bin = TrashBin.Instance;
if (bin == null)
{
return(null);
}
if (node == null)
{
throw new ArgumentNullException("node");
}
//creating a bag has nothing to do with user permissions: Move will handle that
TrashBag bag = null;
var wsId = 0;
var wsRelativePath = string.Empty;
var ws = node.Workspace;
if (ws != null)
{
wsId = ws.Id;
wsRelativePath = node.Path.Substring(ws.Path.Length);
}
using (new SystemAccount())
{
bag = new TrashBag(bin)
{
KeepUntil = DateTime.UtcNow.AddDays(bin.MinRetentionTime),
OriginalPath = RepositoryPath.GetParentPath(node.Path),
WorkspaceRelativePath = wsRelativePath,
WorkspaceId = wsId,
DisplayName = node.DisplayName,
Link = node
};
bag.Save();
CopyPermissions(node, bag);
//add delete permission for the owner
//bag.Security.SetPermission(User.Current, true, PermissionType.Delete, PermissionValue.Allow);
}
try
{
Node.Move(node.Path, bag.Path);
}
catch (Exception ex)
{
Logger.WriteException(ex);
bag.Destroy();
throw new InvalidOperationException("Error moving item to the trash", ex);
}
return(bag);
}