private void ExecuteWeeklyTask() { if (args.Length < 2) { OutputWeeklyTaskList(); return; } switch (args [1].ToLowerInvariant()) { case Constants.WeeklyAdd: { if (args.Length < 4) { OutputWeeklyTaskList(); } string username = args [2]; var amount = (UInt64) Misc.String2Number(args [3]); string creator = IoEnvironment.GetUserName(); var dateTime = new DateTime(DateTime.UtcNow.Ticks); var newWeeklyTask = new WeeklyTask { Creator = creator, Uid = 0, //TODO: get UID from username Credits = amount, Username = username, WeeklyTaskStatus = WeeklyTaskStatus.Enabled, Notes = amount.FormatSize() + " From " + creator, DateTimeStart = dateTime, DateTimeStop = dateTime.AddYears(1), }; List<WeeklyTask> weeklyTasks = taskConfiguration.WeeklyTasks.ToList(); weeklyTasks.Add(newWeeklyTask); taskConfiguration.WeeklyTasks = weeklyTasks.ToArray(); SaveConfiguration(); break; } case Constants.WeeklyDel: { if (args.Length < 3) { OutputWeeklyTaskList(); } string username = args [2]; List<WeeklyTask> weeklyTasks = taskConfiguration.WeeklyTasks.ToList(); List<WeeklyTask> list = weeklyTasks.FindAll(task => task.Username == username); foreach (WeeklyTask weeklyTask in list) { weeklyTasks.Remove(weeklyTask); } taskConfiguration.WeeklyTasks = weeklyTasks.ToArray(); SaveConfiguration(); break; } case Constants.WeeklyCheck: { List<WeeklyTask> weeklyTasks = taskConfiguration.WeeklyTasks.ToList(); var dateTime = new DateTime(DateTime.UtcNow.Ticks); foreach (WeeklyTask weeklyTask in weeklyTasks.Where(weeklyTask => weeklyTask.WeeklyTaskStatus == WeeklyTaskStatus.Enabled)) { if (weeklyTask.DateTimeStop < dateTime) { weeklyTask.WeeklyTaskStatus = WeeklyTaskStatus.Disabled; } else { Misc.ExecuteSiteCommand(String.Format("{0} credits {1}", weeklyTask.Username, weeklyTask.Credits)); } } taskConfiguration.WeeklyTasks = weeklyTasks.ToArray(); SaveConfiguration(); break; } default: { break; } } }
public string FormatWeeklyTask(string line, WeeklyTask weeklyTask) { string formatWeeklyTask = MinimumLength(line) || weeklyTask == null ? line : String.Format(new MyFormat(), line , weeklyTask.WeeklyTaskStatus // {0} , weeklyTask.Uid // {1} , weeklyTask.Username // {2} , weeklyTask.Creator // {3} , weeklyTask.Credits.FormatSize() // {4} , weeklyTask.DateTimeStart // {5} , weeklyTask.DateTimeStop // {6} , weeklyTask.Notes // {7} , Constants.CodeNewLine); //{8} Log.Debug("FormatWeeklyTask: " + formatWeeklyTask); return formatWeeklyTask; }