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:
Markus Ewald 2008-03-26 19:52:28 +00:00
parent 533cbba3c5
commit c21ba759cc
4 changed files with 47 additions and 27 deletions

View File

@ -148,7 +148,7 @@
<Compile Include="Source\Tracking\Internal\ObservedWeightedProgression.cs" />
<Compile Include="Source\Tracking\Internal\WeightedProgressionWrapperCollection.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\ProgressionTracker.cs" />
<Compile Include="Source\Tracking\ProgressionTracker.Test.cs">

View File

@ -26,7 +26,7 @@ using Nuclex.Support.Tracking;
namespace Nuclex.Support.Scheduling {
/// <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>
public abstract void Start();

View File

@ -48,6 +48,7 @@ namespace Nuclex.Support.Tracking {
) {
this.weightedProgression = weightedProgression;
// See if this progression has already ended (initial check for performance)
if(weightedProgression.Progression.Ended) {
this.progress = 1.0f;
@ -60,8 +61,17 @@ namespace Nuclex.Support.Tracking {
this.weightedProgression.Progression.AsyncEnded +=
new EventHandler(asyncEnded);
this.weightedProgression.Progression.AsyncProgressUpdated +=
new EventHandler<ProgressUpdateEventArgs>(asyncProgressUpdated);
// 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 +=
new EventHandler<ProgressUpdateEventArgs>(asyncProgressUpdated);
}
}
}

View File

@ -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.Collections.Generic;
@ -17,17 +37,17 @@ namespace Nuclex.Support.Tracking {
/// OnAsyncEnded(), no matter what the outcome of your background operation is.
/// </para>
/// </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>
private class EndedDummyProgression : FailableProgression {
/// <summary>Creates a new successfully completed dummy progression</summary>
public EndedDummyProgression() : this(null) { }
/// <summary>Creates a new failed dummy progression</summary>
/// <summary>Dummy request that is always in the ended state</summary>
private class EndedDummyRequest : Request {
/// <summary>Creates a new successfully completed dummy request</summary>
public EndedDummyRequest() : this(null) { }
/// <summary>Creates a new failed dummy request</summary>
/// <param name="exception">Exception that caused the dummy to fail</param>
public EndedDummyProgression(Exception exception) {
public EndedDummyRequest(Exception exception) {
OnAsyncEnded();
// 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">
/// Exception that supposedly caused the progression to fail
/// </param>
/// <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>
public static FailableProgression CreateFailedDummyProgression(Exception exception) {
return new EndedDummyProgression(exception);
public static Request CreateFailedDummyRequest(Exception exception) {
return new EndedDummyRequest(exception);
}
/// <summary>Waits for the background operation to end</summary>
@ -59,14 +79,6 @@ namespace Nuclex.Support.Tracking {
/// </remarks>
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(!Ended)
WaitHandle.WaitOne();
@ -101,8 +113,6 @@ namespace Nuclex.Support.Tracking {
/// <summary>Exception that occured while the operation was executing</summary>
private volatile Exception occuredException;
/// <summary>Whether the End() method has been called already</summary>
private volatile bool endCalled;
}