internal TaskCollection(TaskFolder folder, V2Interop.IRegisteredTaskCollection iTaskColl, Regex filter = null)
 {
     this.svc    = folder.TaskService;
     this.Filter = filter;
     fld         = folder;
     v2Coll      = iTaskColl;
 }
        private void wizardControl1_Finished(object sender, System.EventArgs e)
        {
            if (TaskService == null)
            {
                TaskService = TaskService.Instance;
            }

            td.Data = TaskName;
            td.RegistrationInfo.Description = descText.Text;
            td.Triggers.Clear();
            td.Triggers.Add(trigger);
            td.Actions.Clear();
            td.Actions.Add(action);
            if (openDlgAfterCheck.Checked)
            {
                var dlg = new TaskEditDialog(TaskService, td, true, false, TaskName)
                {
                    StartPosition = FormStartPosition.CenterParent
                };
                if (dlg.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    td = dlg.TaskDefinition;
                }
            }
            if (RegisterTaskOnFinish)
            {
                TaskFolder fld = TaskService.RootFolder;
                if (!string.IsNullOrEmpty(TaskFolder) && TaskService.HighestSupportedVersion.CompareTo(TaskServiceVersion.V1_1) != 0)
                {
                    fld = TaskService.GetFolder(TaskFolder);
                }
                task = fld.RegisterTaskDefinition(TaskName, td, TaskCreation.CreateOrUpdate, td.Principal.ToString(), Password, td.Principal.LogonType);
            }
        }
Exemplo n.º 3
0
 internal TaskCollection([NotNull] TaskFolder folder, [NotNull] V2Interop.IRegisteredTaskCollection iTaskColl, Regex filter = null)
 {
     svc    = folder.TaskService;
     Filter = filter;
     fld    = folder;
     v2Coll = iTaskColl;
 }
