Skip to content

Commit

Permalink
Merge pull request #11 from l2d4y3/master
Browse files Browse the repository at this point in the history
tab to 4 spaces
  • Loading branch information
NikolayIT committed Jul 16, 2015
2 parents f675524 + 63a3025 commit d9b1566
Show file tree
Hide file tree
Showing 14 changed files with 9,414 additions and 9,414 deletions.
216 changes: 108 additions & 108 deletions Source/BytesRoads/AsyncBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,122 +25,122 @@

namespace BytesRoad.Net.Sockets.Advanced
{
/// <summary>
/// Summary description for AsyncBase.
/// </summary>
/// <summary>
/// Summary description for AsyncBase.
/// </summary>
public class AsyncBase
{
protected bool inProgress = false;
{
protected bool inProgress = false;
/*
internal AsyncBase()
{
}
internal AsyncBase()
{
}
*/
virtual internal void SetProgress(bool progress)
{
//prevent from nested calls
lock(this)
{
if(progress)
{
if(inProgress)
throw new InvalidOperationException("Attempt to start operation which is already in the progress");
inProgress = true;
}
else
{
inProgress = false;
}
}
}

virtual internal void CheckProgress()
{
lock(this)
{
if(inProgress)
throw new InvalidOperationException("Attempt to start operation which is already in the progress");
}
}

/* virtual internal void HandleAsyncEnd(IAsyncResult ar, Type arType, bool turnProgressOff)
{
HandleAsyncEnd(ar, arType, null, turnProgressOff);
}*/

static internal void VerifyAsyncResult(IAsyncResult ar,
Type arType)
{
VerifyAsyncResult(ar, arType, null);
}

static internal void VerifyAsyncResult(IAsyncResult ar,
Type arType,
string metName)
{
if(null == ar)
throw new ArgumentNullException("asyncResult", "The value cannot be null.");

if(null == metName)
metName = "End*";

if(false == ar.GetType().Equals(arType))
throw new ArgumentException("asyncResult was not returned by a call to the " +
metName + " method.", "asyncResult");

AsyncResultBase stateObj = (AsyncResultBase)ar;
if(stateObj.IsHandled)
throw new InvalidOperationException(metName + " was previously called for the asynchronous operation.");
}

virtual internal void HandleAsyncEnd(IAsyncResult ar, bool turnProgressOff)
{
if((false == ar.GetType().IsSubclassOf(typeof(AsyncResultBase))) &&
(false == ar.GetType().Equals(typeof(AsyncResultBase))))
throw new ArgumentException("asyncResult was not returned by a call to End* method.", "asyncResult");

AsyncResultBase stateObj = (AsyncResultBase)ar;
if(stateObj.IsHandled)
throw new InvalidOperationException("End* method was previously called for the asynchronous operation.");

if(false == stateObj.IsCompleted)
stateObj.AsyncWaitHandle.WaitOne();

stateObj.IsHandled = true;

if(turnProgressOff)
SetProgress(false);

if(null != stateObj.Exception)
{
//dumpActivityException(stateObj);
throw stateObj.Exception;
}
}
virtual internal void SetProgress(bool progress)
{
//prevent from nested calls
lock(this)
{
if(progress)
{
if(inProgress)
throw new InvalidOperationException("Attempt to start operation which is already in the progress");
inProgress = true;
}
else
{
inProgress = false;
}
}
}

virtual internal void CheckProgress()
{
lock(this)
{
if(inProgress)
throw new InvalidOperationException("Attempt to start operation which is already in the progress");
}
}

/* virtual internal void HandleAsyncEnd(IAsyncResult ar, Type arType, bool turnProgressOff)
{
HandleAsyncEnd(ar, arType, null, turnProgressOff);
}*/

static internal void VerifyAsyncResult(IAsyncResult ar,
Type arType)
{
VerifyAsyncResult(ar, arType, null);
}

static internal void VerifyAsyncResult(IAsyncResult ar,
Type arType,
string metName)
{
if(null == ar)
throw new ArgumentNullException("asyncResult", "The value cannot be null.");

if(null == metName)
metName = "End*";

if(false == ar.GetType().Equals(arType))
throw new ArgumentException("asyncResult was not returned by a call to the " +
metName + " method.", "asyncResult");

AsyncResultBase stateObj = (AsyncResultBase)ar;
if(stateObj.IsHandled)
throw new InvalidOperationException(metName + " was previously called for the asynchronous operation.");
}

virtual internal void HandleAsyncEnd(IAsyncResult ar, bool turnProgressOff)
{
if((false == ar.GetType().IsSubclassOf(typeof(AsyncResultBase))) &&
(false == ar.GetType().Equals(typeof(AsyncResultBase))))
throw new ArgumentException("asyncResult was not returned by a call to End* method.", "asyncResult");

AsyncResultBase stateObj = (AsyncResultBase)ar;
if(stateObj.IsHandled)
throw new InvalidOperationException("End* method was previously called for the asynchronous operation.");

if(false == stateObj.IsCompleted)
stateObj.AsyncWaitHandle.WaitOne();

stateObj.IsHandled = true;

if(turnProgressOff)
SetProgress(false);

if(null != stateObj.Exception)
{
//dumpActivityException(stateObj);
throw stateObj.Exception;
}
}
/*
void dumpActivityException(AsyncResultBase ar)
{
Exception e = ar.Exception;
int tid = Thread.CurrentThread.GetHashCode();
string msg = string.Format("{0} -----------------------------", tid);
NSTrace.WriteLineError(msg);
void dumpActivityException(AsyncResultBase ar)
{
Exception e = ar.Exception;
int tid = Thread.CurrentThread.GetHashCode();
string msg = string.Format("{0} -----------------------------", tid);
NSTrace.WriteLineError(msg);
msg = string.Format("{0} Activity: {1}", tid, ar.ActivityName);
NSTrace.WriteLineError(msg);
msg = string.Format("{0} Activity: {1}", tid, ar.ActivityName);
NSTrace.WriteLineError(msg);
msg = string.Format("{0} Exception: {1}", tid, e.GetType().FullName);
NSTrace.WriteLineError(msg);
msg = string.Format("{0} Exception: {1}", tid, e.GetType().FullName);
NSTrace.WriteLineError(msg);
msg = string.Format("{0} Message: {1}", tid, e.Message);
NSTrace.WriteLineError(msg);
msg = string.Format("{0} Message: {1}", tid, e.Message);
NSTrace.WriteLineError(msg);
msg = string.Format("{0} Stack: {1}", tid, e.StackTrace);
NSTrace.WriteLineError(msg);
msg = string.Format("{0} Stack: {1}", tid, e.StackTrace);
NSTrace.WriteLineError(msg);
msg = string.Format("{0} -----------------------------", tid);
NSTrace.WriteLineError(msg);
}
msg = string.Format("{0} -----------------------------", tid);
NSTrace.WriteLineError(msg);
}
*/
}
}
}
Loading

0 comments on commit d9b1566

Please sign in to comment.