namespace GDNXFD.Alert.Config.ViewModel
{
using GalaSoft.MvvmLight.Messaging;
using GDNXFD.Alert.Config.Helpers;
using GDNXFD.Alert.Config.Model;
using GDNXFD.Alert.Config.Resources.Strings;
using GDNXFD.Alert.Config.Services.Navigation;
using GDNXFD.Alert.Config.ViewModel.Base;
using Views;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Xml;
///
/// MainWindow ViewModel
///
public class MainViewModel : VMBase
{
private const string APPIMAGE_PATH = "Resources/Images/icon.png";
private readonly INavigationService navService;
private bool isVisibleDialog;
private CustomDialogMessage dialogMessage;
///
/// Initializes a new instance of the MainViewModel class.
///
public MainViewModel(
INavigationService navService)
{
this.navService = navService;
Messenger.Default.Register(this, HandleLoadingMessage);
Messenger.Default.Register(this, HandleUserLoginMessage);
Messenger.Default.Register(this, HandleDialogMessage);
}
///
/// Initialize data
///
///
public void InitializeData()
{
//Messenger.Default.Send(new LoadingMessage(true));
navService.NavigateToLogin();//.NavigateToRuleList();
}
private static void ShowErrorMessage(string textMessage)
{
CustomDialogMessage message = new CustomDialogMessage(null, textMessage, Visibility.Collapsed);
Messenger.Default.Send(message);
Messenger.Default.Send(new LoadingMessage(false));
}
public bool IsLogin
{
get
{
return string.IsNullOrWhiteSpace(GlobalVar.CurrentUser) ? false : true;
}
}
public string Username
{
get
{
return StringProvider.GetString("Welcome") + GlobalVar.CurrentUser;
}
}
///
/// Is visible dialog control.
///
public bool IsVisibleDialog
{
get { return this.isVisibleDialog; }
set
{
this.isVisibleDialog = value;
RaisePropertyChanged();
}
}
///
/// CustomDialogMessage instance used as datacontext for the confirmation dialog.
///
public CustomDialogMessage DialogMessage
{
get { return this.dialogMessage; }
set
{
this.dialogMessage = value;
RaisePropertyChanged();
}
}
private void HandleLoadingMessage(LoadingMessage msg)
{
IsBusy = msg.IsLoading;
}
private void HandleUserLoginMessage(UserLoginMessage msg)
{
foreach (Window window in App.Current.Windows)
{
if ((window as MainWindow) != null)
{
window.Top = window.Top - (750-window.Height) /2;
window.Left = window.Left - (1024-window.Width)/2;
window.Width = 1024;
window.Height = 750;
}
}
RaisePropertyChanged(() => IsLogin);
RaisePropertyChanged(() => Username);
}
private void HandleDialogMessage(CustomDialogMessage msg)
{
IsVisibleDialog = true;
msg.CancelAction = () =>
{
IsVisibleDialog = false;
};
DialogMessage = msg;
}
///
/// Dispose
///
///
protected override void Dispose(bool dispose)
{
base.Dispose(dispose);
Messenger.Default.Unregister(this, HandleLoadingMessage);
Messenger.Default.Unregister(this, HandleUserLoginMessage);
Messenger.Default.Unregister(this, HandleDialogMessage);
}
}
}