Esempio n. 1
0
        /// <summary>
        /// Creates a new job object.
        /// </summary>
        private Guid CreateJob(
            Guid pParentID,
            string pName,
            string pCode,
            iTaskCollection pTaskCollection,
            iJobContextFactory pJobContextFactory,
            iJobState pJobState,
            int pMaxErrors)
        {
            if (string.IsNullOrWhiteSpace(pName))
            {
                throw new NullReferenceException("Invalid name for a job.");
            }
            if (string.IsNullOrWhiteSpace(pCode))
            {
                throw new NullReferenceException("Invalid code for a job.");
            }
            if (pTaskCollection == null)
            {
                throw new NullReferenceException("pTaskFactory can not be null.");
            }
            if (pJobContextFactory == null)
            {
                throw new NullReferenceException("pContextFactory can not be null.");
            }
            if (pJobState == null)
            {
                throw new NullReferenceException("pJobState can not be null.");
            }

            Job job = new Job(
                pParentID,
                _settings,
                Name,
                pName,
                pCode,
                pTaskCollection,
                pJobContextFactory,
                ObjectFactory.Container.GetInstance<iEventFactory>(),
                pJobState,
                pMaxErrors);

            Jobs.Add(job.ID, job);
            return job.ID;
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="pChild">The child state.</param>
        /// <param name="pStartTime">The start time in HH:MM:SS format.</param>
        /// <param name="pEndTime">The end time in HH:MM:SS format.</param>
        public TimeRangeState([NotNull] iJobState pChild, [NotNull] string pStartTime, [NotNull] string pEndTime)
        {
            if (pChild == null)
            {
                throw new ArgumentNullException("pChild");
            }
            if (pStartTime == null)
            {
                throw new ArgumentNullException("pStartTime");
            }
            if (pEndTime == null)
            {
                throw new ArgumentNullException("pEndTime");
            }

            _child = pChild;
            _startTime = pStartTime;
            _endTime = pEndTime;
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Job(
            Guid pParentID,
            PluginSettings pSettings,
            string pPlugin,
            string pName,
            string pCode,
            iTaskCollection pTasks,
            iJobContextFactory pJobContextFactory,
            iEventFactory pEventFactory,
            iJobState pJobState,
            int pMaxErrors = 0)
        {
            _settings = pSettings;
            _jobContextFactory = pJobContextFactory;
            _jobState = pJobState;
            _eventDelay = new AutoResetEvent(false);

            _isRunning = false;
            _isSuspended = false;

            Tasks = pTasks;
            ParentID = pParentID;
            Plugin = pPlugin;
            Name = pName;
            Code = pCode;
            ID = Guid.NewGuid();
            State = eSTATE.NONE;

            _eventFactory = pEventFactory;

            Errors = 0;
            MaxErrors = pMaxErrors;
            TimeStamp = DateTime.Now;
            ThreadID = 0;
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new runnable job.
        /// </summary>
        /// <param name="pName">Name of the job.</param>
        /// <param name="pCode"></param>
        /// <param name="pTaskCollection">Factory to create tasks for the job.</param>
        /// <param name="pJobContextFactory">Factory to create a context for the job.</param>
        /// <param name="pJobState">Object to control the state of the job.</param>
        /// <param name="pMaxErrors">The job's max errors.</param>
        /// <returns>A new job object.</returns>
        public Guid Create(string pName, string pCode, iTaskCollection pTaskCollection, iJobContextFactory pJobContextFactory,
                           iJobState pJobState, int pMaxErrors = 0)
        {
            Guid id = CreateJob(Guid.Empty, pName, pCode, pTaskCollection, pJobContextFactory, pJobState, pMaxErrors);

            _logger.Fine("Job created:{0}", Jobs[id]);

            return id;
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new runnable job.
        /// </summary>
        /// <param name="pParent">Parent job must finish first before this job starts.</param>
        /// <param name="pName">Name of the job.</param>
        /// <param name="pCode">Unique code for this job (used by the logger)</param>
        /// <param name="pTaskCollection">Factory to create tasks for the job.</param>
        /// <param name="pJobContextFactory">Factory to create a context for the job.</param>
        /// <param name="pJobState">Object to control the state of the job.</param>
        /// <param name="pMaxErrors">The job's max errors.</param>
        /// <returns>A new job object.</returns>
        public Guid Create(Guid pParent, string pName, string pCode, iTaskCollection pTaskCollection,
                           iJobContextFactory pJobContextFactory,
                           iJobState pJobState, int pMaxErrors = 0)
        {
            if (!Jobs.ContainsKey(pParent))
            {
                throw new JobException("Parent job does not exist.");
            }

            Guid child = CreateJob(pParent, pName, pCode, pTaskCollection, pJobContextFactory, pJobState, pMaxErrors);

            _logger.Fine("Job created:{0} Depends On:{1}", Jobs[child], Jobs[pParent]);

            return child;
        }