Questo sito utilizza cookies, anche di terze parti, per mostrare pubblicità e servizi in linea con il tuo account. Leggi l'informativa sui cookies.
Username: Password: oppure
MSN Live Log Manager - Form1.vb

Form1.vb

Caricato da: Totem
Scarica il programma completo

  1. Imports MSN_Live_Log_Manager.LogExplorer
  2. Public Class Form1
  3.     Public Structure Contact
  4.         Private _Address, _FileName As String
  5.  
  6.         Public Property Address() As String
  7.             Get
  8.                 Return _Address
  9.             End Get
  10.             Set(ByVal value As String)
  11.                 _Address = value
  12.             End Set
  13.         End Property
  14.  
  15.         Public Property FileName() As String
  16.             Get
  17.                 Return _FileName
  18.             End Get
  19.             Set(ByVal value As String)
  20.                 _FileName = value
  21.             End Set
  22.         End Property
  23.  
  24.         Sub New(ByVal File As String)
  25.             Me.FileName = File
  26.             Me.Address = IO.Path.GetFileNameWithoutExtension(File)
  27.         End Sub
  28.  
  29.         Public Overrides Function ToString() As String
  30.             Return Me.Address
  31.         End Function
  32.     End Structure
  33.  
  34.     Private ReceivedFiles As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\File ricevuti"
  35.     Private NetProfileDirs As New List(Of String)
  36.     Private Contacts As New List(Of Contact)
  37.  
  38.     'Contatti tab
  39.     Private LoadedLogs As New List(Of Log)
  40.  
  41.     Private Sub LoadLogs(ByVal Dir As String)
  42.         Dim Months() As String = IO.Directory.GetDirectories(Dir)
  43.         Dim User As New TreeNode
  44.         Dim TempUserList As New List(Of String)
  45.  
  46.         User.Text = IO.Path.GetFileName(Dir)
  47.         User.ImageKey = "user"
  48.         User.Tag = "user"
  49.         For Each Month As String In Months
  50.             Dim M As New TreeNode
  51.             M.Text = IO.Path.GetFileName(Month)
  52.             M.ImageKey = "folder"
  53.             M.Tag = "folder"
  54.             For Each Log As String In IO.Directory.GetFiles(Month, "*.html")
  55.                 Dim U As New TreeNode
  56.                 U.Text = IO.Path.GetFileNameWithoutExtension(Log)
  57.                 U.ImageKey = "log"
  58.                 U.Tag = "log"
  59.                 M.Nodes.Add(U)
  60.                 If Not TempUserList.Contains(U.Text) Then
  61.                     Me.Contacts.Add(New Contact(Log))
  62.                     TempUserList.Add(U.Text)
  63.                 End If
  64.             Next
  65.             User.Nodes.Add(M)
  66.         Next
  67.         trwLogs.Nodes.Add(User)
  68.     End Sub
  69.  
  70.     Private Function GetListViewItem(ByVal S As LogExplorer.Session) As ListViewItem
  71.         Dim Main As New ListViewItem
  72.         Main.Text = S.StartTime.ToLongDateString
  73.  
  74.         With Main.SubItems
  75.             .Add(S.StartTime.ToShortTimeString)
  76.             If S.StartTime.Date <> S.EndTime.Date Then
  77.                 .Add(S.EndTime.ToShortTimeString & " di " & S.EndTime.ToLongDateString)
  78.             Else
  79.                 .Add(S.EndTime.ToShortTimeString)
  80.             End If
  81.             .Add(String.Format("{0} ore, {1} minuti", S.ElapsedTime.Hours, S.ElapsedTime.Minutes))
  82.             .Add(S.Messages)
  83.         End With
  84.  
  85.         Dim Users As New System.Text.StringBuilder
  86.         For I As Int16 = 0 To S.Contacts.Count - 1
  87.             If I > 0 Then
  88.                 Users.Append(", ")
  89.             End If
  90.             Users.Append(S.Contacts(I))
  91.         Next
  92.         Main.SubItems.Add(Users.ToString)
  93.         Main.Tag = S
  94.  
  95.         Return Main
  96.     End Function
  97.  
  98.     Private Function GetListViewItem(ByVal ParamArray Texts() As String) As ListViewItem
  99.         Return New ListViewItem(Texts)
  100.     End Function
  101.  
  102.     Private Function FormatSpan(ByVal T As TimeSpan) As String
  103.         If T.Hours = 0 And T.Days = 0 Then
  104.             Return (T.Minutes & " minuti")
  105.         ElseIf T.Days = 0 Then
  106.             Return (T.Hours & " ore e " & T.Minutes & " minuti")
  107.         Else
  108.             Return (T.Days & " giorni, " & T.Hours & " ore e " & T.Minutes & " minuti")
  109.         End If
  110.     End Function
  111.  
  112.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  113.         Dim Confirm As New System.Text.RegularExpressions.Regex(".+\d{10}")
  114.         Dim SubDirs() As String = IO.Directory.GetDirectories(ReceivedFiles)
  115.  
  116.         For Each Dir As String In SubDirs
  117.             If Confirm.IsMatch(IO.Path.GetFileName(Dir)) Then
  118.                 LoadLogs(Dir)
  119.                 NetProfileDirs.Add(Dir)
  120.             End If
  121.         Next
  122.  
  123.         For Each C As Contact In Me.Contacts
  124.             cmbContacts.Items.Add(C)
  125.         Next
  126.         cmbContacts.Sorted = True
  127.  
  128.         If NetProfileDirs.Count > 0 Then
  129.             txtDir.Text = NetProfileDirs(0) & "\Cronologia"
  130.         End If
  131.         txtHelp.Text = My.Resources.Help
  132.         Me.WindowState = FormWindowState.Maximized
  133.     End Sub
  134.  
  135.     Private Sub trwLogs_NodeMouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles trwLogs.NodeMouseDoubleClick
  136.         Dim Selected As TreeNode = e.Node
  137.  
  138.         If Selected.Tag = "log" Then
  139.             Dim FileName As String = ReceivedFiles & "\" & Selected.FullPath & ".html"
  140.             Dim Path As String = "file:///" & FileName.Replace("\", "/")
  141.             wbShowLog.Navigate(Path)
  142.         End If
  143.     End Sub
  144.  
  145.     Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
  146.         If cmbContacts.SelectedIndex < 0 Then
  147.             MessageBox.Show("Selezionare un contatto dalla lista prima!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  148.             Exit Sub
  149.         End If
  150.  
  151.         Dim LogFiles As New List(Of String)
  152.         For Each Dir As String In NetProfileDirs
  153.             LogFiles.AddRange(IO.Directory.GetFiles(Dir, "*.html", IO.SearchOption.AllDirectories))
  154.         Next
  155.  
  156.         Dim Sessions As New List(Of LogExplorer.Session)
  157.         Dim Index As Int16 = 0
  158.         LoadedLogs.Clear()
  159.         For Each LogFile As String In LogFiles
  160.             If LogFile.Contains(cmbContacts.SelectedItem.ToString) Then
  161.                 Dim Log As New LogExplorer.Log(LogFile)
  162.                 Do
  163.                     Application.DoEvents()
  164.                 Loop Until Log.IsLoaded
  165.                 lblStatus.Text = String.Format("{0:N2}% completato", 100 * Index / LogFiles.Count)
  166.                 Sessions.AddRange(Log.Sessions)
  167.                 LoadedLogs.Add(Log)
  168.             End If
  169.             Index += 1
  170.         Next
  171.         lblStatus.Text = "99.00% completato"
  172.         Sessions.Sort(New LogExplorer.SessionByStartTimeComparer())
  173.         lblStatus.Text = "Completato"
  174.  
  175.         If Sessions.Count = 0 Then
  176.             Exit Sub
  177.         End If
  178.  
  179.         lstSessions.Items.Clear()
  180.         lstInfo.Items.Clear()
  181.         For Each S As LogExplorer.Session In Sessions
  182.             lstSessions.Items.Add(GetListViewItem(S))
  183.         Next
  184.  
  185.         'Prima/ultima conversazione
  186.         'Conversazione più lunga:
  187.         'Conversazione più breve:
  188.         'Conversazione con più partecipanti:
  189.         'Totale ore di conversazione:
  190.         'Totale dimensione dei log:
  191.         Dim FirstTemp As Session = Sessions(0)
  192.         Dim LastTemp As Session = Sessions(0)
  193.         Dim MaxTemp As Session = Sessions(0)
  194.         Dim MinTemp As Session = Sessions(0)
  195.         Dim MaxUserTemp As Session = Sessions(0)
  196.         Dim TotalTime As New TimeSpan
  197.         Dim TotalSize, TotalMessages As Int32
  198.  
  199.         For Each S As LogExplorer.Session In Sessions
  200.             If S.StartTime < FirstTemp.StartTime Then
  201.                 FirstTemp = S
  202.             End If
  203.             If S.StartTime > LastTemp.StartTime Then
  204.                 LastTemp = S
  205.             End If
  206.             If S.ElapsedTime.TotalSeconds > MaxTemp.ElapsedTime.TotalSeconds Then
  207.                 MaxTemp = S
  208.             End If
  209.             If S.ElapsedTime.TotalSeconds < MinTemp.ElapsedTime.TotalSeconds Then
  210.                 MinTemp = S
  211.             End If
  212.             If S.Contacts.Count > MaxUserTemp.Contacts.Count Then
  213.                 MaxUserTemp = S
  214.             End If
  215.             TotalTime = TotalTime.Add(S.ElapsedTime)
  216.             TotalMessages += S.Messages
  217.             TotalSize += S.HTML.Length
  218.         Next
  219.  
  220.         With lstInfo.Items
  221.             .Add(GetListViewItem("Prima conversazione", FirstTemp.ToString))
  222.             .Add(GetListViewItem("Ultima conversazione", LastTemp.ToString))
  223.             .Add(GetListViewItem("Conversazione più lunga", MaxTemp.ToString & " (" & FormatSpan(MaxTemp.ElapsedTime) & ")"))
  224.             .Add(GetListViewItem("Conversazione più corta", MinTemp.ToString & " (" & FormatSpan(MinTemp.ElapsedTime) & ")"))
  225.             .Add(GetListViewItem("Conversazione con più partecipanti", MaxUserTemp.ToString & " (" & MaxUserTemp.Contacts.Count & " partecipanti)"))
  226.             .Add(GetListViewItem("Totale ore di conversazione", FormatSpan(TotalTime)))
  227.             .Add(GetListViewItem("Totale dimensione dei log", String.Format("{0:N0}", TotalSize) & " bytes"))
  228.             .Add(GetListViewItem("Totale messaggi", TotalMessages))
  229.         End With
  230.     End Sub
  231.  
  232.     Private Sub lstSessions_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSessions.DoubleClick
  233.         If lstSessions.SelectedIndices.Count = 0 Then
  234.             Exit Sub
  235.         End If
  236.  
  237.         Dim Session As LogExplorer.Session = lstSessions.SelectedItems(0).Tag
  238.         Dim Window As New Form
  239.         Dim Wb As New WebBrowser
  240.         Dim HTML As New System.Text.StringBuilder
  241.  
  242.         HTML.AppendLine(IO.File.ReadAllText(Application.StartupPath & "\LogStyleTemplate.txt"))
  243.         HTML.AppendLine("<body>")
  244.         HTML.AppendLine(Session.HTML)
  245.         HTML.AppendLine("</body></html>")
  246.  
  247.         Window.Text = "Sessione di " & Session.StartTime.ToLongDateString
  248.         Window.Size = New Size(640, 480)
  249.         Window.StartPosition = FormStartPosition.CenterScreen
  250.         Window.Controls.Add(Wb)
  251.         Wb.Dock = DockStyle.Fill
  252.         Wb.DocumentText = HTML.ToString
  253.  
  254.         Window.ShowDialog()
  255.     End Sub
  256.  
  257.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGraphTimePerDay.Click
  258.         If LoadedLogs.Count = 0 Then
  259.             MessageBox.Show("Scegliere un contatto e caricarne le informazioni prima di procedere!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  260.             Exit Sub
  261.         End If
  262.  
  263.         Dim Window As New Form
  264.         Dim Graph As New GraphTimePerDay(Log.MergeLogs(LoadedLogs))
  265.  
  266.         Window.Text = "Grafico Tempo di conversazione al giorno"
  267.         Window.Size = New Size(700, 400)
  268.         Window.StartPosition = FormStartPosition.CenterScreen
  269.         Window.Controls.Add(Graph)
  270.         Graph.Dock = DockStyle.Fill
  271.  
  272.         Window.ShowDialog()
  273.     End Sub
  274.  
  275.     Private Sub btnCalculateGeneral_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateGeneral.Click
  276.         lstGeneralInfo.Items.Clear()
  277.         GC.Collect()
  278.  
  279.         Dim LogFiles As New List(Of String)
  280.         For Each Dir As String In NetProfileDirs
  281.             LogFiles.AddRange(IO.Directory.GetFiles(Dir, "*.html", IO.SearchOption.AllDirectories))
  282.         Next
  283.  
  284.         Dim Sessions As New List(Of LogExplorer.Session)
  285.         Dim UserLogs As New Dictionary(Of String, LogExplorer.ContactLogInfo)
  286.         Dim TotalTime As New TimeSpan
  287.         Dim TotalSize, TotalSessionNumber As Int32
  288.         Dim ContactNumber, TotalMessages As Int32
  289.         Dim MaxSessionContact As New ContactLogInfo
  290.         Dim MinSessionContact As New ContactLogInfo
  291.         Dim Index As Int16 = 0
  292.  
  293.         For Each LogFile As String In LogFiles
  294.             Dim Log As New LogExplorer.Log(LogFile)
  295.             Dim LogName As String = IO.Path.GetFileNameWithoutExtension(LogFile)
  296.             Do
  297.                 Application.DoEvents()
  298.             Loop Until Log.IsLoaded
  299.  
  300.             Sessions.AddRange(Log.Sessions)
  301.             If UserLogs.ContainsKey(LogName) Then
  302.                 With UserLogs(LogName)
  303.                     .LogSize += Log.Size
  304.                     .SessionNumber += Log.Sessions.Count
  305.                     For Each S As Session In Log.Sessions
  306.                         .SessionTime = .SessionTime.Add(S.ElapsedTime)
  307.                         .Messages += S.Messages
  308.                     Next
  309.                     .Name = LogName
  310.                 End With
  311.             Else
  312.                 Dim Info As New ContactLogInfo
  313.                 Info.LogSize = Log.Size
  314.                 Info.SessionNumber = Log.Sessions.Count
  315.                 For Each S As Session In Log.Sessions
  316.                     Info.SessionTime = Info.SessionTime.Add(S.ElapsedTime)
  317.                     Info.Messages += S.Messages
  318.                 Next
  319.                 Info.Name = LogName
  320.                 UserLogs.Add(LogName, Info)
  321.             End If
  322.  
  323.             TotalSize += Log.Size
  324.             For Each S As Session In Log.Sessions
  325.                 TotalTime = TotalTime.Add(S.ElapsedTime)
  326.                 TotalMessages += S.Messages
  327.             Next
  328.             lblStatusGeneral.Text = String.Format("{0:N2}% completato", 70 * Index / LogFiles.Count)
  329.             Index += 1
  330.             Log = Nothing
  331.             Sessions.Clear()
  332.         Next
  333.         ContactNumber = UserLogs.Keys.Count
  334.  
  335.         Index = 0
  336.         MinSessionContact.SessionNumber = 1000
  337.         For Each Key As String In UserLogs.Keys
  338.             With UserLogs(Key)
  339.                 lstGeneralInfo.Items.Add(GetListViewItem(Key, String.Format("{0:N0} bytes", .LogSize), FormatSpan(.SessionTime), .SessionNumber, .Messages))
  340.                 TotalSessionNumber += .SessionNumber
  341.                 If .SessionNumber > MaxSessionContact.SessionNumber Then
  342.                     MaxSessionContact = UserLogs(Key)
  343.                 End If
  344.                 If .SessionNumber < MinSessionContact.SessionNumber Then
  345.                     MinSessionContact = UserLogs(Key)
  346.                 End If
  347.             End With
  348.             lblStatusGeneral.Text = String.Format("{0:N2}% completato", 70 + 30 * Index / UserLogs.Keys.Count)
  349.             Index += 1
  350.             Application.DoEvents()
  351.         Next
  352.  
  353.         lblTotalMessages.Text = "Totale messaggi: " & TotalMessages
  354.         lblTotalTime.Text = "Totale ore di conversazione: " & FormatSpan(TotalTime)
  355.         lblTotalSize.Text = "Total dimensione dei log: " & String.Format("{0:N0} bytes", TotalSize)
  356.         lblTotalSessions.Text = "Numero di conversazioni totali: " & TotalSessionNumber
  357.         lblTotalContacts.Text = "Numero di contatti attivi: " & ContactNumber
  358.         lblBestContact.Text = "Contatto col maggiore numero di conversazioni: " & String.Format("{0} ({1})", MaxSessionContact.Name, MaxSessionContact.SessionNumber)
  359.         lblWorstContact.Text = "Contatto col minor numero di conversazioni: " & String.Format("{0} ({1})", MinSessionContact.Name, MinSessionContact.SessionNumber)
  360.  
  361.         lblStatusGeneral.Text = "Completato"
  362.         btnSaveReport.Visible = True
  363.  
  364.         UserLogs.Clear()
  365.         Sessions.Clear()
  366.         UserLogs = Nothing
  367.         Sessions = Nothing
  368.         TotalTime = Nothing
  369.         MinSessionContact = Nothing
  370.         MaxSessionContact = Nothing
  371.         GC.Collect()
  372.     End Sub
  373.  
  374.     Private Class lstGeneralInfoColumnComparer
  375.         Implements IComparer
  376.         Private Index As Int16
  377.         Private TimeSpanRegex As New System.Text.RegularExpressions.Regex("((?<Days>\d+) giorni, )?((?<Hours>\d+) ore e )?(?<Minutes>\d+) minuti")
  378.  
  379.         Sub New(ByVal Index As Int16)
  380.             Me.Index = Index
  381.         End Sub
  382.  
  383.         Private Function IntOrZero(ByVal S As String) As Int32
  384.             Dim Result As Int32 = 0
  385.  
  386.             If Int32.TryParse(S, Result) Then
  387.                 Return Result
  388.             Else
  389.                 Return 0
  390.             End If
  391.         End Function
  392.  
  393.         Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
  394.             Dim L1, L2 As ListViewItem
  395.             L1 = DirectCast(x, ListViewItem)
  396.             L2 = DirectCast(y, ListViewItem)
  397.  
  398.             Select Case Index
  399.                 Case 1
  400.                     Return String.Compare(L1.Text, L2.Text)
  401.                 Case 2
  402.                     Dim S1, S2 As Int32
  403.                     Dim H1 As String = L1.SubItems(1).Text.Replace(" bytes", "").Replace(".", "")
  404.                     Dim H2 As String = L2.SubItems(1).Text.Replace(" bytes", "").Replace(".", "")
  405.                     S1 = Int32.Parse(H1)
  406.                     S2 = Int32.Parse(H2)
  407.  
  408.                     Return S1.CompareTo(S2)
  409.                 Case 3
  410.                     Dim M1, M2 As System.Text.RegularExpressions.Match
  411.                     Dim T1, T2 As TimeSpan
  412.  
  413.                     M1 = TimeSpanRegex.Match(L1.SubItems(2).Text)
  414.                     M2 = TimeSpanRegex.Match(L2.SubItems(2).Text)
  415.  
  416.                     T1 = New TimeSpan(IntOrZero(M1.Groups("Days").Value), IntOrZero(M1.Groups("Hours").Value), IntOrZero(M1.Groups("Minutes").Value), 0)
  417.                     T2 = New TimeSpan(IntOrZero(M2.Groups("Days").Value), IntOrZero(M2.Groups("Hours").Value), IntOrZero(M2.Groups("Minutes").Value), 0)
  418.  
  419.                     Return TimeSpan.Compare(T1, T2)
  420.                 Case 4, 5
  421.                     Return CInt(L1.SubItems(Index - 1).Text).CompareTo(CInt(L2.SubItems(Index - 1).Text))
  422.             End Select
  423.         End Function
  424.     End Class
  425.  
  426.     Private Sub lstGeneralInfo_ColumnClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles lstGeneralInfo.ColumnClick
  427.         lstGeneralInfo.ListViewItemSorter = New lstGeneralInfoColumnComparer(e.Column + 1)
  428.     End Sub
  429.  
  430.     Private Sub btnSaveReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveReport.Click
  431.         Dim Save As New SaveFileDialog
  432.         Save.Filter = "Pagina web|*.html"
  433.         If Save.ShowDialog = Windows.Forms.DialogResult.OK Then
  434.             Dim Writer As New IO.StreamWriter(Save.FileName)
  435.  
  436.             Writer.WriteLine(IO.File.ReadAllText(Application.StartupPath & "\LogReportTemplate.txt").Replace("|||Log|||", "Rapporto MSN Live Log Manager del " & Date.Now.ToShortDateString))
  437.             Writer.WriteLine("<table style='font-family: ""Segoe UI"",Tahoma, Verdana, sans-serif; font-size:0.95em; color:#333333;' border='0' width='98%'>")
  438.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblTotalMessages.Text)
  439.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblTotalTime.Text)
  440.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblTotalSize.Text)
  441.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblTotalSessions.Text)
  442.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblTotalContacts.Text)
  443.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblBestContact.Text)
  444.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblWorstContact.Text)
  445.             Writer.WriteLine("</table>")
  446.             Writer.WriteLine("<br><br>")
  447.  
  448.             Writer.WriteLine("<table style='font-family: ""Segoe UI"",Tahoma, Verdana, sans-serif; font-size:0.95em; color:#333333;' border='0' width='98%'>")
  449.             Writer.WriteLine("   <tr class='elem'><td class='odd' width='40%'>Contatto</td><td class='odd' width='15%'>Dimensione log</td><td class='odd' width='15%'>Tempo conversazioni</td><td class='odd' width='15%'>Numero conversazioni</td><td class='odd' width='15%'>Numero messaggi</td></tr>")
  450.  
  451.             Dim Even As Boolean = True
  452.             Dim El As New System.Text.StringBuilder
  453.             For Each L As ListViewItem In lstGeneralInfo.Items
  454.                 Writer.WriteLine("   <tr class='elem'><td class='{5}' width='40%'>{0}</td><td class='{5}' width='15%'>{1}</td><td class='{5}' width='15%'>{2}</td><td class='{5}' width='15%'>{3}</td><td class='{5}' width='15%'>{4}</td></tr>", _
  455.                 L.SubItems(0).Text, L.SubItems(1).Text, L.SubItems(2).Text, L.SubItems(3).Text, L.SubItems(4).Text, IIf(Even, "even", "odd"))
  456.                 Even = Not Even
  457.             Next
  458.             Writer.WriteLine("</table></body></html>")
  459.             Writer.Close()
  460.         End If
  461.     End Sub
  462.  
  463.     Private Sub btnCalculateOldGeneral_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateOldGeneral.Click
  464.         If Not IO.Directory.Exists(txtDir.Text) Then
  465.             MessageBox.Show("La cartella selezionata non esiste!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  466.             Exit Sub
  467.         End If
  468.  
  469.         Dim Index As Int32 = 0
  470.         Dim LogFiles() As String = IO.Directory.GetFiles(txtDir.Text, "*.xml", IO.SearchOption.AllDirectories)
  471.         Dim TotalTime As New TimeSpan
  472.         Dim TotalSize, TotalContacts, TotalSessions, TotalMessages As Int32
  473.  
  474.         lstOldGeneralInfo.Items.Clear()
  475.         For Each XmlLog As String In LogFiles
  476.             Try
  477.                 Dim Log As New OldLog(XmlLog)
  478.                 lstOldGeneralInfo.Items.Add(GetListViewItem(IO.Path.GetFileNameWithoutExtension(XmlLog), String.Format("{0:N0} bytes", Log.Size), FormatSpan(Log.ElapsedTime), Log.Sessions, Log.Messages))
  479.                 lblOldStatusGeneral.Text = String.Format("{0:N2}", 100 * Index / LogFiles.Length)
  480.                 Application.DoEvents()
  481.                 TotalTime = TotalTime.Add(Log.ElapsedTime)
  482.                 TotalMessages += Log.Messages
  483.                 TotalSessions += Log.Sessions
  484.                 TotalSize += Log.Size
  485.                 TotalContacts += 1
  486.             Catch Ex As Exception
  487.             End Try
  488.             Index += 1
  489.         Next
  490.  
  491.         lblOldTotalMessages.Text = "Totale messaggi: " & TotalMessages
  492.         lblOldTotalTime.Text = "Totale ore di conversazione: " & FormatSpan(TotalTime)
  493.         lblOldTotalSize.Text = "Total dimensione dei log: " & String.Format("{0:N0} bytes", TotalSize)
  494.         lblOldTotalSessions.Text = "Numero di conversazioni totali: " & TotalSessions
  495.         lblOldContactNumber.Text = "Numero di contatti attivi: " & TotalContacts
  496.        
  497.         lblOldStatusGeneral.Text = "Completato"
  498.         btnOldSaveReport.Visible = True
  499.     End Sub
  500.  
  501.     Private Sub lstOlgGeneralInfo_ColumnClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles lstOldGeneralInfo.ColumnClick
  502.         lstOldGeneralInfo.ListViewItemSorter = New lstGeneralInfoColumnComparer(e.Column + 1)
  503.     End Sub
  504.  
  505.     Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
  506.         Dim Folder As New FolderBrowserDialog
  507.         Folder.Description = "Selezionare la cartella Cronologia all'interno del proprio profilo in Documenti\File ricevuti."
  508.         If Folder.ShowDialog = Windows.Forms.DialogResult.OK Then
  509.             txtDir.Text = Folder.SelectedPath
  510.         End If
  511.     End Sub
  512.  
  513.     Private Sub btnOldSaveReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOldSaveReport.Click
  514.         Dim Save As New SaveFileDialog
  515.         Save.Filter = "Pagina web|*.html"
  516.         If Save.ShowDialog = Windows.Forms.DialogResult.OK Then
  517.             Dim Writer As New IO.StreamWriter(Save.FileName)
  518.  
  519.             Writer.WriteLine(IO.File.ReadAllText(Application.StartupPath & "\LogReportTemplate.txt").Replace("|||Log|||", "Rapporto MSN Live Log Manager del " & Date.Now.ToShortDateString))
  520.             Writer.WriteLine("<table style='font-family: ""Segoe UI"",Tahoma, Verdana, sans-serif; font-size:0.95em; color:#333333;' border='0' width='98%'>")
  521.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblOldTotalMessages.Text)
  522.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblOldTotalTime.Text)
  523.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblOldTotalSize.Text)
  524.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblOldTotalSessions.Text)
  525.             Writer.WriteLine("    <tr class='info'><td>{0}</td></tr>", lblOldContactNumber.Text)
  526.             Writer.WriteLine("</table>")
  527.             Writer.WriteLine("<br><br>")
  528.  
  529.             Writer.WriteLine("<table style='font-family: ""Segoe UI"",Tahoma, Verdana, sans-serif; font-size:0.95em; color:#333333;' border='0' width='98%'>")
  530.             Writer.WriteLine("   <tr class='elem'><td class='odd' width='40%'>Contatto</td><td class='odd' width='15%'>Dimensione log</td><td class='odd' width='15%'>Tempo conversazioni</td><td class='odd' width='15%'>Numero conversazioni</td><td class='odd' width='15%'>Numero messaggi</td></tr>")
  531.  
  532.             Dim Even As Boolean = True
  533.             Dim El As New System.Text.StringBuilder
  534.             For Each L As ListViewItem In lstOldGeneralInfo.Items
  535.                 Writer.WriteLine("   <tr class='elem'><td class='{5}' width='40%'>{0}</td><td class='{5}' width='15%'>{1}</td><td class='{5}' width='15%'>{2}</td><td class='{5}' width='15%'>{3}</td><td class='{5}' width='15%'>{4}</td></tr>", _
  536.                 L.SubItems(0).Text, L.SubItems(1).Text, L.SubItems(2).Text, L.SubItems(3).Text, L.SubItems(4).Text, IIf(Even, "even", "odd"))
  537.                 Even = Not Even
  538.             Next
  539.             Writer.WriteLine("</table></body></html>")
  540.             Writer.Close()
  541.         End If
  542.     End Sub
  543.  
  544.     Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click
  545.         My.Forms.The_Lair_AboutBox1.ShowDialog()
  546.     End Sub
  547. End Class