예제 #1
0
		internal static void AddToRepository(Job2 job)
		{
			if (job != null)
			{
				ScheduledJobSourceAdapter.JobRepository.AddOrReplace(job);
				return;
			}
			else
			{
				throw new PSArgumentNullException("job");
			}
		}
예제 #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;
 }
예제 #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)));
 }
예제 #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);
                 }
             }
         }
     }
 }
예제 #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);
             }
         }
     }
 }
예제 #6
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();
        }
예제 #7
0
 /// <summary>
 /// Remove a job from the store
 /// </summary>
 /// <param name="job">Job object to remove.</param>
 public abstract void RemoveJob(Job2 job);
        public override void RemoveJob(Job2 job)
        {
            lock (JobRepository)
            {
                if (JobRepository.Contains(job))
                {
                    JobRepository.Remove(job);
                }
            }

            job.Dispose();
        }
예제 #9
0
 internal void RemoveChildJob(Job2 childWorkflowJob)
 {
     if (WorkflowJobSourceAdapter.GetInstance().GetJobManager() == this)
     {
         WorkflowJobSourceAdapter.GetInstance().RemoveChildJob(childWorkflowJob);
     }
     else
     {
         this.RemoveJob(childWorkflowJob.InstanceId);
     }
 }
예제 #10
0
			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");
				}
			}
예제 #11
0
        /// <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)
            {
            }
        }
예제 #12
0
 public virtual void PersistJob(Job2 job)
 {
 }
예제 #13
0
		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");
			}
		}
예제 #14
0
            /// <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);
                }
            }
예제 #15
0
            /// <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);
                }
            }
예제 #16
0
            /// <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);
                }
            }
예제 #17
0
        /// <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);
        }
예제 #18
0
        /// <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);
        }
예제 #19
0
파일: Job2.cs 프로젝트: dfinke/powershell
        /// <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)));
        }
예제 #20
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);
         }
     }
 }
예제 #21
0
		public override void PersistJob(Job2 job)
		{
			if (job != null)
			{
				ScheduledJobSourceAdapter.SaveJobToStore(job as ScheduledJob);
				return;
			}
			else
			{
				throw new PSArgumentNullException("job");
			}
		}
예제 #22
0
 /// <summary>
 /// Remove a job from the store 
 /// </summary>
 /// <param name="job">job object to remove</param>
 public abstract void RemoveJob(Job2 job);
예제 #23
0
			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");
				}
			}
예제 #24
0
        internal void RemoveJob(int sessionJobId, Cmdlet cmdlet, bool writeErrorOnException)
        {
            Job2 job = this.GetJobById(sessionJobId, cmdlet, writeErrorOnException, false, false);

            this.RemoveJob(job, cmdlet, false, false);
        }
예제 #25
0
			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");
				}
			}
예제 #26
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.
 }
예제 #27
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);
            }
        }
예제 #28
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");
			}
		}
예제 #29
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.
 }
예제 #30
0
        /// <summary>
        /// Remove a job from the appropriate store.
        /// </summary>
        /// <param name="job">Job object to remove.</param>
        /// <param name="cmdlet"></param>
        /// <param name="writeErrorOnException"></param>
        /// <param name="throwExceptions">If true, will throw all JobSourceAdapter exceptions to caller.
        /// This is needed if RemoveJob is being called from an event handler in Receive-Job.</param>
        /// <returns>True if job is found.</returns>
        internal bool RemoveJob(Job2 job, Cmdlet cmdlet, bool writeErrorOnException, bool throwExceptions = false)
        {
            bool jobFound = false;

            lock (_syncObject)
            {
                foreach (JobSourceAdapter sourceAdapter in _sourceAdapters.Values)
                {
                    Job2 foundJob = null;
#pragma warning disable 56500
                    try
                    {
                        foundJob = sourceAdapter.GetJobByInstanceId(job.InstanceId, true);
                    }
                    catch (Exception exception)
                    {
                        // Since we are calling into 3rd party code
                        // catching Exception is allowed. In all
                        // other cases the appropriate exception
                        // needs to be caught.

                        // sourceAdapter.GetJobByInstanceId() threw unknown exception.
                        _tracer.TraceException(exception);
                        if (throwExceptions)
                        {
                            throw;
                        }
                        WriteErrorOrWarning(writeErrorOnException, cmdlet, exception, "JobSourceAdapterGetJobError", sourceAdapter);
                    }
#pragma warning restore 56500

                    if (foundJob == null)
                    {
                        continue;
                    }
                    jobFound = true;
                    RemoveJobIdForReuse(foundJob);

#pragma warning disable 56500
                    try
                    {
                        sourceAdapter.RemoveJob(job);
                    }
                    catch (Exception exception)
                    {
                        // Since we are calling into 3rd party code
                        // catching Exception is allowed. In all
                        // other cases the appropriate exception
                        // needs to be caught.
                        // sourceAdapter.RemoveJob() threw unknown exception.

                        _tracer.TraceException(exception);
                        if (throwExceptions)
                        {
                            throw;
                        }
                        WriteErrorOrWarning(writeErrorOnException, cmdlet, exception, "JobSourceAdapterRemoveJobError", sourceAdapter);
                    }
#pragma warning restore 56500
                }
            }

            if (!jobFound && throwExceptions)
            {
                var message = PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.ItemNotFoundInRepository,
                                                                             "Job repository", job.InstanceId.ToString());
                throw new ArgumentException(message);
            }

            return(jobFound);
        }