// ログイン async Task <string> LogOn(string userId, string password, string companyCode) { return(await Task.Run(() => { // トップページの取得 var html = wc.Get(AttendanceProURLs.LogOn); // ログイン実行 var query = QueryCreator.QueryForLogOnPage(html, userId, password, companyCode); html = wc.Post(AttendanceProURLs.LogOn, query); // ログインが正常に完了しているかのチェック ResponseValidator.ValidateLoggedIn(html); return html; })); }
IEnumerator <Task <WorkingLogSubordinate> > FetchSubordinateWorkingLogs(string html) { // 部下全員分の情報を取得 var targetSubordinates = QueryCreator.FindTargetSubordinates(html); if (targetSubordinates != null) { foreach (var targetSubordinate in targetSubordinates) { yield return(Task.Run(async() => { /* AttendanceExercisedMonthlyDetails へのアクセス */ await Task.Delay(500 + new Random().Next(500)); return await FetchSubordinateWorkingLog(html, targetSubordinate); })); } } }
async Task <WorkingLogSubordinate> FetchSubordinateWorkingLog(string html, string targetSubordinate) { return(await Task.Run(() => { var today = DateTime.Today.Day; // まずは ApprovalMonthlyへアクセスしてURLを取得する var query = QueryCreator.QueryForApprovalMonthlyPage(html, targetSubordinate); html = wc.Post(AttendanceProURLs.ApprovalMonthly, query); // AttendanceExercisedMonthlyDetails へのアクセス var url = QueryCreator.UrlForAttendanceExercisedMonthlyDetailsPage(html); html = wc.Get(url); var doc = ResponseValidator.ValidateFetchedAttendanceExercisedMonthlyDetails(html); return new WorkingLogSubordinate(doc, today); })); }
async Task <WorkingLogOwn> Attend(string userId, string password, string companyCode, AttendanceTypes type) { // ログイン後のページ var html = await LogOn(userId, password, companyCode); await Task.Run(() => { // 既に出退勤済かどうか ResponseValidator.ValidateAlreadyAttended(html, type); // 出退勤実行 var query = QueryCreator.QueryForAttendanceTableDailyPage(html, type); html = wc.Post(AttendanceProURLs.AttendanceTableDaily, query); // 出退勤が正常に完了しているかのチェック ResponseValidator.ValidateAttended(html, type); }); // 月次勤務表の情報を取得 return(await FetchOwnWorkingLog(userId, password, companyCode, withLogOn : false)); }