Ejemplo n.º 1
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");
            }
        }
Ejemplo n.º 2
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");
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }