コード例 #1
0
        private void CreateSchedule(int jobId,TaskData taskData,DateTimeOffset runTime)
        {
            ISchedulerFactory sf = new StdSchedulerFactory();
            IScheduler sched = sf.GetScheduler();

            // define the job
            IJobDetail job;
            if (jobId < 0)
            {
                job = JobBuilder.Create<QueryJob>()
                .WithIdentity("jobQuery" + jobId, "groupBackup")
                .Build();
            }
            else
            {
                job = JobBuilder.Create<BackupJob>()
                .WithIdentity("jobBackup" + jobId, "groupBackup")
                .Build();
            }

            // Trigger the job
            ITrigger trigger = TriggerBuilder.Create()
            .UsingJobData("date", taskData.Date.ToString("yyyyMMddHHmm"))
                //.UsingJobData("time", taskData.Date.Hour+":"+taskData.Date.Minute+":"+taskData.Date.Second)
            .WithIdentity("triggerBackup" + jobId, "groupBackup")
            .StartAt(runTime)
            .Build();

            // Tell quartz to schedule the job using our trigger
            sched.ScheduleJob(job, trigger);

            // Start up the scheduler (nothing can actually run until the
            // scheduler has been started)
            sched.Start();
        }
コード例 #2
0
        public static TaskData Clone(TaskData oldData)
        {
            TaskData data = new TaskData();
            data.Id=oldData.Id;
            data.Date=oldData.Date;
            data.Repeat=oldData.Repeat;
            data.RepeatDayOftheWeek=oldData.RepeatDayOftheWeek;
            data.RepeatDay=oldData.RepeatDay;
            data.RepeatMonth=oldData.RepeatMonth;
            data.devices = oldData.devices;

            return data;
        }
コード例 #3
0
        private void AddJob(TaskData taskData,int jobId)
        {
            DateTime taskDate = taskData.Date;

            DateTimeOffset runTime;

            switch(taskData.Repeat ){
                case (int) EnumSchedule.Task.Dailey:
                    runTime = DateBuilder.DateOf(taskDate.Hour, taskDate.Minute, taskDate.Second);
                    CreateSchedule(jobId, taskData, runTime);
                    break;
                case (int)EnumSchedule.Task.Once:
                    runTime = DateBuilder.DateOf(taskDate.Hour, taskDate.Minute, taskDate.Second, taskDate.Day, taskDate.Month, taskDate.Year);
                    CreateSchedule(jobId, taskData, runTime);
                    break;
            }
        }
コード例 #4
0
        public void checkDayTasks()
        {
            DateTime now = DateTime.Now;
            /*TaskData taskDataStartUp = new TaskData();
            taskDataStartUp.Repeat = (int)EnumSchedule.Task.Once;
            taskDataStartUp.Date = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute+1, 0);*/

            //Main Task @ 00:00:00 we call the database to check the daily activities
            // Executes also when server startsUp

            TaskData taskData = new TaskData();
            taskData.Repeat = (int)EnumSchedule.Task.Dailey;
            taskData.Date = new DateTime(now.Year, now.Month, now.Day,0,0, 0);

            //AddJob(taskDataStartUp, -1);
            AddJob(taskData, -2);
        }
コード例 #5
0
 private void createTaskImageButton(TableCell tableCell,TaskData data,int i)
 {
     StringBuilder str = new StringBuilder();
     str.Append("<img src='Images/taskItem.png' type='button' class='imageBtnTask' id='btn" + i.ToString() + "' value='Button:" + i.ToString() + "' onclick='javascript:__doPostBack(\"btnShowDevices_OnClick\",\"" + data.Id + "\");' />");
     tableCell.Text+=str.ToString();
 }
