private async Task RemoveSession(Logger logger, SessionsOptions options) { logger.LogTechState("Logging out..."); await sessionManager.Logout(options.SessionName); logger.LogTechInfo("Successfully logged out"); }
private async Task AddSession(Logger logger, SessionsOptions options) { logger.LogTechState("Logging in..."); string sessionName = await sessionManager.Login(options.UserName, options.Password, options.SessionName); logger.LogTechInfo($"Successfully logged in with session name \"{sessionName}\""); }
private static bool ParseArguments(IEnumerable <string> args) { bool ProcessAppOptions(AppOptions o) { if (!string.IsNullOrWhiteSpace(o.ProxyAddress)) { int protocolLength = o.ProxyAddress.IndexOf("://"); if (!o.ProxyAddress.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)) { if (protocolLength > -1) { o.ProxyAddress = "http" + o.ProxyAddress.Substring(protocolLength); } else { o.ProxyAddress = "http://" + o.ProxyAddress; } } if (!Uri.IsWellFormedUriString(o.ProxyAddress, UriKind.Absolute)) { Console.WriteLine("Invalid proxy address"); return(false); } proxySettings = new ProxySettings { Address = o.ProxyAddress, Username = o.ProxyUsername, Password = o.ProxyPassword }; } if (o.UseMirror) { UrlManager.MirrorMode = o.UseMirror; } if (o.ServerUrl != null) { UrlManager.BaseUrl = o.ServerUrl; } return(true); } void CheckWarnProxy(RunOptions o) { if (proxySettings != null && o.NotificationMode.HasFlag(CaptchaNotificationMode.Browser)) { Console.WriteLine($"Warning: proxy usage in browser notification mode is detected{Environment.NewLine}" + "Ensure that same proxy settings are set in your default browser"); } } using (Parser parser = new Parser(cfg => { cfg.CaseInsensitiveEnumValues = true; cfg.HelpWriter = Console.Out; })) { bool success = true; parser.ParseArguments <Run2DOptions, Run3DOptions, CheckUpdatesOption, SessionsOptions>(args) .WithNotParsed(e => success = false) .WithParsed <CheckUpdatesOption>(o => checkUpdates = true) .WithParsed <Run2DOptions>(o => { if (!ProcessAppOptions(o)) { success = false; return; } appOptions = run2dOptions = o; if (o.PlacingOrderMode.HasFlag(PlacingOrderMode2D.Mask) && o.BrightnessMaskImagePath == null) { Console.WriteLine("Mask path not specified"); success = false; return; } CheckWarnProxy(o); }) .WithParsed <Run3DOptions>(o => { if (!ProcessAppOptions(o)) { success = false; return; } if (o.DocumentPath != null && o.ImagePath != null) { Console.WriteLine("Both CSV and PNG are passed, aborting"); success = false; return; } ; appOptions = run3dOptions = o; CheckWarnProxy(o); }) .WithParsed <SessionsOptions>(o => { if (!ProcessAppOptions(o)) { success = false; return; } appOptions = sessionsOptions = o; if (o.Add && o.Remove) { success = false; Console.WriteLine("You can't add and remove session at the same time"); return; } if (!(o.Add || o.Remove || o.PrintSessionList)) { o.PrintSessionList = true; return; } if (o.Add && (o.UserName == null || o.Password == null)) { success = false; Console.WriteLine("Both username and password should be specified to log in"); return; } if (o.Remove && o.SessionName == null) { success = false; Console.WriteLine("Session name to remove should be specified"); return; } }); return(success); } }
public SessionActivity(Logger logger, SessionsOptions options, ProxySettings proxySettings) { this.logger = logger; this.options = options; sessionManager = new SessionManager(proxySettings); }