Skip to content
This repository was archived by the owner on Nov 25, 2019. It is now read-only.

V2 rtm #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/System.Web.Http.SelfHost/HttpSelfHostServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,14 +1040,32 @@ public void Dispose()
/// Releases unmanaged and - optionally - managed resources
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged SRResources.</param>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We never want to fail here so we have to catch all exceptions.")]
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
RequestContext.Close();
Reply.Close();
// RequestContext.Close can throw if the client disconnects before it finishes receiving the response
// Catch here to avoid throwing in a Dispose method
try
{
RequestContext.Close();
}
catch
{
}

// HttpMessage.Close can throw if the request message throws in its Dispose implementation
// Catch here to avoid throwing in a Dispose method
try
{
Reply.Close();
}
catch
{
}
}

_disposed = true;
Expand Down
50 changes: 27 additions & 23 deletions src/System.Web.Razor/Editor/BackgroundParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ internal class BackgroundParser : IDisposable
private MainThreadState _main;
private BackgroundThread _bg;

public bool IsIdle
public BackgroundParser(RazorEngineHost host, string fileName)
{
get { return _main.IsIdle; }
_main = new MainThreadState(fileName);
_bg = new BackgroundThread(_main, host, fileName);

_main.ResultsReady += (sender, args) => OnResultsReady(args);
}

/// <summary>
/// Fired on the main thread.
/// </summary>
public event EventHandler<DocumentParseCompleteEventArgs> ResultsReady;

public BackgroundParser(RazorEngineHost host, string fileName)
public bool IsIdle
{
_main = new MainThreadState(fileName);
_bg = new BackgroundThread(_main, host, fileName);

_main.ResultsReady += (sender, args) => OnResultsReady(args);
get { return _main.IsIdle; }
}

public void Start()
Expand Down Expand Up @@ -144,27 +144,31 @@ private class MainThreadState : ThreadStateBase, IDisposable
private object _stateLock = new object();
private IList<TextChange> _changes = new List<TextChange>();

public CancellationToken CancelToken { get { return _cancelSource.Token; } }
public MainThreadState(string fileName)
{
_fileName = fileName;

SetThreadId(Thread.CurrentThread.ManagedThreadId);
}

public event EventHandler<DocumentParseCompleteEventArgs> ResultsReady;

public CancellationToken CancelToken
{
get { return _cancelSource.Token; }
}

public bool IsIdle
{
get {
get
{
lock (_stateLock)
{
return _currentParcelCancelSource == null;
}
}
}

public MainThreadState(string fileName)
{
_fileName = fileName;

SetThreadId(Thread.CurrentThread.ManagedThreadId);
}

public void Cancel()
{
EnsureOnThread();
Expand Down Expand Up @@ -253,7 +257,7 @@ protected virtual void Dispose(bool disposing)
private class BackgroundThread : ThreadStateBase
{
private MainThreadState _main;
private Thread _bgThread;
private Thread _backgroundThread;
private CancellationToken _shutdownToken;
private RazorEngineHost _host;
private string _fileName;
Expand All @@ -264,18 +268,18 @@ public BackgroundThread(MainThreadState main, RazorEngineHost host, string fileN
{
// Run on MAIN thread!
_main = main;
_bgThread = new Thread(WorkerLoop);
_backgroundThread = new Thread(WorkerLoop);
_shutdownToken = _main.CancelToken;
_host = host;
_fileName = fileName;

SetThreadId(_bgThread.ManagedThreadId);
SetThreadId(_backgroundThread.ManagedThreadId);
}

// **** ANY THREAD ****
public void Start()
{
_bgThread.Start();
_backgroundThread.Start();
}

// **** BACKGROUND THREAD ****
Expand Down Expand Up @@ -444,14 +448,14 @@ private GeneratorResults ParseChange(ITextBuffer buffer, CancellationToken token

private class WorkParcel
{
public CancellationToken CancelToken { get; private set; }
public IList<TextChange> Changes { get; private set; }

public WorkParcel(IList<TextChange> changes, CancellationToken cancelToken)
{
Changes = changes;
CancelToken = cancelToken;
}

public CancellationToken CancelToken { get; private set; }
public IList<TextChange> Changes { get; private set; }
}
}
}
6 changes: 5 additions & 1 deletion src/System.Web.Razor/RazorEditorParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ public RazorEditorParser(RazorEngineHost host, string sourceFileName)
public RazorEngineHost Host { get; private set; }
public string FileName { get; private set; }
public bool LastResultProvisional { get; private set; }
public Block CurrentParseTree { get { return _currentParseTree; } }

public Block CurrentParseTree
{
get { return _currentParseTree; }
}

[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Since this method is heavily affected by side-effects, particularly calls to CheckForStructureChanges, it should not be made into a property")]
public virtual string GetAutoCompleteString()
Expand Down
4 changes: 3 additions & 1 deletion src/System.Web.Razor/Text/SourceLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ public int AbsoluteIndex
get { return _absoluteIndex; }
}

// THIS IS 1-based!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/// <summary>
/// Gets the 1-based index of the line referred to by this Source Location.
/// </summary>
/// <remarks>
/// THIS IS 1-based!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/// </remarks>
public int LineIndex
{
get { return _lineIndex; }
Expand Down