コード例 #6
0
        protected void btnAddDate_OnClick(object sender, EventArgs e)
        {
            if (EnumBackupTask.Procedure.immediately==(EnumBackupTask.Procedure)Session["BackupTask"])
            {
                BackupServerClient serverClient = GlobalVariables.serverClient;
                if (serverClient != null)
                {
                    //Check the selected devices
                    List<TaskData> lstTaskData = new List<TaskData>();

                    DateTime taskDate = DateTime.Now;
                    for (int i = 0; i < grdDevices.Rows.Count; i++)
                    {
                        CheckBox chkSelectDevice = (CheckBox)grdDevices.Rows[i].Cells[0].FindControl("ChbSelect");
                        if (chkSelectDevice.Checked)
                        {
                            TaskData taskData = new TaskData();
                            taskData.Id = -1;
                            taskData.Date = taskDate;
                            taskData.Repeat = (int)EnumSchedule.Task.Once;
                            taskData.RepeatDay = -1; taskData.RepeatDayOftheWeek = -1; taskData.RepeatMonth = -1;
                            lstTaskData.Add(taskData);
                        }
                    }

                    if (lstTaskData.Count > 0)
                    {
                        SocketBackupTransportData socketTransportData = new SocketBackupTransportData();
                        socketTransportData.Date = taskDate;
                        socketTransportData.Command = EnumSocketCommands.Command.FAST_BACKUP.ToString();

                        string sValue = ObjectSerializer.SerializeToString(socketTransportData);
                        bool sended = serverClient.send(sValue);
                        //List<SocketBackupTransportData> lstBackup = ObjectSerializer.SerializeFromString<List<SocketBackupTransportData>>(sValue);

                        if (sended)
                        {
                            for (int i = 0; i < lstTaskData.Count; i++)
                            {
                                TaskDa taskDa = new TaskDa();
                                taskDa.Save(lstTaskData[i]);
                            }
                        }
                        else
                        {
                            Page.RegisterClientScriptBlock("Alert Task", "<script language='javascript'>alert('Server Error: Task not executed!')</script>");
                        }
                    }

                    loadData(DateTime.Now);
                }
                else
                {
                    Page.RegisterClientScriptBlock("Alert Task", "<script language='javascript'>alert('Error: Task not executed!')</script>");
                }
            }
            else
            {
                TaskData taskData = new TaskData();
                DateTime date = DateTime.Parse(txtDate.Text, new CultureInfo("en-US", false));
                string[] time = txtHour.Text.Split(':');
                taskData.Date = new DateTime(date.Year, date.Month, date.Day, int.Parse(time[0]), int.Parse(time[1]), 0);

                switch (drpSchedule.SelectedIndex)
                {
                    case (int)EnumSchedule.Task.Once:
                        taskData.Repeat = (int)EnumSchedule.Task.Once;
                        taskData.RepeatDayOftheWeek = -1; taskData.RepeatDay = -1; taskData.RepeatMonth = -1;
                        break;
                    case (int)EnumSchedule.Task.Dailey:
                        taskData.Repeat = (int)EnumSchedule.Task.Dailey;
                        taskData.RepeatDayOftheWeek = -1; taskData.RepeatDay = -1; taskData.RepeatMonth = -1;
                        break;
                    case (int)EnumSchedule.Task.Weekley:
                        taskData.Repeat = (int)EnumSchedule.Task.Weekley;
                        taskData.RepeatDayOftheWeek = (int)date.DayOfWeek; taskData.RepeatDay = -1; taskData.RepeatMonth = -1;
                        break;
                    case (int)EnumSchedule.Task.Monthly:
                        taskData.Repeat = (int)EnumSchedule.Task.Monthly;
                        taskData.RepeatDayOftheWeek = (int)date.DayOfWeek; taskData.RepeatDay = -1; taskData.RepeatMonth = -1;
                        break;
                    case (int)EnumSchedule.Task.Annually:
                        taskData.Repeat = (int)EnumSchedule.Task.Annually;
                        break;
                }

                TaskDa taskDa = new TaskDa();
                taskDa.Save(taskData);

               //Check the selected devices
                for (int i = 0; i < grdDevices.Rows.Count; i++)
                {
                    CheckBox chkSelectDevice = (CheckBox)grdDevices.Rows[i].Cells[0].FindControl("ChbSelect");
                    if (chkSelectDevice.Checked)
                    {
                        TaskDeviceData taskDeviceData = new TaskDeviceData();
                        taskDeviceData.Bu_device_id = int.Parse(grdDevices.DataKeys[i].Value.ToString());
                        taskDeviceData.Bu_task_id = taskData.Id;
                    }
                }

                loadData(taskData.Date);
            }
        }
