예제 #1
0
        /// <summary>
        /// Open the Scheduled Tasks Form with blank data so that a new record may be entered.
        /// </summary>
        /// <remarks>Created: Theo Crous 18/09/2012</remarks>
        protected override void OnNewRecord()
        {
            try
            {
                base.OnNewRecord();

                //ScheduledTaskForm childForm = new ScheduledTaskForm();
                //TODO: Add Mainform refelction method call
                //ShowForm(childForm);
                //   TaskDescriptor task = new TaskDescriptor();
                //http://technet.microsoft.com/en-us/library/cc766266.aspx
                //using (TaskService ts = new TaskService("\\HENKO-PC", "Henko", "HENKO-PC", "rabbit"))
                using (TaskService ts = new TaskService())
                {
                    TaskDefinition task       = ts.NewTask();
                    TaskEditDialog editorForm = new TaskEditDialog();
                    editorForm.Editable = true;
                    editorForm.Initialize(ts, task);
                    if (editorForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        if (editorForm.TaskName != string.Empty)
                        {
                            ts.RootFolder.RegisterTaskDefinition(editorForm.TaskName, editorForm.TaskDefinition);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
예제 #2
0
 private void createTaskBtn_Click(object sender, EventArgs e)
 {
     using (var taskService = new TaskService())
     {
         var taskDialog = new TaskEditDialog(taskService);
         taskDialog.ShowDialog();
     }
 }
예제 #3
0
파일: FormInit.cs 프로젝트: ATai2/initData
        private void btnTask_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbExePath.Text.Trim()))
            {
                MessageBox.Show("请选择执行文件");
                return;
            }
            var exePath = tbExePath.Text.Trim();

            //            TaskService.Instance.AddTask("test", QuickTriggerType.Daily, "initData.exe");
            using (TaskService ts = new TaskService())
            {
                DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month
                                           , DateTime.Now.Day, 0, 0, 0);
                var    list         = ts.AllTasks;
                string taskName     = lbTaskName.Text.Trim();
                var    taskNameList = new List <string>();
                foreach (var task in list)
                {
                    taskNameList.Add(task.Name);
                }

                if (taskNameList.Contains(taskName))
                {
                    ts.RootFolder.DeleteTask(taskName);
                }

                var addTask = ts.AddTask(taskName, new DailyTrigger()
                {
                    StartBoundary = dt,
                    EndBoundary   = dt + TimeSpan.FromDays(10000),

                    Enabled = true
                }, new ExecAction(exePath));
                var definition = addTask.Definition;
                definition.RegistrationInfo.Description        = "发票备份,每天00:00:00开始执行";
                definition.Settings.DisallowStartIfOnBatteries = false;
                definition.Settings.Enabled           = true;
                definition.Settings.MultipleInstances = TaskInstancesPolicy.StopExisting;
//                definition.Settings.RestartInterval=TimeSpan.FromSeconds(100);
//                definition.Settings.Compatibility
//                definition.Settings.ExecutionTimeLimit = TimeSpan.FromMinutes(2);
//                definition.Settings.IdleSettings.IdleDuration = TimeSpan.FromMinutes(3);
//                definition.Settings.AllowDemandStart = true;
                definition.Settings.Priority = ProcessPriorityClass.High;
                definition.Settings.StopIfGoingOnBatteries = false;
                //definition.Settings.
                TaskEditDialog edit = new TaskEditDialog();
//                edit.
                edit.Editable             = true;
                edit.RegisterTaskOnAccept = true;
                edit.Initialize(addTask);
                edit.ShowDialog();

                //                ts.RootFolder.DeleteTask("ksd");
//                int i = 0;
            }
        }
예제 #4
0
 public static List <Task> EditTask(List <Task> tasks)
 {
     if (tasks.Count > 0)
     {
         TaskEditDialog editorForm = new TaskEditDialog(tasks.First());
         editorForm.ShowDialog();
     }
     return(tasks);
 }
 static TaskDefinition DisplayTask(TaskService ts, TaskDefinition td, bool editable)
 {
     if (editorForm == null)
     {
         editorForm = new TaskEditDialog();
     }
     editorForm.Editable = editable;
     editorForm.Initialize(ts, td);
     editorForm.RegisterTaskOnAccept = true;
     editorForm.AvailableTabs        = AvailableTaskTabs.All;
     return((editorForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) ? editorForm.TaskDefinition : null);
 }
예제 #6
0
 private void editTaskBtn_Click(object sender, EventArgs e)
 {
     using (var taskService = new TaskService())
     {
         var task = taskService.GetTask(_path);
         if (task != null)
         {
             var taskDialog = new TaskEditDialog(task, true);
             taskDialog.ShowDialog();
         }
     }
 }
예제 #7
0
        public void EditTask(string taskName = defaultTaskName)
        {
            Microsoft.Win32.TaskScheduler.Task t = TaskService.Instance.GetTask(taskName);
            if (t == null)
            {
                return;
            }

            TaskEditDialog editorForm = new TaskEditDialog(t, true, true);

            editorForm.ShowDialog();
        }
예제 #8
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                if (taskListView.SelectedIndex < 0)
                {
                    return;
                }

                if (string.IsNullOrEmpty(TaskNameSelected))
                {
                    return;
                }

                using (TaskService ts = new TaskService())
                {
                    if (ts.RootFolder.SubFolders.Exists(TASK_FOLDER))
                    {
                        TaskFolder tf = ts.GetFolder(TASK_FOLDER);

                        foreach (Task task in tf.Tasks)
                        {
                            if (task.Name != TaskNameSelected)
                            {
                                continue;
                            }
                            // Edit task and re-register if user clicks Ok
                            TaskEditDialog frm = new TaskEditDialog(task);
                            frm.AvailableTabs       |= AvailableTaskTabs.RunTimes;
                            frm.RegisterTaskOnAccept = true;
                            frm.ShowDialog(this);
                            break;
                        }
                    }
                }

                DisplayTaskScheduleItems();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
예제 #9
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                EnableScheduleButtons(false);

                using (TaskService ts = new TaskService())
                {
                    Task target = ts.GetTask(TaskName);
                    if (target == null)
                    {
                        GetTaskTemplate();
                        target = ts.GetTask(TaskName);
                    }
                    using (target)
                    {
                        //// Edit task and re-register if user clicks Ok
                        using (TaskEditDialog editorForm = new TaskEditDialog(target)
                        {
                            Editable = true,
                            RegisterTaskOnAccept = true
                        })
                        {
                            editorForm.AvailableTabs |= AvailableTaskTabs.RunTimes;

                            editorForm.ShowDialog();
                        }
                    }
                }
                btnGetSchedules_Click(sender, e);
            }
            catch (Exception ex)
            {
                Log.Error("btnEdit_Click has thrown: ", ex);
                MessageBox.Show(this, ex.Message, "Edit Schedule Task");
            }
            finally
            {
                EnableScheduleButtons(true);
            }
        }
