Permalink
Browse files

Update HomiWpf

Amélioration gestion perte connexion serveur
  • Loading branch information...
jphomi committed Jul 14, 2017
1 parent 8c153c4 commit 76ca92a6c50b6aa409f07f5607d47197b739d33f
@@ -26,7 +26,7 @@ Public Class uWMeteo
If IsConnect = True Then
If String.IsNullOrEmpty(_Id) = False Then
Dim x As HoMIDom.HoMIDom.TemplateDevice
If frmMere.MaJWidgetFromServer Then
If (frmMere.MaJWidgetFromServer) And (IsConnect) Then
x = myService.ReturnDeviceByID(IdSrv, _Id)
Else
x = ReturnDeviceById(_Id)
@@ -35,27 +35,16 @@ Public Class uWMeteo
If x IsNot Nothing Then

LblVille.Content = x.Name
'LblTemp.Content = x.TemperatureActuel & "°"
LblTemp.Content = Format(Val(x.TemperatureActuel), "#0.0") & "°"
'LblMin.Content = "Min: " & x.MinToday & "°"
LblMin.Content = "Min: " & Format(Val(x.MinToday), "#0.0") & "°"
'LblMinJ1.Content = x.MinToday & "°"
LblMinJ1.Content = Format(Val(x.MinToday), "#0.0") & "°"
'LblMinJ2.Content = x.MinJ1 & "°"
LblMinJ2.Content = Format(Val(x.MinJ1), "#0.0") & "°"
'LblMinJ3.Content = x.MinJ2 & "°"
LblMinJ3.Content = Format(Val(x.MinJ2), "#0.0") & "°"
'LblMinJ4.Content = x.MinJ3 & "°"
LblMinJ4.Content = Format(Val(x.MinJ3), "#0.0") & "°"
'LblMax.Content = "Max: " & x.MaxToday & "°"
LblMax.Content = "Max: " & Format(Val(x.MaxToday), "#0.0") & "°"
'LblMaxJ1.Content = x.MaxToday & "°"
LblMaxJ1.Content = Format(Val(x.MaxToday), "#0.0") & "°"
'LblMaxJ2.Content = x.MaxJ1 & "°"
LblMaxJ2.Content = Format(Val(x.MaxJ1), "#0.0") & "°"
'LblMaxJ3.Content = x.MaxJ2 & "°"
LblMaxJ3.Content = Format(Val(x.MaxJ2), "#0.0") & "°"
'LblMaxJ4.Content = x.MaxJ3 & "°"
LblMaxJ4.Content = Format(Val(x.MaxJ3), "#0.0") & "°"
LblJ1.Content = x.JourToday
LblJ2.Content = x.JourJ1
@@ -23,6 +23,7 @@ Public Class uWidgetEmpty
Prise = 11
Gauge = 12
Chart = 13
Thermostat = 14
Device = 99
End Enum

@@ -118,6 +119,9 @@ Public Class uWidgetEmpty
Dim _Periode As Integer = 0
Dim _TypeChart As Integer = 0

'Variables Widget Thermostat
Dim _THERMOSTAT As uThermostat = Nothing

'Variable Min/Max
Dim _Min As Integer
Dim _Max As Integer
@@ -503,6 +507,16 @@ Public Class uWidgetEmpty
AddHandler _Chart.TypeChartChange, AddressOf TypeChartChange
If _Show = False Then Exit Property
StkTool.Children.Add(_Chart)

Case TypeOfWidget.Thermostat
CanEditValue = False
StkEmptyetDevice.Visibility = Windows.Visibility.Collapsed
StkTool.Visibility = Windows.Visibility.Visible
_THERMOSTAT = New uThermostat("")
AddHandler _THERMOSTAT.ChangeValueThermo, AddressOf ChangeValueThermo
If _Show = False Then Exit Property
StkTool.Children.Add(_THERMOSTAT)

Case Else

End Select
@@ -617,6 +631,7 @@ Public Class uWidgetEmpty
_EtiquetteAlignement = value
Lbl.HorizontalContentAlignment = _EtiquetteAlignement
Catch ex As Exception
AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "Erreur uWidgetEmpty.EtiquetteAlignement Set: " & ex.Message, "Erreur", " uWidgetEmpty.EtiquetteAlignement Set")
_EtiquetteAlignement = Windows.HorizontalAlignment.Center
Lbl.HorizontalContentAlignment = _EtiquetteAlignement
End Try
@@ -1344,6 +1359,9 @@ Public Class uWidgetEmpty
If Me.Type = TypeOfWidget.Chart And _Chart IsNot Nothing Then
_Chart.IDDevice = _dev.ID
End If
If Me.Type = TypeOfWidget.Thermostat And _THERMOSTAT IsNot Nothing Then
_THERMOSTAT.Value = _dev.Value
End If
If Me.Type = TypeOfWidget.Moteur And _MOTEUR IsNot Nothing Then
If _dev.Value.GetType.ToString.ToUpper.Contains("BOOLEAN") Then
If _dev.Value Then
@@ -1417,6 +1435,7 @@ Public Class uWidgetEmpty
End If