コード例 #7
0
ファイル: TaskDa.cs プロジェクト: PieterTaelman/BackupProject
        private TaskData fillTask(DataSet ds,int iRow)
        {
            TaskData task = new TaskData();
            task.Id = (int)ds.Tables[0].Rows[iRow]["id"];
            string sDate = ds.Tables[0].Rows[iRow]["datefield"].ToString().Split(' ')[0] + " " + ds.Tables[0].Rows[iRow]["timefield"];
            task.Date = DateTime.Parse(sDate);
            task.Repeat = (int)ds.Tables[0].Rows[iRow]["repeat"];
            task.RepeatDayOftheWeek = (int)ds.Tables[0].Rows[iRow]["repeatDayOftheWeek"];
            task.RepeatDay = (int)ds.Tables[0].Rows[iRow]["repeatDay"];
            task.RepeatMonth = (int)ds.Tables[0].Rows[iRow]["repeatMonth"];

            return task;
        }
コード例 #8
0
ファイル: TaskDa.cs プロジェクト: PieterTaelman/BackupProject
        public void updateTask(TaskData taskData, List<Device> lstActiveDevices)
        {
            List<TaskData> lstOldTask = this.getTasks(taskData.Date);

            List<int> lstDelete = new List<int>();
            List<TaskData> lstSave = new List<TaskData>();

            for (int i = 0; i < lstOldTask.Count; i++)
            {
                //Check to delete
                bool toDelete = true;
                for (int iDevice=0; iDevice < lstActiveDevices.Count; iDevice++)
                {
                    //TaskData data = lstOldTask.Find(delegate(TaskData t) { return t.Id == lstActiveDevices[iDevice].Id; });
                    /*if (lstOldTask[i].TaskDeviceId == lstActiveDevices[iDevice].Id)
                    {
                        toDelete = false;
                        break;
                    }*/
                }

                if (toDelete)
                    lstDelete.Add(lstOldTask[i].Id);
            }

            //Check on New
            for (int iDevice = 0; iDevice < lstActiveDevices.Count; iDevice++)
            {
                bool toAdd = true;
                for (int i = 0; i < lstOldTask.Count; i++)
                {
                    /*if (lstActiveDevices[iDevice].Id == lstOldTask[i].TaskDeviceId)
                    {
                        toAdd = false;break;
                    }*/
                }

                if (toAdd)
                {
                    taskData= TaskData.Clone(taskData);
                    taskData.Id = -1;
                    lstSave.Add(taskData);
                }
            }

            //Excecute
            for (int i = 0; i < lstDelete.Count; i++)
            {
                Delete(lstDelete[i]);
            }

            for (int i = 0; i < lstSave.Count; i++)
            {
                Save(lstSave[i]);
            }
        }
