Modul Analiza sistema

Iz SDMS
Skoči na: navigacija, iskanje

Klic

Sub UsageReport


Sub UsageReport
  Dim I, J, K As Long, D As DateTime, Usg, Rpt As TStringList
  Dim FL, SL As TStringlist
  FL = CreateStringlist
  Usg = CreateStringlist
  FL.FindFiles (Datapath + 'logs\usage\', '*.ini', True)
  For I = 0 To FL.Count - 1
    Hint ('Reading: ' + IntToStr (I+1) + '/' + IntToStr (FL.Count))
    SL = CreateStringlist
    SL.Load (FL.Strings (I))
    J = Length (FL.Strings (I))
    D = EncodeDate (StrToInt (Copy (FL.Strings (I), J-13, 4)), 
                    StrToInt (Copy (FL.Strings (I), J-8, 2)), 
                    StrToInt (Copy (FL.Strings (I), J-5, 2)))
    For J = 0 To SL.Count - 1
      K = Pos ('$', SL.Strings (J))
      If K > 0 Then
        Usg.Add (Copy (SL.Strings (J), K+1, 8))
        Usg.Data (Usg.Count-1) = Trunc (Date - D)
      EndIf
    Next
    Destroy (SL)
  Next
  Destroy (FL)
  Usg.Sorted = True
  Rpt = CreateStringlist
  Rpt.Add ('<html>')
  Rpt.Add ('<head>')
  Rpt.Add ('<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">')
  Rpt.Add ('<meta http-equiv="Content-Language" content="sl">')
  Rpt.Add ('<meta http-equiv="Expires" CONTENT="0">')
  Rpt.Add ('<title></title>')
  Rpt.Add ('<style>')
  Rpt.Add ('<' + '!--')
  Rpt.Add ('  body  { margin: 8; font-family: "MS Sans Serif"; font-size: 8pt; }')
  Rpt.Add ('  p     { margin: 0; padding: 0; }')
  Rpt.Add ('  h1    { margin: 0; padding: 4; background: #C0C0E0; font-family: "Verdana"; font-size: 12pt; }')
  Rpt.Add ('  h2    { margin: 0; margin-top: 8; padding: 2 4; background: #C0C0E0; font-family: "Verdana"; font-size: 12pt; }')
  Rpt.Add ('  pre   { margin: 0; padding: 0; background: #F0F0F7; font-family: "Courier New"; font-size: 8pt; }')
  Rpt.Add ('  table { margin: 0; padding: 0; font-size: 8pt; }')
  Rpt.Add ('  th    { margin: 0; border: 0 solid #FFFFFF; border-top: 1 solid #FFFFFF; padding: 4;' + 
           ' background: #E0E0F0; text-align: left; }')
  Rpt.Add ('  th.l  { border-left: 1 solid #FFFFFF; }')
  Rpt.Add ('  td    { margin: 0; border: 0 solid #FFFFFF; border-top: 1 solid #FFFFFF; padding: 2; background: #F0F0F7; }')
  Rpt.Add ('  td.l  { border-left: 1 solid #FFFFFF }')
  Rpt.Add ('  td.lb { border-left: 1 solid #FFFFFF; font-weight: bold }')
  Rpt.Add ('  a     { color: #000000; }')
  Rpt.Add ('--' + '>')
  Rpt.Add ('</style>')
  Rpt.Add ('</head>')
  Rpt.Add ('<body>')
  Rpt.Add ('<' + 'H1>Analiza uporabe objektov v sistemu dne ' + DateTimeToStr (Now) + '</H1>')
  Rpt.Add ('<' + 'table><tr><th>Ime<th>Uporabljen zadnjih 7<th>14<th>30<th>90<th>180 dni<th>360 dni<th>vse dni</tr></table>')
  UsageReportObject ("", Usg, Rpt, Root.SelectFolder('Izberi mapo za analizo'))
  Rpt.Add ('</body>')
  Rpt.Add ('</html>')
  Rpt.Save (Datapath + 'Analiza.htm')
  ShowHTML('Analiza uporabe', Datapath + 'Analiza.htm')
  Destroy (Rpt)
  Destroy (Usg)
EndSub
Sub UsageReportObject (Level As String, Usg, Rpt As TStringList, F As TFolder)
  Dim I, J, K, C1, C2, C3, C4, C5, C6, C7 as Long, F1 As TFolder, S As String
  Hint ('Analizing: ' + Level + F.Name )
  Rpt.Add ('<' + 'H2><img border=0 src="' + ProgramPath + 'htm\' + Copy (IntToHex (K), 7, 2) + '.gif"> ' + 
           Level + F.Name + '/' + '</H2>')
  Rpt.Add ('<' + 'table>')
  For I = 0 To F.Count - 1
    F1 = F.Items (I)
    If F1.IsObject Then
      S = '<tr><td><img border=0 src="' + ProgramPath + 'htm\' + Copy (IntToHex (F1.ObjectType), 7, 2) + '.gif"> ' + 
          F1.Name + '</td>'
      J = Usg.Find (IntToHex (F1.ID))
      If J >= 0 Then
        C1 = 0 C2 = 0 C3 = 0 C4 = 0 C5 = 0 C6 = 0 C7 = 0
        While Usg.Strings(J) = IntToHex (F1.ID)
          If Usg.Data(J) <=   7 Then C1 = C1 + 1 EndIf
          If Usg.Data(J) <=  14 Then C2 = C2 + 1 EndIf
          If Usg.Data(J) <=  30 Then C3 = C3 + 1 EndIf
          If Usg.Data(J) <=  90 Then C4 = C4 + 1 EndIf
          If Usg.Data(J) <= 180 Then C5 = C5 + 1 EndIf
          If Usg.Data(J) <= 360 Then C6 = C6 + 1 EndIf
                                     C7 = C7 + 1
          J = J + 1
          If J = Usg.Count Then Break EndIf
        Wend
        Rpt.Add (S + '<td>' + FormatFloat ('#', C1) + '</td><td>' + FormatFloat ('#', C2) + '</td><td>' + 
                              FormatFloat ('#', C3) + '</td><td>' + FormatFloat ('#', C4) + '</td><td>' + 
                              FormatFloat ('#', C5) + '</td><td>' + FormatFloat ('#', C6) + '</td><td>' + 
                              FormatFloat ('#', C7) + '</td></tr>')
      Else
        Rpt.Add (S + '<td Colspan=5>Ni uporabljen</td></tr>')
      EndIf
    EndIf
  Next
  Rpt.Add ('</table>')
  For I = 0 To F.Count - 1
    F1 = F.Items (I)
    If F1.IsFolder Then
      UsageReportObject (Level + F.Name + '/', Usg, Rpt, F1)
    EndIf
  Next
EndSub
Osebna orodja