Пример #1
0
        internal static bool IsCliUpToDate()
        {
            var process = new RunProcess(Dependencies.GetPython(), CliLocation, "--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 = Constants.LatestWakaTimeCliVersion();

                if (currentVersion.Equals(latestVersion))
                {
                    Logger.Info("wakatime-cli is up to date.");
                    return true;
                }

                Logger.Info(string.Format("Found an updated wakatime-cli v{0}", latestVersion));
            }
            return false;
        }
Пример #2
0
        private static void ProcessHeartbeats()
        {
            var pythonBinary = Dependencies.GetPython();

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

                // remove all extra heartbeats from queue
                ArrayList extraHeartbeats = new ArrayList();
                Heartbeat h;
                while (heartbeatQueue.TryDequeue(out h))
                {
                    extraHeartbeats.Add(new Heartbeat(h));
                }
                bool hasExtraHeartbeats = extraHeartbeats.Count > 0;

                PythonCliParameters.Key                = ApiKey;
                PythonCliParameters.Plugin             = string.Format("{0}/{1} {2}/{3}", Constants.EditorName, Constants.EditorVersion, Constants.PluginKey, Constants.PluginVersion);
                PythonCliParameters.File               = heartbeat.entity;
                PythonCliParameters.Time               = heartbeat.timestamp;
                PythonCliParameters.IsWrite            = heartbeat.is_write;
                PythonCliParameters.HasExtraHeartbeats = hasExtraHeartbeats;

                string extraHeartbeatsJSON = null;
                if (hasExtraHeartbeats)
                {
                    extraHeartbeatsJSON = new JavaScriptSerializer().Serialize(extraHeartbeats);
                }

                var process = new RunProcess(pythonBinary, PythonCliParameters.ToArray());
                if (Debug)
                {
                    Logger.Debug(string.Format("[\"{0}\", \"{1}\"]", pythonBinary, string.Join("\", \"", PythonCliParameters.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);
                    }
                }
            }
            else
            {
                Logger.Error("Could not send heartbeat because python is not installed");
            }
        }
Пример #3
0
        private static void ProcessHeartbeats()
        {
            var pythonBinary = Dependencies.GetPython();

            if (pythonBinary != null)
            {
                // 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(new Heartbeat(h));
                }
                var hasExtraHeartbeats = extraHeartbeats.Count > 0;

                PythonCliParameters.Key    = Config.ApiKey;
                PythonCliParameters.Plugin =
                    $"{Constants.EditorName}/{Constants.EditorVersion} {Constants.PluginName}/{Constants.PluginVersion}";
                PythonCliParameters.File               = heartbeat.entity;
                PythonCliParameters.Time               = heartbeat.timestamp;
                PythonCliParameters.IsWrite            = heartbeat.is_write;
                PythonCliParameters.Project            = heartbeat.project;
                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)
                {
                    Logger.Error("Could not send heartbeat.");
                    if (!string.IsNullOrEmpty(process.Output))
                    {
                        Logger.Error(process.Output);
                    }
                    if (!string.IsNullOrEmpty(process.Error))
                    {
                        Logger.Error(process.Error);
                    }
                }
            }
            else
            {
                Logger.Error("Could not send heartbeat because python is not installed");
            }
        }