internal static void AddToRepository(Job2 job)
		{
			if (job != null)
			{
				ScheduledJobSourceAdapter.JobRepository.AddOrReplace(job);
				return;
			}
			else
			{
				throw new PSArgumentNullException("job");
			}
		}
Example #2
0
 private bool CheckIfJob2CanBeRemoved(bool checkForRemove, string parameterName, Job2 job2, string resourceString, params object[] args)
 {
     if (!checkForRemove)
     {
         return true;
     }
     if (job2.IsFinishedState(job2.JobStateInfo.State))
     {
         return true;
     }
     Exception exception = new ArgumentException(PSRemotingErrorInvariants.FormatResourceString(resourceString, args), parameterName);
     base.WriteError(new ErrorRecord(exception, "JobObjectNotFinishedCannotBeRemoved", ErrorCategory.InvalidOperation, job2));
     return false;
 }
Example #3
0
 public void AddChildJob(Job2 childJob)
 {
     JobStateInfo jobStateInfo;
     base.AssertNotDisposed();
     if (childJob == null)
     {
         throw new ArgumentNullException("childJob");
     }
     this._tracer.WriteMessage("ContainerParentJob", "AddChildJob", Guid.Empty, childJob, "Adding Child to Parent with InstanceId : ", new string[] { base.InstanceId.ToString() });
     lock (childJob.syncObject)
     {
         jobStateInfo = childJob.JobStateInfo;
         childJob.StateChanged += new EventHandler<JobStateEventArgs>(this.HandleChildJobStateChanged);
     }
     base.ChildJobs.Add(childJob);
     this.ParentJobStateCalculation(new JobStateEventArgs(jobStateInfo, new JobStateInfo(JobState.NotStarted)));
 }
Example #4
0
 private void StoreJobIdForReuseHelper(Hashtable duplicateDetector, Job2 job, bool recurse)
 {
     if (!duplicateDetector.ContainsKey(job.InstanceId))
     {
         duplicateDetector.Add(job.InstanceId, job.InstanceId);
         JobManager.SaveJobId(job.InstanceId, job.Id, base.GetType().Name);
         if (recurse && (job.ChildJobs != null))
         {
             foreach (Job job2 in job.ChildJobs)
             {
                 Job2 job3 = job2 as Job2;
                 if (job3 != null)
                 {
                     this.StoreJobIdForReuseHelper(duplicateDetector, job3, recurse);
                 }
             }
         }
     }
 }
Example #5
0
 public void StoreJobIdForReuse(Job2 job, bool recurse)
 {
     if (job == null)
     {
         PSTraceSource.NewArgumentNullException("job", "remotingerroridstrings", "JobSourceAdapterCannotSaveNullJob", new object[0]);
     }
     JobManager.SaveJobId(job.InstanceId, job.Id, base.GetType().Name);
     if ((recurse && (job.ChildJobs != null)) && (job.ChildJobs.Count > 0))
     {
         Hashtable duplicateDetector = new Hashtable();
         duplicateDetector.Add(job.InstanceId, job.InstanceId);
         foreach (Job job2 in job.ChildJobs)
         {
             Job2 job3 = job2 as Job2;
             if (job3 != null)
             {
                 this.StoreJobIdForReuseHelper(duplicateDetector, job3, true);
             }
         }
     }
 }
        /// <summary>
        /// Remove a job from the store 
        /// </summary>
        /// <param name="job">job object to remove</param>
        public override void RemoveJob(Job2 job)
        {
            if (job == null)
            {
                throw new PSArgumentNullException("job");
            }

            RefreshRepository();

            try
            {
                JobRepository.Remove(job);
                ScheduledJobStore.RemoveJobRun(
                    job.Name,
                    job.PSBeginTime ?? DateTime.MinValue);
            }
            catch (DirectoryNotFoundException)
            {
            }
            catch (FileNotFoundException)
            {
            }
        }
		public override void PersistJob(Job2 job)
		{
			if (job != null)
			{
				ScheduledJobSourceAdapter.SaveJobToStore(job as ScheduledJob);
				return;
			}
			else
			{
				throw new PSArgumentNullException("job");
			}
		}
