internal bool IsCliUpToDate() { var process = new RunProcess(CliLocation, "--version"); process.Run(); if (!process.Success) { _logger.Error(process.Error); return(false); } var currentVersion = process.Output.Trim(); _logger.Info($"Current wakatime-cli version is {currentVersion}"); _logger.Info("Checking for updates to wakatime-cli..."); var latestVersion = LatestWakaTimeCliVersion(); if (currentVersion.Equals(latestVersion)) { _logger.Info("wakatime-cli is up to date."); return(true); } _logger.Info($"Found an updated wakatime-cli v{latestVersion}"); return(false); }
private void ProcessHeartbeats() { var pythonBinary = _dependencies.CliLocation; // get first heartbeat from queue var gotOne = HeartbeatQueue.TryDequeue(out var heartbeat); if (!gotOne) { return; } // remove all extra heartbeats from queue var extraHeartbeats = new ArrayList(); while (HeartbeatQueue.TryDequeue(out var h)) { extraHeartbeats.Add(h); } var hasExtraHeartbeats = extraHeartbeats.Count > 0; _pythonCliParameters.Key = Config.ApiKey; _pythonCliParameters.Plugin = $"{_configuration.EditorName}/{_configuration.EditorVersion} {_configuration.PluginName}/{_configuration.PluginVersion}"; _pythonCliParameters.File = heartbeat.Entity; _pythonCliParameters.Time = heartbeat.Timestamp; _pythonCliParameters.IsWrite = heartbeat.IsWrite; _pythonCliParameters.Project = heartbeat.Project; _pythonCliParameters.Category = heartbeat.Category; _pythonCliParameters.EntityType = heartbeat.EntityType; _pythonCliParameters.HasExtraHeartbeats = hasExtraHeartbeats; string extraHeartbeatsJson = null; if (hasExtraHeartbeats) { extraHeartbeatsJson = new JavaScriptSerializer().Serialize(extraHeartbeats); } var process = new RunProcess(pythonBinary, _pythonCliParameters.ToArray()); if (Config.Debug) { Logger.Debug( $"[\"{pythonBinary}\", \"{string.Join("\", \"", _pythonCliParameters.ToArray(true))}\"]"); process.Run(extraHeartbeatsJson); if (!string.IsNullOrEmpty(process.Output)) { Logger.Debug(process.Output); } if (!string.IsNullOrEmpty(process.Error)) { Logger.Debug(process.Error); } } else { process.RunInBackground(extraHeartbeatsJson); } if (process.Success) { return; } Logger.Error("Could not send heartbeat."); if (!string.IsNullOrEmpty(process.Output)) { Logger.Error(process.Output); } if (!string.IsNullOrEmpty(process.Error)) { Logger.Error(process.Error); } }