Beispiel #1
0
 private void Start()
 {
     cubeMesh    = gameObject.GetComponent <MeshFilter>().mesh;
     trashBin    = GameObject.Find("BottomPlate").GetComponent <TrashBin>();
     gearScript  = GameObject.Find("BottomPlate").GetComponent <GearPlacer>();
     coordScript = GameObject.Find("BottomPlate").GetComponent <CoordinateManager>();
 }
Beispiel #2
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
 }
 protected override void OnModified(object sender, NodeEventArgs e)
 {
     //Debug.WriteLine(String.Format("##WF> WorkflowHandlerBase.OnModified: {0}, {1}, {2}", Id, WorkflowInstanceGuid, Path));
     base.OnModified(sender, e);
     if (e.ChangedData.Any(x => x.Name == WORKFLOWSTATUS))
     {
         // elevation: we need to act here anyway, regardless of the current users permissions
         using (new SystemAccount())
         {
             string wfDefVer;
             var    wfDef = LoadWorkflowDefinition(out wfDefVer);
             if (Node.Exists(this.Path) && !TrashBin.IsInTrash(this)
                 &&
                 (
                     (wfDef.DeleteInstanceAfterFinished == WorkflowDeletionStrategy.DeleteWhenCompleted && this.WorkflowStatus == WorkflowStatusEnum.Completed)
                     ||
                     (wfDef.DeleteInstanceAfterFinished == WorkflowDeletionStrategy.DeleteWhenCompletedOrAborted &&
                      (this.WorkflowStatus == WorkflowStatusEnum.Completed || this.WorkflowStatus == WorkflowStatusEnum.Aborted))
                 ))
             {
                 ForceDelete();
             }
         }
     }
 }
Beispiel #4
0
        //====================================================================== Event handlers


        protected void MessageControl_ButtonsAction(object sender, CommandEventArgs e)
        {
            switch (e.CommandName.ToLower())
            {
            case "ok":
            case "yes":
                try
                {
                    TrashBin.Purge();
                    CallDone();
                }
                catch (Exception ex)
                {
                    Logger.WriteException(ex);
                    if (MessageControl != null)
                    {
                        MessageControl.ShowError(ex.Message);
                    }
                }
                break;

            case "cancel":
            case "no":
            case "errorok":
                CallDone();
                break;
            }
        }
Beispiel #5
0
        public void Delete_Trash_WithoutAddNewPermission()
        {
            Test(true, () =>
            {
                var originalUser = AccessProvider.Current.GetCurrentUser();

                File file;
                using (new SystemAccount())
                {
                    file = CreateTestFile();

                    // give Visitor Delete permission to the file, but not AddNew
                    // (workaround: add permissions for Visitor to the user content and to the Trash to make this test work)
                    Providers.Instance.SecurityHandler.CreateAclEditor()
                    .Allow(file.Id, Identifiers.VisitorUserId, false,
                           PermissionType.OpenMinor, PermissionType.Delete)
                    .Allow(TrashBin.Instance.Id, Identifiers.VisitorUserId, false, PermissionType.Open)
                    .Allow(Identifiers.VisitorUserId, Identifiers.VisitorUserId, false, PermissionType.Open)
                    .Apply();
                }

                try
                {
                    AccessProvider.Current.SetCurrentUser(User.Visitor);

                    // action: try to trash the file as Visitor - it should succeed
                    TrashBin.DeleteNode(file);
                }
                finally
                {
                    AccessProvider.Current.SetCurrentUser(originalUser);
                }
            });
        }
