예제 #1
0
        /// <summary>
        /// Insert a new task
        /// </summary>
        /// <param name="task">
        /// </param>
        /// <remarks>
        /// After a new task is inserted it obtains a IDTask. Before it's -1.
        /// </remarks>
        /// <returns>
        /// </returns>
        public override SchedulerTask InsertTask(SchedulerTask task)
        {
            if (task.IDTask != -1)
            {
                throw new SchedulerException("Could not insert an inserted task");
            }

            task.SetIDTask(this.localSchDB.InsertTask(task));
            if (this._cache.Count != 0 &&
                task.DueTime < ((SchedulerTask)this._cache.GetKey(this._cache.Count - 1)).DueTime)
            {
                lock (this._cache.SyncRoot)
                {
                    this._cache.RemoveAt(this._cache.Count - 1);
                    this._cache.Add(task, task);
                }
            }

            return task;
        }
예제 #2
0
        /// <summary>
        /// Remove tasks
        /// </summary>
        /// <param name="task">
        /// </param>
        public override void RemoveTask(SchedulerTask task)
        {
            if (task.IDTask == -1)
            {
                return;
            }

            // remoce from DB
            base.RemoveTask(task);

            // remove from cache
            lock (this._cache.SyncRoot)
            {
                this._cache.Remove(task);
            }
        }
예제 #3
0
        /// <summary>
        /// Inserts the task.
        /// </summary>
        /// <param name="task">
        /// The scheduler task.
        /// </param>
        /// <returns>
        /// An integer value...
        /// </returns>
        public int InsertTask(SchedulerTask task)
        {
            if (task.DueTime < DateTime.Now)
            {
                throw new SchedulerException("Cannot schedule an expired task");
            }

            byte[] arg;

            using (var ss = new MemoryStream())
            {
                var bf = new BinaryFormatter();
                bf.Serialize(ss, task.Argument);
                arg = ss.ToArray();
                ss.Close();
            }

            int idtask;

            this.cn.Open();

            using (var cmd = this.cn.CreateCommand())
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "rb_SchedulerAddTask";
                var par = cmd.CreateParameter();
                par.ParameterName = "@IDOwner";
                par.DbType        = DbType.Int32;
                par.Direction     = ParameterDirection.Input;
                par.Value         = task.IDModuleOwner;
                cmd.Parameters.Add(par);
                par = cmd.CreateParameter();
                par.ParameterName = "@IDTarget";
                par.DbType        = DbType.Int32;
                par.Direction     = ParameterDirection.Input;
                par.Value         = task.IDModuleTarget;
                cmd.Parameters.Add(par);
                par = cmd.CreateParameter();
                par.ParameterName = "@DueTime";
                par.DbType        = DbType.DateTime;
                par.Direction     = ParameterDirection.Input;
                par.Value         = task.DueTime;
                cmd.Parameters.Add(par);
                par = cmd.CreateParameter();
                par.ParameterName = "@Description";
                par.DbType        = DbType.String;
                par.Size          = 150;
                par.Direction     = ParameterDirection.Input;
                par.Value         = task.Description;
                cmd.Parameters.Add(par);
                par = cmd.CreateParameter();
                par.ParameterName = "@Argument";

                // par.DbType = DbType;
                par.Direction = ParameterDirection.Input;
                par.Value     = arg;
                cmd.Parameters.Add(par);
                par = cmd.CreateParameter();
                par.ParameterName = "@IDTask";
                par.DbType        = DbType.Int32;
                par.Direction     = ParameterDirection.Output;
                cmd.Parameters.Add(par);
                cmd.ExecuteNonQuery();
                idtask = (int)((IDataParameter)cmd.Parameters["@IDTask"]).Value;
            }

            this.cn.Close();

            if (idtask == -1)
            {
                throw new SchedulerException("Task add fail in DB");
            }

            return(idtask);
        }
예제 #4
0
        /// <summary>
        /// Fill internal tasks cache
        /// </summary>
        public void FillCache()
        {
            using (var dr = this.localSchDB.GetOrderedTask())
            {
                while (dr.Read() && this._cache.Count < this._cache.Capacity)
                {
                    var tsk = new SchedulerTask(dr);

                    lock (this._cache.SyncRoot)
                    {
                        this._cache.Add(tsk, tsk);
                    }
                }

                dr.Close();
            }
        }
예제 #5
0
        /// <summary>
        /// Remove a task
        /// </summary>
        /// <param name="task">
        /// The task.
        /// </param>
        /// <remarks>
        /// </remarks>
        public virtual void RemoveTask(SchedulerTask task)
        {
            if (task.IDTask == -1)
            {
                return;
            }

            this.localSchDB.RemoveTask(task.IDTask);
            return;
        }