Me.UpdateLayout()

Catch ex As Exception
AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "Erreur uWidgetEmpty.TraiteRefresh: " & ex.Message, "Erreur", " uWidgetEmpty.TraiteRefresh")
_dt.Stop()
@@ -1425,7 +1444,7 @@ Public Class uWidgetEmpty

Public Sub dispatcherTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
Try
If _FlagBlock = False Then TraiteRefresh()
If (_FlagBlock = False) And (IsConnect) Then TraiteRefresh()
Catch ex As Exception
AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "Erreur dispatcherTimer_Tick: " & ex.Message, "Erreur", " dispatcherTimer_Tick")
End Try
@@ -1451,6 +1470,9 @@ Public Class uWidgetEmpty
Case TypeOfWidget.Chart
_Chart.Width = Me.ActualWidth
_Chart.Height = Me.ActualHeight
Case TypeOfWidget.Thermostat
_THERMOSTAT.Width = Me.ActualWidth
_THERMOSTAT.Height = Me.ActualHeight - 20
Case TypeOfWidget.Volet
_VOLET.Width = Me.ActualWidth
_VOLET.Height = Me.ActualHeight - 30
@@ -1989,7 +2011,9 @@ Public Class uWidgetEmpty
Dim y As New HoMIDom.HoMIDom.DeviceAction.Parametre

If _dev IsNot Nothing Then
If _dev.Type <> HoMIDom.HoMIDom.Device.ListeDevices.VOLET Then
If _dev.Type = HoMIDom.HoMIDom.Device.ListeDevices.TEMPERATURECONSIGNE Then
x.Nom = "SETPOINT"
ElseIf _dev.Type <> HoMIDom.HoMIDom.Device.ListeDevices.VOLET Then
x.Nom = "DIM"
Else
x.Nom = "OUVERTURE"
@@ -2078,6 +2102,45 @@ Public Class uWidgetEmpty
End Try
End Sub

Private Sub ChangeValueThermo(ByVal Value As Integer)
Try
Dim _value As Object = Nothing
Dim _flag As Boolean = False

_CurrentValue = Nothing

If _dev IsNot Nothing And String.IsNullOrEmpty(Value) = False Then
If _dev.Type = HoMIDom.HoMIDom.Device.ListeDevices.GENERIQUEVALUE Or HoMIDom.HoMIDom.Device.ListeDevices.TEMPERATURECONSIGNE Then
If IsNumeric(Value) Then
_value = Value
_flag = True
Else
MessageBox.Show("Erreur: La valeur saisie doit être numérique", "Erreur", MessageBoxButton.OK, MessageBoxImage.Error)
_flag = False
End If
End If

If _flag = True Then
_FlagBlock = True
myService.ChangeValueOfDevice(IdSrv, _dev.ID, _value)
_FlagBlock = False
' If _dev.Type = HoMIDom.HoMIDom.Device.ListeDevices.TEMPERATURECONSIGNE Then
ValueChange(Value)
' End If
End If
End If

If StkPopup.Children.Count > 0 Then
If Popup1.IsOpen = True Then
Popup1.IsOpen = False
End If
End If
Catch ex As Exception
AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "Erreur uWidgetEmpty.ChangeValue: " & ex.Message, "Erreur", " uWidgetEmpty.ChangeValue")
_FlagBlock = False
End Try
End Sub

Private Sub AudioPlay()
Try
Dim x As New HoMIDom.HoMIDom.DeviceAction
@@ -2418,6 +2481,11 @@ Public Class uWidgetEmpty
Case TypeOfWidget.Chart
_Chart.Width = Me.ActualWidth
_Chart.Height = Me.ActualHeight

Case TypeOfWidget.Thermostat
_THERMOSTAT.Width = Me.ActualWidth
_THERMOSTAT.Height = Me.ActualHeight - 20
Exit Sub
End Select

If ShowEtiquette And ShowPicture And Lbl.ActualHeight > 0 And Me.ActualHeight > 0 Then
@@ -2484,7 +2552,6 @@ Public Class uWidgetEmpty
RemoveHandler _dt.Tick, AddressOf dispatcherTimer_Tick
_dt = Nothing
End If