Beispiel #6
0
        public void Delete(object json, string tableName, string description, string deletedBy, int officeId)
        {
            try
            {
                UnitOfWork unitOfWork = new UnitOfWork();
                var        res        = JsonConvert.SerializeObject(json, new JsonSerializerSettings()
                {
                    ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                    PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                });
                var trashbin = new TrashBin()
                {
                    OldValues   = res,
                    TableName   = tableName,
                    DeletedBy   = deletedBy,
                    Description = description,
                    OfficeId    = officeId,
                };

                unitOfWork.TrashBinRepo.Insert(trashbin);
                unitOfWork.Save();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #7
0
        public static Task Restore(Content content, string destination = null, bool?newname = null)
        {
            if (!(content?.ContentHandler is TrashBag tb))
            {
                throw new InvalidContentActionException("The resource content must be a TrashBag.");
            }

            if (string.IsNullOrEmpty(destination))
            {
                destination = tb.OriginalPath;
            }

            // remember the id to load the content later
            var originalId = tb.DeletedContent.Id;

            try
            {
                if (newname.HasValue)
                {
                    TrashBin.Restore(tb, destination, newname.Value);
                }
                else
                {
                    TrashBin.Restore(tb, destination);
                }
            }
            catch (RestoreException rex)
            {
                string msg;

                switch (rex.ResultType)
                {
                case RestoreResultType.ExistingName:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestoreExistingName);
                    break;

                case RestoreResultType.ForbiddenContentType:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestoreForbiddenContentType);
                    break;

                case RestoreResultType.NoParent:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestoreNoParent);
                    break;

                case RestoreResultType.PermissionError:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestorePermissionError);
                    break;

                default:
                    msg = rex.Message;
                    break;
                }

                throw new Exception(msg);
            }

            return(Content.LoadAsync(originalId, CancellationToken.None));
        }
Beispiel #8
0
        private bool ContentsAreInTrash()
        {
            if (RequestIdList.Count == 0)
            {
                return(TrashBin.IsInTrash(ContextNode as GenericContent));
            }

            return(RequestNodeList.Count(n => TrashBin.IsInTrash(n as GenericContent)) > 0);
        }
Beispiel #9
0
        public static object Restore(Content content, string destination = null, bool?newname = null)
        {
            if (!(content?.ContentHandler is TrashBag tb))
            {
                throw new InvalidContentActionException("The resource content must be a TrashBag.");
            }

            if (string.IsNullOrEmpty(destination))
            {
                destination = tb.OriginalPath;
            }

            try
            {
                if (newname.HasValue)
                {
                    TrashBin.Restore(tb, destination, newname.Value);
                }
                else
                {
                    TrashBin.Restore(tb, destination);
                }
            }
            catch (RestoreException rex)
            {
                string msg;

                switch (rex.ResultType)
                {
                case RestoreResultType.ExistingName:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestoreExistingName);
                    break;

                case RestoreResultType.ForbiddenContentType:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestoreForbiddenContentType);
                    break;

                case RestoreResultType.NoParent:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestoreNoParent);
                    break;

                case RestoreResultType.PermissionError:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestorePermissionError);
                    break;

                default:
                    msg = rex.Message;
                    break;
                }

                throw new Exception(msg);
            }

            return(null);
        }
 public override void Delete()
 {
     //Debug.WriteLine(String.Format("##WF> WorkflowHandlerBase.Delete: {0}, {1}, {2}", Id, WorkflowInstanceGuid, Path));
     if (WorkflowStatus == WorkflowStatusEnum.Running)
     {
         InstanceManager.Abort(this, WorkflowApplicationAbortReason.StateContentDeleted);
     }
     if (!TrashBin.IsInTrash(this))
     {
         base.Delete();
     }
 }
Beispiel #11
0
 public override void Delete()
 {
     SnTrace.Workflow.Write("WorkflowHandlerBase.Delete: {0}, {1}, {2}", Id, WorkflowInstanceGuid, Path);
     if (WorkflowStatus == WorkflowStatusEnum.Running)
     {
         InstanceManager.Abort(this, WorkflowApplicationAbortReason.StateContentDeleted);
     }
     if (!TrashBin.IsInTrash(this))
     {
         base.Delete();
     }
 }
Beispiel #12
0
 private void DeleteContentsForever()
 {
     if (RequestIdList.Count == 0)
     {
         TrashBin.ForceDelete(ContextNode as GenericContent);
     }
     else
     {
         foreach (var node in RequestNodeList)
         {
             TrashBin.ForceDelete(node as GenericContent);
         }
     }
 }
