protected override async Task <int> OnExecuteAsync(CommandLineApplication app) { try { Log.Information("登录账号 {Username} 中...", AppConfig.Username); CxSignClient client = null; if (string.IsNullOrEmpty(AppConfig.Fid)) { client = await CxSignClient.LoginAsync(AppConfig.Username, AppConfig.Password); } else { client = await CxSignClient.LoginAsync(AppConfig.Username, AppConfig.Password, AppConfig.Fid); } Log.Information("登录账号 {Username} 成功", AppConfig.Username); var imParams = await client.GetImTokenAsync(); // 上传文件夹下所有图片 if (!Directory.Exists("Images")) { Directory.CreateDirectory("Images"); } DirectoryInfo di = new DirectoryInfo("Images"); FileSystemInfo[] fis = di.GetFileSystemInfos(); foreach (FileSystemInfo fi in fis) { if ((fi.Attributes & FileAttributes.Directory) != FileAttributes.Directory) { Log.Information("正在上传: {FileName} ...", fi.Name); ImageIds.Add(await client.UploadImageAsync("Images/" + fi.Name)); Log.Information("上传成功, Objectid = {Objectid}", ImageIds[^ 1]);
protected async override Task <int> OnExecuteAsync(CommandLineApplication app) { Log.Information("正在登录 {User}...", Username); try { CxSignClient client = null; if (string.IsNullOrEmpty(Fid)) { client = await CxSignClient.LoginAsync(Username, Password); } else { client = await CxSignClient.LoginAsync(Username, Password, Fid); } Log.Information("成功登录账号 {User} ", Username); // 保存登录信息 AppConfig.Username = Username; AppConfig.Password = Password; AppConfig.Fid = Fid; SaveAppConfig(); // 创建 Email 配置文件 Email.LoadEmailConfig(); Email.SaveEmailConfig(); Log.Information("获取课程数据中..."); var courses = await client.GetCoursesAsync(); Directory.CreateDirectory("Courses"); foreach (var course in courses) { Log.Information($"发现课程:{{a}}-{course.ClassName} ({course.CourseId},{course.ClassId})", course.CourseName); File.WriteAllText($"Courses/{course.CourseId}-{course.ClassId}.json", JsonConvert.SerializeObject(course)); } Console.WriteLine(); Log.Warning("\"./Courses\" 文件夹中每个文件对应一门课程, 不需要签到的课程请删除对应文件"); Log.Warning("执行 {a} 开始自动签到", "dotnet ./cx-auto-sign.dll work"); Directory.CreateDirectory("Images"); Log.Information("程序执行完毕."); } catch (Exception ex) { Log.Error(ex.Message); Log.Error(ex.StackTrace); } return(await base.OnExecuteAsync(app)); }
public async Task UpdateAsync() { Log.Information("正在登录账号:{Username}", Username); var client = await CxSignClient.LoginAsync(Username, Password, Fid); Log.Information("成功登录账号"); Log.Information("获取课程数据中..."); await client.GetCoursesAsync(_courses); foreach (var(_, course) in _courses) { Log.Information("发现课程:{CourseName}-{ClassName} ({CourseId}, {ClassId})", course["CourseName"], course["ClassName"], course["CourseId"], course["ClassId"]); } Save(); }