public static void SendHeartbeat(string fileName, bool isWrite)
        {
            PythonCliParameters.Key     = ApiKey;
            PythonCliParameters.File    = fileName;
            PythonCliParameters.Plugin  = string.Format("{0}/{1} {2}/{3}", WakaTimeConstants.EditorName, WakaTimeConstants.EditorVersion, WakaTimeConstants.PluginName, WakaTimeConstants.PluginVersion);
            PythonCliParameters.IsWrite = isWrite;
            PythonCliParameters.Project = GetProjectName();

            var pythonBinary = PythonManager.GetPython();

            if (pythonBinary != null)
            {
                var process = new RunProcess(pythonBinary, PythonCliParameters.ToArray());
                if (Debug)
                {
                    Logger.Debug(string.Format("[\"{0}\", \"{1}\"]", pythonBinary, string.Join("\", \"", PythonCliParameters.ToArray(true))));
                    process.Run();
                    Logger.Debug(string.Format("CLI STDOUT: {0}", process.Output));
                    Logger.Debug(string.Format("CLI STDERR: {0}", process.Error));
                }
                else
                {
                    process.RunInBackground();
                }

                if (!process.Success)
                {
                    Logger.Error(string.Format("Could not send heartbeat: {0}", process.Error));
                }
            }
            else
            {
                Logger.Error("Could not send heartbeat because python is not installed");
            }
        }
        static bool IsCliLatestVersion()
        {
            var process = new RunProcess(PythonManager.GetPython(), PythonCliParameters.Cli, "--version");

            process.Run();

            if (process.Success)
            {
                var currentVersion = process.Error.Trim();
                Logger.Info(string.Format("Current wakatime-cli version is {0}", currentVersion));

                Logger.Info("Checking for updates to wakatime-cli...");
                var latestVersion = WakaTimeConstants.LatestWakaTimeCliVersion();

                if (currentVersion.Equals(latestVersion))
                {
                    Logger.Info("wakatime-cli is up to date.");
                    return(true);
                }
                else
                {
                    Logger.Info(string.Format("Found an updated wakatime-cli v{0}", latestVersion));
                }
            }
            return(false);
        }
        public static void SendHeartbeat(string windowTitle)
        {
            PythonCliParameters.Key    = ApiKey;
            PythonCliParameters.Entity = windowTitle;
            PythonCliParameters.Plugin = $"{WakaTimeConstants.PluginName}/{_version}";

            var pythonBinary = PythonManager.GetPython();

            if (pythonBinary != null)
            {
                var process = new RunProcess(pythonBinary, PythonCliParameters.ToArray());
                if (Debug)
                {
                    Logger.Debug($"[\"{pythonBinary}\", \"{string.Join("\", \"", PythonCliParameters.ToArray(true))}\"]");
                    process.Run();
                    Logger.Debug($"CLI STDOUT: {process.Output}");
                    Logger.Debug($"CLI STDERR: {process.Error}");
                }
                else
                {
                    process.RunInBackground();
                }

                if (!process.Success)
                {
                    Logger.Error($"Could not send heartbeat: {process.Error}");
                }
            }
            else
            {
                Logger.Error("Could not send heartbeat because python is not installed");
            }
        }
Exemplo n.º 4
0
        public static void SendHeartbeat(PythonCliParameters cliParameters)
        {
            var pythonBinary = PythonManager.GetPython();

            if (pythonBinary != null)
            {
                var process = new RunProcess(pythonBinary, cliParameters.ToArray());
                if (WakaTimeConfigFile.Debug)
                {
                    Logger.Debug(string.Format("[\"{0}\", \"{1}\"]", pythonBinary, string.Join("\", \"", cliParameters.ToArray(true))));
                    process.Run();
                    Logger.Debug(string.Format("CLI STDOUT: {0}", process.Output));
                    Logger.Debug(string.Format("CLI STDERR: {0}", process.Error));
                }
                else
                {
                    process.RunInBackground();
                }

                if (!process.Success)
                {
                    Logger.Error(string.Format("Could not send heartbeat: {0}", process.Error));
                }
            }
            else
            {
                Logger.Error("Could not send heartbeat because python is not installed");
            }
        }
Exemplo n.º 5
0
        static bool IsCliLatestVersion()
        {
            var process = new RunProcess(PythonManager.GetPython(), PythonCliParameters.Cli, "--version");

            process.Run();

            var wakatimeVersion = WakaTimeConstants.CurrentWakaTimeCliVersion();

            return(process.Success && process.Error.Equals(wakatimeVersion));
        }
Exemplo n.º 6
0
        static bool IsCliLatestVersion()
        {
            var process = new RunProcess(PythonManager.GetPython(), GetCliPath(), "--version");

            process.Run();

            var version = GetLatestWakaTimeCliVersion();

            return(process.Success && process.Error.Equals(version.ToString()));
        }
Exemplo n.º 7
0
        private static void ProcessHeartbeats()
        {
            var pythonBinary = PythonManager.GetPython();

#if NET35
            if (pythonBinary == null || string.IsNullOrEmpty(pythonBinary.Trim()))
#else
            if (string.IsNullOrWhiteSpace(pythonBinary))
#endif
            {
                Logger.Error("Could not send heartbeat because python is not installed");
                return;
            }

            // get first heartbeat from queue
            var gotOne = heartbeatQueue.TryDequeue(out Heartbeat heartbeat);
            if (!gotOne)
            {
                return;
            }

            // remove all extra heartbeats from queue
            var extraHeartbeats = new List <Heartbeat>();
            while (heartbeatQueue.TryDequeue(out Heartbeat hbOut))
            {
                extraHeartbeats.Add(hbOut.Clone());
            }

            var hasExtraHeartbeats = extraHeartbeats.Any();
            var cliParams          = new PythonCliParameters
            {
                Key                = WakaTimeConfigFile.ApiKey,
                Plugin             = string.Format("{0}/{1} {2}/{3}", editorInfo.Name, editorInfo.Version, editorInfo.PluginKey, editorInfo.PluginVersion),
                File               = heartbeat.FileName,
                Time               = heartbeat.Timestamp,
                IsWrite            = heartbeat.IsWrite,
                HasExtraHeartbeats = hasExtraHeartbeats,
            };

            string extraHeartbeatsJSON = null;
            if (hasExtraHeartbeats)
            {
#if NET45
                var serializer = new JavaScriptSerializer();
                serializer.RegisterConverters(new JavaScriptConverter[] { new DataContractJavaScriptConverter(true) });
                extraHeartbeatsJSON = serializer.Serialize(extraHeartbeats);
#else
                extraHeartbeatsJSON = JsonConvert.SerializeObject(extraHeartbeats, Formatting.None);
#endif
            }

            var process = new RunProcess(pythonBinary, cliParams.ToArray());
            if (WakaTimeConfigFile.Debug)
            {
                Logger.Debug(string.Format("[\"{0}\", \"{1}\"]", pythonBinary, string.Join("\", \"", cliParams.ToArray(true))));
                process.Run(extraHeartbeatsJSON);
                if (process.Output != null && process.Output != "")
                {
                    Logger.Debug(process.Output);
                }
                if (process.Error != null && process.Error != "")
                {
                    Logger.Debug(process.Error);
                }
            }
            else
            {
                process.RunInBackground(extraHeartbeatsJSON);
            }

            if (!process.Success)
            {
                Logger.Error("Could not send heartbeat.");
                if (process.Output != null && process.Output != "")
                {
                    Logger.Error(process.Output);
                }
                if (process.Error != null && process.Error != "")
                {
                    Logger.Error(process.Error);
                }
            }
        }