253 lines
7.8 KiB
C#
253 lines
7.8 KiB
C#
using System.ComponentModel;
|
|
using System.ComponentModel.Composition;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Media;
|
|
using DTS.Common.Enums.Database;
|
|
using DTS.Common.Events;
|
|
using DTS.Common.Events.Database;
|
|
using Prism.Events;
|
|
using Prism.Regions;
|
|
using Unity;
|
|
using DTS.Common.Interactivity;
|
|
using Prism.Commands;
|
|
using DTS.Common.Interface.Database;
|
|
using DTS.Common.Storage;
|
|
|
|
// ReSharper disable CheckNamespace
|
|
// ReSharper disable MemberCanBePrivate.Global
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
namespace DatabaseServices
|
|
{
|
|
/// <summary>
|
|
/// this class handles DatabaseCopy functionality
|
|
/// </summary>
|
|
[PartCreationPolicy(CreationPolicy.Shared)]
|
|
public class DatabaseStatusBarViewModel : IDatabaseStatusBarViewModel
|
|
{
|
|
/// <summary>
|
|
/// The DatabaseCopy view
|
|
/// </summary>
|
|
public IDatabaseStatusBarView View { get; set; }
|
|
|
|
private IEventAggregator _eventAggregator { get; }
|
|
private IRegionManager _regionManager;
|
|
private IUnityContainer UnityContainer { get; }
|
|
|
|
public InteractionRequest<Notification> NotificationRequest { get; }
|
|
public InteractionRequest<Confirmation> ConfirmationRequest { get; }
|
|
|
|
/// <inheritdoc />
|
|
/// <summary>
|
|
/// Occurs when a property value changes.
|
|
/// </summary>
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
public void OnPropertyChanged(string propertyName)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
#region constructors and initializers
|
|
|
|
/// <summary>
|
|
/// Creates a new instance of the DatabaseCopyViewModel
|
|
/// </summary>
|
|
/// <param name="view"></param>
|
|
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
|
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
|
|
/// <param name="unityContainer">The unityContainer.</param>
|
|
public DatabaseStatusBarViewModel(IDatabaseStatusBarView view, IRegionManager regionManager,
|
|
IEventAggregator eventAggregator, IUnityContainer unityContainer)
|
|
{
|
|
View = view;
|
|
View.DataContext = this;
|
|
|
|
NotificationRequest = new InteractionRequest<Notification>();
|
|
ConfirmationRequest = new InteractionRequest<Confirmation>();
|
|
|
|
_eventAggregator = eventAggregator;
|
|
UnityContainer = unityContainer;
|
|
_regionManager = regionManager;
|
|
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
|
|
_eventAggregator.GetEvent<BusyIndicatorChangeNotification>()
|
|
.Subscribe(OnBusyIndicatorNotification, ThreadOption.PublisherThread, true);
|
|
_eventAggregator.GetEvent<DbStatusEvent>().Subscribe(OnDbEvent);
|
|
}
|
|
|
|
public DatabaseStatusBarViewModel()
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
private void OnDbEvent(DbStatusArg args)
|
|
{
|
|
if (args.Status == DbStatusArg.EventTypes.LegacyStatus)
|
|
{
|
|
if (RemoteConnected)
|
|
{
|
|
ServerName = DbOperations.Connection.Server;
|
|
}
|
|
else
|
|
{
|
|
ServerName = "Local";
|
|
}
|
|
OnPropertyChanged("ActiveDbName");
|
|
OnPropertyChanged("BackgroundBrush");
|
|
}
|
|
}
|
|
public void Unset()
|
|
{
|
|
}
|
|
|
|
public DbType DatabaseType { get; private set; }
|
|
|
|
public void InitializeValues(DbType dbType, string serverName, bool remoteConnected)
|
|
{
|
|
DatabaseType = dbType;
|
|
ServerName = serverName;
|
|
OnPropertyChanged("ActiveDbName");
|
|
OnPropertyChanged("BackgroundBrush");
|
|
}
|
|
|
|
public bool RemoteConnected => DbOperations._usingCentralizedDB;
|
|
|
|
public string ServerName { get; private set; }
|
|
|
|
public string ActiveDbName
|
|
{
|
|
get
|
|
{
|
|
switch (DatabaseType)
|
|
{
|
|
case DbType.LocalOnly: return Resources.StringResources.Local;
|
|
case DbType.RemoteOnly: return ServerName;
|
|
case DbType.RemoteLocalHybrid:
|
|
{
|
|
return RemoteConnected ? ServerName : Resources.StringResources.Local;
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public Brush BackgroundBrush
|
|
{
|
|
get
|
|
{
|
|
switch (DatabaseType)
|
|
{
|
|
case DbType.RemoteLocalHybrid:
|
|
return RemoteConnected ? Brushes.Transparent : Brushes.Red;
|
|
}
|
|
return Brushes.Transparent;
|
|
}
|
|
}
|
|
|
|
public void Cleanup()
|
|
{
|
|
}
|
|
|
|
public Task CleanupAsync()
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
}
|
|
|
|
public void Initialize(object parameter)
|
|
{
|
|
}
|
|
|
|
public void Initialize(object parameter, object model)
|
|
{
|
|
}
|
|
|
|
public Task InitializeAsync()
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task InitializeAsync(object parameter)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public void Activated()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Private Event handler for RaiseNotification event.
|
|
/// </summary>
|
|
private void OnBusyIndicatorNotification(bool eventArg)
|
|
{
|
|
IsBusy = eventArg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Private Event handler for RaiseNotification event.
|
|
/// </summary>
|
|
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
|
|
{
|
|
// The NotificationRequest.Raise triggers the Invoke() method of the PopupWindowAction object to show the NotificationWindow window
|
|
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
|
|
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, "",
|
|
eventArgsWithTitle.Image, string.Empty);
|
|
|
|
NotificationRequest.Raise(new Notification
|
|
{
|
|
Content = eventArgsWithoutTitle,
|
|
Title = eventArgsWithTitle.Title
|
|
});
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
public bool IsDirty { get; private set; }
|
|
private bool _isBusy = false;
|
|
public bool IsBusy
|
|
{
|
|
get => _isBusy;
|
|
set
|
|
{
|
|
_isBusy = value;
|
|
OnPropertyChanged("IsBusy");
|
|
}
|
|
}
|
|
|
|
private bool _isMenuIncluded;
|
|
public bool IsMenuIncluded
|
|
{
|
|
get => _isMenuIncluded;
|
|
set
|
|
{
|
|
_isMenuIncluded = value;
|
|
OnPropertyChanged("IsMenuIncluded");
|
|
}
|
|
}
|
|
|
|
private bool _isNavigationIncluded;
|
|
public bool IsNavigationIncluded
|
|
{
|
|
get => _isNavigationIncluded;
|
|
set
|
|
{
|
|
_isNavigationIncluded = value;
|
|
OnPropertyChanged("IsNavigationIncluded");
|
|
}
|
|
}
|
|
#endregion Properties
|
|
|
|
#region Commands
|
|
|
|
#endregion
|
|
}
|
|
}
|