public void SerializationRoundtrip() { var exception = new RestoreException(new Exception("Save failed"), new Exception("Restore failed")); var binaryFormatter = new BinaryFormatter(); using (var steram = PooledMemoryStream.Borrow()) { binaryFormatter.Serialize(steram, exception); steram.Position = 0; var roundtripped = (RestoreException)binaryFormatter.Deserialize(steram); Assert.AreEqual("Save failed", roundtripped.SaveException.Message); Assert.NotNull(roundtripped.InnerException); Assert.AreEqual("Restore failed", roundtripped.InnerException.Message); } }
public void SerializationRoundtrip() { var exception = new RestoreException(new Exception("Save failed"), new Exception("Restore failed")); var binaryFormatter = new BinaryFormatter(); using var stream = PooledMemoryStream.Borrow(); binaryFormatter.Serialize(stream, exception); stream.Position = 0; #pragma warning disable CA2300, CA2301 // Do not use insecure deserializer BinaryFormatter var roundtripped = (RestoreException)binaryFormatter.Deserialize(stream); #pragma warning restore CA2300, CA2301 // Do not use insecure deserializer BinaryFormatter Assert.AreEqual("Save failed", roundtripped.SaveException.Message); Assert.NotNull(roundtripped.InnerException); Assert.AreEqual("Restore failed", roundtripped.InnerException?.Message); }
protected void BuildResultScreen(RestoreException rex) { ClearControls(); if (this.RestoreResult == RestoreResultType.Nonedefined) { return; } var trashBag = GetContextNode() as TrashBag; if (trashBag == null) { return; } var view = this.InfoViewPath; var messageTitle = string.Empty; var messageDesc = string.Empty; switch (this.RestoreResult) { case RestoreResultType.UnknownError: view = this.ErrorViewPath; break; } var c = Page.LoadControl(view); if (c == null) { return; } this.Controls.Add(c); if (rex != null) { //build UI info from the exception var folderName = string.IsNullOrEmpty(rex.ContentPath) ? "{folder}" : RepositoryPath.GetFileNameSafe(RepositoryPath.GetParentPath(rex.ContentPath)); var contentName = string.IsNullOrEmpty(rex.ContentPath) ? "{content}" : RepositoryPath.GetFileNameSafe(rex.ContentPath); switch (rex.ResultType) { case RestoreResultType.Nonedefined: case RestoreResultType.UnknownError: messageTitle = rex.Message; messageDesc = rex.ToString(); break; case RestoreResultType.PermissionError: messageTitle = "Not enough permissions to complete the operation"; messageDesc = rex.Message; break; case RestoreResultType.ForbiddenContentType: messageTitle = "Cannot restore this type of content to the selected target"; break; case RestoreResultType.ExistingName: messageTitle = "Content with this name already exists in the folder " + folderName; messageDesc = string.Format( "You can restore it with a new name (<strong>{0}</strong>) or please choose a different destination", contentName); break; case RestoreResultType.NoParent: messageTitle = "Destination folder is missing"; messageDesc = "Please choose a different destination"; break; } } if (this.MessageControl != null) { this.MessageControl.ButtonsAction += MessageControl_ButtonsAction; if (this.NewNameButton != null) { this.NewNameButton.Command += MessageControl_ButtonsAction; } if (this.MessageLabel != null) { this.MessageLabel.Text = messageTitle; } if (this.MessageDescLabel != null) { this.MessageDescLabel.Text = messageDesc; } } if (this.ContentLabel != null) { var lc = trashBag.DeletedContent; if (lc != null) { this.ContentLabel.Text = HttpUtility.HtmlEncode(SNSR.GetString(lc.DisplayName)); } } ShowHideControls(); }