Destroy() private method

private Destroy ( ) : void
return void
Example #1
0
        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);
        }
Example #2
0
        /// <summary>
        /// Returns a new <see cref="TrashBag"/> instance that packages the
        /// given <see cref="GenericContent"/> instance.
        /// </summary>
        /// <param name="node">The <see cref="GenericContent"/> instance that will be wrapped.</param>
        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      currentUserId  = User.Current.Id;
            var      wsId           = 0;
            var      wsRelativePath = string.Empty;
            var      ws             = SystemAccount.Execute(() => 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,
                    Owner = node.Owner
                };
                bag.Save();

                CopyPermissions(node, bag);

                // Add Delete permission for the owner to let them remove it later and also
                // AddNew permission to let the move operation below actually move
                // the content into the TrashBag.
                Providers.Instance.SecurityHandler.CreateAclEditor()
                .Allow(bag.Id, node.OwnerId, false, PermissionType.Delete, PermissionType.AddNew)
                .Allow(bag.Id, currentUserId, true, PermissionType.Delete, PermissionType.AddNew)
                .Apply();
            }

            try
            {
                Node.Move(node.Path, bag.Path);
            }
            catch (SenseNetSecurityException ex)
            {
                SnLog.WriteException(ex);

                bag.Destroy();

                if (ex.Data.Contains("PermissionType") && (string)ex.Data["PermissionType"] == "Delete")
                {
                    throw new InvalidOperationException("You do not have enough permissions to delete this content to the Trash.", ex);
                }

                throw new InvalidOperationException("Error moving item to the trash", ex);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex);

                bag.Destroy();

                throw new InvalidOperationException("Error moving item to the trash", ex);
            }

            return(bag);
        }
Example #3
0
        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;
        }