public SessionInformation GetSession() { _logger.LogInfo($"Session collector | {nameof(WindowsSession)}"); var startInfo = new ProcessStartInfo { FileName = "cmd.exe", Arguments = $"/c query user", UseShellExecute = false, RedirectStandardOutput = true }; var process = new System.Diagnostics.Process { StartInfo = startInfo }; process.Start(); var cmdContent = process.StandardOutput.ReadToEnd(); DateTime logonTime = GetLogonTime(cmdContent).ToUniversalTime(); var sessionInstance = new SessionInformation { SessionId = Guid.NewGuid(), SessionStarted = logonTime, User = _platformInformation.PlatformInformation.UserName }; _logger.LogInfo("User session created {@data} | WindowsSession", sessionInstance); return(sessionInstance); }
public async Task Check() { try { _logger.LogInfo($"Started fetching communication type: {_time.Now}"); if (!await _internet.CheckForInternetConnectionAsync() || _session.SessionInformation.Offline) { _logger.LogInfo($"Can connect to commuincation point: {_time.Now}"); return; } CommunicationType type = await _communication.GetCommunicationType(); if (type != _communicationTypeService.GetCommunicationType()) { CommunicationType old = _communicationTypeService.GetCommunicationType(); _communicationTypeService.SetCommuncationType(type); _notification.ShowStatusMessage(nameof(CommunicationTypeCheckBehaviour), $"Communication type changed from {old} to {type}"); } _logger.LogInfo($"Finished fetching communication type: {_time.Now} | type is {type}"); } catch (Exception e) { _logger.LogError(e); } }
/// <summary> /// Async call to request the update version info from the web. /// This call raises UpdateFound event notification, if an update is /// found. /// </summary> public void CheckForProductUpdate() { if (false != versionCheckInProgress) { return; } logger.LogInfo("RequestUpdateVersionInfo", "RequestUpdateVersionInfo"); string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; string appVersionFileName = Path.Combine(Path.GetDirectoryName(exePath), Configurations.AppVersionFileName); if (!File.Exists(appVersionFileName)) { logger.LogError("RequestUpdateVersionInfo", string.Format("'{0}' not found!", Configurations.AppVersionFileName)); return; } string[] appVersionInfo = File.ReadAllLines(appVersionFileName); if (appVersionInfo.Length != 3) { logger.LogError("RequestUpdateVersionInfo", string.Format("Invalid '{0}' format!", Configurations.AppVersionFileName)); return; } versionCheckInProgress = true; WebClient client = new WebClient(); client.OpenReadCompleted += new OpenReadCompletedEventHandler(OnUpdateVersionRequested); client.OpenReadAsync(new System.Uri(appVersionInfo[1])); }
/// <summary> /// Validate old token /// </summary> /// <param name="jwtToken">JWT token</param> /// <returns></returns> public async Task <LoginResponseDto> Login(string identifier, string password) { try { var requestModel = new LoginDto { Identifier = identifier, Password = password, }; var response = await _http.PostAsync("authentication/login", CreateContent(requestModel)); _logger.LogInfo("SUCCESS LOGIN"); if (response.IsSuccessStatusCode) { return(await GetInstanceFromBody <LoginResponseDto>(response)); } if (response.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable) { _logger.LogInfo("Server not available!!!"); throw new HttpRequestException("Server not available!!!"); } return(null); } catch (Exception e) { _logger.LogError(e); throw new HttpRequestException("Server not available!!!"); } }
/// <summary> /// Collect application /// </summary> /// <param name="stoppingToken"></param> /// <returns></returns> protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { _logger.LogInfo($"{nameof(ApplicationCollectorHostedService)} service running."); using (var scope = _provider.CreateScope()) { var behaviour = scope.ServiceProvider.GetRequiredService <IApplicationCollectorBehaviour>(); await behaviour.Collect(); } await Task.Delay(30000); //collect every thirty seconds } }
public SessionInformation GetSession() { _logger.LogInfo($"Session collector | {nameof(LinuxSession)}"); var startInfo = new ProcessStartInfo { FileName = "/bin/bash", Arguments = $"-c \" who \"", UseShellExecute = false, RedirectStandardOutput = true }; var process = new System.Diagnostics.Process() { StartInfo = startInfo }; process.Start(); var terminalContent = process.StandardOutput.ReadToEnd(); DateTime logonTime = GetLogonTime(terminalContent).ToUniversalTime(); var userName = Environment.UserName; return(new SessionInformation { SessionId = Guid.NewGuid(), SessionStarted = logonTime, User = _platformInformation.PlatformInformation.UserName }); }
private void OnInstallButtonClicked(object sender, RoutedEventArgs e) { logger.LogInfo("UpdateNotificationControl-OnInstallButtonClicked", "UpdateNotificationControl-OnInstallButtonClicked"); UpdateManager.Instance.QuitAndInstallUpdate(); // Quit application }
/// <summary> /// Force user to type identifier and password /// </summary> /// <returns></returns> protected async Task GetUserCredentials() { _logger.LogInfo("Forcing user to enter username and password"); while (Validating) { PromptMessage("Enter username: "******"Enter password: "******"Service not available", true); PromptMessage("Starting work in offline mode", true); _session.SetMode(WorkMode.OFFLINE); Validating = false; } } }
protected async override Task ExecuteAsync(CancellationToken stoppingToken) { await Task.Delay(10000); while (!stoppingToken.IsCancellationRequested) { _logger.LogInfo($"{nameof(SyncHostedService)} service running."); using (var scope = _provider.CreateScope()) { var behaviour = scope.ServiceProvider.GetRequiredService <ISyncBehaviour>(); await behaviour.Synchronize(); } await Task.Delay(300000); // sync session every 5 minute } }
/// <summary> /// Collector processes /// </summary> /// <param name="stoppingToken"></param> /// <returns></returns> protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await Task.Delay(5000); while (!stoppingToken.IsCancellationRequested) { _logger.LogInfo($"{nameof(ProcessCollectorHostedService)} service running."); using (var scope = _provider.CreateScope()) { var behaviour = scope.ServiceProvider.GetRequiredService <IProcessBehaviour>(); await behaviour.Collect(); } await Task.Delay(120000); //collect every two minutes } }
/// <summary> /// Is internet connection available = /// </summary> /// <returns></returns> public async Task <bool> CheckForInternetConnectionAsync() { try { var response = await _client.GetAsync(_options.Uri); if (response.IsSuccessStatusCode) { _logger.LogInfo($"Internet connection available on {_time.Now}"); return(true); } _logger.LogInfo($"Internet connection unvailable on {_time.Now}"); return(false); } catch (Exception) { _logger.LogInfo($"Internet connection unvailable on {_time.Now}"); return(false); } }
/// <summary> /// Set platform information /// </summary> private void Set() { systemInformation = new PlatformInformation { MachineName = Environment.MachineName, Platform = Environment.OSVersion.Platform.ToString(), PlatformVersion = Environment.OSVersion.VersionString, UserName = Environment.UserName, UserDomainName = Environment.UserDomainName }; SetType(); _logger.LogInfo("Platform information _ {@data}", systemInformation); }
private void OnUpdateInfoMouseUp(object sender, MouseButtonEventArgs e) { logger.LogInfo("AboutWindow-OnUpdateInfoMouseUp", "AboutWindow-OnUpdateInfoMouseUp"); this.InstallNewUpdate = true; this.Close(); }
public async Task Synchronize() { try { _logger.LogInfo($"Sync behaviourr started: {_time.Now}"); //Offline mode so exit if (_sessionService.SessionInformation.Offline) { _notification.ShowStatusMessage(nameof(SyncBehaviour), $"Sessions sync skipped (OFFLINE MODE): {_time.Now}"); _logger.LogInfo($"Sync finished: {_time.Now}, OFFLINE MODE"); return; } //Check for internet connection if (!await _internet.CheckForInternetConnectionAsync()) { _notification.ShowStatusMessage(nameof(SyncBehaviour), $"Sessions sync skipped (No internet connection): {_time.Now}"); _logger.LogInfo($"Sync finished: {_time.Now}, NO INTERNET ACCESS"); return; } //Get all sessions from database var sessions = await _unitOfWork.Sessions.GetAllWithIncludesAsync(); //no records in database so finish sync process if (sessions.Count == 0) { _notification.ShowStatusMessage(nameof(SyncBehaviour), $"No sessions for sync (No sync needed): {_time.Now}"); _logger.LogInfo($"Sync finished: {_time.Now}, NO RECORDS FOR SYNC"); return; } //are we working only with current session ? if (sessions.Count == 1 && IsCurrentSession(sessions)) { var curSession = sessions.First(); if (!SessionNeedsUpdate(curSession)) { _notification.ShowStatusMessage(nameof(SyncBehaviour), $"Current session only (No sync needed): {_time.Now}"); _logger.LogInfo($"Sync finished: {_time.Now}, NO RECORDS FOR SYNC"); return; } } //map entites from database to dtos var dtosSessions = sessions.Adapt <List <UserSessionDto> >(); //list for successfuly synced entites var successStatuses = new List <UserSessionDto>(); //sync process foreach (var session in dtosSessions) { //get sync client var syncClient = _factory.GetClient(); //sync session var result = await syncClient.Sync(session); //if sync successful, add to list if (result) { successStatuses.Add(session); } } //no success on sync if (successStatuses.Count == 0) { _logger.LogInfo($"Sync finished: {_time.Now}, NO SYNC"); _notification.ShowStatusMessage(nameof(SyncBehaviour), $"Sync for session failed (Server error): {_time.Now}"); return; } /// Get successfuly synced sessions -> sessions that needs to be deleted var sessionsForDelete = GetSessionsForDelete(sessions, successStatuses); //remove current session entity -> current sessions = different treatment //get current session var currentSession = GetCurrentSessionFromList(sessionsForDelete); //remove if from deletesessions RemoveCurrentSessionFromList(sessionsForDelete); //handle current session HandleCurrentSession(currentSession); //zero objects, exit if (sessionsForDelete.Count() > 0) { //delete old sessions _unitOfWork.Sessions.RemoveRange(sessionsForDelete); } //save changes await _unitOfWork.CommitAsync(); _notification.ShowStatusMessage(nameof(SyncBehaviour), $"Sync finished: {_time.Now}"); _logger.LogInfo($"Sync finished: {_time.Now}, SYNC"); } catch (Exception e) { _logger.LogError(e); } }
public ActionResult <IEnumerable <string> > Get() { _loggerWrapper.LogInfo(LogLevelWrapper.ERROR, "Error log from web"); return(new string[] { "value1", "value2" }); }