Example #1
0
        public string[] ToArray(bool obfuscate = false)
        {
            var parameters = new Collection <string>
            {
                WakaTimeCli.GetCliPath(),
                "--key",
                obfuscate ? string.Format("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX{0}", Key.Substring(Key.Length - 4)) : Key,
                "--entity",
                File,
                "--time",
                Time.ToString(),
                "--plugin",
                Plugin
            };

            if (IsWrite)
            {
                parameters.Add("--write");
            }

            // ReSharper disable once InvertIf
            if (!string.IsNullOrEmpty(Project))
            {
                parameters.Add("--project");
                parameters.Add(Project);
            }

            if (HasExtraHeartbeats)
            {
                parameters.Add("--extra-heartbeats");
            }

            return(parameters.ToArray());
        }
Example #2
0
        private void Initialize()
        {
            try
            {
                Logger.Initialize(GetLogger());
            }
            catch
            {
                Logger.Initialize(GetConsoleLogger()); // fall-back on console logger
            }

            try
            {
                editorInfo = GetEditorInfo();

                Logger.Info(string.Format("Initializing WakaTime v{0}", editorInfo.PluginVersion));

                WakaTimeCli.Initialized += (s, e) =>
                {
                    if (string.IsNullOrEmpty(WakaTimeConfigFile.ApiKey))
                    {
                        PromptApiKey();
                    }

                    BindEditorEvents();

                    // Setup timer to process queued heartbeats every 8 seconds
                    timer.Interval = 1000 * 8;
                    timer.Elapsed += ProcessHeartbeats;
                    timer.Start();

                    Logger.Info(string.Format("Finished initializing WakaTime v{0}", editorInfo.PluginVersion));
                };

                DownloadProgress.Initialize(() => { return(GetReporter()); });

                PythonManager.Initialized += (s, e) =>
                {
                    WakaTimeCli.Initialize();
                };

                CheckPrerequisites();
            }
            catch (WebException ex)
            {
                Logger.Error("Are you behind a proxy? Try setting a proxy in WakaTime Settings with format https://user:pass@host:port. Exception Traceback:", ex);
            }
            catch (Exception ex)
            {
                Logger.Error("Error initializing Wakatime", ex);
            }
        }