Ticket #891: BrowseCheck.au3

File BrowseCheck.au3, 6.9 KB (added by anonymous, 16 years ago)
Line 
1#region ;**** Directives created by AutoIt3Wrapper_GUI ****
2#AutoIt3Wrapper_outfile=..\bin\BrowserCheck.exe
3#AutoIt3Wrapper_res_comment=Überprüft den Seitenaufbau von ausgewählten Seiten und giebt die Zeiten an eine Datenbank
4#AutoIt3Wrapper_res_fileversion=0.9.1.6
5#AutoIt3Wrapper_res_fileversion_autoincrement=p
6#AutoIt3Wrapper_res_legalcopyright=Alexander Koch, also EDV Beratung, 35606 Solms Germany
7#AutoIt3Wrapper_res_language=1031
8#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
9
10$oMyError = ObjEvent("AutoIt.Error", "ComError")
11
12#include <GUIConstantsEx.au3>
13#include <IE.au3>
14#include <timers.au3>
15#include <File.au3>
16;#include <array.au3>
17#include <IEEvents.au3>
18
19
20$Progname = "BrowserCheck"
21Global $Settings = "Settings.ini"
22$debug = true
23FileInstall("Settings.ini", "Settings.ini")
24
25Global $URLs, $GuiEnable, $Timer, $Log, $trayIcon, $Gui_EnSwitch, $Gui_DeSwitch, $GuiActivateByF8, $ErrorLog
26
27$GUIMain = GUICreate("Event Test", 600, 500)
28__IniRead()
29$Label1 = GUICtrlCreateLabel("Ladevorgänge:", 8, 8, 76, 17)
30$Label2 = GUICtrlCreateLabel("Durchschnitt Zeit:", 8, 32, 88, 17)
31$Label3 = GUICtrlCreateLabel("Min[ms]: ", 8, 56, 46, 17)
32$Label4 = GUICtrlCreateLabel("Min[Time]:", 8, 80, 52, 17)
33$Label5 = GUICtrlCreateLabel("Max[ms]:", 8, 104, 46, 17)
34$Label6 = GUICtrlCreateLabel("Max[Time]:", 8, 128, 55, 17)
35$Label13 = GUICtrlCreateLabel("URL:", 8, 152, 55, 17)
36$Label7 = GUICtrlCreateLabel("", 96, 8, 530, 17)
37$Label8 = GUICtrlCreateLabel("", 96, 32, 530, 17)
38$Label9 = GUICtrlCreateLabel("", 96, 56, 530, 17)
39$Label10 = GUICtrlCreateLabel("", 96, 80, 530, 17)
40$Label11 = GUICtrlCreateLabel("", 96, 104, 530, 17)
41$Label12 = GUICtrlCreateLabel("", 96, 128, 530, 17)
42$Label14 = GUICtrlCreateLabel("", 96, 152, 530, 17)
43$GUIEdit = GUICtrlCreateEdit("", 10, 250, 580, 200)
44$GUIProg = GUICtrlCreateProgress(10, 240, 580, 10)
45$GUIExit = GUICtrlCreateButton(" Close ", 200, 450, 80, 30)
46$GUIreset = GUICtrlCreateButton(" Reset ", 300, 450, 80, 30)
47
48If $GuiEnable = "1" Or $GuiEnable = "true" Then
49        GuiActivate() ;Show GUI
50Else
51        GuiDeActivate()
52EndIf
53
54_Timer_SetTimer($GUIMain, $Timer, "_SaveToDB")
55
56$oShell = ObjCreate("shell.application")
57While 1
58        $msg = GUIGetMsg()
59        If $msg = $GUI_EVENT_CLOSE Or $msg = $GUIExit Then ExitLoop
60        If $msg = $GUIreset Then _reset()
61        $oShellWindows = $oShell.windows
62        If Not IsObj($oShellWindows) Then
63                MsgBox(0, "Error", "Failed to obtain shell windows. Error: " & @error)
64                Exit
65        EndIf
66        For $Window In $oShellWindows ; Count all existing shell windows
67                _IEInit($Window)
68        Next
69WEnd
70
71GUIDelete() ; Remove GUI
72
73Exit
74
75Func _reset($all = 1)
76        _Debug_log(@ScriptLineNumber,$all,"_reset")
77        For $i = 1 To UBound($Sites) - 1
78                $Sites[$i][1] = 0 ; Init Time
79                $Sites[$i][2] = 0 ; Work in Progress
80                $Sites[$i][3] = 0 ; Min
81                $Sites[$i][4] = 0 ; Min Site
82                $Sites[$i][5] = 0 ; Max
83                $Sites[$i][6] = 0 ; Max Site
84                $Sites[$i][7] = 0 ; Zähler
85                $Sites[$i][8] = 0 ; Mittelwert
86        Next
87        If $GuiEnable = "1" Or $GuiEnable = "true" Then
88                If $all Then GUICtrlSetData($GUIEdit, "")
89                GUICtrlSetData($Label7, "")
90                GUICtrlSetData($Label8, "")
91                GUICtrlSetData($Label9, "")
92                GUICtrlSetData($Label10, "")
93                GUICtrlSetData($Label11, "")
94                GUICtrlSetData($Label12, "")
95                GUICtrlSetData($Label14, "")
96                GUICtrlSetData($GUIProg, 0)
97        EndIf
98EndFunc   ;==>_reset
99
100Func _SaveToDB($hWnd, $msg, $iIDTimer, $dwTime)
101        ;_Debug_log(@ScriptLineNumber,"","_SaveToDB")
102        #forceref $hWnd, $Msg, $iIDTimer, $dwTime
103        If $Log = "1" Or $Log = "true" Then
104                For $i = 1 To UBound($Sites) - 1
105                        If $Sites[$i][8] > 0 Then
106                                _FileWriteLog("Log.log", $Sites[$i][0] & "," & $Sites[$i][8] / $Sites[$i][7] & "," & _
107                                                $Sites[$i][4] & "," & _
108                                                $Sites[$i][3] & "," & _
109                                                $Sites[$i][6] & "," & _
110                                                $Sites[$i][5])
111                                If $GuiEnable = "1" Or $GuiEnable = "true" Then
112                                        GUICtrlSetData($GUIEdit, $Sites[$i][0] & "," & $Sites[$i][8] / $Sites[$i][7] & "," & _
113                                                        $Sites[$i][4] & "," & _
114                                                        $Sites[$i][3] & "," & _
115                                                        $Sites[$i][6] & "," & _
116                                                        $Sites[$i][5] & @CRLF, "append")
117                                EndIf
118                        EndIf
119                Next
120        EndIf
121        If UBound($Sites) > 1 Then
122                _reset(0)
123        EndIf
124        __IniRead()
125EndFunc   ;==>_SaveToDB
126
127Func __IniRead()
128        _Debug_log(@ScriptLineNumber,"","__IniRead")
129        If Not FileExists($Settings) Then
130                MsgBox(16, $Progname, "Settings.ini kann nicht gefunden werden." & @CRLF & "Programm wird beendet.")
131                Exit (1)
132        Else
133                If IniRead($Settings, "Settings", "EnableTrayIcon", 0) = 0 Then AutoItSetOption("TrayIconHide", 1)
134                $Timer = IniRead($Settings, "Settings", "Timer", 10) * 1000
135                $GuiEnable = IniRead($Settings, "Settings", "Gui_Enable", 0)
136                $Gui_EnSwitch = IniRead($Settings, "Settings", "Gui_EnSwitch", "")
137                $Gui_DeSwitch = IniRead($Settings, "Settings", "Gui_DeSwitch", "")
138                $ErrorLog = IniRead($Settings, "Settings", "ErrorLog", 0)
139                $Log = IniRead($Settings, "Settings", "Log", 0)
140                $URLs = IniReadSection($Settings, "Sites")
141        EndIf
142EndFunc   ;==>__IniRead
143
144Func __now()
145        local $now = @YEAR & "." & @MON & "." & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC
146        _Debug_log(@ScriptLineNumber,$now,"__now")
147        Return $now
148EndFunc   ;==>__now
149
150Func OnAutoItExit()
151        For $j = 0 To UBound($ieobj) - 1
152                if $ieobj[$j][1] <> "" Then
153                        if IsObj($ieobj[$j][1]) then
154                                $ieobj[$j][1].close
155                        EndIf
156                EndIf
157        Next
158EndFunc   ;==>OnAutoItExit
159
160Func ComError()
161        local $logline
162        If Not $ErrorLog = 0 And Not $ErrorLog = False Then
163                Local $HexNumber
164                If IsObj($oMyError) Then
165                        $HexNumber = Hex($oMyError.number, 8)
166                        $logline = "AutoItCOM , ein COM erreur ist aufgetreten !" & _
167                                        " Beschreibung : '" & @TAB & $oMyError.description & _
168                                        "' Beschreibung Windows : '" & $oMyError.windescription & _
169                                        "' Fehlernummer : '" & @TAB & $HexNumber & _
170                                        "' Fehlerzeile : '" & @TAB & $oMyError.scriptline & "'"         
171                        _Debug_log(@ScriptLineNumber,$logline,"ComError")
172                        _FileWriteLog("Error.log",$logline)
173                EndIf
174        EndIf
175EndFunc   ;==>ComError
176
177Func GuiActivate()
178        _Debug_log(@ScriptLineNumber,"","GuiActivate")
179        if $Gui_EnSwitch <> "" then HotKeySet("{" & $Gui_EnSwitch & "}")
180        if $Gui_DeSwitch <> "" then HotKeySet("{" & $Gui_DeSwitch & "}", "GuiDeActivate")
181        $GuiEnable = "1"
182        $GuiActivateByF8 = False
183        GUISetState()
184EndFunc   ;==>GuiActivate
185
186Func GuiDeActivate()
187        _Debug_log(@ScriptLineNumber,"","GuiDeActivate")
188        if $Gui_EnSwitch <> "" then HotKeySet("{" & $Gui_EnSwitch & "}", "GuiActivate")
189        if $Gui_DeSwitch <> "" then HotKeySet("{" & $Gui_DeSwitch & "}")
190        $GuiEnable = "0"
191        $GuiActivateByF8 = True
192        GUISetState(@SW_HIDE)
193EndFunc   ;==>GuiDeActivate
194
195func _Debug_log($Line,$msg,$FuncName="",$InclFile="")
196        if $debug Then
197                local $file="debug.log"
198                local $logmsg = ""
199                if $InclFile <> "" then $logmsg &= $InclFile & @TAB
200                if $FuncName <> "" then $logmsg &= $FuncName & @TAB
201                $logmsg &= $Line & ": " & $msg
202                if @Compiled then
203                        _FileWriteLog($file,$logmsg)
204                Else
205                        ConsoleWrite($logmsg  & @CRLF)
206                EndIf
207        EndIf
208EndFunc