Imports System.Collections.ObjectModel
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Windows.Threading
Imports EgtBEAMWALL.Core
Imports EgtBEAMWALL.Core.ConstBeam
Imports EgtBEAMWALL.DataLayer.DatabaseModels
Imports EgtUILib
Imports EgtWPFLib5
Imports LiMan.Core
Public Class MainMenuVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Private m_LiManTimer As New DispatcherTimer
Private m_MainMenu_IsEnabled As Boolean = True
Public ReadOnly Property MainMenu_IsEnabled As Boolean
Get
Return m_MainMenu_IsEnabled
End Get
End Property
Private m_SendFeedbackIsEnabled As Boolean = True
Public ReadOnly Property SendFeedbackIsEnabled As Boolean
Get
Return m_SelPage = Pages.VIEW Or m_SelPage = Pages.MACHINING
End Get
End Property
Public Property View_IsChecked As Boolean
Get
Return m_SelPage = Pages.VIEW
End Get
Set(value As Boolean)
If value Then SelPage = Pages.VIEW
End Set
End Property
Public Property Machining_IsChecked As Boolean
Get
Return m_SelPage = Pages.MACHINING
End Get
Set(value As Boolean)
If value Then SelPage = Pages.MACHINING
End Set
End Property
Public Property Supervisor_IsChecked As Boolean
Get
Return m_SelPage = Pages.SUPERVISOR
End Get
Set(value As Boolean)
If value Then SelPage = Pages.SUPERVISOR
End Set
End Property
Public Property Config_IsChecked As Boolean
Get
Return m_SelPage = Pages.CONFIG
End Get
Set(value As Boolean)
If value Then SelPage = Pages.CONFIG
End Set
End Property
Private m_SelPage As Integer = -1
Public Property SelPage As Integer
Get
Return m_SelPage
End Get
Set(value As Integer)
' lancio selezione pagina con verifica file modificato
SetSelPage(value)
End Set
End Property
' funzione che permette di cambiare pagina
' bVerifyModification: se vero verifica modifiche su file e chiede di salvare
Friend Sub SetSelPage(Page As Pages, Optional bVerifyModification As Boolean = True)
Dim bOk As Boolean = True
' Esco dallo stato corrente
Select Case m_SelPage
Case Pages.VIEW
bOk = ExitVIEW(bVerifyModification)
Case Pages.MACHINING
bOk = ExitMACHINING(bVerifyModification)
Case Pages.CONFIG
bOk = ExitCONFIG()
End Select
If bOk Then
' Entro nel nuovo stato
m_SelPage = Page
Select Case m_SelPage
Case Pages.VIEW
' Map.refMachGroupPanelVM.SetMachGroupState(False)
InitVIEW()
'Map.refTopCommandBarVM.IsEnabled = False
Case Pages.MACHINING
' Map.refMachGroupPanelVM.SetMachGroupState(True)
InitMACHINING()
'Map.refTopCommandBarVM.IsEnabled = True
Case Pages.CONFIG
InitCONFIG()
'Map.refMachGroupPanelVM.SetMachGroupState(False)
'Map.refCONFIGTabVM.InitCONFIGation()
'Map.refTopCommandBarVM.IsEnabled = False
End Select
End If
' aggiorno visualizzazione RadioButton
NotifyPropertyChanged("View_IsChecked")
NotifyPropertyChanged("Machining_IsChecked")
NotifyPropertyChanged("Supervisor_IsChecked")
NotifyPropertyChanged("Config_IsChecked")
Map.refProjectVM.NotifyPropertyChanged("SelItem")
End Sub
#Region "Messages"
Public ReadOnly Property Viewer_Msg As String
Get
Return EgtMsg(61830)
End Get
End Property
Public ReadOnly Property Optimizer_Msg As String
Get
Return EgtMsg(61831)
End Get
End Property
Public ReadOnly Property Configuration_Msg As String
Get
Return EgtMsg(61832)
End Get
End Property
Public ReadOnly Property Supervisor_Msg As String
Get
Return EgtMsg(62500)
End Get
End Property
#Region "ToolTip"
'Proprietà ToolTip
Public ReadOnly Property SendFeedbackToolTip As String
Get
Return EgtMsg(MSG_TOPCOMMANDBAR + 13)
End Get
End Property
#End Region ' ToolTip
#End Region ' Messages
' Definizione comandi
Private m_cmdSupervisor As ICommand
Private m_cmdSendFeedback As ICommand
#End Region ' Fields & Properties
#Region "CONSTRUCTOR"
Sub New()
' Creo riferimento a questa classe in EgtCAM5Map
Map.SetRefMainMenuVM(Me)
m_LiManTimer.Interval = TimeSpan.FromMilliseconds(1000)
AddHandler m_LiManTimer.Tick, AddressOf LiManTimer_Tick
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Friend Sub SetMainMenuIsEnabled(bIsEnabled As Boolean)
m_MainMenu_IsEnabled = bIsEnabled
NotifyPropertyChanged(NameOf(MainMenu_IsEnabled))
End Sub
Private Function InitVIEW() As Boolean
Map.refProjectVM.SetBottomPanel_Visibility(True)
Map.refProjectVM.SetLeftPanel_Visibility(True)
Map.refLeftPanelVM.UpdateView()
Map.refProjectVM.SetPartManager_Visibility(False)
Map.refProjectVM.SetFeatureManager_Visibility(True)
Map.refProjectVM.SetTopPanel_Visibility(False)
Map.refProjectVM.SetShowBeamPanel_Visibility(True)
Map.refProjectVM.SetProjManager_Visibility(True)
Map.refProjectVM.SetProdManager_Visibility(False)
Map.refProjectVM.SetOptimizePanel_Visibility(Not IsNothing(Map.refProjectVM.BTLStructureVM) AndAlso Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL AndAlso Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.NESTING_AUTO))
Map.refProjectVM.NotifyAllPanelVisibility()
Map.refCALCPanelVM.SetChooseMachineBtn_Visibility(True)
If Not IsNothing(Map.refFeatureListVM.colFeature_Do) Then
Map.refFeatureListVM.colFeature_Do.ColumnVisibility = Visibility.Visible
End If
' aggiorno la visibilità delle colonne
For Each col In Map.refFeatureListVM.FeatureColumns
col.ColumnVisibility = If(col.Visible, Visibility.Visible, Visibility.Collapsed)
Next
For Each col In Map.refPartListVM.PartColumns
col.ColumnVisibility = If(col.Visible, Visibility.Visible, Visibility.Collapsed)
Next
For Each col In Map.refStatisticsVM.StatisticsColumns
col.ColumnVisibility = If(col.Visible, Visibility.Visible, Visibility.Collapsed)
Next
For Each col In Map.refPParameterListVM.PParameterListColumns
col.ColumnVisibility = If(col.Visible, Visibility.Visible, Visibility.Collapsed)
Next
For Each col In Map.refQParameterListVM.QParameterListColumns
col.ColumnVisibility = If(col.Visible, Visibility.Visible, Visibility.Collapsed)
Next
' imposto dimensioni colonne/righe della Grid
DimensionsIniFile.ReadGridDimensions(ConstDims.PROJECT_VIEW, Map.refProjectVM.GridDims)
DimensionsIniFile.ReadGridDimensions(ConstDims.LEFTPANEL_VIEW, Map.refLeftPanelVM.GridDims)
' apro progetto proj
If Not IsNothing(Map.refProjManagerVM.CurrProj) Then
If Map.refProjManagerVM.CurrProj.bReloadProject Then
Map.refProjManagerVM.OpenProject(Map.refProjManagerVM.CurrProj)
' aggiorno le colonne in base al tipo progetto
If Not IsNothing(Map.refProjectVM.BTLStructureVM) Then
Map.refRawPartListVM.UpdateColumns(Map.refProjectVM.BTLStructureVM.nPROJTYPE)
Map.refPartInRawPartListVM.UpdateColumns(Map.refProjectVM.BTLStructureVM.nPROJTYPE)
Else
Map.refRawPartListVM.UpdateColumns(BWType.BEAM)
Map.refPartInRawPartListVM.UpdateColumns(BWType.BEAM)
End If
DbControllers.m_ProjController.LockByProjId(Map.refProjManagerVM.CurrProj.nProjId, True)
Map.refProjManagerVM.NotifyPropertyChanged(NameOf(Map.refProjManagerVM.MruFileNames))
Else
' verifico se il prod di provenienza ha piu' proj
If Not IsNothing(Map.refProdManagerVM.CurrProd) AndAlso Map.refProdManagerVM.CurrProd.nProjIdList.Count > 1 Then
' se si rigenero BTLStructure
Map.refProjectVM.BTLStructureVM = New BTLStructureVM(BTLStructureM.CreateBTLStructure(Map.refProjManagerVM.CurrProj.nProjId))
End If
' mostro tutti i pezzi
Map.refShowBeamPanelVM.ShowAll()
Map.refProjManagerVM.CurrProj.SetReloadProject(True)
End If
' aggiorno titolo
Map.refMainWindowVM.UpdateTitle()
DbControllers.m_ProjController.LockByProjId(Map.refProjManagerVM.CurrProj.nProjId, True)
Else
Map.refSceneHostVM.MainController.NewProject()
Map.refProjectVM.BTLStructureVM = Nothing
Map.refProjectVM.MachGroupPanelVM = Nothing
End If
Map.refMainWindowVM.NotifyPropertyChanged(NameOf(Map.refMainWindowVM.nSelTabPage))
Map.refMainMenuVM.NotifyPropertyChanged(NameOf(Map.refMainMenuVM.SendFeedbackIsEnabled))
Map.refInstrumentPanelVM.NotifyPropertyChanged(NameOf(Map.refInstrumentPanelVM.ChangeParam_Visibility))
Return True
End Function
Private Function ExitVIEW(bVerifyModification As Boolean) As Boolean
' verifico se progetto modificato, e chiedo se salvare
If bVerifyModification Then
If Not ProjFileVM.VerifyProjectModification(Map.refProjManagerVM.CurrProj, ProjectType.PROJ) Then
Return False
End If
End If
' resetto eventuale visualizzazione statistiche
Map.refInstrumentPanelVM.ResetStatisticsIsChecked()
Map.refProjectVM.SetBottomPanel_Visibility(False)
Map.refProjectVM.SetLeftPanel_Visibility(True)
Map.refProjectVM.SetPartManager_Visibility(False)
Map.refProjectVM.SetFeatureManager_Visibility(False)
Map.refProjectVM.SetTopPanel_Visibility(True)
Map.refProjectVM.SetShowBeamPanel_Visibility(False)
Map.refProjectVM.SetProjManager_Visibility(False)
Map.refProjectVM.SetProdManager_Visibility(True)
Map.refProjectVM.SetOptimizePanel_Visibility(True)
Map.refCALCPanelVM.SetChooseMachine_Visibility(False)
Return True
End Function
Private Function InitMACHINING() As Boolean
Map.refProjectVM.SetBottomPanel_Visibility(False)
Map.refProjectVM.SetLeftPanel_Visibility(True)
Map.refLeftPanelVM.UpdateView()
Map.refProjectVM.SetPartManager_Visibility(False)
Map.refProjectVM.SetFeatureManager_Visibility(False)
Map.refProjectVM.SetTopPanel_Visibility(True)
Map.refProjectVM.SetShowBeamPanel_Visibility(False)
Map.refProjectVM.SetProjManager_Visibility(False)
Map.refProjectVM.SetProdManager_Visibility(True)
Map.refProjectVM.SetOptimizePanel_Visibility(True)
Map.refProjectVM.NotifyAllPanelVisibility()
Map.refCALCPanelVM.SetChooseMachineBtn_Visibility(False)
Map.refTopPanelVM.UpdateQParameterVisibility()
' aggiorno la visibilità delle colonne
For Each col In Map.refFeatureListVM.FeatureColumns
col.ColumnVisibility = If(col.Visible, Visibility.Visible, Visibility.Collapsed)
Next
For Each col In Map.refRawPartListVM.RawPartColumns
col.ColumnVisibility = If(col.Visible, Visibility.Visible, Visibility.Collapsed)
Next
For Each col In Map.refFeatureInPartInRawPartListVM.FeatureInPartInRawPartColumns
col.ColumnVisibility = If(col.Visible, Visibility.Visible, Visibility.Collapsed)
Next
For Each col In Map.refPartInRawPartListVM.PartInRawPartColumns
col.ColumnVisibility = If(col.Visible, Visibility.Visible, Visibility.Collapsed)
Next
For Each col In Map.refStatisticsVM.OptimizerStatisticsColumns
col.ColumnVisibility = If(col.Visible, Visibility.Visible, Visibility.Collapsed)
Next
If Not IsNothing(Map.refFeatureListVM.colFeature_Do) Then
Map.refFeatureListVM.colFeature_Do.ColumnVisibility = Visibility.Collapsed
End If
' imposto dimensioni colonne/righe della Grid
DimensionsIniFile.ReadGridDimensions(ConstDims.PROJECT_OPTIMIZER, Map.refProjectVM.GridDims)
DimensionsIniFile.ReadGridDimensions(ConstDims.LEFTPANEL_OPTIMIZER, Map.refLeftPanelVM.GridDims)
' inizializzo gruppi di lavorazione
If Not IsNothing(Map.refProdManagerVM.CurrProd) AndAlso Not IsNothing(Map.refProdManagerVM.CurrProd.nProdId) AndAlso Map.refProdManagerVM.CurrProd.nProdId > 0 Then
If File.Exists(Map.refProdManagerVM.CurrProd.sProdPath) Then
' apro progetto
If Map.refProdManagerVM.CurrProd.bReloadProject Then
If Map.refSceneHostVM.MainController.OpenProject(Map.refProdManagerVM.CurrProd.sProdPath, False) Then
' aggiorno le colonne in base al tipo progetto
Map.refRawPartListVM.UpdateColumns(Map.refProjectVM.BTLStructureVM.nPROJTYPE)
Map.refPartInRawPartListVM.UpdateColumns(Map.refProjectVM.BTLStructureVM.nPROJTYPE)
DbControllers.m_ProdController.LockByProdId(Map.refProdManagerVM.CurrProd.nProdId, True)
' aggiorno titolo
Map.refMainWindowVM.UpdateTitle()
Map.refProdManagerVM.NotifyPropertyChanged(NameOf(Map.refProdManagerVM.MruFileNames))
End If
Else
' mostro tutti i pezzi
Map.refShowBeamPanelVM.ShowAll(False)
' verifico se il prod ha piu' proj
If Map.refProdManagerVM.CurrProd.nProjIdList.Count > 1 Then
' se si rigenero BTLStructure
Map.refProjectVM.BTLStructureVM = New BTLStructureVM(BTLStructureM.CreateBTLStructure(0))
End If
' recupero indice di modifica progetto
Dim CommIndex As Integer = -1
Dim ActiveSessionList As List(Of StatusMapModel) = DbControllers.m_StatusMapController.GetProd()
For Each ActiveSession In ActiveSessionList
If ActiveSession.ItemId = Map.refProdManagerVM.CurrProd.nProdId Then
CommIndex = ActiveSession.Index
End If
Next
' carico lista dei MachGroup
Map.refProjectVM.MachGroupPanelVM = New MyMachGroupPanelVM(MyMachGroupPanelM.CreateMyMachGroupPanel(Map.refMachinePanelVM.MachineList.ToList()))
' fisso indice sessione di comunicazione
If CommIndex > -1 Then
Map.refProdManagerVM.CurrProd.SetModificationIndex(CommIndex)
End If
Map.refProjManagerVM.CurrProj.SetReloadProject(True)
End If
'DbControllers.m_ProdController.ResetController()
DbControllers.m_ProdController.LockByProdId(Map.refProdManagerVM.CurrProd.nProdId, True)
' seleziono prima barra
Map.refProjectVM.MachGroupPanelVM.SelFirstMachGroup()
Else
MessageBox.Show(EgtMsg(61871))
End If
Else
Map.refSceneHostVM.MainController.NewProject()
Map.refProjectVM.BTLStructureVM = Nothing
Map.refProjectVM.MachGroupPanelVM = Nothing
End If
Map.refMainWindowVM.NotifyPropertyChanged(NameOf(Map.refMainWindowVM.nSelTabPage))
Map.refMainMenuVM.NotifyPropertyChanged(NameOf(Map.refMainMenuVM.SendFeedbackIsEnabled))
Map.refInstrumentPanelVM.NotifyPropertyChanged(NameOf(Map.refInstrumentPanelVM.ChangeParam_Visibility))
Map.refTopPanelVM.NotifyPropertyChanged(NameOf(Map.refTopPanelVM.MovePart_Visibility))
Return True
End Function
Private Function ExitMACHINING(bVerifyModification As Boolean) As Boolean
' verifico se progetto modificato, e chiedo se salvare
If bVerifyModification Then
If ProdFileVM.VerifyProjectModification(Map.refProdManagerVM.CurrProd) = MessageBoxResult.Cancel Then
Return False
End If
End If
' resetto eventuale visualizzazione statistiche
Map.refInstrumentPanelVM.ResetStatisticsIsChecked()
Map.refProjectVM.SetBottomPanel_Visibility(True)
Map.refProjectVM.SetLeftPanel_Visibility(False)
Map.refProjectVM.SetPartManager_Visibility(False)
Map.refProjectVM.SetFeatureManager_Visibility(True)
Map.refProjectVM.SetTopPanel_Visibility(False)
Map.refProjectVM.SetShowBeamPanel_Visibility(True)
Map.refProjectVM.SetProjManager_Visibility(True)
Map.refProjectVM.SetProdManager_Visibility(False)
Map.refProjectVM.SetOptimizePanel_Visibility(Not IsNothing(Map.refProjectVM.BTLStructureVM) AndAlso Map.refProjectVM.BTLStructureVM.nPROJTYPE = BWType.WALL AndAlso Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.NESTING_AUTO))
Map.refCALCPanelVM.SetChooseMachine_Visibility(False)
EgtResetCurrMachGroup()
Return True
End Function
Private Function InitCONFIG() As Boolean
Map.refMainWindowVM.NotifyPropertyChanged(NameOf(Map.refMainWindowVM.nSelTabPage))
Map.refMainMenuVM.NotifyPropertyChanged(NameOf(Map.refMainMenuVM.SendFeedbackIsEnabled))
Return True
End Function
Private Function ExitCONFIG() As Boolean
Map.refConfigurationPageVM.VerifyConfigPageModification()
' resetto flag inserimento password
Map.refConfigurationPageVM.bModifyMachParam = False
If Not IsNothing(Map.refProjectVM.BTLStructureVM) Then
Map.refRawPartListVM.UpdateColumns(Map.refProjectVM.BTLStructureVM.nPROJTYPE)
Map.refPartInRawPartListVM.UpdateColumns(Map.refProjectVM.BTLStructureVM.nPROJTYPE)
Else
Map.refRawPartListVM.UpdateColumns(BWType.BEAM)
Map.refPartInRawPartListVM.UpdateColumns(BWType.BEAM)
End If
Return True
End Function
#End Region ' METHODS
#Region "COMMANDS"
#Region "Supervisor"
Public ReadOnly Property Supervisor_Command As ICommand
Get
If m_cmdSupervisor Is Nothing Then
m_cmdSupervisor = New Command(AddressOf Supervisor)
End If
Return m_cmdSupervisor
End Get
End Property
Public Sub Supervisor()
Dim sSupervisorName As String = "EgtBEAMWALL.SupervisorR32"
' recupero processo del supervisore
Dim localProc As Process() = Process.GetProcessesByName(sSupervisorName)
If localProc.Length > 0 Then
For Each p As Process In localProc
' porto in primo piano il Supervisor
BringWindowToFront(p.MainWindowHandle)
Exit For
Next
Else
Dim sSupervisorPath As String = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory) & "\" & sSupervisorName & ".exe"
Try
Process.Start(sSupervisorPath)
Catch ex As Exception
EgtOutLog("Error: impossible starting supervisor from path " & sSupervisorPath)
End Try
End If
End Sub
#End Region ' Supervisor
#Region "SendFeedbackCommand"
'''
''' Returns a command that do SendFeedback.
'''
Public ReadOnly Property SendFeedbackCommand As ICommand
Get
If m_cmdSendFeedback Is Nothing Then
m_cmdSendFeedback = New Command(AddressOf SendFeedback)
End If
Return m_cmdSendFeedback
End Get
End Property
'''
''' Execute the SendFeedback. This method is invoked by the SendFeedbackCommand.
'''
Public Sub SendFeedback(ByVal param As Object)
If SelPage = Pages.MACHINING AndAlso IsNothing(Map.refProdManagerVM.CurrProd) Then
MessageBox.Show(EgtMsg(61891), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
Dim FileToSendList As New List(Of String)
' Recupero indirizzo a cui spedire la mail
Dim sSupportAddress As String = String.Empty
GetMainPrivateProfileString(S_GENERAL, K_SUPPORT, "support@egaltech.com", sSupportAddress)
' se vuoto do messaggio di errore ed esco
If String.IsNullOrWhiteSpace(sSupportAddress) Then
MessageBox.Show(EgtMsg(MSG_TOPCOMMANDBAR + 10), EgtMsg(MSG_MESSAGEBOX + 1), MessageBoxButton.OK, MessageBoxImage.Error)
Return
End If
' Recupero numero chiave
Dim sKey As String = String.Empty
EgtGetKeyInfo(sKey)
'' Recupero file del progetto corrente
'Dim sCurrProject As String = String.Empty
'EgtGetCurrFilePath(sCurrProject)
'' se nome file vuoto, chiedo se si vuole salvare
'If String.IsNullOrWhiteSpace(sCurrProject) Then
' If MessageBox.Show(EgtMsg(MSG_TOPCOMMANDBAR + 11), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
' Map.refSceneHostVM.SaveProject()
' End If
' EgtGetCurrFilePath(sCurrProject)
' ' se modificato, chiedo se si vuole salvare
'Else
' If EgtGetModified() Then
' If MessageBox.Show(EgtMsg(MSG_TOPCOMMANDBAR + 11), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
' Map.refSceneHostVM.SaveProject()
' End If
' End If
'End If
' Esporto il progetto
Dim ProjFileMList As List(Of ProjFileM)
If SelPage = Pages.MACHINING And Not IsNothing(Map.refProdManagerVM.CurrProd) Then
ProjFileMList = DbControllers.m_ProjController.GetByProdAsc(Map.refProdManagerVM.CurrProd.nProdId)
Map.refProjManagerVM.SetCurrProj(ProjFileMList(0).nProjId)
End If
Dim sExportFileName = Map.refProjManagerVM.CurrProj.nProjId.ToString("0000") & " - " & Map.refProjManagerVM.CurrProj.sBTLFileName & " - ProjectExport"
Dim sExpZipToCreate = Map.refProjManagerVM.ExportProject(sExportFileName)
' creo zip del progetto esportato, BTLFeatures.ini e Log
Dim sExpAndMoreZipToCreate As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\" & sExportFileName & " and more.zip"
If File.Exists(sExpAndMoreZipToCreate) Then
File.Delete(sExpAndMoreZipToCreate)
End If
Try
Using zip As New Ionic.Zip.ZipFile(sExpAndMoreZipToCreate, Console.Out)
' aggiungo progetto esportato
If File.Exists(sExpZipToCreate) Then
zip.AddItem(sExpZipToCreate, "")
End If
' aggiungo file log
If File.Exists(Map.refMainWindowVM.MainWindowM.sLogFile) Then
zip.AddItem(Map.refMainWindowVM.MainWindowM.sLogFile, "")
End If
' aggiungo file parametri P e Q
If File.Exists(BTLIniFile.m_sBTLIniFile) Then
zip.AddItem(BTLIniFile.m_sBTLIniFile, "")
End If
' salvo lo zip
zip.Save()
End Using
FileToSendList.Add(sExpAndMoreZipToCreate)
' creo zip della cartella macchina
Dim sMachineZipToCreate As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\" & sMachineName & ".zip"
If File.Exists(sMachineZipToCreate) Then
File.Delete(sMachineZipToCreate)
End If
Using zip As New Ionic.Zip.ZipFile(sMachineZipToCreate, Console.Out)
' aggiungo cartella macchina del progetto
Dim sMachineDir As String = Map.refMainWindowVM.MainWindowM.sMachinesRoot & "\" & sMachineName
If Directory.Exists(sMachineDir) Then
zip.AddItem(sMachineDir, sMachineName)
End If
' salvo lo zip
zip.Save()
End Using
FileToSendList.Add(sMachineZipToCreate)
' aggiungo Prod e Proj associati
Dim ProdId As Integer
Select Case Map.refMainMenuVM.SelPage
Case Pages.VIEW
ProdId = Map.refProjManagerVM.CurrProj.nProdId
Case Pages.MACHINING
ProdId = Map.refProdManagerVM.CurrProd.nProdId
End Select
If ProdId = 0 Then
' Creo zip del Proj
Dim sProjZipToCreate As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\Projs.zip"
If File.Exists(sProjZipToCreate) Then
File.Delete(sProjZipToCreate)
End If
' aggiungo lo zip del solo Proj
Using zip As New Ionic.Zip.ZipFile(sProjZipToCreate, Console.Out)
zip.AddItem(Map.refProjManagerVM.CurrProj.sProjDirPath, "Projs\" & Map.refProjManagerVM.CurrProj.nProjId.ToString("0000"))
' salvo lo zip
zip.Save()
End Using
FileToSendList.Add(sProjZipToCreate)
Else
ProjFileMList = DbControllers.m_ProjController.GetByProdAsc(ProdId)
' se piu' di uno
If IsNothing(ProjFileMList) Then
Return
ElseIf ProjFileMList.Count > 0 Then
Dim ProjFileVMList As New List(Of ProjectFileVM)
For Each Project In ProjFileMList
ProjFileVMList.Add(New ProjFileVM(Project))
Next
' prima creo zip del Proj
Dim sProjZipToCreate As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\Projs.zip"
If File.Exists(sProjZipToCreate) Then
File.Delete(sProjZipToCreate)
End If
' aggiungo lo zip del Proj riempiendolo con tutti i Proj associati
Using zip As New Ionic.Zip.ZipFile(sProjZipToCreate, Console.Out)
For Each ProjFileVMItem In ProjFileVMList
zip.AddItem(ProjFileVMItem.sProjDirPath, "Projs\" & ProjFileVMItem.nProjId.ToString("0000"))
Next
' salvo lo zip
zip.Save()
End Using
FileToSendList.Add(sProjZipToCreate)
' ora creo zip del Prod
Dim sProdZipToCreate As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\Prods.zip"
If File.Exists(sProdZipToCreate) Then
File.Delete(sProdZipToCreate)
End If
' ora aggiungo lo zip del Prod
Using zip As New Ionic.Zip.ZipFile(sProdZipToCreate, Console.Out)
zip.AddItem(ProjFileVMList(0).sProdDirPath, "Prods\" & ProjFileVMList(0).nProdId.ToString("0000"))
' salvo lo zip
zip.Save()
End Using
FileToSendList.Add(sProdZipToCreate)
End If
End If
Catch ex1 As Exception
EgtOutLog("Exception in zip: " & ex1.ToString())
End Try
' Codice Applicazione (es EBW-UP)
' Codice Impegno (es codice chiave HW)
' Codice Cliente/Installazione
' Email x contatto
' Nome del richiedente/clietne
' Tel richeidente/cliente
' Chiave master di comunicazione da LiMan
' Testo delal richiesta
' Idx univoco di sublic (es x gestione utenti)
' tipo ticket da gestire (Default fileUpload)
' recuperare codice chiave SW/HW
' recuperare contatti cliente
Dim sp As SupportRequest = New SupportRequest("Uploader",
"",
"EgalWare",
"info@egalware.com",
"Utente",
"035-460560",
"4AIc8fMEXcSyDIMl1Ro05O/1xar7nrVHXAQzrh/fmxfvlczA13tQwXAqida6hTqV",
"Upload da sendlog di EGT BeamWall",
0,
TipologiaTicket.FileUpload)
' specifico le cartelle Data (da cui prendere i file) e Archive (in cui archiviare i file)
Dim sDataFolderPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\Data"
Dim sArchiveFolderPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\Archive"
' creo le cartelle
DeleteDirectory(sDataFolderPath)
Directory.CreateDirectory(sDataFolderPath)
If Not Directory.Exists(sArchiveFolderPath) Then
Directory.CreateDirectory(sArchiveFolderPath)
End If
' muovo zip e json nella cartella Data
For Each FileName In FileToSendList
Dim mFile As FileInfo = New FileInfo(FileName)
mFile.MoveTo(sDataFolderPath & "\" & mFile.Name)
Next
SupportRequest.SaveRequest(sp, sDataFolderPath & "\request.json")
' eseguo LiMan Transfer con le 2 cartelle come argomenti
Dim Proc = New Process()
Proc.StartInfo.FileName = "C:\EgwProg\LiManTransfer\win-x86\" & Map.refMainWindowVM.MainWindowM.sLiManTransferExe
Proc.StartInfo.Arguments = sDataFolderPath & " " & sArchiveFolderPath
Proc.StartInfo.CreateNoWindow = True
Proc.StartInfo.UseShellExecute = False
AddHandler Proc.Exited, AddressOf Proc_Exited
For Inde = 0 To 100
If Not m_LiManTimer.IsEnabled Then Exit For
Threading.Thread.Sleep(100)
Next
If Not m_LiManTimer.IsEnabled AndAlso Proc.Start() Then
m_LiManTimer.Start()
End If
End Sub
Private Sub Proc_Exited()
m_LiManTimer.Stop()
End Sub
Private Sub LiManTimer_Tick()
m_LiManTimer.Stop()
EgtOutLog("LiMan Transfer timeout!")
End Sub
Private Sub DeleteDirectory(path As String)
If Directory.Exists(path) Then
'Delete all files from the Directory
For Each filepath As String In Directory.GetFiles(path)
File.Delete(filepath)
Next
'Delete all child Directories
For Each dir As String In Directory.GetDirectories(path)
DeleteDirectory(dir)
Next
'Delete a Directory
Directory.Delete(path)
End If
End Sub
#End Region ' SendFeedbackCommand
#Region "TEST"
#End Region ' TEST
#End Region ' COMMANDS
End Class