Renamed FailableOperation to Request, this is a much shorter name that better represents the concept implemented by the class
git-svn-id: file:///srv/devel/repo-conversion/nusu@62 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
533cbba3c5
commit
c21ba759cc
|
@ -148,7 +148,7 @@
|
||||||
<Compile Include="Source\Tracking\Internal\ObservedWeightedProgression.cs" />
|
<Compile Include="Source\Tracking\Internal\ObservedWeightedProgression.cs" />
|
||||||
<Compile Include="Source\Tracking\Internal\WeightedProgressionWrapperCollection.cs" />
|
<Compile Include="Source\Tracking\Internal\WeightedProgressionWrapperCollection.cs" />
|
||||||
<Compile Include="Source\Tracking\IStatusReporter.cs" />
|
<Compile Include="Source\Tracking\IStatusReporter.cs" />
|
||||||
<Compile Include="Source\Tracking\FailableProgression.cs" />
|
<Compile Include="Source\Tracking\Request.cs" />
|
||||||
<Compile Include="Source\Tracking\Progression.cs" />
|
<Compile Include="Source\Tracking\Progression.cs" />
|
||||||
<Compile Include="Source\Tracking\ProgressionTracker.cs" />
|
<Compile Include="Source\Tracking\ProgressionTracker.cs" />
|
||||||
<Compile Include="Source\Tracking\ProgressionTracker.Test.cs">
|
<Compile Include="Source\Tracking\ProgressionTracker.Test.cs">
|
||||||
|
|
|
@ -26,7 +26,7 @@ using Nuclex.Support.Tracking;
|
||||||
namespace Nuclex.Support.Scheduling {
|
namespace Nuclex.Support.Scheduling {
|
||||||
|
|
||||||
/// <summary>Base class for observable operations running in the background</summary>
|
/// <summary>Base class for observable operations running in the background</summary>
|
||||||
public abstract class Operation : FailableProgression {
|
public abstract class Operation : Request {
|
||||||
|
|
||||||
/// <summary>Launches the background operation</summary>
|
/// <summary>Launches the background operation</summary>
|
||||||
public abstract void Start();
|
public abstract void Start();
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace Nuclex.Support.Tracking {
|
||||||
) {
|
) {
|
||||||
this.weightedProgression = weightedProgression;
|
this.weightedProgression = weightedProgression;
|
||||||
|
|
||||||
|
// See if this progression has already ended (initial check for performance)
|
||||||
if(weightedProgression.Progression.Ended) {
|
if(weightedProgression.Progression.Ended) {
|
||||||
|
|
||||||
this.progress = 1.0f;
|
this.progress = 1.0f;
|
||||||
|
@ -60,8 +61,17 @@ namespace Nuclex.Support.Tracking {
|
||||||
this.weightedProgression.Progression.AsyncEnded +=
|
this.weightedProgression.Progression.AsyncEnded +=
|
||||||
new EventHandler(asyncEnded);
|
new EventHandler(asyncEnded);
|
||||||
|
|
||||||
|
// Check whether this progression might have ended before we were able to
|
||||||
|
// attach ourselfes to its event. If so, don't bother registering to the
|
||||||
|
// other event and (important) set our progress to 1.0 because, since we
|
||||||
|
// might not have gotten the 'Ended' event, it might otherwise stay at 0.0
|
||||||
|
// even though the progression is in the 'Ended' state.
|
||||||
|
if(weightedProgression.Progression.Ended) {
|
||||||
|
this.progress = 1.0f;
|
||||||
|
} else {
|
||||||
this.weightedProgression.Progression.AsyncProgressUpdated +=
|
this.weightedProgression.Progression.AsyncProgressUpdated +=
|
||||||
new EventHandler<ProgressUpdateEventArgs>(asyncProgressUpdated);
|
new EventHandler<ProgressUpdateEventArgs>(asyncProgressUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,23 @@
|
||||||
|
#region CPL License
|
||||||
|
/*
|
||||||
|
Nuclex Framework
|
||||||
|
Copyright (C) 2002-2008 Nuclex Development Labs
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the IBM Common Public License as
|
||||||
|
published by the IBM Corporation; either version 1.0 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
IBM Common Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the IBM Common Public
|
||||||
|
License along with this library
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
@ -17,17 +37,17 @@ namespace Nuclex.Support.Tracking {
|
||||||
/// OnAsyncEnded(), no matter what the outcome of your background operation is.
|
/// OnAsyncEnded(), no matter what the outcome of your background operation is.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class FailableProgression : Progression {
|
public class Request : Progression {
|
||||||
|
|
||||||
#region class EndedDummyProgression
|
#region class EndedDummyRequest
|
||||||
|
|
||||||
/// <summary>Dummy progression that is always in the ended state</summary>
|
/// <summary>Dummy request that is always in the ended state</summary>
|
||||||
private class EndedDummyProgression : FailableProgression {
|
private class EndedDummyRequest : Request {
|
||||||
/// <summary>Creates a new successfully completed dummy progression</summary>
|
/// <summary>Creates a new successfully completed dummy request</summary>
|
||||||
public EndedDummyProgression() : this(null) { }
|
public EndedDummyRequest() : this(null) { }
|
||||||
/// <summary>Creates a new failed dummy progression</summary>
|
/// <summary>Creates a new failed dummy request</summary>
|
||||||
/// <param name="exception">Exception that caused the dummy to fail</param>
|
/// <param name="exception">Exception that caused the dummy to fail</param>
|
||||||
public EndedDummyProgression(Exception exception) {
|
public EndedDummyRequest(Exception exception) {
|
||||||
OnAsyncEnded();
|
OnAsyncEnded();
|
||||||
|
|
||||||
// Only call SetException() if an actual exception was provided. Who knows what
|
// Only call SetException() if an actual exception was provided. Who knows what
|
||||||
|
@ -37,17 +57,17 @@ namespace Nuclex.Support.Tracking {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion // EndedDummyProgression
|
#endregion // EndedDummyRequest
|
||||||
|
|
||||||
/// <summary>Creates a new failed dummy progression</summary>
|
/// <summary>Creates a new failed dummy request</summary>
|
||||||
/// <param name="error">
|
/// <param name="error">
|
||||||
/// Exception that supposedly caused the progression to fail
|
/// Exception that supposedly caused the progression to fail
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A failed progression that reports the provided exception as cause for its failure
|
/// A failed request that reports the provided exception as cause for its failure
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static FailableProgression CreateFailedDummyProgression(Exception exception) {
|
public static Request CreateFailedDummyRequest(Exception exception) {
|
||||||
return new EndedDummyProgression(exception);
|
return new EndedDummyRequest(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Waits for the background operation to end</summary>
|
/// <summary>Waits for the background operation to end</summary>
|
||||||
|
@ -59,14 +79,6 @@ namespace Nuclex.Support.Tracking {
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual void Join() {
|
public virtual void Join() {
|
||||||
|
|
||||||
// By design, end can only be called once!
|
|
||||||
lock(this) {
|
|
||||||
if(this.endCalled)
|
|
||||||
throw new InvalidOperationException("End() has already been called");
|
|
||||||
|
|
||||||
this.endCalled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the progression itself hasn't ended yet, block the caller until it has.
|
// If the progression itself hasn't ended yet, block the caller until it has.
|
||||||
if(!Ended)
|
if(!Ended)
|
||||||
WaitHandle.WaitOne();
|
WaitHandle.WaitOne();
|
||||||
|
@ -101,8 +113,6 @@ namespace Nuclex.Support.Tracking {
|
||||||
|
|
||||||
/// <summary>Exception that occured while the operation was executing</summary>
|
/// <summary>Exception that occured while the operation was executing</summary>
|
||||||
private volatile Exception occuredException;
|
private volatile Exception occuredException;
|
||||||
/// <summary>Whether the End() method has been called already</summary>
|
|
||||||
private volatile bool endCalled;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user