|
using System;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel.Composition;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using IssueVision.Common;
using MVVMPlugin;
namespace IssueVision.Client
{
public partial class MainPage : UserControl
{
#region "Private Data"
private bool noErrorMessage = true;
private PluginCatalogService _catalogService = PluginCatalogService.Instance;
#endregion "Private Data"
#region "Constructor"
public MainPage()
{
InitializeComponent();
if (!ViewModelBase.IsInDesignModeStatic)
{
// Use MEF To load the View Model
CompositionInitializer.SatisfyImports(this);
}
// register for ChangeScreenMessage
AppMessages.ChangeScreenMessage.Register(this, OnChangeScreenMessage);
// register for ChangeScreenNoAnimationMessage
AppMessages.ChangeScreenNoAnimationMessage.Register(this, OnChangeScreenNoAnimationMessage);
// register for RaiseErrorMessage
AppMessages.RaiseErrorMessage.Register(this, OnRaiseErrorMessage);
// register for PleaseConfirmMessage
AppMessages.PleaseConfirmMessage.Register(this, OnPleaseConfirmMessage);
// register for StatusUpdateMessage
AppMessages.StatusUpdateMessage.Register(this, OnStatusUpdateMessage);
}
#endregion "Constructor"
#region "Public Properties"
[Import(ViewModelTypes.MainPageViewModel)]
public object ViewModel
{
set
{
DataContext = value;
}
}
#endregion "Public Properties"
#region "ChangeScreenMessage"
private void OnChangeScreenMessage(string changeScreen)
{
object currentScreen;
// call Cleanup() on the current screen before switching
ICleanup cleanUp = this.mainPageContent.Content as ICleanup;
if (cleanUp != null)
cleanUp.Cleanup();
// reset noErrorMessage
this.noErrorMessage = true;
switch (changeScreen)
{
case ViewTypes.HomeView:
currentScreen = new Home();
break;
case ViewTypes.NewIssueView:
currentScreen = _catalogService.FindPlugin(
ViewTypes.NewIssueView, PluginType.View);
break;
case ViewTypes.AllIssuesView:
currentScreen = _catalogService.FindPlugin(
ViewTypes.AllIssuesView, PluginType.View);
break;
case ViewTypes.MyIssuesView:
currentScreen = _catalogService.FindPlugin(
ViewTypes.MyIssuesView, PluginType.View);
break;
case ViewTypes.BugReportView:
currentScreen = _catalogService.FindPlugin(
ViewTypes.BugReportView, PluginType.View);
break;
case ViewTypes.MyProfileView:
currentScreen = _catalogService.FindPlugin(
ViewTypes.MyProfileView, PluginType.View);
break;
case ViewTypes.UserMaintenanceView:
currentScreen = _catalogService.FindPlugin(
ViewTypes.UserMaintenanceView, PluginType.View);
break;
default:
throw new NotImplementedException();
}
// change main page content with animation
currentScreen = this.mainPageContent.ChangeMainPageContent(currentScreen, true);
// call ReleasePlugin on replaced screen
_catalogService.ReleasePlugin(currentScreen);
}
#endregion "ChangeScreenMessage"
#region "ChangeScreenNoAnimationMessage"
private void OnChangeScreenNoAnimationMessage(string changeScreen)
{
object currentScreen;
// call Cleanup() on the current screen before switching
ICleanup cleanUp = this.mainPageContent.Content as ICleanup;
if (cleanUp != null)
cleanUp.Cleanup();
// reset noErrorMessage
this.noErrorMessage = true;
switch (changeScreen)
{
case ViewTypes.HomeView:
currentScreen = new Home();
break;
case ViewTypes.MyProfileView:
currentScreen = _catalogService.FindPlugin(ViewTypes.MyProfileView);
break;
default:
throw new NotImplementedException();
}
// change main page content without animation
currentScreen = this.mainPageContent.ChangeMainPageContent(currentScreen, false);
// call ReleasePlugin on replaced screen
_catalogService.ReleasePlugin(currentScreen);
}
#endregion "ChangeScreenNoAnimationMessage"
#region "RaiseErrorMessage"
private void OnRaiseErrorMessage(Exception ex)
{
if (this.noErrorMessage && ex != null)
{
ErrorWindow.CreateNew(ex);
// logout after display the error message
this.hyperlinkButton_Logout.Command.Execute(true);
this.noErrorMessage = false;
}
}
#endregion "RaiseErrorMessage"
#region "PleaseConfirmMessage"
private void OnPleaseConfirmMessage(DialogMessage dialogMessage)
{
if (dialogMessage != null)
{
MessageBoxResult result = MessageBox.Show(dialogMessage.Content,
dialogMessage.Caption, dialogMessage.Button);
dialogMessage.ProcessCallback(result);
}
}
#endregion "PleaseConfirmMessage"
#region "StatusUpdateMessage"
private void OnStatusUpdateMessage(DialogMessage dialogMessage)
{
if (dialogMessage != null)
{
MessageBoxResult result = MessageBox.Show(dialogMessage.Content,
dialogMessage.Caption, dialogMessage.Button);
dialogMessage.ProcessCallback(result);
}
}
#endregion "StatusUpdateMessage"
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET