SenseNet.ContentRepository.TrashBag.BagThis C# (CSharp) Метод

BagThis() публичный статический Метод

public static BagThis ( GenericContent node ) : TrashBag
node GenericContent
Результат TrashBag
        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;
            
            using (new SystemAccount())
            {
                bag = new TrashBag(bin)
                          {
                              KeepUntil = DateTime.Now.AddDays(bin.MinRetentionTime),
                              OriginalPath = RepositoryPath.GetParentPath(node.Path),
                              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;
        }

Usage Example

Пример #1
0
        public static bool DeleteNode(GenericContent n)
        {
            if (Instance != null && Instance.IsActive && n.IsTrashable)
            {
                if (Instance.BagCapacity > 0 && n.NodesInTree > Instance.BagCapacity)
                {
                    throw new ApplicationException("Node tree size exceeds trash bag limit, use ForceDelete to purge physically.");
                }

                TrashBag.BagThis(n);
            }
            else
            {
                ForceDelete(n);
            }
            return(true);
        }