コード例 #9
0
ファイル: TaskDa.cs プロジェクト: PieterTaelman/BackupProject
        public int Save(TaskData taskData)
        {
            StringBuilder sql = new StringBuilder();
            if (taskData.Id > 0)
            {
                /*sql.Append("UPDATE bu_task SET datefield='");
                sql.Append(taskData.Date.Year+""+taskData.Date.Month+""+taskData.Date.Day);
                sql.Append("',timefield="); sql.Append(taskData.Date.Hour+":"+taskData.Date.Minute);
                sql.Append("',repeat='"); sql.Append(taskData.Repeat);
                sql.Append("',repeatDayOftheWeek='"); sql.Append(taskData.RepeatDayOftheWeek);
                sql.Append("',repeatDay='"); sql.Append(taskData.RepeatDay);
                sql.Append("',repeatMonth='"); sql.Append(taskData.RepeatMonth);
                sql.Append("',bu_device_id='"); sql.Append(taskData.DeviceId);

                sql.Append("' WHERE id="); sql.Append(taskData.Id);*/
                throw new NotImplementedException();
            }
            else
            {
                sql.Append("INSERT INTO bu_task (bu_task.datefield, bu_task.timefield, bu_task.repeat,bu_task.repeatDayOftheWeek,bu_task.repeatDay,bu_task.repeatMonth) VALUES ('");
                sql.Append(taskData.Date.Year+ "" + taskData.Date.Month.ToString("D2") + "" + taskData.Date.Day.ToString("D2") + "','");
                sql.Append(taskData.Date.Hour.ToString("D2") + ":" + taskData.Date.Minute.ToString("D2") + "',");
                sql.Append(taskData.Repeat + ",");
                sql.Append(taskData.RepeatDayOftheWeek + ",");
                sql.Append(taskData.RepeatDay + ",");
                sql.Append(taskData.RepeatMonth);
                sql.Append(");");
            }
            sss
            MySqlParameterCollection sqlCollection = new MySqlDa().ExecuteNonQuery(sql.ToString());
            return (int)sqlCollection["@id"].Value;
        }
コード例 #10
0
ファイル: TaskDa.cs プロジェクト: PieterTaelman/BackupProject
        public List<TaskData> getTasks(DateTime date)
        {
            //Get all jobs for today from when the server is started
            StringBuilder SQLString = new StringBuilder();
            SQLString.Append("SELECT * FROM bu_task where (datefield='"+date.ToString("yyyyMMdd")+"' ");
            SQLString.Append("and time(timefield) > '"+date.Hour.ToString("d2")+":"+date.Minute.ToString("d2")+"' and bu_task.repeat=0) or");
            SQLString.Append("(bu_task.repeat='1' and time(timefield) > '"+date.Hour.ToString("d2")+":"+date.Minute.ToString("d2")+"') or");
            SQLString.Append("(repeatDayOfTheWeek ='"+((int)date.DayOfWeek).ToString() +"' and bu_task.repeat=2 and time(timefield) > '"+date.Hour.ToString("d2")+":"+date.Minute.ToString("d2")+"') or ");
            SQLString.Append("(repeatDay ='"+date.ToString("dd") +"' and bu_task.repeat=3 and time(timefield) > '"+date.Hour.ToString("d2")+":"+date.Minute.ToString("d2")+"') or");
            SQLString.Append("(repeatDay ='"+date.ToString("dd")+"' and repeatMonth='"+date.ToString("MM")+"' and bu_task.repeat=4 and time(timefield) > '"+date.Hour.ToString("d2")+":"+date.Minute.ToString("d2")+"')");

            DataSet ds = new MySqlDa().fillDataSet(SQLString.ToString());

            List<TaskData> lstTaskData = new List<TaskData>();

            //Create Object
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                TaskData task = new TaskData();
                task.Id = (int)ds.Tables[0].Rows[i]["id"];
                string sDate = ds.Tables[0].Rows[i]["datefield"].ToString().Split(' ')[0] + " " + ds.Tables[0].Rows[i]["timefield"];
                task.Date = DateTime.Parse(sDate);
                task.Repeat = (int)ds.Tables[0].Rows[i]["repeat"];
                task.RepeatDayOftheWeek = (int)ds.Tables[0].Rows[i]["repeatDayOftheWeek"];
                task.RepeatDay = (int)ds.Tables[0].Rows[i]["repeatDay"];
                task.RepeatMonth = (int)ds.Tables[0].Rows[i]["repeatMonth"];

                lstTaskData.Add(task);
            }

            return lstTaskData;
        }