Image.Source = Nothing
_Webbrowser = Nothing
_RSS = Nothing
@@ -2496,6 +2563,7 @@ Public Class uWidgetEmpty
_PRISE = Nothing
_Gauge = Nothing
_Chart = Nothing
_THERMOSTAT = Nothing
Catch ex As Exception
AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "Erreur uWidgetEmpty.Unloaded: " & ex.Message, "Erreur", " uWidgetEmpty.Unloaded")
End Try
@@ -1787,6 +1787,7 @@ Class Window1
End If
Catch ex As Exception
IsConnect = False
AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "ConnectToHomidom, Erreur lors de la connexion : " & ex.Message, "Erreur", "ConnectToHomidom")
End Try

Catch ex As Exception
@@ -1835,15 +1836,40 @@ Class Window1
Catch ex As Exception
dtstart.Stop()
dtstart = Nothing
AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "dispatcherTimerSart_Tick, Erreur: " & ex.Message, "Erreur", "dispatcherTimerSart_Tick")
End Try
End Sub

'Affiche la date et heure, heures levé et couché du soleil
Public Sub dispatcherTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
Try
LblTime.Content = Now.ToLongDateString & " "

'test si serveur est connecté apres deconnexion
If Not IsConnect Then
Try
Dim client As New System.Net.WebClient
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://" & IP & ":" & PortSOAP & "/service")
Dim response As System.Net.HttpWebResponse = request.GetResponse()
If response.StatusCode = System.Net.HttpStatusCode.OK Then
IsConnect = True
For Each icmnu In ListMnu
If icmnu.Label = LblZone.Content Then
IconMnuDoubleClick(icmnu, Nothing)
Exit For
End If
Next
End If
client = Nothing
request = Nothing
response = Nothing
FlagMsgDeconnect = Not IsConnect
Catch ex As Exception
End Try
End If

If IsConnect And ShowTimeFromServer Then
LblTime.Content &= myService.GetTime & " / Serveur"
LblTime.Content &= myService.GetTime() & " / Serveur"
Else
LblTime.Content &= Now.ToLongTimeString & "/ Local"
End If
@@ -1858,6 +1884,9 @@ Class Window1
For Each icmnu In ListMnu
If icmnu.Label = _DefautPage Then
IconMnuDoubleClick(icmnu, Nothing)
Refresh_Zone()
Refresh()

Exit For
End If
Next
@@ -1869,14 +1898,15 @@ Class Window1
If Now.Minute = 0 And Now.Second = 0 Then
HeureSoleilChanged()
End If
'If Now.Second = 0 Then
' 'MaJ Liste des devices au moins toutes les minutes
' Dim x As New Thread(AddressOf Refresh)
' x.Priority = ThreadPriority.Highest
' x.Start()
' x = Nothing
'MaJ Liste des devices au moins toutes les minutes
' If IsConnect And (Now.Second = 0) Then
'Dim x As New Thread(AddressOf Refresh)
'x.Priority = ThreadPriority.Highest
'x.Start()
'x = Nothing
'End If


Catch ex As Exception
IsConnect = False

@@ -1886,11 +1916,11 @@ Class Window1
End If

Log(TypeLog.INFO, TypeSource.CLIENT, "DispatcherTimer", "DispatcherTimer: " & ex.Message)
LblTime.Content = Now.ToLongDateString & " " & Now.ToShortTimeString
' LblTime.Content = Now.ToLongDateString & " " & Now.ToShortTimeString
LblLeve.Content = "?"
LblCouche.Content = "?"

AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "Erreur: " & ex.Message, "Erreur")
' AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "Erreur: " & ex.Message, "Erreur")
End Try
End Sub

@@ -1903,6 +1933,7 @@ Class Window1
DesAff_TaskMnu()
_TimeMouseDown = Now
LblZone.Content = sender.Label
' _zoneLabel = sender.Label

For Each _ctl In _ListMnu
_ctl.IsSelect = False
@@ -2005,7 +2036,7 @@ Class Window1

Private Sub Window1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.Closing
Try
'push.Close()
' push.Close()
myService = Nothing
Log(TypeLog.INFO, TypeSource.CLIENT, "Client", "Fermeture de l'application")
Catch ex As Exception
@@ -2804,7 +2835,7 @@ Class Window1
lbl.IsHitTestVisible = True
Next
Catch ex As Exception
AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "Erreur Resize: " & ex.Message, "Erreur", "Resize")
AfficheMessageAndLog(FctLog.TypeLog.ERREUR, "Erreur MaJ_Element: " & ex.Message, "Erreur", "MaJ_Element")
End Try
End Sub

BIN +512 Bytes (100%) RELEASE_HoMIWpF/HoMIWpF.exe
Binary file not shown.

0 comments on commit 76ca92a

Please sign in to comment.