Exemplo n.º 4
0
        /// <summary>Gets the path to a folder of registered tasks.</summary>
        /// <param name="folderName">
        /// The path to the folder to retrieve. Do not use a backslash following the last folder name in the path. The root task folder is specified with a
        /// backslash (\). An example of a task folder path, under the root task folder, is \MyTaskFolder. The '.' character cannot be used to specify the
        /// current task folder and the '..' characters cannot be used to specify the parent task folder in the path.
        /// </param>
        /// <returns><see cref="TaskFolder"/> instance for the requested folder or <c>null</c> if <paramref name="folderName"/> was unrecognized.</returns>
        /// <exception cref="NotV1SupportedException">Folder other than the root (\) was requested on a system not supporting Task Scheduler 2.0.</exception>
        public TaskFolder GetFolder(string folderName)
        {
            TaskFolder f = null;

            if (v2TaskService != null)
            {
                if (string.IsNullOrEmpty(folderName))
                {
                    folderName = TaskFolder.rootString;
                }
                try
                {
                    var ifld = v2TaskService.GetFolder(folderName);
                    if (ifld != null)
                    {
                        f = new TaskFolder(this, ifld);
                    }
                }
                catch (System.IO.DirectoryNotFoundException) { }
                catch (System.IO.FileNotFoundException) { }
            }
            else if (folderName == TaskFolder.rootString || string.IsNullOrEmpty(folderName))
            {
                f = new TaskFolder(this);
            }
            else
            {
                throw new NotV1SupportedException("Folder other than the root (\\) was requested on a system only supporting Task Scheduler 1.0.");
            }
            return(f);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Finds the task in folder.
        /// </summary>
        /// <param name="fld">The folder.</param>
        /// <param name="filter">The filter to use when looking for tasks.</param>
        /// <param name="results">The results.</param>
        /// <param name="recurse">if set to <c>true</c> recurse folders.</param>
        /// <returns>True if any tasks are found, False if not.</returns>
        private bool FindTaskInFolder([NotNull] TaskFolder fld, Predicate <Task> filter, ref System.Collections.Generic.List <Task> results, bool recurse = true)
        {
            foreach (Task t in fld.GetTasks())
            {
                try
                {
                    if (filter(t))
                    {
                        results.Add(t);
                    }
                }
                catch
                {
                    System.Diagnostics.Debug.WriteLine($"Unable to evaluate filter for task '{t.Path}'.");
                }
            }

            if (recurse)
            {
                foreach (var f in fld.SubFolders)
                {
                    if (FindTaskInFolder(f, filter, ref results))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 6
0
 public void EnumFolderTasks(WinTaskScheduler.TaskFolder fld)
 {
     foreach (WinTaskScheduler.Task task in fld.Tasks)
     {
         DisplayTask(task);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Checks tasks in one folder
        /// </summary>
        /// <param name="ts"></param>
        /// <param name="path"></param>
        private void CheckTasks(wts.TaskFolder folder)
        {
            foreach (wts.Task task in folder.Tasks)
            {
                try
                {
                    // if task is disabled, ignore it.
                    if (task.State == wts.TaskState.Disabled)
                    {
                        continue;
                    }
                    // if tasks is currently running, ignore it.
                    if (task.State == wts.TaskState.Running)
                    {
                        continue;
                    }

                    // if the task ran last before our last check, we already checked it
                    // so ignore it this time
                    if (task.LastRunTime < LastCheck)
                    {
                        continue;
                    }

                    // get a list of allowed exit codes for this tasks, if no custom ones found
                    // only 0 is allowed
                    List <int> allowedResultCodes = GetAllowedResults(task.Definition.RegistrationInfo.Description + "");

                    const int SCHED_S_TASK_RUNNING = 267009;
                    // also allow exit code 0x00041301 or 267009 which is SCHED_S_TASK_RUNNING
                    // why this is not covered by wts.TaskState.Running above, I don't know
                    allowedResultCodes.Add(SCHED_S_TASK_RUNNING);

                    // check whether we have an exit code that is not allowed
                    if (!allowedResultCodes.Contains(task.LastTaskResult))
                    {
                        Failures.Add(new Failure
                        {
                            Name    = task.Name,
                            Path    = task.Path,
                            LastRun = task.LastRunTime,
                            Result  = task.LastTaskResult
                        });
                    }
                }
                catch (Exception ex)
                {
                    // in any error case, also add a problem
                    Exceptions.Log(ex);
                    Failures.Add(new Failure
                    {
                        Name    = task.Name,
                        Path    = task.Path,
                        LastRun = DateTime.Now,
                        Result  = task.LastTaskResult
                    });
                }
            }
        }
Exemplo n.º 8
0
 public void Init()
 {
     _service = new TaskService();
     _folder = _service.RootFolder.SubFolders.Any(a => a.Name == "WarewolfTestFolder") ? _service.GetFolder("WarewolfTestFolder") : _service.RootFolder.CreateFolder("WarewolfTestFolder");
     var task = _service.NewTask();
         task.Actions.Add(new ExecAction("Notepad.exe"));
         _folder.RegisterTaskDefinition("TestTask", task);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskEventWatcher"/> class watching only those events for
 /// the tasks whose name matches the <paramref name="taskFilter"/> in the specified <paramref name="taskFolder"/>
 /// and optionally all subfolders.
 /// </summary>
 /// <param name="taskFolder">The task folder to watch.</param>
 /// <param name="taskFilter">The filter for task names using standard file system wildcards. Use "*" to include all tasks.</param>
 /// <param name="includeSubfolders">if set to <c>true</c> include events from tasks subfolders.</param>
 /// <exception cref="ArgumentNullException">Occurs if the <paramref name="taskFolder"/> is <c>null</c>.</exception>
 public TaskEventWatcher([NotNull] TaskFolder taskFolder, string taskFilter = "*", bool includeSubfolders = false) : this(taskFolder?.TaskService)
 {
     if (taskFolder == null)
     {
         throw new ArgumentNullException(nameof(taskFolder));
     }
     InitTask(taskFolder, taskFilter, includeSubfolders);
 }
Exemplo n.º 10
0
 private void SetupWatcher(TaskFolder tf)
 {
     if (tf != null)
     {
         watcher = new TaskEventWatcher(tf)
         {
             SynchronizingObject = this
         };
         watcher.EventRecorded += Watcher_EventRecorded;
         watcher.Enabled        = true;
     }
 }
Exemplo n.º 11
0
        public void Cleanup()
        {
            _folder = _service.GetFolder("WarewolfTestFolder");
            foreach (var task in _folder.Tasks)
            {
                _folder.DeleteTask(task.Name, false);
            }

            _service.RootFolder.DeleteFolder("WarewolfTestFolder");
            _service.Dispose();
            _folder.Dispose();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Handles the Click event of the okBtn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>Changed in release 1.8.4 so that when a user cancels the password dialog, it no longer throws an exception but rather displays an error.</remarks>
        private void okBtn_Click(object sender, System.EventArgs e)
        {
            if (TaskDefinition.Actions.Count == 0)
            {
                MessageBox.Show(EditorProperties.Resources.TaskMustHaveActionsError, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (TaskDefinition.Settings.DeleteExpiredTaskAfter != TimeSpan.Zero && !ValidateOneTriggerExpires())
            {
                MessageBox.Show(EditorProperties.Resources.Error_TaskDeleteMustHaveExpiringTrigger, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (TaskDefinition.LowestSupportedVersion > TaskDefinition.Settings.Compatibility)
            {
                MessageBox.Show(EditorProperties.Resources.Error_TaskPropertiesIncompatibleSimple, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (RegisterTaskOnAccept)
            {
                if (Task != null && !TaskDefinition.Principal.RequiresPassword())
                {
                    Task.RegisterChanges();
                }
                else
                {
                    var user = TaskDefinition.Principal.ToString();
                    user = string.IsNullOrEmpty(user) ? WindowsIdentity.GetCurrent().Name : user;
                    string     pwd = null;
                    TaskFolder fld = TaskService.GetFolder(TaskFolder);
                    if (TaskDefinition.Principal.RequiresPassword())
                    {
                        pwd = InvokeCredentialDialog(user, this);
                        if (pwd == null)
                        {
                            //throw new System.Security.Authentication.AuthenticationException(EditorProperties.Resources.UserAuthenticationError);
                            MessageBox.Show(EditorProperties.Resources.Error_PasswordMustBeProvided, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    Task = fld.RegisterTaskDefinition(taskPropertiesControl1.TaskName, TaskDefinition, TaskCreation.CreateOrUpdate,
                                                      user, pwd, TaskDefinition.Principal.LogonType);
                }
            }
            DialogResult = DialogResult.OK;
            Close();
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            if (this.TaskDefinition.Actions.Count == 0)
            {
                MessageBox.Show(EditorProperties.Resources.TaskMustHaveActionsError, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (this.TaskDefinition.Settings.DeleteExpiredTaskAfter != TimeSpan.Zero && !TaskEditDialog.ValidateOneTriggerExpires(this.TaskDefinition.Triggers))
            {
                MessageBox.Show(EditorProperties.Resources.Error_TaskDeleteMustHaveExpiringTrigger, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (this.TaskDefinition.LowestSupportedVersion > this.TaskDefinition.Settings.Compatibility)
            {
                MessageBox.Show(EditorProperties.Resources.Error_TaskPropertiesIncompatibleSimple, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (RegisterTaskOnAccept)
            {
                if (this.Task != null && this.Task.Definition.Principal.LogonType != TaskLogonType.InteractiveTokenOrPassword && this.Task.Definition.Principal.LogonType != TaskLogonType.Password)
                {
                    this.Task.RegisterChanges();
                }
                else
                {
                    string     user = this.TaskDefinition.Principal.ToString();
                    string     pwd  = null;
                    TaskFolder fld  = this.TaskService.GetFolder(this.TaskFolder);
                    if (this.TaskDefinition.Principal.LogonType == TaskLogonType.InteractiveTokenOrPassword || this.TaskDefinition.Principal.LogonType == TaskLogonType.Password)
                    {
                        pwd = TaskEditDialog.InvokeCredentialDialog(user, this);
                        if (pwd == null)
                        {
                            //throw new System.Security.Authentication.AuthenticationException(EditorProperties.Resources.UserAuthenticationError);
                            MessageBox.Show(EditorProperties.Resources.Error_PasswordMustBeProvided, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    this.Task = fld.RegisterTaskDefinition(this.TaskName, this.TaskDefinition, TaskCreation.CreateOrUpdate,
                                                           user, pwd, this.TaskDefinition.Principal.LogonType);
                }
            }
            this.DialogResult = DialogResult.OK;
            Close();
        }
Exemplo n.º 14
0
        private void ProcessFolder(wts.TaskFolder folder, string filter)
        {
            foreach (wts.TaskFolder subFolder in folder.SubFolders)
            {
                if (filter != "")
                {
                    if (!Regex.IsMatch(subFolder.Name, filter, RegexOptions.IgnoreCase))
                    {
                        continue;
                    }
                }

                CheckTasks(subFolder);
                ProcessFolder(subFolder, "");
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Finds the task in folder.
        /// </summary>
        /// <param name="fld">The folder.</param>
        /// <param name="taskName">The wildcard expression to compare task names with.</param>
        /// <param name="results">The results.</param>
        /// <param name="recurse">if set to <c>true</c> recurse folders.</param>
        /// <returns>True if any tasks are found, False if not.</returns>
        private bool FindTaskInFolder([NotNull] TaskFolder fld, System.Text.RegularExpressions.Regex taskName, ref System.Collections.Generic.List <Task> results, bool recurse = true)
        {
            results.AddRange(fld.GetTasks(taskName));

            if (recurse)
            {
                foreach (var f in fld.SubFolders)
                {
                    if (FindTaskInFolder(f, taskName, ref results))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Runs the actual checks, sets the Problem count and string
        /// </summary>
        /// <returns></returns>
        public int Check()
        {
            // check for the correct setup, if one of the checks fails, exit right away.
            // with the new wrapper, it seems to work without being an admin
            //     if (!IsAdmin()) return SetProblem(AppName + " does not run as an administrator. This is required");
            if (Environment.OSVersion.Version.Major < 6)
            {
                return(SetProblem("Windows Vista or newer is required"));
            }
            if (!IsServiceRunning())
            {
                return(SetProblem("The Task Scheduler service is not running"));
            }
            if (RootFolderPattern == "")
            {
                return(SetProblem("No RootFolderPattern set, check your config file."));
            }

            try
            {
                using (wts.TaskService ts = new wts.TaskService())
                {
                    wts.TaskFolder root = ts.RootFolder;

                    if (CheckRootTasks)
                    {
                        CheckTasks(root);
                    }

                    ProcessFolder(root, RootFolderPattern);
                }
            }
            catch (Exception ex)
            {
                Exceptions.Log(ex);
                Failures.Add(new Failure
                {
                    Name    = "Application Exception",
                    Path    = ex.Message,
                    LastRun = DateTime.Now,
                    Result  = _appErrorId,
                });
            }

            // return the number of problems found
            return(Failures.Count);
        }
Exemplo n.º 17
0
 internal void Persist([NotNull] TaskFolder folder, AccessControlSections includeSections = Task.defaultAccessControlSections)
 {
     WriteLock();
     try
     {
         AccessControlSections accessControlSectionsFromChanges = GetAccessControlSectionsFromChanges();
         if (accessControlSectionsFromChanges != AccessControlSections.None)
         {
             folder.SetSecurityDescriptorSddlForm(GetSecurityDescriptorSddlForm(accessControlSectionsFromChanges));
             OwnerModified = GroupModified = AccessRulesModified = AuditRulesModified = false;
         }
     }
     finally
     {
         WriteUnlock();
     }
 }
 internal void Persist(TaskFolder folder, AccessControlSections includeSections = AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner)
 {
     base.WriteLock();
     try
     {
         AccessControlSections accessControlSectionsFromChanges = this.GetAccessControlSectionsFromChanges();
         if (accessControlSectionsFromChanges != AccessControlSections.None)
         {
             folder.SetSecurityDescriptorSddlForm(this.GetSecurityDescriptorSddlForm(includeSections), TaskSecurity.Convert(includeSections));
             base.OwnerModified = base.GroupModified = base.AccessRulesModified = base.AuditRulesModified = false;
         }
     }
     finally
     {
         base.WriteUnlock();
     }
 }
Exemplo n.º 19
0
        private void wizardControl1_Finished(object sender, System.EventArgs e)
        {
            bool myTS = false;

            if (TaskService == null)
            {
                TaskService = new TaskService();
                myTS        = true;
            }

            td.Data = TaskName;
            td.RegistrationInfo.Description = descText.Text;
            td.Triggers.Clear();
            td.Triggers.Add(trigger);
            td.Actions.Clear();
            td.Actions.Add(action);
            if (openDlgAfterCheck.Checked)
            {
                TaskEditDialog dlg = new TaskEditDialog();
                dlg.Editable = true;
                dlg.Initialize(TaskService, td);
                dlg.RegisterTaskOnAccept = false;
                dlg.TaskName             = TaskName;
                if (dlg.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    td = dlg.TaskDefinition;
                }
            }
            if (RegisterTaskOnFinish)
            {
                TaskFolder fld = TaskService.RootFolder;
                if (!string.IsNullOrEmpty(TaskFolder) && TaskService.HighestSupportedVersion.CompareTo(new Version(1, 1)) != 0)
                {
                    fld = TaskService.GetFolder(TaskFolder);
                }
                task = fld.RegisterTaskDefinition(TaskName, td, TaskCreation.CreateOrUpdate, td.Principal.ToString(), Password, td.Principal.LogonType);
            }

            if (myTS)
            {
                TaskService = null;
            }
        }
Exemplo n.º 20
0
        private static bool CheckTaskName(string taskName)
        {
            bool result = false;

            using (Microsoft.Win32.TaskScheduler.TaskService ts = new Microsoft.Win32.TaskScheduler.TaskService())
            {
                using (Microsoft.Win32.TaskScheduler.TaskFolder taskFolder = ts.GetFolder(@"\"))
                {
                    foreach (Task t in taskFolder.Tasks)
                    {
                        if (t.Name.Contains(taskName))
                        {
                            result = true;
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 21
0
        private void RefreshTasks()
        {
            DGV_taskBackumsoutlook.Rows.Clear();

            using (Microsoft.Win32.TaskScheduler.TaskService ts = new Microsoft.Win32.TaskScheduler.TaskService())
            {
                using (Microsoft.Win32.TaskScheduler.TaskFolder taskFolder = ts.GetFolder(@"\"))
                {
                    foreach (Task t in taskFolder.Tasks)
                    {
                        if (t.Name.Contains("backupmsoutlook_"))
                        {
                            TaskDefinition td      = t.Definition;
                            string         lastRun = t.LastRunTime.ToString();
                            if (lastRun.Contains("1899"))
                            {
                                lastRun = string.Empty;
                            }
                            string actions = td.Actions[0].ToString();
                            if (actions.Contains("\t"))
                            {
                                actions = actions.Replace("\t", " -> ");
                            }
                            string[] row = new string[] { t.Name, t.State.ToString(), actions, t.NextRunTime.ToString(), lastRun, "0x" + t.LastTaskResult, td.RegistrationInfo.Author, td.RegistrationInfo.Date.ToString() };
                            DGV_taskBackumsoutlook.Rows.Add(row);
                            DGV_taskBackumsoutlook.Rows[DGV_taskBackumsoutlook.Rows.Count - 1].Selected = true;
                        }
                    }
                }
            }

            if (DGV_taskBackumsoutlook.Rows.Count > 0)
            {
                DGV_taskBackumsoutlook.Rows[0].Cells[0].Selected = false;
                DGV_taskBackumsoutlook.Rows[DGV_taskBackumsoutlook.Rows.Count - 1].Selected = true;
            }
        }
 internal static void FolderTaskAction(TaskFolder fld, Action<TaskFolder> fldAction, Action<Task> taskAction, int level = 0)
 {
     if (fldAction != null)
         fldAction(fld);
     if (taskAction != null)
         foreach (var task in fld.Tasks)
             taskAction(task);
     foreach (var sfld in fld.SubFolders)
         FolderTaskAction(sfld, fldAction, taskAction, level + 1);
 }
Exemplo n.º 23
0
 public Dev2TaskFolder(ITaskServiceConvertorFactory taskServiceConvertorFactory, TaskFolder instance)
 {
     _taskServiceConvertorFactory = taskServiceConvertorFactory;
     _instance = instance;
 }
Exemplo n.º 24
0
        private int Walk(TaskFolder fo) {
            int n = 0;
            foreach (var t in fo.Tasks) {
                try {
                    String s = t.Xml;
                }
                catch (Exception err) {
                    FlowLayoutPanel flp = new FlowLayoutPanel();
                    PictureBox pb = new PictureBox();
                    pb.Image = Resources.warn;
                    pb.SizeMode = PictureBoxSizeMode.AutoSize;
                    pb.Parent = flp;
                    pb.Anchor = AnchorStyles.Left;

                    String fp = Environment.SystemDirectory + "\\Tasks\\" + t.Path.TrimStart('\\');

                    LinkLabel ll = new LinkLabel();
                    ll.AutoSize = true;
                    ll.Text = t.Path;
                    ll.Parent = flp;
                    ll.Anchor = AnchorStyles.Left;
                    ll.LinkClicked += delegate {
                        Process.Start("explorer.exe", " /select,\"" + fp + "\"");
                    };

                    {
                        Button b = new Button();
                        b.Text = "例外情報";
                        b.AutoSize = true;
                        b.Anchor = AnchorStyles.Left;
                        b.Parent = flp;
                        b.Click += delegate {
                            MessageBox.Show(this, err.Message);
                        };
                    }
                    {
                        Button b = new Button();
                        b.Text = "デスクトップへ複製する";
                        b.AutoSize = true;
                        b.Anchor = AnchorStyles.Left;
                        b.Parent = flp;
                        b.Click += delegate {
                            File.Copy(fp, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Path.GetFileName(fp)));
                            MessageBox.Show(this, "完了");
                        };
                    }
                    {
                        Button b = new Button();
                        b.Text = "デスクトップへ移動する";
                        b.AutoSize = true;
                        b.Anchor = AnchorStyles.Left;
                        b.Parent = flp;
                        b.Click += delegate {
                            if (MessageBox.Show(this, "元の場所からは無くなります。", "", MessageBoxButtons.OKCancel) == DialogResult.OK) {
                                File.Move(fp, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Path.GetFileName(fp)));
                                MessageBox.Show(this, "完了");
                            }
                        };
                    }

                    flp.AutoSize = true;
                    flp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                    flp.Parent = flpE;

                    flpE.SetFlowBreak(flp, true);
                    n++;
                }
            }
            foreach (var sf in fo.SubFolders)
                n += Walk(sf);
            return n;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskSecurity" /> class with the specified sections of the access control security rules from the specified task.
 /// </summary>
 /// <param name="folder">The folder.</param>
 /// <param name="sections">The sections of the ACL to retrieve.</param>
 public TaskSecurity(TaskFolder folder, AccessControlSections sections = System.Security.AccessControl.AccessControlSections.Access | System.Security.AccessControl.AccessControlSections.Owner | System.Security.AccessControl.AccessControlSections.Group)
     : base(false)
 {
     this.SetSecurityDescriptorSddlForm(folder.GetSecurityDescriptorSddlForm(TaskSecurity.Convert(sections)));
 }
Exemplo n.º 26
0
 internal V2TaskEnumerator(TaskFolder folder, V2Interop.IRegisteredTaskCollection iTaskColl, Regex filter = null) :
     base(iTaskColl, o => Task.CreateTask(folder.TaskService, (V2Interop.IRegisteredTask)o))
 {
     this.filter = filter;
 }
Exemplo n.º 27
0
        public static Report GetScheduledReport(TaskFolder taskFolder, string reportPath, string reportGUID, string scheduleGUID, Repository repository)
        {
            Report report = null;
            if (File.Exists(reportPath)) report = Report.LoadFromFile(reportPath, repository);

            if (!File.Exists(reportPath) || (report != null && report.GUID != reportGUID))
            {
                //Report has been moved or renamed: search report from its GUID in the report folder
                report = repository.FindReport(repository.ReportsFolder, reportGUID);
                if (report == null)
                {
                    //Remove the schedules of the report
                    foreach (Task oldTask in taskFolder.GetTasks().Where(i => i.Definition.RegistrationInfo.Source.EndsWith(scheduleGUID)))
                    {
                        taskFolder.DeleteTask(oldTask.Name);
                    }
                }
            }
            return report;
        }
Exemplo n.º 28
0
        void StepThroughEachTaskSubFolder(TaskFolder fold)
        {
            string taskName, taskDescription;

            foreach (Task task in fold.Tasks)
            {
                taskName = task.Name;
                taskDescription = task.Definition.RegistrationInfo.Description;
                ScheduledTask st = new ScheduledTask(taskName, taskDescription);
                st.CopyTriggers(task.Definition.Triggers.ToList());
                try
                {

                    List<ExecAction> actions = task.Definition.Actions.Cast<ExecAction>().ToList();
                    st.CopyActions(actions);

                }
                catch (Exception e)
                {
                }
                scheduledTasks.Add(st);
            }

            foreach (TaskFolder tf in fold.SubFolders)
            {
                StepThroughEachTaskSubFolder(tf);
            }
        }
 internal V2TaskEnumerator(TaskFolder folder, TaskScheduler.V2Interop.IRegisteredTaskCollection iTaskColl, Regex filter = null)
 {
     this.fld    = folder;
     this.iEnum  = iTaskColl.GetEnumerator();
     this.filter = filter;
 }
Exemplo n.º 30
0
 public ITaskFolder CreateRootFolder(TaskFolder taskFolder)
 {
     return new Dev2TaskFolder(this, taskFolder);
 }
Exemplo n.º 31
0
 private static Task loadTask(string name, TaskFolder folder = null) {
     if (folder == null)
         folder = loadTaskFolder();
     TaskCollection tasks = folder.GetTasks();
     return tasks.FirstOrDefault(x => x.Name == name);
 }
        /// <summary>
        /// Finds the task in folder.
        /// </summary>
        /// <param name="fld">The folder.</param>
        /// <param name="taskName">The wildcard expression to compare task names with.</param>
        /// <param name="results">The results.</param>
        /// <param name="recurse">if set to <c>true</c> recurse folders.</param>
        /// <returns>True if any tasks are found, False if not.</returns>
        private bool FindTaskInFolder(TaskFolder fld, System.Text.RegularExpressions.Regex taskName, ref System.Collections.Generic.List<Task> results, bool recurse = true)
        {
            results.AddRange(fld.GetTasks(taskName));

            if (recurse)
            {
                foreach (var f in fld.SubFolders)
                {
                    if (FindTaskInFolder(f, taskName, ref results, recurse))
                        return true;
                }
            }
            return false;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskSecurity" /> class with the specified sections of the access control security rules from the specified task.
 /// </summary>
 /// <param name="folder">The folder.</param>
 /// <param name="sections">The sections of the ACL to retrieve.</param>
 public TaskSecurity(TaskFolder folder, AccessControlSections sections = System.Security.AccessControl.AccessControlSections.Access | System.Security.AccessControl.AccessControlSections.Owner | System.Security.AccessControl.AccessControlSections.Group)
     : base(false)
 {
     this.SetSecurityDescriptorSddlForm(folder.GetSecurityDescriptorSddlForm(TaskSecurity.Convert(sections)));
 }
 private void ShowFolder(TaskFolder folder)
 {
     if (folderPanel == null)
     {
         folderPanel = new FolderPanel();
         splitContainer1.Panel2.Controls.Add(folderPanel);
         folderPanel.Dock = DockStyle.Fill;
     }
     folderPanel.Tasks = folder.Tasks;
     ShowPanel(folderPanel);
 }
 static void FindTaskWithComAction(System.IO.TextWriter output, TaskFolder tf)
 {
     foreach (Task t in tf.Tasks)
     {
         foreach (Microsoft.Win32.TaskScheduler.Action ac in t.Definition.Actions)
         {
             ComHandlerAction a = ac as ComHandlerAction;
             if (a == null)
                 continue;
             string name = null, model = null, path = null, asm = null;
             try
             {
                 Microsoft.Win32.RegistryKey k = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("CLSID\\" + a.ClassId.ToString("B"));
                 if (k == null)
                     k = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("Wow6432Node\\CLSID\\" + a.ClassId.ToString("B"));
                 name = k.GetValue(null, "").ToString();
                 Microsoft.Win32.RegistryKey sk = k.OpenSubKey("InprocServer32");
                 path = sk.GetValue(null, "").ToString();
                 if (!string.IsNullOrEmpty(path))
                 {
                     try
                     {
                         System.Reflection.AssemblyName.GetAssemblyName(path);
                         asm = "Yes";
                     }
                     catch { asm = "No"; }
                 }
                 model = sk.GetValue("ThreadingModel", "").ToString();
             }
             catch { }
             output.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}", t.Path, t.Name, a.ClassId, a.Data, name, path, model, asm);
         }
     }
     foreach (var f in tf.SubFolders)
     {
         FindTaskWithComAction(output, f);
     }
 }
Exemplo n.º 36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskSecurity" /> class with the specified sections of the access control security rules from the specified task.
 /// </summary>
 /// <param name="folder">The folder.</param>
 /// <param name="sections">The sections of the ACL to retrieve.</param>
 public TaskSecurity([NotNull] TaskFolder folder, AccessControlSections sections = Task.defaultAccessControlSections)
     : base(false)
 {
     SetSecurityDescriptorSddlForm(folder.GetSecurityDescriptorSddlForm(Convert(sections)), sections);
 }
        static void FindTaskWithPropertyInFolder(System.IO.TextWriter output, TaskFolder tf, string arg, System.Text.RegularExpressions.Match match = null)
        {
            if (match == null)
                match = System.Text.RegularExpressions.Regex.Match(arg, "^(\\.?\\w+)+\\s*(==|!=)\\s*\\\"([^\"]*)\\\"$");
            if (!match.Success)
                return;

            foreach (Task t in tf.Tasks)
            {
                try
                {
                    bool found = false;
                    System.Reflection.PropertyInfo pi;
                    Object lastObj = t;
                    int i;
                    for (i = 0; i < match.Groups[1].Captures.Count && lastObj != null; i++)
                    {
                        string prop = match.Groups[1].Captures[i].Value.TrimStart('.');
                        pi = lastObj.GetType().GetProperty(prop);
                        if (pi == null)
                        {
                            output.WriteLine("Unable to locate property {0}", prop);
                            return;
                        }
                        lastObj = pi.GetValue(lastObj, null);
                    }
                    if (i == match.Groups[1].Captures.Count)
                    {
                        string res = (lastObj == null) ? string.Empty : lastObj.ToString();
                        found = res.Equals(match.Groups[3].Value, StringComparison.InvariantCultureIgnoreCase);
                        if (match.Groups[2].Value == "!=")
                            found = !found;
                        if (found)
                            output.WriteLine("+ {1} ({2})({4})\n\r== {3}", t.Name, t.Path, t.State, res, t.Definition.Settings.Compatibility);
                    }
                }
                catch { }
            }

            TaskFolderCollection tfs = tf.SubFolders;
            if (tfs.Count > 0)
            {
                try
                {
                    foreach (TaskFolder sf in tfs)
                        FindTaskWithPropertyInFolder(output, sf, arg, match);
                }
                catch (Exception ex)
                {
                    output.WriteLine(ex.ToString());
                }
            }
        }
Exemplo n.º 38
0
 public static ReportSchedule GetReportSchedule(TaskFolder taskFolder, Report report, string scheduleGUID)
 {
     ReportSchedule schedule = report.Schedules.FirstOrDefault(i => i.GUID == scheduleGUID);
     if (schedule == null)
     {
         //Remove the schedule
         foreach (Task oldTask in taskFolder.GetTasks().Where(i => i.Definition.RegistrationInfo.Source.EndsWith(scheduleGUID)))
         {
             taskFolder.DeleteTask(oldTask.Name);
         }
     }
     return schedule;
 }
Exemplo n.º 39
0
 internal V2TaskEnumerator(TaskFolder folder, V2Interop.IRegisteredTaskCollection iTaskColl, Regex filter = null) :
     base(() => iTaskColl.Count, (object o) => iTaskColl[o], o => Task.CreateTask(folder.TaskService, o))
 {
     this.filter = filter;
 }
 internal void Persist(TaskFolder folder, AccessControlSections includeSections = AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner)
 {
     base.WriteLock();
     try
     {
         AccessControlSections accessControlSectionsFromChanges = this.GetAccessControlSectionsFromChanges();
         if (accessControlSectionsFromChanges != AccessControlSections.None)
         {
             folder.SetSecurityDescriptorSddlForm(this.GetSecurityDescriptorSddlForm(includeSections), TaskSecurity.Convert(includeSections));
             base.OwnerModified = base.GroupModified = base.AccessRulesModified = base.AuditRulesModified = false;
         }
     }
     finally
     {
         base.WriteUnlock();
     }
 }
Exemplo n.º 41
0
 private void InitTask(TaskFolder taskFolder, string taskFilter, bool includeSubfolders)
 {
     this.includeSubfolders = includeSubfolders;
     Filter.TaskName        = taskFilter;
     Folder = taskFolder?.Path;
 }