Imports System.Windows.Threading
Imports EgtBEAMWALL.Core
Imports EgtWPFLib5
Imports EgtUILib

Public Class WaitingWndVM
   Inherits VMBase

#Region "FIELDS & PROPERTIES"

   Friend Event m_CloseWindow(bDialogResult As Boolean)

   Private m_Waiting_Timer As New DispatcherTimer

   Private m_nProgress_Value As Integer = 0
   Public ReadOnly Property nProgress_Value As Integer
      Get
         Return m_nProgress_Value
      End Get
   End Property

#Region "Messages"

   Public ReadOnly Property Msg_Text As String
      Get
         Return EgtMsg(61968)
      End Get
   End Property

   Public ReadOnly Property Cancel_Msg As String
      Get
         Return EgtMsg(61969)
      End Get
   End Property


#End Region    ' Messages

   ' definizione comandi
   Private m_cmdCancel As ICommand

#End Region    ' FIELDS & PROPERTIES

#Region "CONSTRUCTORS"

   Sub New()
      ' avvio contatore
      m_Waiting_Timer.Interval = TimeSpan.FromMilliseconds(500)
      AddHandler m_Waiting_Timer.Tick, AddressOf WaitingTimer_Tick
      m_Waiting_Timer.Start()
   End Sub

#End Region    ' CONSTRUCTORS

   Private Sub WaitingTimer_Tick()
      m_nProgress_Value += 1
      NotifyPropertyChanged(NameOf(nProgress_Value))
      If ViewerOptimizerCommThread.bViewerOptimizerBlocked Then 'OrElse nProgress_Value = 20 Then
         m_Waiting_Timer.Stop()
         RaiseEvent m_CloseWindow(True)
      End If
   End Sub

#Region "COMMANDS"

#Region "Cancel"

   Public ReadOnly Property Cancel_Command As ICommand
      Get
         If m_cmdCancel Is Nothing Then m_cmdCancel = New Command(AddressOf Cancel)
         Return m_cmdCancel
      End Get
   End Property

   Public Sub Cancel(ByVal param As Object)
      Map.refLeftPanelVM.bRestart = False
      ' mando notifica di sblocco ottimizzatore
      DbControllers.m_StatusMapController.UpdateAction("", Map.refSupervisorManagerVM.CurrProd.nProdId, Map.refSupervisorManagerVM.CurrProd.nProdId, StatusMapItemType.Comm, StatusMapOpType.SupervisorReleaseStop, "")
      RaiseEvent m_CloseWindow(False)
   End Sub

#End Region    ' Cancel

#End Region    ' COMMANDS

End Class
