Imports EgtWPFLib5
Imports EgwProxy.LiMan

Public Module Configuration

   ' Test per comunicazione
   Public m_commLib As DataSyncro

   ''' <summary>
   ''' Flag per impostare la visualizzazione con la singola pagina
   ''' </summary>
   Private m_bOnlyProd As Boolean
   Public ReadOnly Property bOnlyProd As Boolean
      Get
         Return m_bOnlyProd
      End Get
   End Property
   Public Sub SetOnlyProd(value As Boolean)
      m_bOnlyProd = value
   End Sub

   ''' <summary>
   ''' Flag per visualizzare il pulsante Db Attrezzaggi
   ''' </summary>
   Private m_bModifySetup As Boolean
   Public ReadOnly Property bModifySetup As Boolean
      Get
         Return m_bModifySetup
      End Get
   End Property
   Public Sub SetModifySetup(value As Boolean)
      m_bModifySetup = value
   End Sub

   ''' <summary>
   ''' Flag per salvare correttamente i dati nel file lua corretto
   ''' </summary>
   Private m_bMachConfig As Boolean
   Public ReadOnly Property bMachConfig As Boolean
      Get
         Return m_bMachConfig
      End Get
   End Property
   Public Sub SetMachConfig(value As Boolean)
      m_bMachConfig = value
   End Sub

   ''' <summary>
   ''' Flag per impostare la visualizzazione con la singola pagina
   ''' </summary>
   Private m_sServerAddressRelease As String
   Public ReadOnly Property sServerAddressRelease As String
      Get
         Return m_sServerAddressRelease
      End Get
   End Property
   Public Sub SetServerAddressRelease(value As String)
      m_sServerAddressRelease = value
   End Sub

   ' Versione attuale del programma
   Public ReadOnly Property ActualVersion As String
      Get
         Return My.Application.Info.Version.ToString()
      End Get
   End Property

   ''' <summary>
   ''' Funzione che recupera la directory del file INI
   ''' </summary>
   Public Sub GetIniFileDirectory()
      ' Impostazione path radice per i dati
      Dim m_sDataRoot As String = System.AppDomain.CurrentDomain.BaseDirectory
      If EgtUILib.GetPrivateProfileString(ConstGen.S_DATA, ConstGen.K_DATAROOT, "", m_sDataRoot, m_sDataRoot & "\" & ConstGen.DAT_FILE_NAME) = 0 Then
         m_sDataRoot = System.AppDomain.CurrentDomain.BaseDirectory
      End If
      ' Impostazione direttorio di configurazione
      Dim m_sConfigDir As String = m_sDataRoot & "\" & ConstGen.CONF_DIR
      ' Impostazione path Ini file
      IniFile.m_sIniFile = m_sConfigDir & "\" & Core.ConstIni.INI_FILE_NAME
   End Sub

   ''' <summary>
   ''' Funzione per recuperare bOnlyProd
   ''' </summary>
   ''' <param name="Section">Sezione dove si trova la variabile che devo cercare</param>
   ''' <param name="Key">Variabile che sto cercando</param>
   ''' <param name="Path">Cartella dove e' presente il file ini</param>
   ''' <param name="Default_Value">Valore di defaul opzionabile</param>
   ''' <returns></returns>
   Public Function Read_Value(Section As String, Key As String, Path As String, Optional Default_Value As String = "") As String
      Dim Reader_Lines As String() = System.IO.File.ReadAllLines(Path)
      Dim Current_Section As String = ""

      For Each Reader_Line As String In Reader_Lines

         If Reader_Line.StartsWith("[") AndAlso Reader_Line.EndsWith("]") Then
            Current_Section = Reader_Line
         ElseIf Current_Section.Equals($"[{Section}]") Then
            Dim lineParts As String() = Reader_Line.Split({"="c}, 2)

            If lineParts.Length >= 1 AndAlso lineParts(0) = Key Then
               Return If(lineParts.Length >= 2, lineParts(1), Default_Value)
            End If
         End If
      Next

      Return Default_Value
   End Function

   ''' <summary>
   ''' Metodo che controlla la comunicazione server
   ''' </summary>
   ''' <returns></returns>
   Public Function GetComunication() As Boolean
      ' eseguo test per comunicazione server (ping, alive)
      m_commLib = New DataSyncro(EgtBEAMWALL.Core.Configuration.sServerAddressRelease)
      If m_commLib.CheckRemote() Then
         Return True
      Else
         Return False
      End If
   End Function

End Module
