RunInBackground() private méthode

private RunInBackground ( ) : void
Résultat void
Exemple #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");
            }
        }
        public static void SendHeartbeat(string fileName, bool isWrite)
        {
            PythonCliParameters.Key = ApiKey;
            PythonCliParameters.File = fileName;
            PythonCliParameters.Plugin = string.Format("{0}/{1} {2}/{3}", WakaTimeConstants.EditorName, _editorVersion, WakaTimeConstants.PluginName, _version);
            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");
        }
        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");
            }
        }
        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");
            }
        }
        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");
        }
        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");
            }
        }
        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");
            }
        }
Exemple #8
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");
            }
        }
        public static void SendHeartbeat(string fileName, bool isWrite)
        {
            var arguments = new List<string>
            {
                GetCli(),
                "--key",
                ApiKey,
                "--file",
                fileName,
                "--plugin",
                WakaTimeConstants.EditorName + "/" + _editorVersion + " " + WakaTimeConstants.PluginName + "/" + _version
            };

            if (isWrite)
                arguments.Add("--write");

            var projectName = GetProjectName();
            if (!string.IsNullOrEmpty(projectName))
            {
                arguments.Add("--project");
                arguments.Add(projectName);
            }

            var pythonBinary = PythonManager.GetPython();
            if (pythonBinary != null)
            {

                var process = new RunProcess(pythonBinary, arguments.ToArray());
                if (DEBUG)
                {
                    Logger.Instance.Info("[\"" + pythonBinary + "\", \"" + string.Join("\", ", arguments) + "\"]");
                    process.Run();
                    Logger.Instance.Info("WakaTime CLI STDOUT:" + process.Output);
                    Logger.Instance.Info("WakaTime CLI STDERR:" + process.Error);
                }
                else
                {
                    process.RunInBackground();
                }

            }
            else
            {
                Logger.Instance.Error("Could not send heartbeat because python is not installed.");
            }
        }
        private 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.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 (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");
        }
Exemple #11
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);
                }
            }
        }