예제 #1
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));
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
        //====================================================================== 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);
            }
        }