123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- 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;
- /// <summary>
- /// MainWindow ViewModel
- /// </summary>
- public class MainViewModel : VMBase
- {
- private const string APPIMAGE_PATH = "Resources/Images/icon.png";
- private readonly INavigationService navService;
- private bool isVisibleDialog;
- private CustomDialogMessage dialogMessage;
- /// <summary>
- /// Initializes a new instance of the MainViewModel class.
- /// </summary>
- public MainViewModel(
- INavigationService navService)
- {
- this.navService = navService;
- Messenger.Default.Register<LoadingMessage>(this, HandleLoadingMessage);
- Messenger.Default.Register<UserLoginMessage>(this, HandleUserLoginMessage);
- Messenger.Default.Register<CustomDialogMessage>(this, HandleDialogMessage);
- }
- /// <summary>
- /// Initialize data
- /// </summary>
- /// <returns></returns>
- 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<CustomDialogMessage>(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;
- }
- }
- /// <summary>
- /// Is visible dialog control.
- /// </summary>
- public bool IsVisibleDialog
- {
- get { return this.isVisibleDialog; }
- set
- {
- this.isVisibleDialog = value;
- RaisePropertyChanged();
- }
- }
- /// <summary>
- /// CustomDialogMessage instance used as datacontext for the confirmation dialog.
- /// </summary>
- 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;
- }
- /// <summary>
- /// Dispose
- /// </summary>
- /// <param name="dispose"></param>
- protected override void Dispose(bool dispose)
- {
- base.Dispose(dispose);
- Messenger.Default.Unregister<LoadingMessage>(this, HandleLoadingMessage);
- Messenger.Default.Unregister<UserLoginMessage>(this, HandleUserLoginMessage);
- Messenger.Default.Unregister<CustomDialogMessage>(this, HandleDialogMessage);
- }
- }
- }
|