Files
effector.plugin.fivelakes/Effector.Plugin.FiveLakes/DoorListPage/DoorListPageVM.vb
T
Emmanuele Sassi 717519bb2c - aggiunto debug delle ripartenze
- eliminata colonna quantita' che e' sempre 1
- aggiunto colore di sfondo righe in base allo stato
- aggiunto reset stato porte su reset macchina
- aggiunta eliminazione file di generazione porta su verifica
- aggiunta configurazione per delimitatore csv
- aggiunta gestione cartella separata dei ddf di ogni porta con indice
- aggiunta gestione grafica dello sfrido
- aggiunta posizione porta
- aggiunta progressbar su finestra di verifica
- migliorata gestione pagina di restart
2024-11-08 16:35:06 +01:00

935 lines
35 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports Newtonsoft.Json
Imports System.Windows.Threading
Imports System.Text.RegularExpressions
Public Class DoorListPageVM
Inherits VMBase
Private m_BackupTimer As New DispatcherTimer
Private m_RefreshGraphicsTimer As New DispatcherTimer
Private m_ExecProcessManager As ExecProcessManager
Private m_DoorList As New ObservableCollection(Of Door)
Public ReadOnly Property DoorList As ObservableCollection(Of Door)
Get
Return m_DoorList
End Get
End Property
Private m_SelDoor As Door
Public Property SelDoor As Door
Get
Return m_SelDoor
End Get
Set(value As Door)
m_SelDoor = value
End Set
End Property
Private m_bExecButton_IsEnabled As Boolean = True
Public ReadOnly Property bExecButton_IsEnabled As Boolean
Get
Return m_bExecButton_IsEnabled
End Get
End Property
Private Sub SetExecButtonIsEnabled(bValue As Boolean)
m_bExecButton_IsEnabled = bValue
NotifyPropertyChanged(NameOf(bExecButton_IsEnabled))
End Sub
Private m_nModifyIndex As Integer = 0
Private m_nBackupindex As Integer = 0
Private m_bWritingBackup As Boolean = False
' Definizione comandi
Private m_cmdOpenCSV As ICommand
Private m_cmdSkipDoor As ICommand
Private m_cmdMoveUp As ICommand
Private m_cmdMoveDown As ICommand
Private m_cmdDelete As ICommand
Private m_cmdDeleteAll As ICommand
Private m_cmdProduce As ICommand
Private m_cmdProduceAll As ICommand
Private m_cmdResetProductionQueue As ICommand
Private m_cmdVerify As ICommand
#Region "CONSTRUCTOR"
Sub New()
' imposto riferimento in Map
Map.SetRefDoorListPageVM(Me)
Dim sBackupDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "BackupDir", "", sBackupDirPath)
Dim sBackupFilePath As String = sBackupDirPath & "\Backup.json"
Read(sBackupFilePath)
m_BackupTimer.Interval = New TimeSpan(0, 0, 1)
AddHandler m_BackupTimer.Tick, AddressOf BackupTimer_Tick
m_RefreshGraphicsTimer.Interval = New TimeSpan(0, 0, 1)
AddHandler m_RefreshGraphicsTimer.Tick, AddressOf RefreshGraphicsTimer_Tick
m_BackupTimer.Start()
m_RefreshGraphicsTimer.Start()
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Function ExecCAMProcess(sDDFName As String) As Boolean
' lancio esecuzione programma
Dim sCamExePath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "CAMExePath", "", sCamExePath)
Dim sMainLuaPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "MainLUA", "", sMainLuaPath)
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
Dim sDDFFilePath As String = sGenDDFDirPath & "\" & sDDFName
Return Map.refSupervisorFunction.PlgExecProcess(sCamExePath, sMainLuaPath, sDDFFilePath)
End Function
Friend Function ExecCAMProcessAsync(sDDFName As String) As Boolean
' lancio esecuzione programma
Dim sCamExePath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "CAMExePath", "", sCamExePath)
Dim sMainLuaPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "MainLUA", "", sMainLuaPath)
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
Dim sDDFFilePath As String = sGenDDFDirPath & "\" & sDDFName
Return Map.refSupervisorFunction.PlgExecProcessAsync(sCamExePath, sMainLuaPath, sDDFFilePath)
End Function
Public Sub Read(FilePath As String)
If Not File.Exists(FilePath) Then Return
Dim sReadedFile As String = File.ReadAllText(FilePath)
Dim JsonDoorList As List(Of JsonDoor) = JsonConvert.DeserializeObject(Of List(Of JsonDoor))(sReadedFile)
JsonDoorList = JsonDoorList.OrderBy(Of Integer)(Function(x) x.nListIndex).ToList()
m_DoorList = New ObservableCollection(Of Door)((From JsonDoor In JsonDoorList
Select New Door(JsonDoor)).ToList())
End Sub
Public Sub Write(FilePath As String)
Dim JsonDoorList As New List(Of JsonDoor)
For nDoorIndex As Integer = 0 To m_DoorList.Count - 1
JsonDoorList.Add(New JsonDoor(nDoorIndex + 1, m_DoorList(nDoorIndex)))
Next
Dim JsonFromWindow As String = JsonConvert.SerializeObject(JsonDoorList, Formatting.Indented)
If File.Exists(FilePath) Then
Dim sBackupFilePath As String = Path.ChangeExtension(FilePath, ".bck")
If File.Exists(sBackupFilePath) Then
Try
File.Delete(sBackupFilePath)
Catch ex As Exception
Map.refSupervisorFunction.PlgOutLog("Error! Impossible deleting backup file!")
End Try
End If
Try
File.Move(FilePath, sBackupFilePath)
Catch ex As Exception
Map.refSupervisorFunction.PlgOutLog("Error! Impossible renaming backup file!")
End Try
End If
File.WriteAllText(FilePath, JsonFromWindow)
End Sub
Private Sub WriteBackupCmd()
If m_bWritingBackup Then Return
m_bWritingBackup = True
m_nBackupindex = m_nModifyIndex
Dim sBackupDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_BACKUPDIR, "", sBackupDirPath)
Dim sBackupFilePath As String = sBackupDirPath & "\Backup.json"
Write(sBackupFilePath)
m_bWritingBackup = False
End Sub
Friend Sub WriteBackup()
m_nModifyIndex += 1
End Sub
Private Sub BackupTimer_Tick(sender As Object, e As EventArgs)
If m_nBackupindex < m_nModifyIndex Then
WriteBackupCmd()
End If
End Sub
Private Sub RefreshGraphicsTimer_Tick(sender As Object, e As EventArgs)
If IsNothing(m_ExecProcessManager) Then Return
' ciclo su coda risultati
Dim ArgumentsResult As ProcessArgsResult = m_ExecProcessManager.ArgumentsResultDequeue
While Not IsNothing(ArgumentsResult)
' aggiorno risultato sulla porta
Dim CurrRequestDoor As Door = m_DoorList.FirstOrDefault(Function(x) x.nId = ArgumentsResult.ProcessArgs.nId)
If Not IsNothing(CurrRequestDoor) Then
CurrRequestDoor.SetState(If(ArgumentsResult.nResult = 0, Door.DoorStates.VERIFIED, Door.DoorStates.VERIFICATION_FAILED))
' elimino file generati
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
Dim sDoorFileName As String = CurrRequestDoor.sDDFName & "_" & CurrRequestDoor.nId
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & ".tok")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & "_2.tok")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & ".cnc")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & "_a.cnc")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & "_b.cnc")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & "_2.cnc")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & "_2_a.cnc")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & ".html")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & "_2.html")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & ".log")
File.Delete(sGenDDFDirPath & "\" & CurrRequestDoor.sDDFName & ".nge")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & ".nge")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & ".sest")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & "_2.sest")
File.Delete(sGenDDFDirPath & "\" & CurrRequestDoor.sDDFName & ".txt")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & ".txt")
File.Delete(sGenDDFDirPath & "\" & sDoorFileName & "_2.txt")
End If
WriteBackup()
ArgumentsResult = m_ExecProcessManager.ArgumentsResultDequeue
End While
If Not bExecButton_IsEnabled AndAlso m_ExecProcessManager.ExecutionThreadStatus = ExecProcessManager.ExecutionThreadStatuses.STOPPED Then
SetExecButtonIsEnabled(True)
End If
End Sub
Friend Function GetNextDoor() As Door
Dim NextDoor As Door = m_DoorList.FirstOrDefault(Function(x) x.nState = Door.DoorStates.READY_FOR_PRODUCTION)
If Not IsNothing(NextDoor) Then
Map.refSupervisorFunction.PlgOutLog("GetNextDoor: door " & NextDoor.nId & " set at ON_LOAD_STATION")
NextDoor.SetState(Door.DoorStates.ON_LOAD_STATION)
WriteBackup()
End If
Return NextDoor
End Function
Public Sub ResetProductionQueue()
For Each Door In m_DoorList
If Door.nState = Door.DoorStates.READY_FOR_PRODUCTION Then
Door.SetState(Door.DoorStates.VERIFIED, False)
End If
Next
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "OpenCSV"
Public ReadOnly Property OpenCSV_Command As ICommand
Get
If m_cmdOpenCSV Is Nothing Then
m_cmdOpenCSV = New Command(AddressOf OpenCSV)
End If
Return m_cmdOpenCSV
End Get
End Property
Public Sub OpenCSV()
Dim sDir As String = String.Empty
'GetMainPrivateProfileString(S_GENERAL, K_LASTIMPDIR, "", sDir)
Dim OpenFileDialog As New Microsoft.Win32.OpenFileDialog() With {
.DefaultExt = ".csv",
.Filter = "CSV (*.csv)|*.csv",
.InitialDirectory = If(Directory.Exists(sDir), sDir, ""),
.CheckFileExists = True,
.ValidateNames = True}
If OpenFileDialog.ShowDialog() Then
Dim sCSVPath As String = OpenFileDialog.FileName
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(sCSVPath)
MyReader.TextFieldType = FileIO.FieldType.Delimited
Dim sDelimiter As String = ""
GetPluginPrivateProfileString(S_CSV, K_DELIMITER, ";", sDelimiter)
MyReader.SetDelimiters(sDelimiter)
' leggo intestazione
Dim Headers As String() = MyReader.ReadFields()
Dim sDDFName As String = ""
Dim sQuantityName As String = ""
Dim sHeightName As String = ""
Dim sWidthName As String = ""
Dim sThicknessName As String = ""
GetPluginPrivateProfileString(S_CSV, K_DDFNAME, K_DDFNAME, sDDFName)
GetPluginPrivateProfileString(S_CSV, K_QUANTITY, "", sQuantityName)
GetPluginPrivateProfileString(S_CSV, K_HEIGHT, "", sHeightName)
GetPluginPrivateProfileString(S_CSV, K_WIDTH, "", sWidthName)
GetPluginPrivateProfileString(S_CSV, K_THICKNESS, "", sThicknessName)
Dim nDDFNameIndex As Integer = Array.IndexOf(Headers, sDDFName)
Dim nQuantityNameIndex As Integer = Array.IndexOf(Headers, sQuantityName)
Dim nHeightNameIndex As Integer = Array.IndexOf(Headers, sHeightName)
Dim nWidthNameIndex As Integer = Array.IndexOf(Headers, sWidthName)
Dim nThicknessNameIndex As Integer = Array.IndexOf(Headers, sThicknessName)
If nDDFNameIndex = -1 Then
Dim sMessage As String = "Error! DDFName column not found! Csv file will not be read!"
' egtoutlog(sMessage)
MessageBox.Show(sMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
Dim Values As String()
Dim nLineIndex As Integer = 1
Dim sLineErrorList As String = ""
While Not MyReader.EndOfData
Try
Values = MyReader.ReadFields()
Dim nQuantity As Integer = 1
If nQuantityNameIndex >= 0 AndAlso nQuantityNameIndex < Values.Count Then
If Not Integer.TryParse(Values(nQuantityNameIndex), nQuantity) OrElse nQuantity < 1 Then
nQuantity = 1
Dim sLine As String = ""
For nValueIndex = 0 To Values.Count - 1
sLine &= Values(nValueIndex) & If(nValueIndex < Values.Count, ";", "")
Next
sLineErrorList &= "Quantity not readable in line " & sLine & ". This line will be skipped"
Continue While
End If
End If
Dim dWidth As Double = 0
If nWidthNameIndex >= 0 AndAlso nWidthNameIndex < Values.Count Then
If Not StringToDouble(Values(nWidthNameIndex), dWidth) OrElse dWidth < 0 Then
dWidth = 0
End If
End If
Dim dHeight As Double = 0
If nHeightNameIndex >= 0 AndAlso nHeightNameIndex < Values.Count Then
If Not StringToDouble(Values(nHeightNameIndex), dHeight) OrElse dHeight < 0 Then
dHeight = 0
End If
End If
Dim dThickness As Double = 0
If nThicknessNameIndex >= 0 AndAlso nThicknessNameIndex < Values.Count Then
If Not StringToDouble(Values(nThicknessNameIndex), dThickness) OrElse dThickness < 0 Then
dThickness = 0
End If
End If
For nQuantityIndex = 1 To nQuantity
Dim nId As Integer = 1
If m_DoorList.Count > 0 Then
Dim nMaxId As Integer = m_DoorList.Max(Of Integer)(Function(x) x.nId)
'If nMaxId < 100 Then
nId = nMaxId + 1
'End If
End If
Dim NewDoor As New Door(nId, nLineIndex, Values(nDDFNameIndex), Path.GetFileName(sCSVPath),
1, dWidth, dHeight, dThickness, Headers, Values)
m_DoorList.Add(NewDoor)
Next
nLineIndex += 1
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
Dim sMessage As String = "Line " & ex.Message & "is not valid and will be skipped."
' egtoutlog(sMessage)
sLineErrorList &= Environment.NewLine & ex.Message
End Try
End While
If Not String.IsNullOrWhiteSpace(sLineErrorList) Then
MessageBox.Show("The following lines are not valid and have been skipped:" & sLineErrorList, "Error", MessageBoxButton.OK, MessageBoxImage.Error)
End If
End Using
Dim sCamExePath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "CAMExePath", "", sCamExePath)
Dim sMainLuaPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "MainPipeLUA", "", sMainLuaPath)
Dim bStartExecProcessManager As Boolean = False
If IsNothing(m_ExecProcessManager) Then
bStartExecProcessManager = True
m_ExecProcessManager = New ExecProcessManager(sCamExePath, """" & sMainLuaPath & """")
AddHandler m_ExecProcessManager.m_AllArgsProcessed, AddressOf ExecProcessManager_AllArgsProcessed
m_ExecProcessManager.SetMaxCamInstances(3)
End If
Dim sDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_DDFDIR, "", sDDFDirPath)
Dim sGenDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, K_GENDDFDIR, "", sGenDDFDirPath)
For Each Door In m_DoorList
If Door.nState = Door.DoorStates.LOADED_FROM_CSV Then
Dim sDDFFilePath As String = sDDFDirPath & "\" & Door.sDDFName & ".ddf"
Dim sGenDDFFilePath As String = sGenDDFDirPath & "\" & Door.sDDFName & "_" & Door.nId & ".ddf"
Try
File.Copy(sDDFFilePath, sGenDDFFilePath, True)
Catch ex As Exception
Map.refSupervisorFunction.PlgOutLog("Error: Copy file from " & sDDFFilePath & " to " & sGenDDFFilePath & " failed!")
End Try
m_ExecProcessManager.ArgumentsEnqueue(New ProcessArgs(Door.nId, sGenDDFFilePath))
End If
Next
If bStartExecProcessManager OrElse m_ExecProcessManager.ExecutionThreadStatus = ExecProcessManager.ExecutionThreadStatuses.STOPPED Then
m_ExecProcessManager.StartExecutionThread()
SetExecButtonIsEnabled(False)
End If
End If
WriteBackup()
End Sub
Public Sub ExecProcessManager_AllArgsProcessed()
m_ExecProcessManager.StopExecutionThread()
End Sub
Public Sub ExecProcessManager_PostProcess(ProcessArgsResult As ProcessArgsResult)
' verifico file di risultati
Dim sDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "DDFDir", "", sDDFDirPath)
Dim sDDFFilePath As String = sDDFDirPath & "\" & ProcessArgsResult.ProcessArgs.sArgs
Dim sTxtFilePath As String = Path.ChangeExtension(sDDFDirPath, ".txt")
If Not File.Exists(sTxtFilePath) Then
ProcessArgsResult.SetResult(-1)
Return
End If
Dim TxtFileLines As String() = File.ReadAllLines(sTxtFilePath)
For nLineIndex As Integer = 0 To TxtFileLines.Count - 1
Dim Match As Match = Regex.Match(TxtFileLines(nLineIndex), "\s*Err\s*=\s*(\d*)\s*")
If Not IsNothing(Match) AndAlso Not IsNothing(Match.Groups(1)) Then
Dim sResult As String = Match.Groups(1).Value
Dim nResult As Integer = -2
If Integer.TryParse(sResult, nResult) Then
ProcessArgsResult.SetResult(nResult)
Else
ProcessArgsResult.SetResult(-2)
End If
End If
Next
End Sub
#End Region ' OpenCSV
#Region "SkipDoor"
Public ReadOnly Property SkipDoor_Command As ICommand
Get
If m_cmdSkipDoor Is Nothing Then
m_cmdSkipDoor = New Command(AddressOf SkipDoor)
End If
Return m_cmdSkipDoor
End Get
End Property
Public Sub SkipDoor()
If IsNothing(SelDoor) OrElse (SelDoor.nState <> Door.DoorStates.VERIFIED AndAlso SelDoor.nState <> Door.DoorStates.SKIPPED) Then Return
SelDoor.SetState(If(SelDoor.nState = Door.DoorStates.VERIFIED, Door.DoorStates.SKIPPED, Door.DoorStates.VERIFIED))
WriteBackup()
End Sub
#End Region ' SkipDoor
#Region "MoveUp"
Public ReadOnly Property MoveUp_Command As ICommand
Get
If m_cmdMoveUp Is Nothing Then
m_cmdMoveUp = New Command(AddressOf MoveUp)
End If
Return m_cmdMoveUp
End Get
End Property
Public Sub MoveUp()
If IsNothing(SelDoor) Then Return
Dim nOldIndex As Integer = m_DoorList.IndexOf(SelDoor)
If nOldIndex = 0 Then Return
If m_DoorList(nOldIndex - 1).nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Return
m_DoorList.Move(nOldIndex, nOldIndex - 1)
WriteBackup()
End Sub
#End Region ' MoveUp
#Region "MoveDown"
Public ReadOnly Property MoveDown_Command As ICommand
Get
If m_cmdMoveDown Is Nothing Then
m_cmdMoveDown = New Command(AddressOf MoveDown)
End If
Return m_cmdMoveDown
End Get
End Property
Public Sub MoveDown()
If IsNothing(SelDoor) OrElse SelDoor.nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Return
Dim nOldIndex As Integer = m_DoorList.IndexOf(SelDoor)
If nOldIndex = m_DoorList.Count - 1 Then Return
m_DoorList.Move(nOldIndex, nOldIndex + 1)
WriteBackup()
End Sub
#End Region ' MoveDown
#Region "Delete"
Public ReadOnly Property Delete_Command As ICommand
Get
If m_cmdDelete Is Nothing Then
m_cmdDelete = New Command(AddressOf Delete)
End If
Return m_cmdDelete
End Get
End Property
Public Sub Delete()
If IsNothing(SelDoor) OrElse SelDoor.nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Return
If MessageBox.Show("Are you sure you want to delete the selected door?", "Info", MessageBoxButton.YesNo, MessageBoxImage.Information) = MessageBoxResult.Yes Then
m_DoorList.Remove(SelDoor)
WriteBackup()
End If
End Sub
#End Region ' Delete
#Region "DeleteAll"
Public ReadOnly Property DeleteAll_Command As ICommand
Get
If m_cmdDeleteAll Is Nothing Then
m_cmdDeleteAll = New Command(AddressOf DeleteAll)
End If
Return m_cmdDeleteAll
End Get
End Property
Public Sub DeleteAll()
If m_DoorList.Count = 0 Then Return
If MessageBox.Show("Are you sure you want to delete all the doors?", "Info", MessageBoxButton.YesNo, MessageBoxImage.Information) = MessageBoxResult.Yes Then
For nDoorIndex = m_DoorList.Count - 1 To 0 Step -1
Dim Door As Door = m_DoorList(nDoorIndex)
If Door.nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Continue For
m_DoorList.Remove(Door)
Next
WriteBackup()
End If
End Sub
#End Region ' DeleteAll
#Region "Produce"
Public ReadOnly Property Produce_Command As ICommand
Get
If m_cmdProduce Is Nothing Then
m_cmdProduce = New Command(AddressOf Produce)
End If
Return m_cmdProduce
End Get
End Property
Public Sub Produce()
ProduceDoor(m_SelDoor)
WriteBackup()
End Sub
Public Sub ProduceDoor(DoorToProduce As Door, Optional bWriteBackup As Boolean = True)
If IsNothing(DoorToProduce) OrElse DoorToProduce.nState = Door.DoorStates.SKIPPED OrElse
DoorToProduce.nState = Door.DoorStates.VERIFICATION_FAILED OrElse
DoorToProduce.nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Return
' la sposto dopo l'ultima da produrre
Dim nNewIndex As Integer = m_DoorList.IndexOf(m_DoorList.FirstOrDefault(Function(x) x.nState < Door.DoorStates.READY_FOR_PRODUCTION))
Dim nOldIndex As Integer = m_DoorList.IndexOf(DoorToProduce)
m_DoorList.Move(nOldIndex, nNewIndex)
DoorToProduce.SetState(Door.DoorStates.READY_FOR_PRODUCTION, bWriteBackup)
End Sub
#End Region ' Produce
#Region "ProduceAll"
Public ReadOnly Property ProduceAll_Command As ICommand
Get
If m_cmdProduceAll Is Nothing Then
m_cmdProduceAll = New Command(AddressOf ProduceAll)
End If
Return m_cmdProduceAll
End Get
End Property
Public Sub ProduceAll()
If m_DoorList.Count = 0 Then Return
For nDoorIndex = 0 To m_DoorList.Count - 1
Dim CurrDoor As Door = m_DoorList(nDoorIndex)
ProduceDoor(CurrDoor, False)
Next
WriteBackup()
End Sub
#End Region ' ProduceAll
#Region "ResetProductionQueue"
Public ReadOnly Property ResetProductionQueue_Command As ICommand
Get
If m_cmdResetProductionQueue Is Nothing Then
m_cmdResetProductionQueue = New Command(AddressOf ResetProductionQueueCmd)
End If
Return m_cmdResetProductionQueue
End Get
End Property
Public Sub ResetProductionQueueCmd()
ResetProductionQueue()
WriteBackup()
End Sub
#End Region ' ResetProductionQueue
#Region "Verify"
Public ReadOnly Property Verify_Command As ICommand
Get
If m_cmdVerify Is Nothing Then
m_cmdVerify = New Command(AddressOf Verify)
End If
Return m_cmdVerify
End Get
End Property
Public Sub Verify()
Dim sCamExePath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "CAMExePath", "", sCamExePath)
Dim sMainLuaPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "MainPipeLUA", "", sMainLuaPath)
Dim bStartExecProcessManager As Boolean = False
If IsNothing(m_ExecProcessManager) Then
bStartExecProcessManager = True
m_ExecProcessManager = New ExecProcessManager(sCamExePath, """" & sMainLuaPath & """")
'm_ExecProcessManager.SetPostProcess(AddressOf ExecProcessManager_PostProcess)
AddHandler m_ExecProcessManager.m_AllArgsProcessed, AddressOf ExecProcessManager_AllArgsProcessed
m_ExecProcessManager.SetMaxCamInstances(3)
End If
Dim sDDFDirPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "DDFDir", "", sDDFDirPath)
For Each Door In m_DoorList
If Door.nState = Door.DoorStates.LOADED_FROM_CSV Or Door.nState = Door.DoorStates.VERIFICATION_FAILED Then
Dim sDDFFilePath As String = sDDFDirPath & "\" & Door.sDDFName & ".ddf"
m_ExecProcessManager.ArgumentsEnqueue(New ProcessArgs(Door.nId, sDDFFilePath))
End If
Next
If bStartExecProcessManager OrElse m_ExecProcessManager.ExecutionThreadStatus = ExecProcessManager.ExecutionThreadStatuses.STOPPED Then
m_ExecProcessManager.StartExecutionThread()
SetExecButtonIsEnabled(False)
End If
WriteBackup()
End Sub
#End Region ' Verify
#End Region ' COMMANDS
End Class
Public Class Door
Inherits VMBase
Public Enum DoorStates As Integer
NULL = 0
LOADED_FROM_CSV = 1
VERIFIED = 10
VERIFICATION_FAILED = 11
SKIPPED = 20
READY_FOR_PRODUCTION = 30
ON_LOAD_STATION = 31
MACHINE_1_START = 33
MACHINE_1_END = 34
MACHINE_2_START = 35
MACHINE_2_END = 36
PRODUCED = 37
SCRAP = 40
End Enum
Public Enum DoorProdStates As Integer
NOT_INIT = 0
IMPORTED = 1
SENT_1 = 2
START_MACHINING_1 = 3
MACHINED_1 = 4
SENT_2 = 5
START_MACHINING_2 = 6
MACHINED_2 = 7
UNLOADED = 8
End Enum
Private m_nId As Integer
Public ReadOnly Property nId As Integer
Get
Return m_nId
End Get
End Property
Private m_nCSVLine As Integer
Public ReadOnly Property nCSVLine As Integer
Get
Return m_nCSVLine
End Get
End Property
Private m_sDDFName As String
Public ReadOnly Property sDDFName As String
Get
Return m_sDDFName
End Get
End Property
Private m_nQuantity As Integer
Public ReadOnly Property nQuantity As Integer
Get
Return m_nQuantity
End Get
End Property
Private m_dWidth As Double
Public ReadOnly Property dWidth As Double
Get
Return m_dWidth
End Get
End Property
Private m_dHeight As Double
Public ReadOnly Property dHeight As Double
Get
Return m_dHeight
End Get
End Property
Private m_dThickness As Double
Public ReadOnly Property dThickness As Double
Get
Return m_dThickness
End Get
End Property
Private m_sCSVName As String
Public ReadOnly Property sCSVName As String
Get
Return m_sCSVName
End Get
End Property
Private m_CustomerParameters As New List(Of CustomerParameter)
Public ReadOnly Property CustomerParameters As List(Of CustomerParameter)
Get
Return m_CustomerParameters
End Get
End Property
Private m_nState As DoorStates = DoorStates.LOADED_FROM_CSV
Public ReadOnly Property nState As DoorStates
Get
Return m_nState
End Get
End Property
Friend Sub SetState(value As DoorStates, Optional bWriteBackup As Boolean = True, Optional bUpdate As Boolean = True)
m_nState = value
If bWriteBackup Then Map.refDoorListPageVM.WriteBackup()
If bUpdate Then
NotifyPropertyChanged(NameOf(nState))
NotifyPropertyChanged(NameOf(Background))
End If
End Sub
#Region "Statistics"
Private m_nProdState As DoorProdStates = DoorProdStates.NOT_INIT
Public ReadOnly Property nProdState As DoorProdStates
Get
Return m_nProdState
End Get
End Property
Friend Sub SetProdState(value As DoorProdStates)
m_nProdState = value
Select Case value
Case DoorProdStates.SENT_1
SetState(DoorStates.ON_LOAD_STATION)
Case DoorProdStates.START_MACHINING_1
SetState(DoorStates.MACHINE_1_START)
Case DoorProdStates.MACHINED_1
SetState(DoorStates.MACHINE_1_END)
Case DoorProdStates.START_MACHINING_2
SetState(DoorStates.MACHINE_2_START)
Case DoorProdStates.MACHINED_2
SetState(DoorStates.MACHINE_2_END)
Case DoorProdStates.UNLOADED
SetState(DoorStates.PRODUCED)
End Select
NotifyPropertyChanged(NameOf(nProdState))
End Sub
Private m_dtLoadTime As DateTime = DateTime.MinValue
Friend ReadOnly Property dtLoadTime As DateTime
Get
Return m_dtLoadTime
End Get
End Property
Public ReadOnly Property sLoadTime As String
Get
Return If(m_dtLoadTime <> DateTime.MinValue, m_dtLoadTime.ToString("yy/MM/dd hh:mm:ss"), "")
End Get
End Property
Friend Sub SetLoadTime(LoadTime As Long)
m_dtLoadTime = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(LoadTime).ToLocalTime()
NotifyPropertyChanged(NameOf(sLoadTime))
End Sub
Private m_dtMachining1Start As DateTime = DateTime.MinValue
Friend ReadOnly Property dtMachining1Start As DateTime
Get
Return m_dtMachining1Start
End Get
End Property
Public ReadOnly Property sMachining1Start As String
Get
Return If(m_dtMachining1Start <> DateTime.MinValue, m_dtMachining1Start.ToString("yy/MM/dd hh:mm:ss"), "")
End Get
End Property
Friend Sub SetMachining1Start(Machining1Start As Long)
m_dtMachining1Start = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Machining1Start).ToLocalTime()
NotifyPropertyChanged(NameOf(sMachining1Start))
End Sub
Private m_dtMachining1End As DateTime = DateTime.MinValue
Friend ReadOnly Property dtMachining1End As DateTime
Get
Return m_dtMachining1End
End Get
End Property
Public ReadOnly Property sMachining1End As String
Get
Return If(m_dtMachining1End <> DateTime.MinValue, m_dtMachining1End.ToString("yy/MM/dd hh:mm:ss"), "")
End Get
End Property
Friend Sub SetMachining1End(Machining1End As Long)
m_dtMachining1End = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Machining1End).ToLocalTime()
NotifyPropertyChanged(NameOf(sMachining1End))
End Sub
Private m_dtMachining2Start As DateTime = DateTime.MinValue
Friend ReadOnly Property dtMachining2Start As DateTime
Get
Return m_dtMachining2Start
End Get
End Property
Public ReadOnly Property sMachining2Start As String
Get
Return If(m_dtMachining2Start <> DateTime.MinValue, m_dtMachining2Start.ToString("yy/MM/dd hh:mm:ss"), "")
End Get
End Property
Friend Sub SetMachining2Start(Machining2Start As Long)
m_dtMachining2Start = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Machining2Start).ToLocalTime()
NotifyPropertyChanged(NameOf(sMachining2Start))
End Sub
Private m_dtMachining2End As DateTime = DateTime.MinValue
Friend ReadOnly Property dtMachining2End As DateTime
Get
Return m_dtMachining2End
End Get
End Property
Public ReadOnly Property sMachining2End As String
Get
Return If(m_dtMachining2End <> DateTime.MinValue, m_dtMachining2End.ToString("yy/MM/dd hh:mm:ss"), "")
End Get
End Property
Friend Sub SetMachining2End(Machining2End As Long)
m_dtMachining2End = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Machining2End).ToLocalTime()
NotifyPropertyChanged(NameOf(sMachining2End))
End Sub
Private m_dtUnloadTime As DateTime = DateTime.MinValue
Friend ReadOnly Property dtUnloadTime As DateTime
Get
Return m_dtUnloadTime
End Get
End Property
Public ReadOnly Property sUnloadTime As String
Get
Return If(m_dtUnloadTime <> DateTime.MinValue, m_dtUnloadTime.ToString("yy/MM/dd hh:mm:ss"), "")
End Get
End Property
Friend Sub SetUnloadTime(UnloadTime As Long)
m_dtUnloadTime = New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(UnloadTime).ToLocalTime()
NotifyPropertyChanged(NameOf(sUnloadTime))
End Sub
#End Region ' Statistics
Public ReadOnly Property Background As SolidColorBrush
Get
Select Case m_nState
Case DoorStates.LOADED_FROM_CSV
Return Brushes.White
Case DoorStates.VERIFICATION_FAILED
Return Brushes.Red
Case DoorStates.SKIPPED
Return Brushes.Orange
Case DoorStates.READY_FOR_PRODUCTION
Return Brushes.LightSkyBlue
Case DoorStates.ON_LOAD_STATION
Return Brushes.SkyBlue
Case DoorStates.MACHINE_1_START
Return Brushes.DodgerBlue
Case DoorStates.MACHINE_1_END
Return Brushes.Yellow
Case DoorStates.MACHINE_2_START
Return Brushes.DodgerBlue
Case DoorStates.MACHINE_2_END, DoorStates.PRODUCED
Return Brushes.LightGray
Case DoorStates.SCRAP
Return Brushes.MediumPurple
Case Else
Return Brushes.White
End Select
End Get
End Property
Sub New(nId As Integer, nCSVLine As Integer, sDDFName As String, sCSVName As String, nQuantity As Integer, dWidth As Double, dHeight As Double, dThickness As Double, HeaderList As String(), ValueList As String())
m_nId = nId
m_nCSVLine = nCSVLine
m_sDDFName = sDDFName
m_sCSVName = sCSVName
m_nQuantity = nQuantity
m_dHeight = dHeight
m_dWidth = dWidth
m_dThickness = dThickness
If Not IsNothing(HeaderList) AndAlso HeaderList.Count > 0 AndAlso Not IsNothing(ValueList) AndAlso ValueList.Count > 0 Then
For nParamIndex = 0 To Math.Max(HeaderList.Count, ValueList.Count) - 1
m_CustomerParameters.Add(New CustomerParameter(If(HeaderList.Count > nParamIndex, HeaderList(nParamIndex), ""), If(ValueList.Count > nParamIndex, ValueList(nParamIndex), "")))
Next
End If
End Sub
Sub New(JsonDoor As JsonDoor)
m_nId = JsonDoor.nId
m_nCSVLine = JsonDoor.nCSVLine
m_sDDFName = JsonDoor.sDDFName
m_sCSVName = JsonDoor.sCSVName
m_nQuantity = JsonDoor.nQuantity
m_dHeight = JsonDoor.dHeight
m_dWidth = JsonDoor.dWidth
m_dThickness = JsonDoor.dThickness
m_nState = JsonDoor.nState
m_CustomerParameters = JsonDoor.CustomerParameters
m_nProdState = JsonDoor.nProdState
m_dtLoadTime = JsonDoor.dtLoadTime
m_dtMachining1Start = JsonDoor.dtMachining1Start
m_dtMachining1End = JsonDoor.dtMachining1End
m_dtMachining2Start = JsonDoor.dtMachining2Start
m_dtMachining2End = JsonDoor.dtMachining2End
m_dtUnloadTime = JsonDoor.dtUnloadTime
End Sub
End Class
Public Class CustomerParameter
Private m_sHeader As String
Public ReadOnly Property sHeader As String
Get
Return m_sHeader
End Get
End Property
Private m_sValue As String
Public ReadOnly Property sValue As String
Get
Return m_sValue
End Get
End Property
Sub New(sHeader As String, sValue As String)
m_sHeader = sHeader
m_sValue = sValue
End Sub
End Class