Example #8
0
        /// <summary>
        /// SubmitOperation
        /// </summary>
        /// <param name="job"></param>
        /// <param name="operationHandler"></param>
        /// <param name="state"></param>
        /// <param name="expectedState"></param>
        internal void SubmitOperation(Job2 job, Action<object> operationHandler, object state, JobState expectedState)
        {
            Debug.Assert(job != null, "Null job passed");
            Debug.Assert(operationHandler != null, "Null delegate passed");

            if (job == null) throw new ArgumentNullException("job");

            // Adding OnJobStateChanged event handler here caused negative _inProgressCount when jobs are stopped before they got picked up by servicing thread.
            _pendingQueue.Enqueue(Tuple.Create(operationHandler, state, expectedState));
            PerfCountersMgr.UpdateCounterByValue(
                PSWorkflowPerformanceCounterSetInfo.CounterSetId,
                PSWorkflowPerformanceCounterIds.WaitingWorkflowJobsCount);
            CheckAndStartServicingThread();
        }
        /// <summary>
        /// Saves job to scheduled job run store.
        /// </summary>
        /// <param name="job">ScheduledJob</param>
        public override void PersistJob(Job2 job)
        {
            if (job == null)
            {
                throw new PSArgumentNullException("job");
            }

            SaveJobToStore(job as ScheduledJob);
        }
Example #10
0
 /// <summary>
 /// Remove a job from the store 
 /// </summary>
 /// <param name="job">job object to remove</param>
 public abstract void RemoveJob(Job2 job);
        /// <summary>
        /// Adds a Job2 object to the repository.
        /// </summary>
        /// <param name="job">Job2</param>
        internal static void AddToRepository(Job2 job)
        {
            if (job == null)
            {
                throw new PSArgumentNullException("job");
            }

            JobRepository.AddOrReplace(job);
        }
			public void AddOrReplace(Job2 job)
			{
				if (job != null)
				{
					lock (this._syncObject)
					{
						if (this._jobs.ContainsKey(job.InstanceId))
						{
							this._jobs.Remove(job.InstanceId);
						}
						this._jobs.Add(job.InstanceId, job);
					}
					return;
				}
				else
				{
					throw new PSArgumentNullException("job");
				}
			}
Example #13
0
 public void StoreJobIdForReuse(Job2 job, bool recurse)
 {
     if (job == null)
     {
         PSTraceSource.NewArgumentNullException("job", RemotingErrorIdStrings.JobSourceAdapterCannotSaveNullJob);
     }
     JobManager.SaveJobId(job.InstanceId, job.Id, this.GetType().Name);
     if (recurse && job.ChildJobs != null && job.ChildJobs.Count > 0)
     {
         Hashtable duplicateDetector = new Hashtable();
         duplicateDetector.Add(job.InstanceId, job.InstanceId);
         foreach (Job child in job.ChildJobs)
         {
             Job2 childJob = child as Job2;
             if (childJob == null) continue;
             StoreJobIdForReuseHelper(duplicateDetector, childJob, true);
         }
     }
 }
		public override void RemoveJob(Job2 job)
		{
			DateTime valueOrDefault;
			if (job != null)
			{
				this.RefreshRepository();
				try
				{
					ScheduledJobSourceAdapter.JobRepository.Remove(job);
					string name = job.Name;
					DateTime? pSBeginTime = job.PSBeginTime;
					if (pSBeginTime.HasValue)
					{
						valueOrDefault = pSBeginTime.GetValueOrDefault();
					}
					else
					{
						valueOrDefault = DateTime.MinValue;
					}
					ScheduledJobStore.RemoveJobRun(name, valueOrDefault);
				}
				catch (DirectoryNotFoundException directoryNotFoundException)
				{
				}
				catch (FileNotFoundException fileNotFoundException)
				{
				}
				return;
			}
			else
			{
				throw new PSArgumentNullException("job");
			}
		}
Example #15
0
 public virtual void PersistJob(Job2 job)
 {
 }
            /// <summary>
            /// Remove Job2 from repository.
            /// </summary>
            /// <param name="job"></param>
            public void Remove(Job2 job)
            {
                if (job == null)
                {
                    throw new PSArgumentNullException("job");
                }

                lock (_syncObject)
                {
                    if (_jobs.ContainsKey(job.InstanceId) == false)
                    {
                        string msg = StringUtil.Format(ScheduledJobErrorStrings.ScheduledJobNotInRepository, job.Name);
                        throw new ScheduledJobException(msg);
                    }
                    _jobs.Remove(job.InstanceId);
                }
            }
            /// <summary>
            /// Add or replace passed in Job2 object to repository.
            /// </summary>
            /// <param name="job">Job2 to add</param>
            public void AddOrReplace(Job2 job)
            {
                if (job == null)
                {
                    throw new PSArgumentNullException("job");
                }

                lock (_syncObject)
                {
                    if (_jobs.ContainsKey(job.InstanceId))
                    {
                        _jobs.Remove(job.InstanceId);
                    }
                    _jobs.Add(job.InstanceId, job);
                }
            }
            /// <summary>
            /// Add Job2 to repository.
            /// </summary>
            /// <param name="job">Job2 to add</param>
            public void Add(Job2 job)
            {
                if (job == null)
                {
                    throw new PSArgumentNullException("job");
                }

                lock (_syncObject)
                {
                    if (_jobs.ContainsKey(job.InstanceId))
                    {
                        string msg = StringUtil.Format(ScheduledJobErrorStrings.ScheduledJobAlreadyExistsInLocal, job.Name, job.InstanceId);
                        throw new ScheduledJobException(msg);
                    }
                    _jobs.Add(job.InstanceId, job);
                }
            }
			public void Add(Job2 job)
			{
				if (job != null)
				{
					lock (this._syncObject)
					{
						if (!this._jobs.ContainsKey(job.InstanceId))
						{
							this._jobs.Add(job.InstanceId, job);
						}
						else
						{
							object[] name = new object[2];
							name[0] = job.Name;
							name[1] = job.InstanceId;
							string str = StringUtil.Format(ScheduledJobErrorStrings.ScheduledJobAlreadyExistsInLocal, name);
							throw new ScheduledJobException(str);
						}
					}
					return;
				}
				else
				{
					throw new PSArgumentNullException("job");
				}
			}
