Esempio n. 1
0
		internal static void AddToRepository(Job2 job)
		{
			if (job != null)
			{
				ScheduledJobSourceAdapter.JobRepository.AddOrReplace(job);
				return;
			}
			else
			{
				throw new PSArgumentNullException("job");
			}
		}
Esempio n. 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;
 }
Esempio n. 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)));
 }
Esempio n. 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);
                 }
             }
         }
     }
 }
Esempio n. 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);
             }
         }
     }
 }
Esempio n. 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();
        }
Esempio n. 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();
        }
Esempio n. 9
0
 internal void RemoveChildJob(Job2 childWorkflowJob)
 {
     if (WorkflowJobSourceAdapter.GetInstance().GetJobManager() == this)
     {
         WorkflowJobSourceAdapter.GetInstance().RemoveChildJob(childWorkflowJob);
     }
     else
     {
         this.RemoveJob(childWorkflowJob.InstanceId);
     }
 }
Esempio n. 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");
				}
			}
Esempio n. 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)
            {
            }
        }
Esempio n. 12
0
 public virtual void PersistJob(Job2 job)
 {
 }
Esempio n. 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");
			}
		}
Esempio n. 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);
                }
            }
Esempio n. 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);
                }
            }
Esempio n. 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);
                }
            }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 19
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)));
        }
Esempio n. 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);
         }
     }
 }
Esempio n. 21
0
		public override void PersistJob(Job2 job)
		{
			if (job != null)
			{
				ScheduledJobSourceAdapter.SaveJobToStore(job as ScheduledJob);
				return;
			}
			else
			{
				throw new PSArgumentNullException("job");
			}
		}
Esempio n. 22
0
 /// <summary>
 /// Remove a job from the store 
 /// </summary>
 /// <param name="job">job object to remove</param>
 public abstract void RemoveJob(Job2 job);
Esempio n. 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");
				}
			}
Esempio n. 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);
        }
Esempio n. 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");
				}
			}
Esempio n. 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.
 }
Esempio n. 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);
            }
        }
Esempio n. 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");
			}
		}
Esempio n. 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.
 }
Esempio n. 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);
        }