コード例 #1
0
        public bool Handle(HostArguments args, ITask task)
        {
            string         str;
            ServiceAccount serviceAccount;
            string         str1;
            string         str2;
            string         str3;

            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (!args.CommandArgs.TryGetValue("scheduledTask", out str3))
            {
                return(false);
            }
            ScheduledTaskConfiguration scheduledTaskConfiguration = (new ScheduledTaskConfiguration(task.Name(), this.Folder(), ScheduledTaskHandler.ExePath, ScheduledTaskHandler.ExeArgs(args))).Description(task.Description);
            Func <KeyValuePair <string, string>, bool> func       = (KeyValuePair <string, string> command) => string.Equals(command.Value, str3, StringComparison.OrdinalIgnoreCase);

            if (func(ScheduledTaskHandler.InstallCommand))
            {
                if (!args.CommandArgs.TryGetValue("account", out str))
                {
                    args.CommandArgs.TryGetValue("username", out str1);
                    args.CommandArgs.TryGetValue("password", out str2);
                    if (!string.IsNullOrWhiteSpace(str1) && !string.IsNullOrWhiteSpace(str2))
                    {
                        scheduledTaskConfiguration.RunAsUser(str1, str2);
                    }
                }
                else if (Enum.TryParse <ServiceAccount>(str, out serviceAccount))
                {
                    scheduledTaskConfiguration.RunAs(serviceAccount);
                }
                this._taskScheduler.InstallOrUpdate(scheduledTaskConfiguration);
            }
            else if (func(ScheduledTaskHandler.UninstallCommand))
            {
                this._taskScheduler.Uninstall(scheduledTaskConfiguration.Name, scheduledTaskConfiguration.Folder);
            }
            return(true);
        }
コード例 #2
0
 /// <summary>
 /// 计划任务执行日志路径。
 /// </summary>
 /// <param name="date">日期。</param>
 /// <param name="config">配置值。</param>
 /// <returns>完整路径。</returns>
 public static string ScheduleTaskLogFilePath(DateTime date, ScheduledTaskConfiguration config)
 {
     return(AppDomain.CurrentDomain.BaseDirectory + "LogFiles/ScheduleTask/" + FormatConvertor.DateTimeToDateString(date, true) + ".log");
 }