How do I navigate from one view to another in Caliburn.Micro? - silverlight-4.0

So let me put it this way.
I have a LogInViewModel and a LogInView. There is a Login() method in the ViewModel that gets called if the user clicks on a button in the View. Now I want the dashboard to show if the login was successful. How do I do this? I can't find a clear answer to this in the documentation.

I assume that your dashboard is essentially your shell. In which case, you can bootstrap your LoginViewModel and in the Login method, after a successful login, you can show the DashboardViewModel and close the LoginViewModel using the Caliburn.Micro WindowManager.
Something like (using MEF):
Bootstrapper.cs
public class Bootstrapper : Caliburn.Micro.Bootstrapper<ILoginViewModel>
{
...
}
LoginViewModel.cs
public class LoginViewModel : Screen, ILoginViewModel
{
private readonly IWindowManager windowManager;
private readonly IDashboardViewModel dashboardViewModel;
[ImportingConstructor]
public LoginViewModel(IWindowManager windowManager, IDashboardViewModel dashboardViewModel)
{
this.windowManager = windowManager;
this.dashboardViewModel = dashboardViewModel;
}
public void Login()
{
// if login success...
this.windowManager.ShowDialog(this.dashboardViewModel);
this.TryClose();
}
}

I've just added a very simple login example SL4 project in my "lab repository" for Caliburn.Micro.
https://github.com/jenspettersson/Caliburn.Micro.Labs/tree/master/src/Login
It uses the Show class that Rob Eisenberg uses in his "Game Library" example to switch between views.
In the Login() method, it tells my Shell (your dashboard?) to show my LoginResultViewModel and sets the login result message.
yield return Show.Child<LoginResultViewModel>().In<IShell>().Configured(c => c.ResultMessage = "Successfully logged in!");
Check the code in my github repo.
I havent used Caliburn.Micro very much lately, so I am by no means an expert, but this way works for me.
//J
Edit: This answers how to navigate between views, if you want to show a "popup" to display if the login was successful, go with the other recomendations.

Related

NoCache is not working as expected

I used an Action Filter named [NoCache] to disable the access of login page after login by pressing the browser back button. The code is given below.
public class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
filterContext.HttpContext.Response.Cache.SetNoStore();
base.OnResultExecuting(filterContext);
}
}
Then i referred it in login page as shown below.
[HttpPost]
[NoCache]
public ActionResult Index(Login objLogin)
{
return RedirectToAction("Index", "Blood");
}
But the result was unexpected. Instead of redirecting to Blood/Index action, the control transfered to the url : http://localhost:4506/Account/Login?ReturnUrl=%2fBlood
How can i correct this ?. Thanks.
This probably related with Form Authentication feature. Do you need it? If not, just don't use it.
For more details, please refer to:
How to remove returnurl from url?

how can i change menu view by user access role?

