Skip to content

Commit

Permalink
Merge pull request #4 from burnacid/development
Browse files Browse the repository at this point in the history
Fix crash and improve performance
  • Loading branch information
burnacid authored Jul 12, 2022
2 parents e6d6ef9 + 1a2ea78 commit f482927
Show file tree
Hide file tree
Showing 44 changed files with 68 additions and 121 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ local.properties
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

.vs/

# User-specific files
*.suo
*.user
Expand Down
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
90 changes: 65 additions & 25 deletions SOURCE/Radius Log Browser/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

Expand All @@ -20,6 +22,8 @@ public partial class Form1 : Form
private Dictionary<int, ListViewItem> oldItems = new Dictionary<int, ListViewItem>();
private Dictionary<int, ListViewItem> newItems = new Dictionary<int, ListViewItem>();

private FileSystemWatcher watcher = new FileSystemWatcher();

private string Lines;
private string Directory;
private string FileName;
Expand All @@ -46,22 +50,46 @@ public Form1()
lvLogTable.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}

private void procesLogFile()
private void setProgress(int current, int total)
{
const string title = "RADIUS Log Browser";
if (!this.IsDisposed)
{
if (InvokeRequired)
{
Invoke(new Action<int, int>(setProgress), new object[] { current, total });
return;
}
if (current < total)
Text = title + ": Parsing log entry " + current.ToString() + " of " + total.ToString();
else
Text = title;
}
}

private void procesLogFile(bool initalrun = false)
{
XDocument doc = XDocument.Parse("<events>"+ Lines + "</events>");
string classID;

int total_elements = doc.Descendants("Event").Count();
int current_element = 0;
List<ListViewItem> itemlist = new List<ListViewItem>();
foreach (var events in doc.Descendants("Event"))
{
classID = events.Element("Class").Value;
setProgress(++current_element, total_elements);


if (requests.ContainsKey(classID))
XElement element = events.Element("Class");
if (element != null)
{
requests[classID].setResponce(events);
classID = element.Value;


ListViewItem item = new ListViewItem(new string[]
if (requests.ContainsKey(classID))
{
requests[classID].setResponce(events);

ListViewItem item = new ListViewItem(new string[]
{
requests[classID].timestamp,
requests[classID].getRequestType(),
requests[classID].server,
Expand All @@ -71,22 +99,39 @@ private void procesLogFile()
requests[classID].samAccountName,
requests[classID].getResponceType(),
requests[classID].getReason()
});
});

item.BackColor = requests[classID].getRowColor();
item.BackColor = requests[classID].getRowColor();
itemlist.Add(item);

this.Invoke(new MethodInvoker(delegate { lvLogTable.Items.Add(item); }));
if (cbScroll.Checked)
}
else
{
this.Invoke(new MethodInvoker(delegate { lvLogTable.Items[lvLogTable.Items.Count - 1].EnsureVisible(); }));
}
}
else
{
requests[classID] = new RadiusRequest(events);
requests[classID] = new RadiusRequest(events);
}
}

}

// Bulk adding new lines is much much much faster
this.Invoke(new MethodInvoker(delegate { lvLogTable.Items.AddRange(itemlist.ToArray()); }));
if (cbScroll.Checked)
{
this.Invoke(new MethodInvoker(delegate { lvLogTable.Items[lvLogTable.Items.Count - 1].EnsureVisible(); }));
}

if (initalrun)
{
this.Invoke(new MethodInvoker(delegate
{
lvLogTable.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
lvLogTable.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

RunWatcher();
}));
}
else
watcher.EnableRaisingEvents = true;
}

private void filterToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -150,12 +195,7 @@ private void selectFileToolStripMenuItem_Click(object sender, EventArgs e)
FileName = Path.GetFileName(ofdFile.FileName);

ReadLines(ofdFile.FileName);
procesLogFile();

lvLogTable.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
lvLogTable.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

RunWatcher();
Task task = Task.Run(() => procesLogFile(true));
}
}

Expand Down Expand Up @@ -354,7 +394,6 @@ private void cmRemoveSearch_Click(object sender, EventArgs e)

public void RunWatcher()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = Directory;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Filter = FileName;
Expand All @@ -367,7 +406,8 @@ public void RunWatcher()
private void OnChanged(object source, FileSystemEventArgs e)
{
ReadLines(ofdFile.FileName);
procesLogFile();
watcher.EnableRaisingEvents = false;
Task task = Task.Run(() => procesLogFile(false));
}

public void ReadLines(string path)
Expand Down
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

2 changes: 1 addition & 1 deletion SOURCE/Radius Log Browser/help.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.

0 comments on commit f482927

Please sign in to comment.