using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace IReaper.Statues{
/*
* iReaper
* 1.
* 2.
* 3.
* 4.
* 12
*
*
* 3
*
* 4
*/
public partial class iReaperStatusStrip : StatusStrip, IReaper.Statues.IiReaperStatusStrip
{
#region static
internal static IiReaperStatusStrip statuStripInstance;
#endregion
volatile bool isBusy;
bool hasNewVersion = false;
Queue<AsyncWork> timeConsumingTaskQueue = new Queue<AsyncWork>();
public iReaperStatusStrip()
{
InitializeComponent();
statuStripInstance = this;
LoadVersionInfo();
}
public iReaperStatusStrip(IContainer container) : this()
{
container.Add(this);
}
#region ()
/// <summary>
///
/// </summary>
/// <param name="Work"></param>
public void BeginAsyncWork(AsyncWork Work)
{
if (this.isBusy)
{
lock (timeConsumingTaskQueue)
{
this.timeConsumingTaskQueue.Enqueue(Work);
}
return;
}
else
{
Work.RunWorkerCompleted += new RunWorkerCompletedEventHandler(EndAsyncWork);
this.isBusy = true;
Work.RunWorkerAsync(this);
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void EndAsyncWork(object sender, RunWorkerCompletedEventArgs e)
{
this.isBusy = false;
lock (timeConsumingTaskQueue)
{
if (this.timeConsumingTaskQueue.Count > 0)
{
AsyncWork work = this.timeConsumingTaskQueue.Dequeue();
this.BeginAsyncWork(work);
return;
}
else
{
try
{
if (!this.IsDisposed)
{
this.BeginInvoke(new ThreadStart(delegate()
{
this.toolStripTaskName.Visible = false;
}));
}
}
catch
{ }
}
}
}
#endregion
/// <summary>
///
/// </summary>
[Browsable(false)]
public string TaskMessage
{
set
{
SetMessage(this.toolStripTaskName, value);
}
}
/// <summary>
///
/// </summary>
[Browsable(false)]
public string InfomationMessage
{
set
{
SetMessage(this.toolStripPrimaryInfo, value);
}
}
/// <summary>
/// ToolStripItem
/// </summary>
/// <param name="item"></param>
/// <param name="Message"></param>
private static void SetMessage(ToolStripItem item, object Message)
{
if (item == null || Message == null)
{
return;
}
Control control = item.Owner;
if (control == null)
{
return;
}
if (item is ToolStripProgressBar)
{
control.BeginInvoke(new ThreadStart(delegate()
{
((ToolStripProgressBar)item).Value = (int)Message;
item.Visible = true;
}));
}
else
{
try
{
control.BeginInvoke(new ThreadStart(delegate()
{
item.Text = Message.ToString();
item.Visible = true;
}));
}
catch
{ }
}
}
/// <summary>
/// Strip
/// </summary>
public bool IsBusy
{
get { return isBusy; }
set { isBusy = value; }
}
private void LoadVersionInfo()
{
this.hasNewVersion = (bool)Core.CoreData[CoreDataType.HasNewVersion];
if (hasNewVersion)
{
this.toolStripStatusLabelVersionLabel.Text = Properties.Resources.HasNewVersion;
}
}
private void OpeniReaperWebsite(object sender, EventArgs e)
{
Browser.BrowserManager.OpenWebsite("http://www.ireaper.net");
}
#region IiReaperStatusStrip
/// <summary>
///
/// 0 - 100
/// </summary>
public int Percentage
{
set
{
try
{
if (value >= 100 || value == 0)
{
toolStripProgressBar.Visible = false;
toolStripProgressBar.Value = value;
}
else
{
toolStripProgressBar.Visible = true;
toolStripProgressBar.Value = value;
}
}
catch
{ }
}
}
#endregion
}
}
|