Archive Browser
Download AssemblyReferenceScanner.zip, last updated 06/10/2012 (90.98 KB)
Download- md5: 47bd4bf571be76c33b954d358dca933b
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace Cyotek.Tools.AssemblyReferenceScanner
{
public partial class MainForm : Form
{
#region��Private�Member�Declarations
private bool _errorsFound;
private readonly string _extension = "refscan";
private readonly string _filter = "Scan Result Files (*.refscan)|*.refscan|All Files (*.*)|*.*";
private AssemblyInfoCollection _results;
#endregion��Private�Member�Declarations
#region��Public�Constructors
public MainForm()
{
InitializeComponent();
}
#endregion��Public�Constructors
#region��Event�Handlers
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void exportButton_Click(object sender, EventArgs e)
{
using (FileDialog dialog = new SaveFileDialog())
{
dialog.Filter = _filter;
dialog.DefaultExt = _extension;
if (dialog.ShowDialog(this) == DialogResult.OK)
{
try
{
XmlSerializer serializer;
serializer = new XmlSerializer(typeof(AssemblyInfoCollection));
using (FileStream stream = File.Create(dialog.FileName))
serializer.Serialize(stream, _results);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void folderBrowseButton_Click(object sender, EventArgs e)
{
using (FolderBrowserDialog dialog = new FolderBrowserDialog())
{
dialog.SelectedPath = folderTextBox.Text;
dialog.Description = "Select the folder to scan:";
if (dialog.ShowDialog(this) == DialogResult.OK)
folderTextBox.Text = dialog.SelectedPath;
}
}
private void importButton_Click(object sender, EventArgs e)
{
using (FileDialog dialog = new OpenFileDialog())
{
dialog.Filter = _filter;
dialog.DefaultExt = _extension;
if (dialog.ShowDialog(this) == DialogResult.OK)
{
try
{
XmlSerializer serializer;
serializer = new XmlSerializer(typeof(AssemblyInfoCollection));
using (FileStream stream = File.OpenRead(dialog.FileName))
_results = (AssemblyInfoCollection)serializer.Deserialize(stream);
this.LoadResults();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void scanButton_Click(object sender, EventArgs e)
{
string folder;
folder = folderTextBox.Text;
if (string.IsNullOrEmpty(folder))
MessageBox.Show("Enter or select the folder to scan.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
else if (!Directory.Exists(folder))
MessageBox.Show("Specified folder not found.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else
{
#if !DEBUG
try
#endif
{
AssemblyScanner scanner;
_errorsFound = false;
scanner = new AssemblyScanner();
foreach (string exclusion in exclusionsTextBox.Lines)
{
if (!string.IsNullOrEmpty(exclusion))
scanner.Exclusions.Add(exclusion);
}
_results = scanner.Scan(folder);
this.LoadResults();
}
#if !DEBUG
catch (Exception ex)
{
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
#endif
if (_errorsFound)
MessageBox.Show("One or more errors were found during scanning.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
#endregion��Event�Handlers
#region��Private�Methods
private void AddAssembly(AssemblyInfo result)
{
TreeNode node;
TreeNode dependenciesNode;
node = this.CreateNode(result);
dependenciesNode = new TreeNode()
{
Text = "Dependencies",
ForeColor = Color.Green
};
foreach (AssemblyNameInfo info in result.Dependencies)
{
TreeNode dependencyNode;
AssemblyInfo dependentAssembly;
dependencyNode = this.CreateNode(info);
dependenciesNode.Nodes.Add(dependencyNode);
dependentAssembly = _results.Contains(info.Name) ? _results[info.Name] : null;
if (dependentAssembly == null || dependentAssembly.Version != info.Version)
{
node.ForeColor = Color.Red;
dependencyNode.ForeColor = Color.Red;
dependenciesNode.ForeColor = Color.Red;
_errorsFound = true;
}
}
if (dependenciesNode.Nodes.Count != 0)
node.Nodes.Add(dependenciesNode);
assembliesTreeView.Nodes.Add(node);
}
private TreeNode CreateNode(AssemblyNameInfo info)
{
TreeNode node;
node = new TreeNode()
{
Text = string.Format("{0} [{1}]", info.Name, info.Version),
Name = info.Name,
ForeColor = Color.Green
};
return node;
}
private void LoadResults()
{
assembliesTreeView.BeginUpdate();
assembliesTreeView.Nodes.Clear();
foreach (AssemblyInfo result in _results)
this.AddAssembly(result);
assembliesTreeView.Sort();
assembliesTreeView.EndUpdate();
}
#endregion��Private�Methods
}
}
Donate
This software may be used free of charge, but as with all free software there are costs involved to develop and maintain.
If this site or its services have saved you time, please consider a donation to help with running costs and timely updates.
Donate