예제 #6
0
        /// <summary>
        /// Call the correct ISchedulable methods of a target module assigned to the task.
        /// </summary>
        /// <param name="task">
        /// The task.
        /// </param>
        /// <remarks>
        /// </remarks>
        protected void ExecuteTask(SchedulerTask task)
        {
            ISchedulable module;
            try
            {
                module = this.localSchDB.GetModuleInstance(task.IDModuleTarget);
            }
            catch
            {
                // TODO:
                return;
            }

            try
            {
                module.ScheduleDo(task);
            }
            catch (Exception ex)
            {
                try
                {
                    module.ScheduleRollback(task);
                }
                catch (Exception ex2)
                {
                    throw new SchedulerException("ScheduleDo fail. Rollback fails", ex2);
                }

                throw new SchedulerException("ScheduleDo fails. Rollback called successfully", ex);
            }

            try
            {
                module.ScheduleCommit(task);
            }
            catch (Exception ex)
            {
                throw new SchedulerException("ScheduleDo called successfully. Commit fails", ex);
            }
        }
예제 #7
0
        /// <summary>
        /// Insert a new task
        /// </summary>
        /// <param name="task">
        /// The task.
        /// </param>
        /// <returns>
        /// </returns>
        /// <remarks>
        /// </remarks>
        public virtual SchedulerTask InsertTask(SchedulerTask task)
        {
            if (task.IDTask != -1)
            {
                throw new SchedulerException("Could not insert an inserted task");
            }

            task.SetIDTask(this.localSchDB.InsertTask(task));
            return task;
        }
예제 #8
0
        /// <summary>
        /// Inserts the task.
        /// </summary>
        /// <param name="task">
        /// The scheduler task.
        /// </param>
        /// <returns>
        /// An integer value...
        /// </returns>
        public int InsertTask(SchedulerTask task)
        {
            if (task.DueTime < DateTime.Now)
            {
                throw new SchedulerException("Cannot schedule an expired task");
            }

            byte[] arg;

            using (var ss = new MemoryStream())
            {
                var bf = new BinaryFormatter();
                bf.Serialize(ss, task.Argument);
                arg = ss.ToArray();
                ss.Close();
            }

            int idtask;
            this.cn.Open();

            using (var cmd = this.cn.CreateCommand())
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "rb_SchedulerAddTask";
                var par = cmd.CreateParameter();
                par.ParameterName = "@IDOwner";
                par.DbType = DbType.Int32;
                par.Direction = ParameterDirection.Input;
                par.Value = task.IDModuleOwner;
                cmd.Parameters.Add(par);
                par = cmd.CreateParameter();
                par.ParameterName = "@IDTarget";
                par.DbType = DbType.Int32;
                par.Direction = ParameterDirection.Input;
                par.Value = task.IDModuleTarget;
                cmd.Parameters.Add(par);
                par = cmd.CreateParameter();
                par.ParameterName = "@DueTime";
                par.DbType = DbType.DateTime;
                par.Direction = ParameterDirection.Input;
                par.Value = task.DueTime;
                cmd.Parameters.Add(par);
                par = cmd.CreateParameter();
                par.ParameterName = "@Description";
                par.DbType = DbType.String;
                par.Size = 150;
                par.Direction = ParameterDirection.Input;
                par.Value = task.Description;
                cmd.Parameters.Add(par);
                par = cmd.CreateParameter();
                par.ParameterName = "@Argument";

                // par.DbType = DbType;
                par.Direction = ParameterDirection.Input;
                par.Value = arg;
                cmd.Parameters.Add(par);
                par = cmd.CreateParameter();
                par.ParameterName = "@IDTask";
                par.DbType = DbType.Int32;
                par.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(par);
                cmd.ExecuteNonQuery();
                idtask = (int)((IDataParameter)cmd.Parameters["@IDTask"]).Value;
            }

            this.cn.Close();

            if (idtask == -1)
            {
                throw new SchedulerException("Task add fail in DB");
            }

            return idtask;
        }
예제 #9
0
 /// <summary>
 /// Called after ScheduleDo if it throws an exception
 /// </summary>
 /// <param name="task"></param>
 public void ScheduleRollback(SchedulerTask task)
 {
     // TODO:  Add Monitoring.ScheduleRollback implementation
 }
예제 #10
0
 /// <summary>
 /// Called when a task occurs
 /// </summary>
 /// <param name="task"></param>
 public void ScheduleDo(SchedulerTask task)
 {
     // TODO:  Add Monitoring.ScheduleDo implementation
 }
예제 #11
0
 /// <summary>
 /// Called after ScheduleDo if it doesn't throw any exception
 /// </summary>
 /// <param name="task"></param>
 public void ScheduleCommit(SchedulerTask task)
 {
     // TODO:  Add Monitoring.ScheduleCommit implementation
 }