예제 #10
0
        //protected override IQueryable GetQueryable()
        //{
        //    return GetTasks().AsQueryable<TaskDescriptor>();
        //}

        /// <summary>
        /// Open the Scheduled Tasks form for the record indicated in the parameter.
        /// </summary>
        /// <param name="Id">The id (primary key) of the record to open.</param>
        /// <remarks>Created: Theo Crous 14/11/2011</remarks>
        protected override void OnOpenRecord(long Id)
        {
            try
            {
                base.OnOpenRecord(Id);

                string task = (GetTasks().AsQueryable <TaskDescriptor>()).Where(n => n.Id == Id).Select(n => n.Name).FirstOrDefault();
                //http://technet.microsoft.com/en-us/library/cc766266.aspx
                //using (TaskService ts = new TaskService("\\HENKO-PC", "Henko", "HENKO-PC", "rabbit"))
                using (TaskService ts = new TaskService())
                {
                    //Microsoft.Win32.TaskScheduler.TaskEditDialog ted = new TaskEditDialog(ts.RootFolder.Tasks.FirstOrDefault(n => n.Name == task.Name));
                    //TaskSchedulerWizard wis = new TaskSchedulerWizard(ts.RootFolder.Tasks.FirstOrDefault(n => n.Name == task.Name));
                    //ted.Show();

                    Task t = ts.RootFolder.Tasks.FirstOrDefault(n => n.Name == task);

                    TaskEditDialog editorForm = new TaskEditDialog();
                    editorForm.Editable = true;
                    editorForm.Initialize(t);
                    if (editorForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        ts.RootFolder.RegisterTaskDefinition(t.Name, editorForm.TaskDefinition);
                    }
                }


                //ScheduledTaskForm childForm = new ScheduledTaskForm();
                //childForm.OpenRecord(task.Name);
                //ShowForm(childForm);
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
예제 #11
0
        public static List <Task> CreateTask(List <Task> tasks)
        {
            const string taskName = "New Task";
            Task         t        = TaskService.Instance.AddTask(taskName,
                                                                 new TimeTrigger()
            {
                StartBoundary = DateTime.Now + TimeSpan.FromHours(1),
                Enabled       = false
            },
                                                                 new ShowMessageAction("Hello world", "Title"));

            // Edit task and re-register if user clicks Ok
            TaskEditDialog editorForm = new TaskEditDialog(t);

            // ** The four lines above can be replaced by using the full constructor
            // TaskEditDialog editorForm = new TaskEditDialog(t, true, true);
            editorForm.ShowDialog();

            return(new List <Task>()
            {
                t
            });
        }
예제 #12
0
 private void btnScheduleTest_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string taskName = txtTaskName.Text;
         if (string.IsNullOrEmpty(taskName))
         {
             MessageBox.Show("Please enter task name.");
             return;
         }
         var xmlScenario = XMLSerializer.SerializeObject(lstSchScenario);
         var schArgument = schBrowser + "|" + xmlScenario + "|" + hostURL + "|" + schRoleconfig.username + "|" + schRoleconfig.password;
         //Triggering scheduler using win32 dll
         using (TaskService ts = new TaskService())
         {
             // Create a new task
             //const string taskName = "CRMAutomation";
             Task t = ts.AddTask(taskName,
                                 new TimeTrigger()
             {
                 StartBoundary = DateTime.Now + TimeSpan.FromHours(1),
                 Enabled       = false,
             },
                                 new ExecAction(@"D:\AutomationFramework\Microsoft.Dynamics365.UIAutomation.AutomationScheduler\bin\Debug\Microsoft.Dynamics365.UIAutomation.AutomationScheduler.exe", schArgument, @"D:\"));
             // Edit task and re-register if user clicks Ok
             TaskEditDialog editorForm = new TaskEditDialog();
             editorForm.Editable             = true;
             editorForm.RegisterTaskOnAccept = true;
             editorForm.Initialize(t);
             // ** The four lines above can be replaced by using the full constructor
             editorForm.ShowDialog();
         }
     }
     catch (Exception ex)
     {
     }
 }
예제 #13
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            //Создаем адаптер для отображения
            var lvTasks = FindViewById <ListView>(Resource.Id.lvTasks);

            tasklist        = new TaskListAdapter(this, UpdateTasks(true));
            lvTasks.Adapter = tasklist;

            // Initialize the "storage"
            Storage.Instance.Init();


            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;
            FloatingActionButton fabNext = FindViewById <FloatingActionButton>(Resource.Id.fabNextPage);
            FloatingActionButton fabPrev = FindViewById <FloatingActionButton>(Resource.Id.fabPrevPage);

            fabNext.Click     += FabNext_Click;
            fabPrev.Click     += FabPrev_Click;
            fabPrev.Visibility = ViewStates.Invisible;

            RadioButton rb = FindViewById <RadioButton>(Resource.Id.rbSortId);

            rb.Click += Rb_Click;
            rb        = FindViewById <RadioButton>(Resource.Id.rbSortUsename);
            rb.Click += Rb_Click;
            rb        = FindViewById <RadioButton>(Resource.Id.rbSortEmail);
            rb.Click += Rb_Click;
            rb        = FindViewById <RadioButton>(Resource.Id.rbSortStatus);
            rb.Click += Rb_Click;

            lvTasks.ItemClick += LvTasks_Click;

            // Instance dialogs and set actions when hiding dialogs
            authDialog = new AuthDialog(this);
            authDialog.OnHide(() => { // When hiding the authorization dialog, we check whether it has been completed. And if so, change the menu items
                if (!string.IsNullOrEmpty(Storage.Instance.GetToken()))
                {
                    mnuAuth.SetVisible(false);
                    mnuLogoff.SetVisible(true);
                }
            });
            taskEditDialog = new TaskEditDialog(this);
            taskEditDialog.OnHide((modified) => { // When hiding the dialog, we update the task list data if there are changes.
                if (modified)
                {
                    if (taskEditDialog.IsNewItem) // If we created a new task, then reload the data with the current sorting parameters.
                    {
                        tasklist.ListSource = UpdateTasks(false) ?? tasklist.ListSource;
                    }
                    tasklist.NotifyDataSetChanged();
                }
            });
        }
예제 #14
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            //Создаем адаптер для отображения
            var lvTasks = FindViewById <ListView>(Resource.Id.lvTasks);

            tasklist        = new TaskListAdapter(this, UpdateTasks(true));
            lvTasks.Adapter = tasklist;

            //Инициализируем "хранилище"
            Storage.Instance.Init();

            //Вешаем обработчики событий
            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;
            FloatingActionButton fabNext = FindViewById <FloatingActionButton>(Resource.Id.fabNextPage);
            FloatingActionButton fabPrev = FindViewById <FloatingActionButton>(Resource.Id.fabPrevPage);

            fabNext.Click     += FabNext_Click;
            fabPrev.Click     += FabPrev_Click;
            fabPrev.Visibility = ViewStates.Invisible; //Скрываем кнопку предидущей страницы, т.к. стартуем на первой странице.

            RadioButton rb = FindViewById <RadioButton>(Resource.Id.rbSortId);

            rb.Click += Rb_Click;
            rb        = FindViewById <RadioButton>(Resource.Id.rbSortUsename);
            rb.Click += Rb_Click;
            rb        = FindViewById <RadioButton>(Resource.Id.rbSortEmail);
            rb.Click += Rb_Click;
            rb        = FindViewById <RadioButton>(Resource.Id.rbSortStatus);
            rb.Click += Rb_Click;

            lvTasks.ItemClick += LvTasks_Click;

            //Инстансим диалоги и задаем действия при скрытии диалогов
            authDialog = new AuthDialog(this);
            authDialog.OnHide(() => { //При скрытии диалога авторизации проверяем была ли она выполнена. И если да, то меняем пункты меню
                if (!string.IsNullOrEmpty(Storage.Instance.GetToken()))
                {
                    mnuAuth.SetVisible(false);
                    mnuLogoff.SetVisible(true);
                }
            });
            taskEditDialog = new TaskEditDialog(this);
            taskEditDialog.OnHide((modified) => { //При скрытии диалога выполняем обновление данных списка задач в случае наличия изменений.
                if (modified)
                {
                    if (taskEditDialog.IsNewItem) //Если создали новую задачу, тогда перезагружаем данные с текущими параметрами сортировки.
                    {
                        tasklist.ListSource = UpdateTasks(false) ?? tasklist.ListSource;
                    }
                    tasklist.NotifyDataSetChanged();
                }
            });
        }