using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL; using Tango.Core.DI; using Tango.PPC.Common.Application; using Tango.PPC.Common.Authentication; using Tango.PPC.Common.Bit; using Tango.PPC.Common.Build; using Tango.PPC.Common.Connection; using Tango.PPC.Common.Connectivity; using Tango.PPC.Common.EventLogging; using Tango.PPC.Common.ExternalBridge; using Tango.PPC.Common.HotSpot; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; using Tango.PPC.Common.Printing; using Tango.PPC.Common.RemoteAssistance; using Tango.PPC.Common.RemoteDesktop; using Tango.PPC.Common.RemoteJobUpload; using Tango.PPC.Common.Resume; using Tango.PPC.Common.SMS; using Tango.PPC.Common.Storage; using Tango.PPC.Common.Synchronization; using Tango.PPC.Common.ThreadLoading; using Tango.Settings; using Tango.SharedUI; using static Tango.SharedUI.Controls.NavigationControl; namespace Tango.PPC.Common { /// /// Represents a PPC view model base class. /// /// public abstract class PPCViewModel : ViewModel, INavigationBlocker { /// /// Gets the static observable entities adapter. /// public ObservablesStaticCollections Adapter { get { return ObservablesStaticCollections.Instance; } } /// /// Gets or sets the application manager. /// [TangoInject] public IPPCApplicationManager ApplicationManager { get; set; } /// /// Gets or sets the authentication provider. /// [TangoInject] public IAuthenticationProvider AuthenticationProvider { get; set; } /// /// Gets or sets the navigation manager. /// [TangoInject] public INavigationManager NavigationManager { get; set; } /// /// Gets or sets the notification provider. /// [TangoInject] public INotificationProvider NotificationProvider { get; set; } /// /// Gets or sets the machine provider. /// [TangoInject] public IMachineProvider MachineProvider { get; set; } /// /// Gets or sets the external bridge service. /// [TangoInject] public IPPCExternalBridgeService ExternalBridgeService { get; set; } /// /// Gets or sets the printing manager. /// [TangoInject] public IPrintingManager PrintingManager { get; set; } /// /// Gets or sets the connectivity provider. /// [TangoInject] public IConnectivityProvider ConnectivityProvider { get; set; } /// /// Gets or sets the hot spot provider. /// [TangoInject] public IHotSpotProvider HotSpotProvider { get; set; } /// /// Gets or sets the remote assistance provider. /// [TangoInject] public IRemoteAssistanceProvider RemoteAssistanceProvider { get; set; } /// /// Gets or sets the storage provider. /// [TangoInject] public IStorageProvider StorageProvider { get; set; } /// /// Gets or sets the event logger. /// [TangoInject] public IEventLogger EventLogger { get; set; } /// /// Gets or sets the machine data synchronizer. /// [TangoInject] public IMachineDataSynchronizer MachineDataSynchronizer { get; set; } /// /// Gets or sets the remote desktop service. /// [TangoInject] public IRemoteDesktopService RemoteDesktopService { get; set; } /// /// Gets or sets the thread loading service. /// [TangoInject] public IThreadLoadingService ThreadLoadingService { get; set; } /// /// Gets or sets the bit manager. /// [TangoInject] public IBitManager BitManager { get; set; } [TangoInject] public IRemoteJobUploadService RemoteJobUploadService { get; set; } [TangoInject] public IBuildProvider BuildProvider { get; set; } [TangoInject] public IJobResumeManager JobResumeManager { get; set; } [TangoInject] public ISMSNotificationProvider SMSNotificationProvider { get; set; } private PPCSettings _settings; /// /// Gets the main PPC settings. /// public PPCSettings Settings { get { if (_settings == null) { _settings = SettingsManager.Default.GetOrCreate(); } return _settings; } private set { _settings = value; } } private bool _isVisible; /// /// Gets or sets a value indicating whether this view is visible. /// public bool IsVisible { get { return _isVisible; } private set { _isVisible = value; RaisePropertyChangedAuto(); } } /// /// Called when the application has been started. /// public abstract void OnApplicationStarted(); /// /// Called when the application is shutting down. /// public virtual void OnApplicationShuttingDown() { } /// /// Called when the navigation system has navigated to this VM view. /// public virtual void OnNavigatedTo() { IsVisible = true; } /// /// Called when the navigation system has navigated to this VM view. /// /// The view model instance of the previous view model public virtual void OnNavigatedTo(PPCViewModel fromVM) { } /// /// Called when the navigation system has navigated from this VM view. /// public virtual void OnNavigatedFrom() { IsVisible = false; } /// /// Called before the navigation system has navigated to this VM view. /// public virtual void OnBeforeNavigatedTo() { } /// /// Called before the navigation system has navigated from this VM view. /// public virtual void OnBeforeNavigatedFrom() { IsVisible = false; } /// /// Raises the specified message using the default . /// /// /// The message. protected void RaiseMessage(T message) where T : class { TangoMessenger.Default.Send(message); } /// /// Raises the specified message using the default . /// /// protected void RaiseMessage() where T : class { TangoMessenger.Default.Send(Activator.CreateInstance()); } /// /// Registers a message handle for the specified message type T. /// /// /// The handler. protected void RegisterForMessage(Action handler) { TangoMessenger.Default.Register(handler); } /// /// Called before the navigation system navigates from this object. /// Return false to abort the navigation. /// /// public virtual Task OnNavigateOutRequest() { return Task.FromResult(true); } /// /// Called before the navigation system navigates back from this object. /// Return false to abort the navigation. /// /// public virtual Task OnNavigateBackRequest() { return Task.FromResult(true); } /// /// Called when the application is ready and all modules views are loaded. /// public virtual void OnApplicationReady() { } } /// /// Represents a PPC view model base class a View property as an instance of a contract. /// /// /// public abstract class PPCViewModel : PPCViewModel where T : IPPCView { private T _view; /// /// Gets the IPPCView instance. /// [TangoInject(TangoInjectMode.WhenAvailable)] public T View { get { return _view; } set { _view = value; ViewAttached = true; OnViewAttached(); } } /// /// Gets a value indicating whether the instance of IPPCView is available. /// public bool ViewAttached { get; private set; } /// /// Called when the application has been started. /// public override void OnApplicationStarted() { } /// /// Called when the instance of IPPCView is available. /// public virtual void OnViewAttached() { } } }