Imports AgentObjects
Imports AxAgentObjects
Imports Microsoft.Win32
Public Class frmHelper
#Region "Enumeratori / Strutture"
Public Enum SenNum
Saluto_Iniziale
Saluto_Finale
Impegni_Salvati
Impegni_Cancellati
End Enum
#End Region
#Region "Variabili"
'Queste variabili vengono utilizzate con gli eventi:
' RequestStart e RequestComplete
'Vedi note ed esempi relativi
'------------------------------------------------------------------------
'Dim MyRequest As IAgentCtlRequest
'Dim MySecondRequest As IAgentCtlRequest
'Dim MyThirdRequest As IAgentCtlRequest
'Dim AzioneCorrente As Integer
'**********************************************************
'Agente
Public Agente As IAgentCtlCharacterEx
'Le misure dello schermo
Public Display As Rectangle = Screen.PrimaryScreen.Bounds
'Posizione dell'agente
Public Position As Point
Public Personaggio As String = "Peedy"
'Costanti per la modifica dello stile del fumetto
Private Const BallonOn As Long = 1
Private Const SizeToText As Long = 2
Private Const AutoHide As Long = 4
Private Const AutoPace As Long = 8
'Frasi di default
Public Shared Options As New clsOptions
'Azioni
Private Actions As New ArrayList
'Gli array sono difficili da gestire, così questa hashtable è utilizzata
'per migliorare la gestione di Options.Alarms
Public Shared Alarms As New Hashtable
#End Region
#Region "Procedure / Funzioni"
'Carica il personaggio
Public Sub LoadChar()
Personaggio = Options.Agent
'Carica il modello e i dati del personaggio nella lista
AxAgent1.Characters.Load(Personaggio, "C:\WINDOWS\msagent\chars\" + Personaggio + ".acs")
'Attribuisce ad 'Agente' il riferimento a tale personaggio
Agente = AxAgent1.Characters(Personaggio)
With Agente
.LanguageID = &H410 ' ITALIANO
.Balloon.FontName = Options.Balloon_Font_Name
.Balloon.FontSize = Options.Balloon_Font_Size
End With
End Sub
'Animazione iniziale
Public Sub StartAnim()
With Agente
.Show()
.MoveTo(Display.Width - 250, Display.Height - 250)
'Saluto iniziale
SaySentence(0)
End With
End Sub
'Restituisce il quadrante in cui si trova l'agente, supposto lo schermo diviso in 4 parti uguali
'Serve per determinare la posizione delle finestre ausiliarie
'Inutilizzato dalla versione 1.2
Public Function Quadrante() As Byte
If Position.X > Display.Width / 2 Then
If Position.Y > Display.Height / 2 Then
Return 4
Else
Return 1
End If
Else
If Position.Y > Display.Height / 2 Then
Return 3
Else
Return 2
End If
End If
End Function
'Pronuncia una frase di quelle impostate dall'utente, ma solo se Play = true
Public Shared Sub SaySentence(ByVal Index As Byte)
If Options.Sentences(Index).Play Then
frmHelper.Agente.Speak(Options.Sentences(Index).Text)
End If
End Sub
'Pronunica una frase di quelle preimpostate, ma solo se Play = true
Public Shared Sub SayPredSentence(ByVal Index As Byte)
If Options.PredSentences(Index).Play Then
frmHelper.Agente.Speak(Options.PredSentences(Index).Text)
End If
End Sub
'Restituisce una sottostringa del testo, dati gli elementi tra cui è compresa
'Serve per i dati meteo
Public Function SubStr(ByVal Str As String, ByVal Prev_String As String, ByVal Next_String As String)
Dim Start_Index As Int32
Dim End_Index As Int32
Dim Result As String
Start_Index = Str.IndexOf(Prev_String) + Prev_String.Length
End_Index = Str.IndexOf(Next_String, Start_Index)
Result = Str.Substring(Start_Index, End_Index - Start_Index)
Return Result
End Function
#End Region
'Carica le opzioni, il personaggio ed eventualmente le sveglie
Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'Controlla se Microsoft Agent è installato
If Not IO.Directory.Exists("C:\WINDOWS\msagent") Then
MessageBox.Show("Microsoft Agent risulta non essere installato su questo computer. Per installare il software necessario, " + _
"eseguire tutti i programmi presenti nella sottocartella 'Microsoft Agent' che verrà aperta tra breve.", "Error #0", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Shell("C:\WINDOWS\explorer.exe " + Chr(34) + Application.StartupPath + "\Microsoft Agent" + Chr(34), AppWinStyle.NormalFocus)
Application.Exit()
End If
'Controlla se esistono le directory adeguate
If Not IO.Directory.Exists(Application.StartupPath + "\Imp") Then
IO.Directory.CreateDirectory(Application.StartupPath + "\Imp")
End If
If Not IO.Directory.Exists(Application.StartupPath + "\Macro") Then
IO.Directory.CreateDirectory(Application.StartupPath + "\Macro")
End If
Options = Options.Load(Application.StartupPath + "\Settings.xml")
LoadChar()
If Options.Alarms.Length = 0 Then
Exit Sub
Else
If Options.Alarms(0).Time = Nothing Then
Exit Sub
End If
End If
'Copia Options.Alarms in Alarms
For Each A As clsOptions.Alarm In Options.Alarms
Alarms.Add(A.Time, A)
Next
'Attiva il timer se necessario
If Options.Alarms_Enabled Then
tmrAlarm.Start()
End If
'Controlla Meteo se necessario
If Options.Meteo_On_startup Then
imgMeteo_Click(Me, New EventArgs)
End If
'Da perfezionare
If Options.POP3_Enabled Then
'tmrControlMail.Start()
End If
End Sub
'Esegue l'animazione iniziale e nasconde il form
Private Sub Form_Activate(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Shown
StartAnim()
Me.Visible = False
Me.Opacity = 0
End Sub
'Comunica l'ora
Private Sub imgDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgDate.Click
Dim D As Date = Date.Now
Dim S As String
S = "Oggi è "
Select Case D.DayOfWeek
Case DayOfWeek.Monday : S += "Lunedì"
Case DayOfWeek.Tuesday : S += "Martedì"
Case DayOfWeek.Wednesday : S += "Mercoledì"
Case DayOfWeek.Thursday : S += "Giovedì"
Case DayOfWeek.Friday : S += "Venerdì"
Case DayOfWeek.Saturday : S += "Sabato"
Case DayOfWeek.Sunday : S += "Domenica"
End Select
S += " " & D.Day & " "
Select Case D.Month
Case 1 : S += "Gennaio"
Case 2 : S += "Febbraio"
Case 3 : S += "Marzo"
Case 4 : S += "Aprile"
Case 5 : S += "Maggio"
Case 6 : S += "Giugno"
Case 7 : S += "Luglio"
Case 8 : S += "Agosto"
Case 9 : S += "Settembre"
Case 10 : S += "Ottobre"
Case 11 : S += "Novembre"
Case 12 : S += "Dicembre"
End Select
S += " " & D.Year & " e sono le ore " & D.Hour & " e " & D.Minute & " minuti."
Agente.Stop()
Agente.Speak(S)
End Sub
'Esce dal programma
Private Sub imgExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strExit.Click
With Agente
.Show()
.Stop()
'Saluto finale
SaySentence(1)
.Play("Wave")
tmrExit.Start()
End With
End Sub
'Esegue l'animazione di congedo e chiude il programma, salvando prima le opzioni
Private Sub tmrExit_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrExit.Tick
ReDim Options.Alarms(Alarms.Count - 1)
Dim I As UInt16 = 0
For Each A As clsOptions.Alarm In Alarms.Values
Options.Alarms(I) = A
I += 1
Next
Options.Save(Application.StartupPath + "\Settings.xml")
icnHelper.Visible = False
Application.Exit()
End Sub
'Visualizza gli impegni
Private Sub imgImp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgImp.Click
Dim TImp As New frmTodayImp
Dim X, Y As Int32
Select Case Quadrante()
Case 1, 4
X = Position.X - TImp.Width - 50
Y = Position.Y
Case 2, 3
X = Position.X + Agente.Width + 50
Y = Position.Y
End Select
TImp.Show()
'TImp.Location = New Point(X, Y)
Agente.Speak(TImp.txtImp.Text.Replace(vbCrLf, "\Pau=500\"))
End Sub
'Muove l'agente in alto a sinistra
Private Sub strTopLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strTopLeft.Click
With Agente
.StopAll()
.MoveTo(10, 10)
Position = New Point(10, 10)
End With
End Sub
'Muove l'agente in basso a sinistra
Private Sub strBottomLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strBottomLeft.Click
With Agente
.StopAll()
.MoveTo(10, Display.Height - 200)
Position = New Point(10, Display.Height - 200)
End With
End Sub
'Muove l'agente in alto a destra
Private Sub strTopRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strTopRight.Click
With Agente
.StopAll()
.MoveTo(Display.Width - 200, 200)
Position = New Point(Display.Width - 200, 200)
End With
End Sub
'Muove l'agente in basso a destra
Private Sub strBottomRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strBottomRight.Click
With Agente
.StopAll()
.MoveTo(Display.Width - 200, Display.Height - 200)
Position = New Point(Display.Width - 200, Display.Height - 200)
End With
End Sub
'Modifica gli impegni
Private Sub imgModImp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgModImp.Click
Dim MImp As New frmModImp
Dim X, Y As Int32
Select Case Quadrante()
Case 1, 4
X = Position.X - MImp.Width - 50
Y = Position.Y
Case 2, 3
X = Position.X + Agente.Width + 50
Y = Position.Y
End Select
MImp.Show()
'MImp.Location = New Point(X, Y)
With Agente
.StopAll()
.Play("Suggest")
'Suggerimento
SayPredSentence(0)
End With
End Sub
'Legge un file
Private Sub imgReadFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgReadFile.Click
If imgReadFile.Tag = "Smetti" Then
imgReadFile.Tag = "Leggi file"
Agente.StopAll()
Exit Sub
End If
Dim O As New OpenFileDialog
O.Filter = "File di testo|*.txt"
If O.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim R As New IO.StreamReader(O.FileName)
Dim S As String = R.ReadToEnd
S = S.Replace(":", ":\Pau=200\")
Dim Lines() As String = S.Split(".")
R.Close()
With Agente
.Play("Read")
For Each Fr As String In Lines
If Fr = Nothing Then
Continue For
End If
.Speak(Fr)
Next
.Play("Announce")
'Lettura terminata
SayPredSentence(1)
End With
imgReadFile.Tag = "Smetti"
End If
End Sub
'Visualizza / nasconde il menù
Private Sub icnHelper_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles icnHelper.DoubleClick
If Me.Opacity = 0 Then
Dim X, Y As Int32
X = Position.X + (Agente.Width / 2) - Me.Width / 2
Y = Position.Y + (Agente.Height / 2) - Me.Height / 2
Me.Opacity = 100
Me.Visible = 100
Me.Location = New Point(X, Y)
'Introduzione
SayPredSentence(2)
Else
Me.Visible = False
Me.Opacity = 0
End If
End Sub
'Sposta l'agente a seconda dei movimenti del mouse
Private Sub AxAgent1_MoveEvent(ByVal sender As System.Object, ByVal e As AxAgentObjects._AgentEvents_MoveEvent) Handles AxAgent1.MoveEvent
Position = New Point(e.x, e.y)
Me.Location = New Point(e.x - (Me.Width - Agente.Width) / 2, e.y - (Me.Height - Agente.Height) / 2)
End Sub
'Visualizza le opzioni
Private Sub imgOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgOption.Click, strOptions.Click
Dim O As New frmOption
O.ShowDialog()
End Sub
'Informazioni sul software
Private Sub strAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAbout.Click
Dim A As New frmAbout
A.ShowDialog()
'MsgBox("Prodotto: Virtual Agent Helper" + vbCrLf + "Versione: 1.0.0.0" + vbCrLf + "Sviluppatore: Totem" + vbCrLf + "Società: Piero Tofy's Community" + vbCrLf + _
'"Licenza: Questo prodotto è distribuito sotto la 'free license' senza scopo di lucro e in modo libero poiché parte del suo contenuto di terza parti è sotto la licenza GNU GPL (http://gnu.org/copyleft/lgpl.html)", MsgBoxStyle.Information)
End Sub
'Indica un'immagine e la descrive
Private Sub img_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgReadFile.MouseHover, imgModImp.MouseHover, imgImp.MouseHover, imgDate.MouseHover, imgOption.MouseHover, imgMacros.MouseHover, imgMeteo.MouseHover, imgAlarm.MouseHover
With Agente
.GestureAt(Me.Location.X + sender.Location.X, Me.Location.Y + sender.Location.Y)
If Options.Speak_On_MouseOver Then
.Speak(sender.Tag)
End If
End With
End Sub
'Visualizza / nasconde il menù
Private Sub AxAgent1_DblClick(ByVal sender As System.Object, ByVal e As AxAgentObjects._AgentEvents_DblClickEvent) Handles AxAgent1.DblClick
icnHelper_DoubleClick(Me, New EventArgs)
End Sub
'Controlla se ci sono sveglie e le notifica
Private Sub tmrAlarm_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAlarm.Tick
Dim Time As String
Dim D As Date = Date.Now
Time = D.Hour & "." & D.Minute
If Alarms.Contains(Time) Then
Dim Al As clsOptions.Alarm = Alarms(Time)
'Se vi è già stata una notifica, non fa nulla
If Al.Played Then
Exit Sub
End If
'Se la descrizione ha il seguente formato Macro: <nomemacro>, esegue la macro
If Al.Desc.ToLower.StartsWith("macro: ") Then
Dim MacroName As String = Al.Desc.Remove(0, "macro: ".Length).ToLower
Dim Files() As String = IO.
Directory.
GetFiles(Application.
StartupPath + "\Macro")
If IO.
Path.
GetFileNameWithoutExtension(File).
ToLower = MacroName
Then
Agente.Speak("Sto eseguendo la macro '" + MacroName + "'.")
Exit For
End If
Next
Exit Sub
End If
Dim S As String = Alarms(Time).Desc
S = S.Replace(":", ":\Pau=200\")
Dim Lines() As String = S.Split(".")
With Agente
.Play("Read")
.Speak("Ore " & D.Hour & " e " & D.Minute)
For Each Fr As String In Lines
If Fr = Nothing Then
Continue For
End If
.Speak(Fr)
Next
.Play("Announce")
'Lettura terminata
SayPredSentence(1)
End With
End If
End Sub
'Visualizza il menù delle sveglie
Private Sub imgAlarm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgAlarm.Click
Dim A As New frmAlarm
A.Show()
End Sub
'Apre il menù delle macro
Private Sub imgMacros_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgMacros.Click
Dim M As New frmMacro
M.ShowDialog()
End Sub
'Esegue il tutorial del programma
Private Sub strTutorial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strTutorial.Click
'Agente.MoveTo(Display.Width / 2 - Agente.Width / 2, Display.Height / 2 - Agente.Height / 2)
'Agente.StopAll()
Agente.Speak("Benvenuto nel tutòrial del programma.\Pau=500\Ora ti spiegherò come utilizzare tutte le mie funzionalità.")
Dim X, Y As Int32
X = Position.X + (Agente.Width / 2) - Me.Width / 2
Y = Position.Y + (Agente.Height / 2) - Me.Height / 2
Me.Opacity = 100
Me.Visible = 100
Me.Location = New Point(X, Y)
With Agente
'Data e ora
'.MoveTo(Me.Location.X - .Width, Me.Location.Y - .Height / 2)
'.GestureAt(Me.Location.X + imgDate.Location.X, Me.Location.Y + imgDate.Location.Y)
.Speak("Data e Ora")
.Speak("Data e Ora: \Pau=200\Visualizza la data e l'ora odierni.")
'Impegni per oggi
'.MoveTo(Me.Location.X + Me.Width / 2, Me.Location.Y - .Height)
'.GestureAt(Me.Location.X + imgImp.Location.X, Me.Location.Y + imgImp.Location.Y)
.Speak("Impegni per oggi")
.Speak("Qui vengono visualizzati tutti gli impegni che hai progettato per oggi.")
'Modifica impegni
'.MoveTo(Me.Location.X - .Width, Me.Location.Y + .Height / 2)
'.GestureAt(Me.Location.X + imgModImp.Location.X, Me.Location.Y + imgModImp.Location.Y)
.Speak("Modifica impegni")
.Speak("Qui puoi modificare i tuoi impegni. \Pau=500\Seleziona il giorno che preferisci, scrivi quello che vuoi, quindi clicca Salva.")
.Speak("Cliccando Cancella, cancellerai l'impegno selezionato.")
'Sveglie
'.MoveTo(Me.Location.X + (Me.Width - .Width) / 2, Me.Location.Y - .Height)
'.GestureAt(Me.Location.X + imgAlarm.Location.X, Me.Location.Y + imgAlarm.Location.Y)
.Speak("Sveglie")
.Speak("Qui puoi aggiungere quante sveglie vuoi. \Pau=500\Ogni trenta secondi controllerò se hai impostato qualche sveglia per l'ora attuale.")
.Speak("Se l'avrai fatto, ti dirò quello che hai scritto come un promemoria.")
.Speak("Puoi scrivere 'macro: <nome macro>' al posto del testo per eseguire una macro a una data ora.")
'Leggi file
'.MoveTo(Me.Location.X - .Width, Me.Location.Y + .Height)
'.GestureAt(Me.Location.X + imgReadFile.Location.X, Me.Location.Y + imgReadFile.Location.Y)
.Speak("Leggi file")
.Speak("Cliccando qui mi potrai far leggere un file di testo con estensione TXT.")
'Opzioni
'.MoveTo(Me.Location.X + Math.Abs(Me.Width - .Width) / 2, Me.Location.Y + Math.Abs(Me.Height - .Height) / 2)
'.GestureAt(Me.Location.X + imgOption.Location.X, Me.Location.Y + imgOption.Location.Y)
.Speak("Opzioni")
.Speak("Qui potrai modificare le frasi che dico e decidere anche di non farmi parlare.")
.Speak("Inoltre puoi modificare il carattere dei fumetti, la mia posizione iniziale e cambiare agente.")
.Speak("Clicca Salva per salvare le modifiche.")
'Macro
'.GestureAt(Me.Location.X + imgMacros.Location.X, Me.Location.Y + imgMacros.Location.Y)
.Speak("Macro")
.Speak("Qui puoi aggiungere nuove macro. \Pau=500\Le macro sono combinazioni di azioni che puoi farmi eseguire.")
.Speak("Posso aprire file, programmi o cartelle per conto tuo in un solo click.")
.Speak("Clicca con il pulsante destro del mouse sulla casella di testo più grande per avere le opzioni.")
.Speak("Una volta risposto alle finestre di dialogo sarò io a generare il codice batch per te.")
.Speak("Clicca Salva per salvare o Cancella per cancellare la macro selezionata.")
'Meteo
'.GestureAt(Me.Location.X + imgMeteo.Location.X, Me.Location.Y + imgMeteo.Location.Y)
.Speak("Méteo")
.Speak("Cliccando qui potrai sapere le previsioni di oggi per la tua zona.")
.Speak("Per attivare questa funzionalità è necessaria una connessione a Internet: il tempo impiegato per scaricare le informazioni varia a seconda della velocità della tua connessione.")
End With
End Sub
'Controlla se ci sono nuove mail
'Questo rimane da perfezionare
Private Sub tmrControlMail_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Handles tmrControlMail.Tick
'Try
Dim Client As New Net.Sockets.TcpClient
Dim NetStr As Net.Sockets.NetworkStream
Dim Msg() As Byte
Dim Ret As String
'Si connette
Client.Connect(Options.POP3_Server, Options.POP3_Port)
ReDim Msg(Client.ReceiveBufferSize)
NetStr = Client.GetStream
'While Client.Available = 0
'End While
'Riceve il messaggio di conferma
NetStr.Read(Msg, 0, Client.ReceiveBufferSize)
Ret = System.Text.ASCIIEncoding.ASCII.GetString(Msg)
If Not Ret.StartsWith("+OK") Then
Exit Sub
End If
'Invia l'username
Msg = System.Text.ASCIIEncoding.ASCII.GetBytes("USER " + Options.POP3_User)
NetStr.Write(Msg, 0, Msg.Length)
'While Client.Available = 0
'End While
'Riceve conferma
NetStr.Read(Msg, 0, Client.ReceiveBufferSize)
Ret = System.Text.ASCIIEncoding.ASCII.GetString(Msg)
If Not Ret.StartsWith("+OK") Then
MessageBox.Show("Username errato! Modificare le opzioni!", "Error #6", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
tmrControlMail.Stop()
Exit Sub
End If
'Invia la password
Msg = System.Text.ASCIIEncoding.ASCII.GetBytes("PASS " + Options.POP3_Password)
NetStr.Write(Msg, 0, Msg.Length)
'While Client.Available = 0
'End While
'Riceve conferma
NetStr.Read(Msg, 0, Client.ReceiveBufferSize)
Ret = System.Text.ASCIIEncoding.ASCII.GetString(Msg)
If Not Ret.StartsWith("+OK") Then
MessageBox.Show("Nome utente o password errati! Modificare le opzioni!", "Error #7", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
'While Client.Available = 0
'End While
'Richiede il numero di mail
Msg = System.Text.ASCIIEncoding.ASCII.GetBytes("LIST")
NetStr.Write(Msg, 0, Msg.Length)
'While Client.Available = 0
'End While
'Riceve conferma
NetStr.Read(Msg, 0, Client.ReceiveBufferSize)
Ret = System.Text.ASCIIEncoding.ASCII.GetString(Msg)
If Ret.StartsWith("+OK") Then
Dim FirstNumIndex As Int16 = 4
Dim LastNumIndex As Int16 = Ret.IndexOf("mes") - 1
Dim Number As String = Ret.Substring(FirstNumIndex, LastNumIndex - FirstNumIndex + 1)
Agente.Speak("Hai " + Number + " nuove mail!")
Else
MsgBox("Errore di login!")
End If
' Catch Ex As Exception
'MsgBox(Ex.Message)
'End Try
End Sub
'Permette di scrivere una mail per riportare eventuali bugs
Private Sub strBugReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strBugReport.Click
Dim M As New frmMail
M.ShowDialog()
End Sub
'Questo codice permette di prelevare informazione meteo da Yahoo! Meteo
Public WithEvents WB As New WebBrowser
'Naviga sulla pagina del meteo contraddistinta dall'indice selezionato
Private Sub imgMeteo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imgMeteo.Click
WB.Navigate("http://it.weather.yahoo.com/ITXX/ITXX" + CInt(Options.Meteo).ToString.PadLeft(4, "0") + "/index_c.html")
End Sub
'Cerca nella pagina le informzioni
Private Sub WB_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WB.DocumentCompleted
Dim Html As String = WB.DocumentText
Dim Previsione, Alba, Tramonto, Umi As String
Dim Max, Min, Vento, Condensazione, Visib As String
Previsione = SubStr(Html, "width=52 height=52 alt=" + Chr(34), Chr(34) + ">")
Max = SubStr(Html, "Massime</small> <b>", "°")
Min = SubStr(Html, "Minime</small><b> ", "°")
If Options.Meteo_Detailed Then
Vento = SubStr(Html, "Vento:</font></td><td><font size=-1>", "</font>")
Visib = SubStr(Html, "Visibilità:</font></td><td><font size=-1>", "</font>")
Condensazione = SubStr(Html, "Punto di condensazione:</font></td><td><font size=-1>", "°")
Alba = SubStr(Html, "Alba:</font></td><td><font size=-1>", "</font>")
Tramonto = SubStr(Html, "Tramonto</font></td><td><font size=-1>", "</font>")
'Umidità e Visibilità generano errori nella ricerca, forse a causa dei caratteri 'à'
Dim Start_Index As Int32 = Html.IndexOf("Umidit") + "Umidità:</font></td><td><font size=-1>".Length
Dim End_Index As Int32 = Html.IndexOf("</font>", Start_Index)
Umi = Html.Substring(Start_Index, End_Index - Start_Index)
Start_Index = Html.IndexOf("Visibilit") + "Visibilità:</font></td><td><font size=-1>".Length
End_Index = Html.IndexOf("</font>", Start_Index)
Visib = Html.Substring(Start_Index, End_Index - Start_Index)
Umi = Umi.Replace("%", " per cento")
Vento = Vento.Replace(" ", " ")
Vento = Vento.Replace("km/h", "chilometri orari")
Vento = Vento.Replace("/", " a ")
If Vento.Contains("-") Then
Vento = Vento.Replace("N", "Nord")
Vento = Vento.Replace("S", "Sud")
Vento = Vento.Replace("O", "Ovest")
Vento = Vento.Replace("E", "Est")
End If
Vento = "verso " + Vento
Visib = Visib.Replace(" ", " ")
Visib = Visib.Replace("km", "chilometri")
Condensazione = Condensazione + " gradi"
Alba = Alba.Replace(":", " e ") + " minuti"
Tramonto = Tramonto.Replace(":", " e ") + " minuti"
End If
With Agente
.Play("Read")
.Speak("Previsioni di oggi")
.Speak(Previsione + ", con una temperatura massima di " + Max + " gradi e una minima di " + Min + " gradi.")
If Options.Meteo_Detailed Then
.Speak("Informazioni aggiuntive")
.Speak("Ora dell'alba: " + Alba + ".")
.Speak("Ora del tramonto: " + Tramonto + ".")
.Speak("Il punto di condensazione è di " + Condensazione + ", con un'umidità del " + Umi + ", mentre la visibilità è di " + Visib + ".")
.Speak("Tira un vento " + Vento + ".")
End If
End With
WB.Stop()
End Sub
End Class