using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Threading;
namespace Issue
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label MemberLabel;
internal System.Windows.Forms.MainMenu MainMenu;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.TextBox MemberTextBox;
private System.Windows.Forms.Button AddButton;
private System.Windows.Forms.ListBox QueuedListBox;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.NotifyIcon NotifyIcon;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button StartButton;
private System.Windows.Forms.Button StopButton;
private System.Windows.Forms.GroupBox IssueCloseGroup;
private System.Windows.Forms.CheckBox Issue12CheckBox;
private System.Windows.Forms.CheckBox Issue28CheckBox;
private System.Windows.Forms.CheckBox Issue29CheckBox;
private System.Windows.Forms.MenuItem ImportMenuItem;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem ExitMenuItem;
private System.Windows.Forms.OpenFileDialog ImportFileDialog;
// member processing variables
private Thread pProcessingThread;
private bool bStopSignal;
private Queue pMemberQueue;
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
// setup member processing variables
bStopSignal = true;
pMemberQueue = new Queue();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// </summary>
private void SyncLists()
{
QueuedListBox.Items.Clear();
object[] contents = new object[pMemberQueue.Count];
pMemberQueue.CopyTo( contents, 0 );
QueuedListBox.Items.AddRange( contents );
}
/// <summary>
/// </summary>
private void ThreadProc()
{
MessageBox.Show( "Please browse to the issue viewer base URL to
start" );
string member = null;
while( !bStopSignal )
{
// get the next member
lock( pMemberQueue )
{
if( pMemberQueue.Count < 1 )
{
Thread.Sleep( 100 );
continue;
}
member = (string)pMemberQueue.Dequeue();
// sync the QueuedListBox and pMemberQueue contencts
SyncLists();
///////////////////////////////////////////////////////////
// Busines logic was here
///////////////////////////////////////////////////////////
}
}
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(MainForm));
this.MemberLabel = new System.Windows.Forms.Label();
this.MainMenu = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.MemberTextBox = new System.Windows.Forms.TextBox();
this.AddButton = new System.Windows.Forms.Button();
this.QueuedListBox = new System.Windows.Forms.ListBox();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.NotifyIcon = new
System.Windows.Forms.NotifyIcon(this.components);
this.StartButton = new System.Windows.Forms.Button();
this.StopButton = new System.Windows.Forms.Button();
this.IssueCloseGroup = new System.Windows.Forms.GroupBox();
this.Issue29CheckBox = new System.Windows.Forms.CheckBox();
this.Issue28CheckBox = new System.Windows.Forms.CheckBox();
this.Issue12CheckBox = new System.Windows.Forms.CheckBox();
this.ImportMenuItem = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.ExitMenuItem = new System.Windows.Forms.MenuItem();
this.ImportFileDialog = new System.Windows.Forms.OpenFileDialog();
this.IssueCloseGroup.SuspendLayout();
this.SuspendLayout();
//
// MemberLabel
//
this.MemberLabel.Location = new System.Drawing.Point(8, 8);
this.MemberLabel.Name = "MemberLabel";
this.MemberLabel.Size = new System.Drawing.Size(48, 23);
this.MemberLabel.TabIndex = 0;
this.MemberLabel.Text = "Member";
//
// MainMenu
//
this.MainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[]
{
this.menuItem1,
this.menuItem2,
this.menuItem3,
this.menuItem4});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.ImportMenuItem,
this.menuItem6,
this.ExitMenuItem});
this.menuItem1.Text = "&File";
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "&Edit";
//
// menuItem3
//
this.menuItem3.Index = 2;
this.menuItem3.Text = "&View";
//
// menuItem4
//
this.menuItem4.Index = 3;
this.menuItem4.Text = "&Help";
//
// MemberTextBox
//
this.MemberTextBox.Location = new System.Drawing.Point(56, 8);
this.MemberTextBox.Name = "MemberTextBox";
this.MemberTextBox.Size = new System.Drawing.Size(168, 20);
this.MemberTextBox.TabIndex = 1;
this.MemberTextBox.Text = "";
//
// AddButton
//
this.AddButton.Location = new System.Drawing.Point(232, 8);
this.AddButton.Name = "AddButton";
this.AddButton.Size = new System.Drawing.Size(50, 23);
this.AddButton.TabIndex = 2;
this.AddButton.Text = "Add";
this.AddButton.Click += new
System.EventHandler(this.AddButton_Click);
//
// QueuedListBox
//
this.QueuedListBox.Location = new System.Drawing.Point(8, 40);
this.QueuedListBox.Name = "QueuedListBox";
this.QueuedListBox.Size = new System.Drawing.Size(272, 108);
this.QueuedListBox.TabIndex = 3;
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 245);
this.statusBar1.Name = "statusBar1";
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(288, 22);
this.statusBar1.TabIndex = 4;
this.statusBar1.Text = "statusBar1";
//
// NotifyIcon
//
// this.NotifyIcon.Icon =
((System.Drawing.Icon)(resources.GetObject("NotifyIcon.Icon")));
this.NotifyIcon.Text = "Issue Closing Daemon";
this.NotifyIcon.Visible = true;
this.NotifyIcon.DoubleClick += new
System.EventHandler(this.NotifyIcon_DoubleClick);
//
// StartButton
//
this.StartButton.Location = new System.Drawing.Point(120, 160);
this.StartButton.Name = "StartButton";
this.StartButton.Size = new System.Drawing.Size(160, 32);
this.StartButton.TabIndex = 5;
this.StartButton.Text = "Start";
this.StartButton.Click += new
System.EventHandler(this.StartButton_Click);
//
// StopButton
//
this.StopButton.Enabled = false;
this.StopButton.Location = new System.Drawing.Point(120, 208);
this.StopButton.Name = "StopButton";
this.StopButton.Size = new System.Drawing.Size(160, 32);
this.StopButton.TabIndex = 6;
this.StopButton.Text = "Stop";
this.StopButton.Click += new
System.EventHandler(this.StopButton_Click);
//
// IssueCloseGroup
//
this.IssueCloseGroup.Controls.Add(this.Issue29CheckBox);
this.IssueCloseGroup.Controls.Add(this.Issue28CheckBox);
this.IssueCloseGroup.Controls.Add(this.Issue12CheckBox);
this.IssueCloseGroup.Location = new System.Drawing.Point(8, 152);
this.IssueCloseGroup.Name = "IssueCloseGroup";
this.IssueCloseGroup.Size = new System.Drawing.Size(104, 88);
this.IssueCloseGroup.TabIndex = 7;
this.IssueCloseGroup.TabStop = false;
this.IssueCloseGroup.Text = "Issues to close";
//
// Issue29CheckBox
//
this.Issue29CheckBox.Checked = true;
this.Issue29CheckBox.CheckState =
System.Windows.Forms.CheckState.Checked;
this.Issue29CheckBox.Location = new System.Drawing.Point(8, 64);
this.Issue29CheckBox.Name = "Issue29CheckBox";
this.Issue29CheckBox.Size = new System.Drawing.Size(72, 15);
this.Issue29CheckBox.TabIndex = 2;
this.Issue29CheckBox.Text = "Issue 29";
//
// Issue28CheckBox
//
this.Issue28CheckBox.Checked = true;
this.Issue28CheckBox.CheckState =
System.Windows.Forms.CheckState.Checked;
this.Issue28CheckBox.Location = new System.Drawing.Point(8, 40);
this.Issue28CheckBox.Name = "Issue28CheckBox";
this.Issue28CheckBox.Size = new System.Drawing.Size(72, 15);
this.Issue28CheckBox.TabIndex = 1;
this.Issue28CheckBox.Text = "Issue 28";
//
// Issue12CheckBox
//
this.Issue12CheckBox.Location = new System.Drawing.Point(8, 16);
this.Issue12CheckBox.Name = "Issue12CheckBox";
this.Issue12CheckBox.Size = new System.Drawing.Size(72, 15);
this.Issue12CheckBox.TabIndex = 0;
this.Issue12CheckBox.Text = "Issue 12";
//
// ImportMenuItem
//
this.ImportMenuItem.Index = 0;
this.ImportMenuItem.Text = "&Import File";
this.ImportMenuItem.Click += new
System.EventHandler(this.ImportMenuItem_Click);
//
// menuItem6
//
this.menuItem6.Index = 1;
this.menuItem6.Text = "-";
//
// ExitMenuItem
//
this.ExitMenuItem.Index = 2;
this.ExitMenuItem.Text = "&Exit";
this.ExitMenuItem.Click += new
System.EventHandler(this.ExitMenuItem_Click);
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(288, 267);
this.Controls.Add(this.IssueCloseGroup);
this.Controls.Add(this.StopButton);
this.Controls.Add(this.StartButton);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.QueuedListBox);
this.Controls.Add(this.AddButton);
this.Controls.Add(this.MemberTextBox);
this.Controls.Add(this.MemberLabel);
this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Menu = this.MainMenu;
this.Name = "MainForm";
this.Text = "Issue Closing Daemon";
this.Resize += new System.EventHandler(this.MainForm_Resize);
this.Closing += new
System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
this.IssueCloseGroup.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// start application
Application.Run( new MainForm() );
}
#region Form Event Handlers
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddButton_Click(object sender, System.EventArgs e)
{
// add member to queue and clear text box
pMemberQueue.Enqueue( MemberTextBox.Text ); MemberTextBox.Clear();
// update the QueuedListBox
SyncLists();
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// stop the processing thread.
bStopSignal = true;
if( pProcessingThread != null )
pProcessingThread.Join();
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_Resize(object sender, System.EventArgs e)
{
// hide the form if minimize requested
if( FormWindowState.Minimized == this.WindowState )
this.Hide();
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void NotifyIcon_DoubleClick(object sender, System.EventArgs
e)
{
// show MainForm and set to appropriate state
this.Show(); this.WindowState = FormWindowState.Normal;
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartButton_Click(object sender, System.EventArgs e)
{
if( bStopSignal )
{
// disable controls that aren't valid when running
StartButton.Enabled = false;
Issue12CheckBox.Enabled = false;
Issue28CheckBox.Enabled = false;
Issue29CheckBox.Enabled = false;
// enable controls that are valid when running
StopButton.Enabled = true;
// start the processing thread
bStopSignal = false;
MessageBox.Show( "Starting Processing Thread" );
(pProcessingThread = new Thread( new ThreadStart( ThreadProc )
)).Start();
}
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StopButton_Click(object sender, System.EventArgs e)
{
// enable controls that are valid when stopped
StartButton.Enabled = true;
Issue12CheckBox.Enabled = true;
Issue28CheckBox.Enabled = true;
Issue29CheckBox.Enabled = true;
// disable controls that aren't valid when stopped
StopButton.Enabled = false;
// stop the processing thread
bStopSignal = true;
if( pProcessingThread != null )
{
MessageBox.Show( "Stopping Processing Thread" );
pProcessingThread.Join();
pProcessingThread = null;
}
}
private void ExitMenuItem_Click(object sender, System.EventArgs e)
{
}
private void ImportMenuItem_Click(object sender, System.EventArgs e)
{
if( ImportFileDialog.ShowDialog() == DialogResult.OK )
{
try
{
using( StreamReader reader = new StreamReader(
ImportFileDialog.FileName ) )
{
string line = null;
while( ( line = reader.ReadLine() ) != null )
{
// add member to queue and clear text box
pMemberQueue.Enqueue( line );
}
// update the QueuedListBox
SyncLists();
}
}
catch( Exception ex )
{
MessageBox.Show( "Exception: " + ex.ToString() );
}
}
}
#endregion Form Event Handlers
}
}
I commented the Icon setting line because I wasn't sure if it was
needed. I can't verify that compiles, it should, all I did was remove
the references to the other forms which aren't valid for this problem.
Thanks for any help, this is driving me nuts.