00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 using System;
00013 using System.Threading;
00014 using Mcs.Epm.MicrosoftProject.mpFx.QueueWebService;
00015 using LibraryResources = Mcs.Epm.MicrosoftProject.mpFx.Properties.Resources;
00016
00017 namespace Mcs.Epm.MicrosoftProject.mpFx
00018 {
00019
00020
00021
00022 public class Queue
00023 {
00024 #region Instance Data
00025
00026 private readonly ProjectServer _Parent;
00027
00028 #endregion
00029
00030 #region Constructor
00031
00032
00033
00034
00035
00036 public Queue(ProjectServer parent)
00037 {
00038 if (parent == null)
00039 {
00040 throw new ArgumentNullException( );
00041 }
00042 _Parent = parent;
00043 }
00044
00045 #endregion
00046
00047 #region Public Methods
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 public bool WaitOnJobStatus(Guid jobGuid,
00059 JobState jobState,
00060 int count,
00061 int duration,
00062 out string errorString)
00063 {
00064 errorString = string.Empty;
00065
00066 for (int i = 0; i < count - 1; i++)
00067 {
00068 JobState currentState = _Parent.WebServices.Queue.GetJobCompletionState(jobGuid, out errorString);
00069
00070 if (currentState == jobState)
00071 {
00072 return true;
00073 }
00074
00075 if (currentState == JobState.Canceled && jobState != JobState.Canceled)
00076 {
00077 throw MpFxException.Create(LibraryResources.ExceptionOperationCanceled);
00078 }
00079
00080 if (IsFailureState(jobState))
00081 {
00082 return false;
00083 }
00084
00085 Thread.Sleep(duration);
00086 }
00087
00088 return false;
00089 }
00090
00091 private static bool IsFailureState(JobState jobState)
00092 {
00093 return jobState == JobState.Unknown
00094 || jobState == JobState.Failed
00095 || jobState == JobState.FailedNotBlocking
00096 || jobState == JobState.CorrelationBlocked;
00097 }
00098
00099 #endregion
00100
00101 public void CancelJob(Guid jobGuid)
00102 {
00103 _Parent.WebServices.Queue.CancelJob(jobGuid, true, true);
00104 }
00105 }
00106 }
00107
00108
00109
00110
00111
00112
00113