Beispiel #13
0
        public override IEnumerable <IndexFieldInfo> GetIndexFieldInfos(ContentRepository.Field snField, out string textExtract)
        {
            textExtract = String.Empty;

            var content   = snField.Content;
            var boolValue = false;

            //check Trash
            if (TrashBin.IsInTrash(content.ContentHandler as GenericContent))
            {
                boolValue = true;
            }

            //check SystemFile
            if (!boolValue)
            {
                if (content.ContentHandler.NodeType.IsInstaceOfOrDerivedFrom("SystemFile"))
                {
                    boolValue = true;
                }
            }

            //check SystemFolder
            if (!boolValue)
            {
                var parent = content.ContentHandler;

                using (new SystemAccount())
                {
                    while (parent != null)
                    {
                        if (parent.NodeType.IsInstaceOfOrDerivedFrom("SystemFolder"))
                        {
                            boolValue = true;
                            break;
                        }

                        parent = parent.Parent;
                    }
                }
            }

            return(CreateFieldInfo(snField.Name, boolValue ? BooleanIndexHandler.YES : BooleanIndexHandler.NO));
        }
Beispiel #14
0
        public void Delete_Trash_WithoutDeletePermission()
        {
            Test(true, () =>
            {
                var originalUser = AccessProvider.Current.GetCurrentUser();

                File file;
                using (new SystemAccount())
                {
                    file = CreateTestFile();

                    // give Visitor only Open permission, not Delete
                    // (workaround: add permissions for Visitor to the user content and to the Trash to make this test work)
                    Providers.Instance.SecurityHandler.CreateAclEditor()
                    .Allow(file.Id, Identifiers.VisitorUserId, false, PermissionType.OpenMinor)
                    .Allow(TrashBin.Instance.Id, Identifiers.VisitorUserId, false, PermissionType.Open)
                    .Allow(Identifiers.VisitorUserId, Identifiers.VisitorUserId, false, PermissionType.Open)
                    .Apply();
                }

                var thrown = false;

                try
                {
                    AccessProvider.Current.SetCurrentUser(User.Visitor);

                    // action: try to trash the file as Visitor
                    TrashBin.DeleteNode(file);
                }
                catch (InvalidOperationException ex)
                {
                    if (ex.Message.Contains("You do not have enough permissions to delete this content"))
                    {
                        thrown = true;
                    }
                }
                finally
                {
                    AccessProvider.Current.SetCurrentUser(originalUser);
                }

                Assert.IsTrue(thrown, "The expected exception was not thrown.");
            });
        }
Beispiel #15
0
        public override IEnumerable <string> GetParsableValues(SnCR.Field snField)
        {
            var content   = snField.Content;
            var boolValue = false;

            //check Trash
            if (TrashBin.IsInTrash(content.ContentHandler as GenericContent))
            {
                boolValue = true;
            }

            //check SystemFile
            if (!boolValue)
            {
                if (content.ContentHandler.NodeType.IsInstaceOfOrDerivedFrom("SystemFile"))
                {
                    boolValue = true;
                }
            }

            //check SystemFolder
            if (!boolValue)
            {
                var parent = content.ContentHandler;

                using (new SystemAccount())
                {
                    while (parent != null)
                    {
                        if (parent.NodeType.IsInstaceOfOrDerivedFrom("SystemFolder"))
                        {
                            boolValue = true;
                            break;
                        }

                        parent = parent.Parent;
                    }
                }
            }

            return(new[] { boolValue?BooleanIndexHandler.YES : BooleanIndexHandler.NO });
        }
