Update of /cvsroot/sharpcvslib/sharpcvslib/src/SharpCvsAddIn In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16220 Modified Files: Connect.cs Controller.cs IController.cs IUIShell.cs JobQueue.cs SharpCvsAddIn.csproj UIShell.cs sharpcvsaddin-log.config Log Message: Finished up jobqueue to execute cvs operations on seperate thread. Created a job for cvs checkout Index: sharpcvsaddin-log.config =================================================================== RCS file: /cvsroot/sharpcvslib/sharpcvslib/src/SharpCvsAddIn/sharpcvsaddin-log.config,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sharpcvsaddin-log.config 26 Feb 2005 23:50:51 -0000 1.4 --- sharpcvsaddin-log.config 28 Feb 2005 00:09:54 -0000 1.5 *************** *** 7,11 **** </appender> <root> ! <level value="DEBUG" /> <appender-ref ref="A1" /> </root> --- 7,11 ---- </appender> <root> ! <level value="WARN" /> <appender-ref ref="A1" /> </root> Index: SharpCvsAddIn.csproj =================================================================== RCS file: /cvsroot/sharpcvslib/sharpcvslib/src/SharpCvsAddIn/SharpCvsAddIn.csproj,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SharpCvsAddIn.csproj 27 Feb 2005 06:07:30 -0000 1.4 --- SharpCvsAddIn.csproj 28 Feb 2005 00:09:54 -0000 1.5 *************** *** 294,300 **** /> <File ! RelPath = "Resources\app-strings.txt" ! BuildAction = "Content" /> <File RelPath = "UI\SolutionExplorer.cs" --- 294,302 ---- /> <File ! RelPath = "Jobs\CvsCheckout.cs" ! SubType = "Code" ! BuildAction = "Compile" /> + <Folder RelPath = "Resources\" /> <File RelPath = "UI\SolutionExplorer.cs" Index: IController.cs =================================================================== RCS file: /cvsroot/sharpcvslib/sharpcvslib/src/SharpCvsAddIn/IController.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IController.cs 26 Feb 2005 23:50:51 -0000 1.2 --- IController.cs 28 Feb 2005 00:09:54 -0000 1.3 *************** *** 141,144 **** --- 141,146 ---- /// <returns>The string.</returns> string GetLocalizedString( string resourceId ); + + JobQueue Jobs { get; } } } Index: Connect.cs =================================================================== RCS file: /cvsroot/sharpcvslib/sharpcvslib/src/SharpCvsAddIn/Connect.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Connect.cs 7 Feb 2005 04:54:09 -0000 1.1 --- Connect.cs 28 Feb 2005 00:09:53 -0000 1.2 *************** *** 110,113 **** --- 110,115 ---- solutionEvents_.AddHandlers(); + controller_.Jobs.Start(); + #if ALWAYS_REGISTER *************** *** 144,147 **** --- 146,150 ---- { logger_.Debug( "Disconnecting" ); + controller_.Jobs.Stop(); solutionEvents_.RemoveHandlers(); } Index: IUIShell.cs =================================================================== RCS file: /cvsroot/sharpcvslib/sharpcvslib/src/SharpCvsAddIn/IUIShell.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IUIShell.cs 7 Feb 2005 04:54:09 -0000 1.1 --- IUIShell.cs 28 Feb 2005 00:09:54 -0000 1.2 *************** *** 54,76 **** void SetRepositoryExplorerSelection( object[] selection ); ! /// <summary> ! /// Display a message box. ! /// </summary> ! /// <param name="caption"></param> ! /// <param name="text"></param> ! /// <param name="buttons"></param> ! /// <returns></returns> ! DialogResult ShowMessageBox( string text, string caption, ! MessageBoxButtons buttons ); - /// <summary> - /// Display a message box. - /// </summary> - /// <param name="caption"></param> - /// <param name="text"></param> - /// <param name="buttons"></param> - /// <returns></returns> - DialogResult ShowMessageBox( string text, string caption, - MessageBoxButtons buttons, MessageBoxIcon icon ); } } --- 54,59 ---- void SetRepositoryExplorerSelection( object[] selection ); ! DialogResult ShowMessageBox( string messageResource, MessageBoxButtons buttons, MessageBoxIcon icons); } } Index: JobQueue.cs =================================================================== RCS file: /cvsroot/sharpcvslib/sharpcvslib/src/SharpCvsAddIn/JobQueue.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JobQueue.cs 27 Feb 2005 06:07:30 -0000 1.1 --- JobQueue.cs 28 Feb 2005 00:09:54 -0000 1.2 *************** *** 2,46 **** using System.Collections; using System.Threading; namespace SharpCvsAddIn { ! public interface IJob { ! void DoWork(); } ! public class JobQueue { private Queue jobs_ = Queue.Synchronized( new Queue() ); ! private AutoResetEvent addJobEvent_ = new AutoResetEvent(false); private AutoResetEvent stopEvent_ = new AutoResetEvent(false); private void JobRunner() { ! // note stop event has to come first because ! // if duplicate events get triggered, the lowest ! // index is returned, we want stop to take precedence ! // over add job ! WaitHandle[] evts = { stopEvent_, addJobEvent_ }; ! while(true) { ! int eventId = WaitHandle.WaitAny( evts ); ! // stop was signalled, exit thread ! if( eventId == 0 ) break; ! while( jobs_.Count > 0 ) ! { ! IJob job = (IJob)jobs_.Dequeue(); ! job.DoWork(); ! } } ! } ! public JobQueue() { ! Thread t = new Thread( new ThreadStart( this.JobRunner ) ); ! t.Start(); } --- 2,107 ---- using System.Collections; using System.Threading; + using System.Diagnostics; + using System.Windows.Forms; + using log4net ; namespace SharpCvsAddIn { ! /// <summary> ! /// If a event handler is provided, it will be triggered when the associated job ! /// completes. jobData can contain data produced in job ! /// </summary> ! public delegate void JobCompletionHandler( object sender, object jobData); ! ! public interface IJob : ICloneable { ! string Name { get; } ! object DoWork(); } ! /// <summary> ! /// this class manages jobs that are performed on a seperate thread, this facility exists ! /// to let you perform lengthy operations without locking up the user interface, jobs ! /// are processed FIFO ! /// </summary> ! public class JobQueue : IDisposable { + // utility class to manage jobs + private class JobInfo + { + internal JobCompletionHandler OnComplete_ = null; + internal IJob job_ = null; + } + private Queue jobs_ = Queue.Synchronized( new Queue() ); ! private ManualResetEvent addJobEvent_ = new ManualResetEvent(false); private AutoResetEvent stopEvent_ = new AutoResetEvent(false); + // this is signalled initially so we won't block if job + // thread never gets started + private ManualResetEvent jobRunnerExitEvent_ = new ManualResetEvent(true); + private static readonly ILog log_ = LogManager.GetLogger(typeof(JobQueue)); + private bool disposed = false; + private IController controller_ = null; + private const int WAIT_PERIOD = 10000 ; // 10 seconds private void JobRunner() { ! log_.Debug( "JobRunner started" ); ! try { ! jobRunnerExitEvent_.Reset(); ! // note stop event has to come first because ! // if duplicate events get triggered, the lowest ! // index is returned, we want stop to take precedence ! // over add job ! WaitHandle[] evts = { stopEvent_, addJobEvent_ }; ! while(true) ! { ! int eventId = WaitHandle.WaitAny( evts ); ! // stop was signalled, exit thread ! if( eventId == 0 ) break; ! if( jobs_.Count > 0 ) ! { ! JobInfo ji = (JobInfo)jobs_.Dequeue(); ! log_.Debug( string.Format("Processing job {0}", ji.job_.Name)); ! ! try ! { ! object data = ji.job_.DoWork(); ! ! if(ji.OnComplete_ != null) ! { ! ji.OnComplete_(this, data ); ! } ! } ! catch(Exception e) ! { ! log_.Error("A job threw an exception", e ); ! ! } ! } ! ! // this will cause the thread to wait ! // until we get more jobs ! if( jobs_.Count == 0 ) addJobEvent_.Reset(); ! ! } // end thread loop } ! finally ! { ! log_.Debug("job thread exiting"); ! // send signal to things that may be blocking that we ! // are done ! jobRunnerExitEvent_.Set(); ! } ! } ! public JobQueue(IController controller) { ! controller_ = controller; ! } *************** *** 48,61 **** public void AddJob( IJob job ) { ! jobs_.Enqueue( job ); addJobEvent_.Set(); } public void Stop() { stopEvent_.Set(); } } } \ No newline at end of file --- 109,177 ---- public void AddJob( IJob job ) { ! this.AddJob( job, null ); ! } ! ! ! ! /// <summary> ! /// Add a job to the job queue ! /// </summary> ! /// <param name="job">A job, override Work </param> ! /// <param name="handler">The event, if supplied will be triggered on successful completion of the job</param> ! /// <param name="data">Information to pass to the job</param> ! public void AddJob( IJob job, JobCompletionHandler handler ) ! { ! Debug.Assert( job != null ); ! log_.Debug( string.Format("Adding job {0}", job.Name) ); ! JobInfo ji = new JobInfo(); ! ji.job_ = (IJob)job.Clone(); ! ji.OnComplete_ += handler; ! jobs_.Enqueue(ji); addJobEvent_.Set(); + } + /// <summary> + /// stops the processing of more jobs + /// </summary> public void Stop() { + log_.Debug("Called Stop"); stopEvent_.Set(); + // block for up to 10 seconds to all jobs to finish up + while( !jobRunnerExitEvent_.WaitOne( JobQueue.WAIT_PERIOD, true )) + { + DialogResult result = controller_.UIShell.ShowMessageBox( + "MSGBOX_QUERY_WAITFORCLOSE", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question ); + + if( result == DialogResult.No ) break; + } + } + + /// <summary> + /// Starts the job queue + /// </summary> + public void Start() + { + log_.Debug("Called Start"); + Thread t = new Thread( new ThreadStart( this.JobRunner ) ); + t.Start(); } + #region IDisposable Members + + public void Dispose() + { + if( !disposed ) + { + disposed = true; + stopEvent_.Set(); + jobRunnerExitEvent_.WaitOne( 3000, true ); + } + } + #endregion } } \ No newline at end of file Index: UIShell.cs =================================================================== RCS file: /cvsroot/sharpcvslib/sharpcvslib/src/SharpCvsAddIn/UIShell.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** UIShell.cs 7 Feb 2005 04:54:09 -0000 1.1 --- UIShell.cs 28 Feb 2005 00:09:54 -0000 1.2 *************** *** 84,99 **** } ! public System.Windows.Forms.DialogResult ShowMessageBox(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons) { ! // TODO: Add UIShell.ShowMessageBox implementation ! return new System.Windows.Forms.DialogResult (); ! } - System.Windows.Forms.DialogResult SharpCvsAddIn.IUIShell.ShowMessageBox(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon) - { - // TODO: Add UIShell.SharpCvsAddIn.IUIShell.ShowMessageBox implementation - return new System.Windows.Forms.DialogResult (); } #endregion --- 84,102 ---- } ! public DialogResult ShowMessageBox( string messageResource, MessageBoxButtons buttons, MessageBoxIcon icons) { ! ResourceManager rm = controller_.Model.ResourceManager; ! ! return MessageBox.Show( controller_.HostWindow, ! rm.GetString( messageResource ), ! rm.GetString( "APPLICATION_TITLE" ), ! buttons, ! icons ! ); } + + #endregion Index: Controller.cs =================================================================== RCS file: /cvsroot/sharpcvslib/sharpcvslib/src/SharpCvsAddIn/Controller.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Controller.cs 27 Feb 2005 06:07:30 -0000 1.5 --- Controller.cs 28 Feb 2005 00:09:54 -0000 1.6 *************** *** 23,26 **** --- 23,27 ---- private SolutionExplorer solutionExplorer_ = null; private Events.ProjectFileEvents fileEvents_ = null; + private JobQueue jobs_ = null; public Controller(EnvDTE._DTE dte, EnvDTE.AddIn addin,IErrorHandler errorHandler) *************** *** 36,39 **** --- 37,41 ---- fileEvents_ = new Events.ProjectFileEvents( this ); + jobs_ = new JobQueue( this); //solutionExplorer_.Initialize(); *************** *** 44,47 **** --- 46,56 ---- + public JobQueue Jobs + { + get + { + return jobs_; + } + } public event System.EventHandler Unloading; *************** *** 65,68 **** --- 74,79 ---- public void HandleSolutionOpenEvent() { + // start processing cvs commands + addInLoadedForSolution_ = true; // synch user interface with loaded project |