I have a web application project with MVC 4 and I use Telerik panel bar and bind it by site map for my menu.but now i want to each user according to user access roles in my program see particular items of menu and hide remind menu items . how can i do this work in MVC any tips or trick would be welcome
this is link of Telerik website that i use it for creating my menu just i use it in partial view and just render its action in my layout razor code
Assume you have this global class :
public class AccessControlList{
public static bool IsAdmin {
get{
//put your code here
return false;
}
}
public static bool HasOpenFileAccess{
get{
//put your code here
return true;
}
}
}
then in your view.cshtml you may have something like this :
#(Html.Telerik().Menu()
.Name("mnuMain")
.Items(itemAdder =>
{
itemAdder.Add()
.Text("Admin Menu")
.Visible(false)
.Url("~/Home")
.Visible(AccessControlList.IsAdmin);
itemAdder.Add()
.Text("Files")
.Items(subItemAdder =>
{
subItemAdder.Add()
.Text("Open File...")
.Url("~/Files/Open")
.Visible(AccessControlList.HasOpenFileAccess)
....
complete your AccessControlList class (AccessControlList.cs file) to check if the authenticated person has your required access or not.

How to click back button programatically in IWizardPage in Eclipse

I'm writing an Eclipse plugin, I want to create a wizard for my new project type. I created pages by classes extends org.eclipse.jface.wizard.WizardPage. My requirement is, based on some condition in one page, I need to go back to previous page without pressing back button on page(programmatically).
Is it possible?
Thanks a million in advance!
I don't think this is a good idea. The user will be confused by doing this. I would disable the finish and the next button and give an error, telling the user that he has to go back to the first page.
If you want to reuse some UI from the first page, define the UI as a new class and reuse it.
I implemented something similar using the WizardDialog:showPage() method:
MyWizard.java
public void createPageControls(Composite pageContainer) {
// TODO Auto-generated method stub
super.createPageControls(pageContainer);
wizardDialog = (WizardDialog) getContainer();
}
public void skipProcessPage() {
wizardDialog.showPage(workPage == arisDbPage ? focusPage : arisDbPage);
}
public void setWorkPage(IWizardPage workPage) {
this.workPage = workPage;
}
here the processPage does the lengthy db lookup!
HTH thomas

Eclipse RCP disable a view from a dialog

I have a simple RCP application. I have a perspective and three views added to it. Initially one of the view will be disabled for the users. There is a toolbar item which launches a dialog. User authenticates himself in the dialog. After successful authentication, I want to make the view editable. I could get the reference of that specific view in my dialog.But I dont know how to enable it. I could not use selection listener as I am not selecting anything. Also I saw an example about using activities extension. But that opens/closes the view and not just enable/disable it. Can someone help me? Thanks.
As I understand you, you want to show the view in one of two states: either disabled if the user is not authenticated, or enabled when the user has been authenticated.
This is actually pretty easy :-) and I have made a small example application for you that illustrates the technique: so-edi.zip
UPDATED with new link
In RCP 3.x you have to expose the View's Control's enabled state in your implementation of ViewPart:
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.part.ViewPart;
public class View extends ViewPart {
private Control control;
#Override
public void createPartControl(Composite parent) {
control = new Composite(parent, SWT.NONE);
}
#Override
public void setFocus() {
}
public void setEnabled(boolean enabled) {
control.setEnabled(enabled);
}
public boolean isEnabled() {
return control.getEnabled()
}
}

Silverlight RIA Application that only accepts registered users

I have implemented the RIA WCF side to authenticate with Forms Authentication and everything works from the client as expected.
This application should only allow registered users to use it (users are created by admin - no registeration page).
My question is then, what (or where) should be the efficient way to make the authentication; it has to show up at application start up (unless remember me was on and cookie is still active) and if the user logs out, it should automatically get out the interface and return to login form again.
Update (code trimmed for brevity):
Public Class MainViewModel
....
Public Property Content As Object 'DP property
Private Sub ValidateUser()
If Not IsUserValid Login()
End Sub
Private Sub Login()
'I want, that when the login returns a success it should continue
'navigating to the original content i.e.
Dim _content = Me.Content
Me.Content = Navigate(Of LoginPage)
If IsUserValid Then Me.Content = _content
End Sub
End Class
I saw you other question so I assume you're using mvvm. I accomplish this by creating a RootPage with a grid control and a navigation frame. I set the RootVisual to the RootPage. I bind the navigation frames source to a variable in the RootPageVM, then in the consructor of RootPageVM you can set the frame source to either MainPage or LoginPage based on user auth. RootPageVM can also receive messages to control further navigation like logging out.
Using MVVM-Light.
So, in the RootPageView (set as the RootVisual), something like:
public RootPageViewModel()
{
Messenger.Default.Register<NotificationMessage>
(this, "NavigationRequest", Navigate);
if (IsInDesignMode)
{
}
else
{
FrameSource =
WebContext.Current.User.IsAuthenticated ?
"Home" :
"Login";
}
}
And a method for navigation:
private void Navigate(NotificationMessage obj)
{
FrameSource = obj.Notification;
}
In the LoginViewModel:
if (loginOperation.LoginSuccess)
{
Messenger.Default.Send
(new NotificationMessage(this, "Home"), "NavigationRequest");
}