Beispiel #16
0
        private async Task DeleteByAction(string body, bool permanent)
        {
            // workaround: remove the old Delete application that is
            // not compatible with the .net core method
            var deleteAppPath = "/Root/(apps)/GenericContent/Delete";

            if (Node.Exists(deleteAppPath))
            {
                Node.ForceDelete(deleteAppPath);
            }

            // ARRANGE
            var testRoot = CreateTestRoot("ODataTestRoot");
            var name     = "Content1";
            var content  = Content.CreateNew("File", testRoot, name);

            content.Save();
            var repoPath = $"{testRoot.Path}/{name}";
            var resource = $"/OData.svc/{testRoot.Path}('{name}')/Delete";

            // ACTION
            var response = await ODataPostAsync(resource, "", body).ConfigureAwait(false);

            // ASSERT
            AssertNoError(response);
            Assert.IsFalse(Node.Exists(repoPath));

            // reload
            content = Content.Load(content.Id);

            if (permanent)
            {
                Assert.IsNull(content);
            }
            else
            {
                Assert.IsTrue(TrashBin.IsInTrash(content.ContentHandler as GenericContent));
            }
        }
        internal MembershipExtension GetSharingExtension(string contextValue)
        {
            // check the url first
            var sharingGroup = GetSharingGroupByUrlParameter()?.ContentHandler as Group;

            // check the context param next
            if (sharingGroup == null && contextValue != null)
            {
                sharingGroup = SharingHandler.GetSharingGroupBySharingId(contextValue)?.ContentHandler as Group;
            }

            if (sharingGroup == null)
            {
                return(MembershipExtension.Placeholder);
            }

            var sharedNode = sharingGroup.GetReference <GenericContent>(Constants.SharedContentFieldName);

            // Check if the related shared content exists.
            if (sharedNode == null)
            {
                // Invalid sharing group: no related content. Delete the group and move on.
                SnTrace.Security.Write($"SharingMembershipExtender: Deleting orphaned sharing group {sharingGroup.Id} ({sharingGroup.Path}).");

                sharingGroup.ForceDelete();
                sharingGroup = null;
            }

            // If found and the content is not in the Trash, return a new extension collection
            // containing the sharing group.
            if ((sharingGroup?.ContentType.IsInstaceOfOrDerivedFrom(Constants.SharingGroupTypeName) ?? false) &&
                !TrashBin.IsInTrash(sharedNode))
            {
                return(new MembershipExtension(new[] { sharingGroup.Id }));
            }

            return(MembershipExtension.Placeholder);
        }
Beispiel #18
0
 private void Awake()
 {
     mainScript = transform.GetComponentInParent <TrashBin>();
 }
Beispiel #19
0
        public override object Execute(Content content, params object[] parameters)
        {
            //optional destination
            var destination = parameters != null && parameters.Length > 0 ? (string)parameters[0] : null;

            //optional new name parameter
            var addNewName = parameters != null && parameters.Length > 1 && parameters[1] != null ? (bool)parameters[1] : (bool?)null;

            var tb = content.ContentHandler as TrashBag;

            if (tb == null)
            {
                throw new InvalidContentActionException("The resource content must be a trashbag.");
            }

            if (string.IsNullOrEmpty(destination))
            {
                destination = tb.OriginalPath;
            }

            try
            {
                if (addNewName.HasValue)
                {
                    TrashBin.Restore(tb, destination, addNewName.Value);
                }
                else
                {
                    TrashBin.Restore(tb, destination);
                }
            }
            catch (RestoreException rex)
            {
                string msg;

                switch (rex.ResultType)
                {
                case RestoreResultType.ExistingName:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestoreExistingName);
                    break;

                case RestoreResultType.ForbiddenContentType:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestoreForbiddenContentType);
                    break;

                case RestoreResultType.NoParent:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestoreNoParent);
                    break;

                case RestoreResultType.PermissionError:
                    msg = SNSR.GetString(SNSR.Exceptions.OData.RestorePermissionError);
                    break;

                default:
                    msg = rex.Message;
                    break;
                }

                throw new Exception(msg);
            }

            return(null);
        }
