Example #1
0
        /// <summary>
        /// 得到计划任务
        /// </summary>
        public ScheduledTaskUnit Get(int taskId)
        {
            for (int i = 0; i < _taskList.Count; i++)
            {
                ScheduledTaskUnit unit = _taskList[i] as ScheduledTaskUnit;
                if (unit.Task.SecurityObject.Id == taskId)
                {
                    return(unit);
                }
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// 启用计划任务
        /// </summary>
        public bool Enable(int taskId, bool enabled)
        {
            ScheduledTaskUnit taskUnit = Get(taskId);

            if (taskUnit != null)
            {
                if (taskUnit.Task.Enabled != enabled)
                {
                    taskUnit.Task.Enabled = enabled;
                    Update(taskId, taskUnit.Task, taskUnit.Task.SecurityObject.Name, taskUnit.Task.SecurityObject.Comment);
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
        /// <summary>
        /// 载入计划任务
        /// </summary>
        public void Load()
        {
            this.SecurityObject = AdminServer.TheInstance.SecurityManager.Get(SecurityObjectScheduledTaskManager);
            _taskList.Clear();

            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName);
                DataSet     ds = new DataSet();
                scheduledTaskTable.Get(ds);
                DataTable table = ds.Tables[TableString.ScheduledTaskTableName];
                foreach (DataRow row in table.Rows)
                {
                    try
                    {
                        int    id       = (int)row[TableString.ScheduledTaskFieldId];
                        byte[] taskData = (byte[])row[TableString.ScheduledTaskFieldTaskData];

                        MemoryStream   taskDataStream = new MemoryStream(taskData);
                        IFormatter     formatter      = new BinaryFormatter();
                        IScheduledTask task           = (IScheduledTask)formatter.Deserialize(taskDataStream);
                        if (task != null)
                        {
                            FSEyeObject secObj = AdminServer.TheInstance.SecurityManager.Get(id);
                            if (secObj != null)
                            {
                                task.SecurityObject = secObj;

                                ScheduledTaskUnit unit = new ScheduledTaskUnit();
                                unit.Task = task;
                                unit.AvoidCheckTimeout = 0;
                                _taskList.Add(unit);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Util.DebugLog(e.StackTrace);
                        continue;
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// 删除计划任务
        /// </summary>
        /// <param name="taskId">计划任务ID</param>
        public bool Delete(int taskId)
        {
            for (int i = 0; i < _taskList.Count; i++)
            {
                ScheduledTaskUnit unit = _taskList[i] as ScheduledTaskUnit;
                if (unit.Task.SecurityObject.Id == taskId)
                {
                    using (IBlazeDatabase db = DbFactory.GetDatabase())
                    {
                        try
                        {
                            db.BeginTrans();

                            AdminServer.TheInstance.SecurityManager.Delete(taskId, db);

                            IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName);
                            scheduledTaskTable.Delete(FilterFactory.CreateEqualFilter(TableString.ScheduledTaskFieldId, taskId));

                            AdminServer.TheInstance.SecurityManager.Delete(taskId, db);

                            _taskList.RemoveAt(i);

                            db.CommitTrans();
                            return(true);
                        }
                        catch (Exception ex)
                        {
                            if (db != null)
                            {
                                db.RollbackTrans();
                            }

                            throw ex;
                        }
                    }
                }
            }

            return(false);
        }
Example #5
0
        /// <summary>
        /// 添加计划任务
        /// </summary>
        public void Add(IScheduledTask task, string name, string comment)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (comment == null)
            {
                throw new ArgumentNullException("comment");
            }

            using (IBlazeDatabase db = DbFactory.GetDatabase())
            {
                try
                {
                    db.BeginTrans();

                    SecurityManager sm             = AdminServer.TheInstance.SecurityManager;
                    FSEyeObject     newObject      = sm.Get(SecurityObject.FullPath + SecurityManager.ObjectPathDelimiter + name, db);
                    byte[]          automationData = AdminServer.TheInstance.AutomationManager.Save(task.Automation);

                    MemoryStream taskDataStream = new MemoryStream();
                    IFormatter   formatter      = new BinaryFormatter();
                    formatter.Serialize(taskDataStream, task);
                    byte[] taskData = taskDataStream.ToArray();
                    if (newObject != null && automationData != null && taskData != null)
                    {
                        newObject.Comment = comment;
                        sm.Set(newObject);
                        task.SecurityObject = newObject;

                        IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName);
                        DataSet     ds = new DataSet();
                        scheduledTaskTable.Get(ds);
                        DataTable table = ds.Tables[TableString.ScheduledTaskTableName];
                        DataRow   row   = table.NewRow();
                        row[TableString.ScheduledTaskFieldId]       = newObject.Id;
                        row[TableString.ScheduledTaskFieldTaskData] = taskData;
                        table.Rows.Add(row);
                        scheduledTaskTable.Set(table);

                        ScheduledTaskUnit unit = new ScheduledTaskUnit();
                        unit.Task = task;
                        unit.AvoidCheckTimeout = 0;
                        _taskList.Add(unit);

                        //设置权限
                        AdminServer.TheInstance.SecurityManager.CopyAce(newObject.Parent, newObject, true);

                        db.CommitTrans();
                    }
                }
                catch (Exception)
                {
                    db.RollbackTrans();
                }
            }
        }
Example #6
0
	protected void Page_Load(object sender, EventArgs e)
	{
        if (!WebUtil.CheckPrivilege(WebConfig.FunctionAutomationAddScheduledTask, OpType.READ, Session))
        {
            Response.Redirect(WebConfig.PageNotEnoughPrivilege, true);
        }

		string op = Request.Params[WebConfig.ParamOperation];
		if (op != null && op == WebConfig.OpTypeModify && Session[WebConfig.SessionScheduledTask] != null)
		{
			_opType = PageOpType.Modify;
            _taskUnit = Session[WebConfig.SessionScheduledTask] as ScheduledTaskUnit;
            
            if (_taskUnit == null) return;
            
            //修改自动化作业需要对ScheduledTaskManager有写权限
            if (!WebUtil.CheckPrivilege(TheAdminServer.ScheduledTaskManager.SecurityObject, OpType.WRITE, Session))
            {
                Response.Redirect(WebConfig.PageNotEnoughPrivilege, true);
            }
		}
		else
		{
			_opType = PageOpType.Add;

            //添加自动化作业需要对ScheduledTaskManager有写权限
            if (!WebUtil.CheckPrivilege(TheAdminServer.ScheduledTaskManager.SecurityObject, OpType.WRITE, Session))
            {
                Response.Redirect(WebConfig.PageNotEnoughPrivilege, true);
            }
		}
		
		if (!IsPostBack)
		{
			ListScheduledTaskType();

			if (_opType == PageOpType.Modify)
			{
				LabelOpType.Text = StringDef.EditScheduledTask;
                if (_taskUnit != null)
				{
                    AutomationEditor1.Automation = _taskUnit.Task.Automation;
                    TextBoxName.Text = _taskUnit.Task.SecurityObject.Name;
                    TextBoxComment.Text = _taskUnit.Task.SecurityObject.Comment;

                    switch (_taskUnit.Task.Type)
					{
						case ScheduledTaskType.Once:
							{
                                OnceScheduledTask task = _taskUnit.Task as OnceScheduledTask;
								TextBoxExecuteTime.Text = task.ExecuteTime.ToString();
							}
							break;
						case ScheduledTaskType.Repeat:
							{
                                RepeatScheduledTask task = _taskUnit.Task as RepeatScheduledTask;
								TextBoxStartTime.Text = task.StartTime.ToString();
								TextBoxEndTime.Text = task.EndTime.ToString();
								TextBoxInterval.Text = task.Interval.ToString();
							}
							break;
                        case ScheduledTaskType.DayOfWeek:
                            {
                                DayOfWeekScheduledTask task = _taskUnit.Task as DayOfWeekScheduledTask;
                                TextBoxDayOfWeekExecuteTime.Text = task.TimeOfDay.ToString();
                                foreach (DayOfWeek day in task.DayOfWeek)
                                    CheckBoxListDayOfWeek.Items[(int)day].Selected = true;
                            }
                            break;
					}

                    SetScheduledTaskType(_taskUnit.Task.Type);
				}
			}
			else if (_opType == PageOpType.Add)
			{
				AutomationEditor1.Automation = null;
				LabelOpType.Text = StringDef.AddScheduledTask;
			}
            LabelOnceExecuteTime.Text += "[yyyy-mm-dd hh:mm:ss]";
            LabelRepeatStartTime.Text += "[hh:mm:ss]";
            LabelRepeatEndTime.Text += "[hh:mm:ss]";
            LabelIntervalTime.Text += "[hh:mm:ss]";
            LabelDayOfWeekExecuteTime.Text += "[hh:mm:ss]";
		}
        OperateResult.Text = string.Empty;
	}
Example #7
0
		/// <summary>
		/// 添加计划任务
		/// </summary>
		public void Add(IScheduledTask task, string name, string comment)
		{
			if (task == null)
				throw new ArgumentNullException("task");
			if (name == null)
				throw new ArgumentNullException("name");
			if (comment == null)
				throw new ArgumentNullException("comment");

			using (IBlazeDatabase db = DbFactory.GetDatabase())
			{
				try
				{
					db.BeginTrans();

					SecurityManager sm = AdminServer.TheInstance.SecurityManager;
					FSEyeObject newObject = sm.Get(SecurityObject.FullPath + SecurityManager.ObjectPathDelimiter + name, db);
					byte[] automationData = AdminServer.TheInstance.AutomationManager.Save(task.Automation);

					MemoryStream taskDataStream = new MemoryStream();
					IFormatter formatter = new BinaryFormatter();
					formatter.Serialize(taskDataStream, task);
					byte[] taskData = taskDataStream.ToArray();
					if (newObject != null && automationData != null && taskData != null)
					{
						newObject.Comment = comment;
						sm.Set(newObject);
						task.SecurityObject = newObject;

						IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName);
						DataSet ds = new DataSet();
						scheduledTaskTable.Get(ds);
						DataTable table = ds.Tables[TableString.ScheduledTaskTableName];
						DataRow row = table.NewRow();
						row[TableString.ScheduledTaskFieldId] = newObject.Id;
						row[TableString.ScheduledTaskFieldTaskData] = taskData;
						table.Rows.Add(row);
						scheduledTaskTable.Set(table);

						ScheduledTaskUnit unit = new ScheduledTaskUnit();
						unit.Task = task;
						unit.AvoidCheckTimeout = 0;
						_taskList.Add(unit);

                        //设置权限
                        AdminServer.TheInstance.SecurityManager.CopyAce(newObject.Parent, newObject, true);

						db.CommitTrans();
					}
				}
				catch (Exception)
				{
					db.RollbackTrans();
				}
			}
		}
Example #8
0
		/// <summary>
		/// 载入计划任务
		/// </summary>
		public void Load()
		{
            this.SecurityObject = AdminServer.TheInstance.SecurityManager.Get(SecurityObjectScheduledTaskManager);
			_taskList.Clear();

			using (IBlazeDatabase db = DbFactory.GetDatabase())
			{
				IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName);
				DataSet ds = new DataSet();
				scheduledTaskTable.Get(ds);
				DataTable table = ds.Tables[TableString.ScheduledTaskTableName];
				foreach (DataRow row in table.Rows)
				{
                    try
                    {
                        int id = (int)row[TableString.ScheduledTaskFieldId];
                        byte[] taskData = (byte[])row[TableString.ScheduledTaskFieldTaskData];

                        MemoryStream taskDataStream = new MemoryStream(taskData);
                        IFormatter formatter = new BinaryFormatter();
                        IScheduledTask task = (IScheduledTask)formatter.Deserialize(taskDataStream);
                        if (task != null)
                        {
                            FSEyeObject secObj = AdminServer.TheInstance.SecurityManager.Get(id);
                            if (secObj != null)
                            {
                                task.SecurityObject = secObj;

                                ScheduledTaskUnit unit = new ScheduledTaskUnit();
                                unit.Task = task;
                                unit.AvoidCheckTimeout = 0;
                                _taskList.Add(unit);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Util.DebugLog(e.StackTrace);
                        continue;
                    }
				}
			}
		}