|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Threading;
using System.IO;
namespace RoslynCodeSearcher
{
public class WorkspaceUpdater
{
private BackgroundWorker _worker;
private CodeRepository.ProgressBarMaxUpdateHandler _progressBarMaxUpdateHandler;
private CodeRepository.ProgressBarProgressUpdateHandler _progressBarProgressUpdateHandler;
/// <summary>
/// Constructor for Worker that instantiates a backgroundworker to do the work in a separate thread.
/// </summary>
public WorkspaceUpdater(CodeRepository.ProgressBarMaxUpdateHandler progressBarMaxUpdateHandler, CodeRepository.ProgressBarProgressUpdateHandler progressBarProgressUpdateHandler)
{
_progressBarMaxUpdateHandler = progressBarMaxUpdateHandler;
_progressBarProgressUpdateHandler = progressBarProgressUpdateHandler;
IsReady = false;
_worker = new BackgroundWorker();
_worker.DoWork += new DoWorkEventHandler(worker_DoWork);
_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
}
public void Start()
{
_worker.RunWorkerAsync();
}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
IsReady = true;
}
public static bool IsReady {get;set;}
/// <summary>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void worker_DoWork(object sender, DoWorkEventArgs e)
{
string baseDirectorySolutionsTxtPath = Paths.BaseDirectorySolutionsTxtPath;
if (File.Exists(baseDirectorySolutionsTxtPath))
{
string contents = File.ReadAllText(baseDirectorySolutionsTxtPath);
if (contents.Length > 10)
{
//Put errors in front of solution files that don't exist anymore.
CodeRepository.FixSolutions(baseDirectorySolutionsTxtPath);
//Get the solutions from the solutions.txt file
CodeRepository.Solutions = CodeRepository.GetSolutions(baseDirectorySolutionsTxtPath);
CodeRepository.Workspaces = CodeRepository.GetWorkspacesParallel(CodeRepository.Solutions, _progressBarMaxUpdateHandler, _progressBarProgressUpdateHandler);
//Sometimes the progressbar is not completely finished after getting the workspaces.
//Even though I use locking.
//Finish it manually
if (_progressBarProgressUpdateHandler != null)
{
_progressBarProgressUpdateHandler(CodeRepository.SolutionCount);
}
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.