Beispiel #20
0
 private static void CreateTrash(string parentPath, string name, int minRetentionTime, int sizeQuota, int bagCapacity, bool isAct)
 {
     var parent = Node.LoadNode(parentPath);
     var tb = new TrashBin(parent)
                  {
                      Name = name,
                      IsActive = isAct,
                      BagCapacity = bagCapacity,
                      MinRetentionTime = minRetentionTime,
                      SizeQuota = sizeQuota
                  };
     tb.Save();
     
 }
        private void ProcessCommand(CommandEventArgs e)
        {
            switch (e.CommandName.ToLower())
            {
            case "yes":
                try
                {
                    var permanentDelete = this.FindControlRecursive("PermanentDeleteCheckBox") as CheckBox;


                    var      originalName = ContextNode.Name;
                    var      back         = PortalContext.Current.BackUrl;
                    var      oldUrlName   = string.Format("/{0}", originalName);
                    TrashBin trashBin     = null;

                    try
                    {
                        trashBin = TrashBin.Instance;
                    }
                    catch (SenseNetSecurityException)
                    {
                        //trashbin is not accessible
                    }

                    var trashIsAvailable = trashBin != null && (trashBin.BagCapacity <= 0 || trashBin.BagCapacity > GetNodesInTreeCount());

                    if ((permanentDelete != null && permanentDelete.Checked) || !trashIsAvailable)
                    {
                        DeleteContentsForever();
                    }
                    else
                    {
                        DeleteContentsToTrash();
                    }

                    if (RequestIdList.Count == 0 && back.Contains(oldUrlName))
                    {
                        back = back.Replace(oldUrlName, string.Empty);
                        var p = Page as PageBase;
                        if (p != null)
                        {
                            p.Response.Redirect(back, false);
                        }
                    }
                    else
                    {
                        CallDone(false);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteException(ex);
                    ShowException(ex);
                }
                break;

            case "ok":
            case "errorok":
            case "no":
            case "cancel":
                CallDone();
                break;

            default:
                break;
            }
        }
Beispiel #22
0
        private void BindEvents()
        {
            if (MessageControl == null)
            {
                return;
            }

            MessageControl.ButtonsAction += MessageControlButtonsAction;

            // switching visibility of the controls on and off within the user control

            var gContent  = ContextNode as GenericContent;
            var bag       = ContextNode as TrashBag;
            var title     = gContent == null ? ContextNode.Name : SNSR.GetString(gContent.DisplayName);
            var isInTrash = ContentsAreInTrash();

            var folder = bag == null ? ContextNode as IFolder : bag.DeletedContent as IFolder;

            if (folder == null)
            {
                SetLabel(MessageControl, "DeleteOneLabel", title, ContextNode.ParentPath);
            }
            else
            {
                SetLabel(MessageControl, "DeleteFolderLabel", title, ContextNode.ParentPath);
            }


            TrashBin trashBin = null;

            try
            {
                trashBin = TrashBin.Instance;
            }
            catch (SenseNetSecurityException)
            {
                // trashbin is not accessible due to lack of permissions
            }

            if (trashBin == null)   // trashbin ain't available
            {
                MessageControl.Errors.Add("Trashbin node not found under /Root/Trash, trashbin functionality unavailable.");
                ToggleControlVisibility(MessageControl, "PermanentDeleteLabel", true);
                ToggleControlVisibility(MessageControl, "BinEnabledLabel", false);
                ToggleControlVisibility(MessageControl, "PermanentDeleteCheckBox", false);
            }
            else
            {   // trashbin is available
                var nodesInTreeCount = GetNodesInTreeCount();

                bool?trashDisabled = !ContentsAreTrashable();

                if (gContent != null)
                {
                    ToggleControlVisibility(MessageControl, "BinDisabledGlobalLabel", !trashBin.IsActive);

                    if (isInTrash)
                    {
                        ToggleControlVisibility(MessageControl, "BinEnabledLabel", false);
                        ToggleControlVisibility(MessageControl, "PermanentDeleteCheckBox", false);
                        ToggleControlVisibility(MessageControl, "BinNotConfiguredLabel", false);
                        ToggleControlVisibility(MessageControl, "PermanentDeleteLabel", true);
                        ToggleControlVisibility(MessageControl, "PurgeFromTrashLabel", true);
                        ToggleControlVisibility(MessageControl, "TooMuchContentLabel", false);
                    }
                    else if (trashBin.BagCapacity == 0 || trashBin.BagCapacity > nodesInTreeCount)
                    {
                        if (trashDisabled.Value)
                        {
                            ToggleControlVisibility(MessageControl, "BinEnabledLabel", false);
                            ToggleControlVisibility(MessageControl, "BinNotConfiguredLabel", trashBin.IsActive);
                            ToggleControlVisibility(MessageControl, "PermanentDeleteLabel", true);
                        }
                        else
                        {
                            ToggleControlVisibility(MessageControl, "BinEnabledLabel", trashBin.IsActive);
                            ToggleControlVisibility(MessageControl, "PermanentDeleteCheckBox", trashBin.IsActive);
                            ToggleControlVisibility(MessageControl, "BinNotConfiguredLabel", false);
                            ToggleControlVisibility(MessageControl, "PermanentDeleteLabel", !trashBin.IsActive);
                        }
                    }
                    else
                    {
                        // too much content flow
                        ToggleControlVisibility(MessageControl, "BinEnabledLabel", false);
                        ToggleControlVisibility(MessageControl, "PermanentDeleteCheckBox", false);
                        ToggleControlVisibility(MessageControl, "BinNotConfiguredLabel", trashDisabled.Value && trashBin.IsActive);
                        ToggleControlVisibility(MessageControl, "PermanentDeleteLabel", true);
                        ToggleControlVisibility(MessageControl, "TooMuchContentLabel", !trashDisabled.Value && trashBin.IsActive);
                    }
                }
                else
                {
                    MessageControl.Errors.Add("System Message: You can't delete a content which is not derived from GenericContent.");
                }
            }
        }
Beispiel #23
0
 void Awake()
 {
     trashCan = GameObject.Find("BottomPlate").GetComponent <TrashBin>();
 }
Beispiel #24
0
        private void ProcessCommand(CommandEventArgs e)
        {
            switch (e.CommandName.ToLower())
            {
            case "yes":
                try
                {
                    var permanentDelete = this.FindControlRecursive("PermanentDeleteCheckBox") as CheckBox;


                    var      originalName = ContextNode.Name;
                    var      back         = PortalContext.Current.BackUrl;
                    var      oldUrlName   = string.Format("/{0}", originalName);
                    TrashBin trashBin     = null;

                    try
                    {
                        trashBin = TrashBin.Instance;
                    }
                    catch (SenseNetSecurityException)
                    {
                        // trashbin is not accessible
                    }

                    var trashIsAvailable = trashBin != null && (trashBin.BagCapacity <= 0 || trashBin.BagCapacity > GetNodesInTreeCount());

                    if ((permanentDelete != null && permanentDelete.Checked) || !trashIsAvailable)
                    {
                        DeleteContentsForever();
                    }
                    else
                    {
                        DeleteContentsToTrash();
                    }

                    var queryIndex = back.IndexOf("?");
                    var backtarget = queryIndex == -1 ? back : back.Substring(0, queryIndex);
                    if (RequestIdList.Count == 0 && backtarget.EndsWith(oldUrlName))
                    {
                        // The user called the action from the content itself, we need to redirect
                        // the page to the parent, because we just deleted the content.
                        back  = backtarget.Substring(0, backtarget.Length - oldUrlName.Length);
                        back += PortalContext.GetUrlParametersForParent();

                        var p = Page as PageBase;
                        if (p != null)
                        {
                            p.Response.Redirect(back, false);
                        }
                    }
                    else if (string.IsNullOrEmpty(PortalContext.Current.BackUrl))
                    {
                        var p = Page as PageBase;
                        if (p != null)
                        {
                            p.Response.Redirect(ContextNode.ParentPath, false);
                        }
                    }
                    else
                    {
                        CallDone(false);
                    }
                }
                catch (Exception ex)
                {
                    SnLog.WriteException(ex);
                    ShowException(ex);
                }
                break;

            case "ok":
            case "errorok":
            case "no":
            case "cancel":
                CallDone();
                break;

            default:
                break;
            }
        }
        //====================================================================== Event handlers

        protected void MessageControl_ButtonsAction(object sender, CommandEventArgs e)
        {
            var trashBag = GetContextNode() as TrashBag;
            var target   = string.Empty;

            try
            {
                switch (e.CommandName)
                {
                case "Ok":
                case "Cancel":
                    if (this.RestoreResult != RestoreResultType.Nonedefined)
                    {
                        //we are on the info/error page, reset
                        //data and go back to the main screen
                        this.RestoreResult = RestoreResultType.Nonedefined;
                        this.RestoreTarget = null;

                        BuildMainScreen();
                    }
                    else
                    {
                        CallDone(false);
                    }
                    break;

                case "Restore":

                    if (this.DestinationTextBox != null)
                    {
                        target = this.DestinationTextBox.Text;
                    }

                    if (trashBag != null)
                    {
                        TrashBin.Restore(trashBag, target);
                        RedirectSafely(trashBag, target);
                    }

                    break;

                case "RestoreWithNewName":
                    if (this.RestoreResult != RestoreResultType.Nonedefined && trashBag != null)
                    {
                        //use the previously serialized target here, to try again
                        TrashBin.Restore(trashBag, this.RestoreTarget, true);
                        RedirectSafely(trashBag, this.RestoreTarget);
                    }
                    break;

                case "TryAgain":
                    if (this.RestoreResult != RestoreResultType.Nonedefined && trashBag != null)
                    {
                        //use the previously serialized target here, to try again
                        TrashBin.Restore(trashBag, this.RestoreTarget);
                        RedirectSafely(trashBag, this.RestoreTarget);
                    }
                    break;
                }
            }
            catch (RestoreException rex)
            {
                //collect data from the exception to serialize it later
                this.RestoreResult = rex.ResultType;
                this.RestoreTarget = RepositoryPath.GetParentPath(rex.ContentPath);

                BuildResultScreen(rex);
            }
        }
Beispiel #26
0
        public void Notification_Event_DeleteRestore()
        {
            var trash = Node.Load<TrashBin>("/Root/Trash");
            if (trash == null)
            {
                trash = new TrashBin(Repository.Root);
                trash.Name = "Trash";
                trash.IsActive = true;
                trash.Save();
            }
            else
            {
                if (!trash.IsActive)
                {
                    trash.IsActive = true;
                    trash.Save();
                }
            }
            TrashBin.Purge();

            var source = Content.CreateNew("Folder", TestRoot, "DeleteRestore");
            source.Save();
            var doc = Content.CreateNew("Car", source.ContentHandler, "car_DeleteRestore");
            doc.Save();

            Subscription.Subscribe(Subscriber1, TestRoot, NotificationFrequency.Daily, "en", TESTSITEPATH, TESTSITEURL);

            Configuration.Enabled = true;
            source.Delete();
            var bags = TrashBin.Instance.Children.OfType<TrashBag>().ToArray();
            var bag = bags.FirstOrDefault(x => ((TrashBag)x).DeletedContent.Path.EndsWith("/DeleteRestore"));
            if (bag == null)
                Assert.Inconclusive();
            TrashBin.Restore(bag);
            Configuration.Enabled = false;

            var events = (Event[])Event.GetAllEvents();
            Assert.IsTrue(events.Length == 2, "#1");
            Assert.IsTrue(events[0].NotificationType == NotificationType.Deleted, "#2");
            Assert.IsTrue(events[0].ContentPath == source.Path, String.Concat("#3: Path is: ", events[0].ContentPath, ", expected: ", source.Path));
            Assert.IsTrue(events[1].NotificationType == NotificationType.Restored, "#4");
            Assert.IsTrue(events[1].ContentPath == source.Path, String.Concat("#5: Path is: ", events[1].ContentPath, ", expected: ", source.Path));
        }