Example #20
0
		internal void SubmitOperation(Job2 job, Action<object> operationHandler, object state, JobState expectedState)
		{
			if (job != null)
			{
				this._pendingQueue.Enqueue(Tuple.Create<Action<object>, object, JobState>(operationHandler, state, expectedState));
				PSWorkflowJobManager.PerfCountersMgr.UpdateCounterByValue(PSWorkflowPerformanceCounterSetInfo.CounterSetId, 15, (long)1, true);
				this.CheckAndStartServicingThread();
				return;
			}
			else
			{
				throw new ArgumentNullException("job");
			}
		}
			public void Remove(Job2 job)
			{
				if (job != null)
				{
					lock (this._syncObject)
					{
						if (this._jobs.ContainsKey(job.InstanceId))
						{
							this._jobs.Remove(job.InstanceId);
						}
						else
						{
							string str = StringUtil.Format(ScheduledJobErrorStrings.ScheduledJobNotInRepository, job.Name);
							throw new ScheduledJobException(str);
						}
					}
					return;
				}
				else
				{
					throw new PSArgumentNullException("job");
				}
			}
        public override void RemoveJob(Job2 job)
        {
            lock (JobRepository)
            {
                if (JobRepository.Contains(job))
                {
                    JobRepository.Remove(job);
                }
            }

            job.Dispose();
        }
Example #23
0
        private void StoreJobIdForReuseHelper(Hashtable duplicateDetector, Job2 job, bool recurse)
        {
            if (duplicateDetector.ContainsKey(job.InstanceId)) return;
            duplicateDetector.Add(job.InstanceId, job.InstanceId);

            JobManager.SaveJobId(job.InstanceId, job.Id, this.GetType().Name);

            if (!recurse || job.ChildJobs == null) return;
            foreach (Job child in job.ChildJobs)
            {
                Job2 childJob = child as Job2;
                if (childJob == null) continue;
                StoreJobIdForReuseHelper(duplicateDetector, childJob, recurse);
            }
        }
Example #24
0
 internal void RemoveChildJob(Job2 childWorkflowJob)
 {
     if (WorkflowJobSourceAdapter.GetInstance().GetJobManager() == this)
     {
         WorkflowJobSourceAdapter.GetInstance().RemoveChildJob(childWorkflowJob);
     }
     else
     {
         this.RemoveJob(childWorkflowJob.InstanceId);
     }
 }
Example #25
0
 /// <summary>
 /// Saves the job to a persisted store.
 /// </summary>
 /// <param name="job">Job2 type job to persist</param>
 public virtual void PersistJob(Job2 job)
 {
     // Implemented only if job needs to be told when to persist.
 }
Example #26
0
        /// <summary>
        /// Add a child job to the parent job
        /// </summary>
        /// <param name="childJob">child job to add</param>
        /// <exception cref="ObjectDisposedException">Thrown if the job is disposed.</exception>
        /// <exception cref="ArgumentNullException">Thrown if child being added is null.</exception>
        public void AddChildJob(Job2 childJob)
        {
            AssertNotDisposed();
            if (childJob == null)
            {
                throw new ArgumentNullException("childJob");
            }
            _tracer.WriteMessage(TraceClassName, "AddChildJob", Guid.Empty, childJob, "Adding Child to Parent with InstanceId : ", InstanceId.ToString());

            JobStateInfo childJobStateInfo;
            lock (childJob.syncObject)
            {
                // Store job's state and subscribe to State Changed event. Locking here will
                // ensure that the jobstateinfo we get is the state before any state changed events are handled by ContainerParentJob.
                childJobStateInfo = childJob.JobStateInfo;
                childJob.StateChanged += new EventHandler<JobStateEventArgs>(HandleChildJobStateChanged);
            }
            ChildJobs.Add(childJob);
            ParentJobStateCalculation(new JobStateEventArgs(childJobStateInfo, new JobStateInfo(JobState.NotStarted)));
        }