示例#1
0
        private static void InitializeAsync()
        {
            try
            {
                // Delete existing log file to save space
                Logger.Delete();
            }
            catch { }

            try
            {
                Logger.Info(string.Format("Initializing Code::Stats v{0}", Constants.PluginVersion));

                //Logger.Debug(Assembly.GetExecutingAssembly().GetManifestResourceNames().ToString());
                //Logger.Debug(Assembly.GetExecutingAssembly().GetName().Name);

                Assembly     _assembly;
                StreamReader _textStreamReader;
                Stream       _stream;
                string       extensionMappingJson;

                try
                {
                    var client = new WebClient {
                        Proxy = CodeStatsPackage.GetProxy()
                    };
                    client.Headers[HttpRequestHeader.UserAgent] = Constants.PluginUserAgent;

                    try
                    {
                        extensionMappingJson = client.DownloadString("https://raw.githubusercontent.com/p0358/notepadpp-CodeStats/master/CodeStats/Resources/extension_mapping.json");
                        if (!extensionMappingJson.Trim().StartsWith("{") || !extensionMappingJson.Trim().EndsWith("}"))
                        {
                            extensionMappingJson = string.Empty;
                        }
                    }
                    catch (Exception ex)
                    {
                        extensionMappingJson = string.Empty;
                        Logger.Error("Exception when trying to download latest extension mappings, using local ones instead", ex);
                    }
                }
                catch
                {
                    extensionMappingJson = string.Empty;
                }

                if (String.IsNullOrWhiteSpace(extensionMappingJson))
                {
                    // Load precompiled/included extension mapping
                    _assembly            = Assembly.GetExecutingAssembly();
                    _stream              = _assembly.GetManifestResourceStream("CodeStats.Resources.extension_mapping.json");
                    _textStreamReader    = new StreamReader(_stream);
                    extensionMappingJson = _textStreamReader.ReadToEnd();
                }

                Logger.Debug("Extension mapping JSON: " + extensionMappingJson);

                //var json = "{\"id\":\"13\", \"value\": true}";
                var serializer = new JavaScriptSerializer();
                //var table = serializer.Deserialize<dynamic>(json);
                //Dictionary<string, string> values = serializer.Deserialize<Dictionary<string, string>>(json);

                extensionMapping = serializer.Deserialize <Dictionary <string, string> >(extensionMappingJson);

                //Logger.Debug(values["id"]);
                //Logger.Debug(table["value"]);
            }
            catch (Exception ex)
            {
                Logger.Error("Error loading extension mappings!", ex);
            }

            try
            {
                // Settings Form
                _settingsForm              = new CodeStats.Forms.SettingsForm();
                _settingsForm.ConfigSaved += SettingsFormOnConfigSaved;

                // Load config file
                _CodeStatsConfigFile = new ConfigFile();
                GetSettings();

                try
                {
                    // Check for updates
                    string latest = Constants.LatestPluginVersion();
                    if (Constants.PluginVersion != latest && !String.IsNullOrWhiteSpace(latest))
                    {
                        MessageBox.Show("There is Code::Stats plugin update available!\nDownload it from Plugin Manager or GitHub.\nYour version: " + Constants.PluginVersion + "\nLatest: " + latest, "Code::Stats");
                    }
                }
                catch { }

                currentPulse = new Pulse();

                if (string.IsNullOrEmpty(ApiKey))
                {
                    Stats = false;  // Disable stats reporting for this session/launch
                    PromptApiKey(); // Prompt for API token if not already set
                }

                // setup timer to process queued pulses
                timer.Interval = pulseFrequency;
                timer.Elapsed += ProcessPulses;
                timer.Start();

                if (Stats)
                {
                    ReportStats();
                }

                Logger.Info(string.Format("Finished initializing Code::Stats v{0}", Constants.PluginVersion));
            }
            catch (Exception ex)
            {
                Logger.Error("Error Initializing Code::Stats", ex);
            }
        }
示例#2
0
        private static void InitializeAsync()
        {
            if (System.Net.ServicePointManager.SecurityProtocol != 0)
            {
                // If the value is not set to 0 (SystemDefault), disable old protocols and make sure TLS 1.3, 1.2, 1.1 are enabled
                System.Net.ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
                System.Net.ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls;
                System.Net.ServicePointManager.SecurityProtocol |= (SecurityProtocolType)12288 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
            }
            //System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)0; // SystemDefault, we don't use this since it's supported only since .NET 4.7

            //Updater.RenameTest();
            //Updater.SignatureVerificationTest();
            try
            {
                // Delete existing log file to save space
                Logger.Delete();
            }
            catch { }

            Logger.Info(string.Format("Initializing Code::Stats v{0}", Constants.PluginVersion));

            try
            {
                currentPulse = new Pulse();

                Logger.Info("Initialing settings form...");
                // Settings Form
                _settingsForm              = new CodeStats.Forms.SettingsForm();
                _settingsForm.ConfigSaved += SettingsFormOnConfigSaved;
                Logger.Info("Initialized settings form"); // it takes 5 seconds to get here from Initializing Code::Stats message...

                // Load config file
                _CodeStatsConfigFile = new ConfigFile();
                GetSettings(true);

                Logger.Debug("Loaded config");

                LoadExtensionMapping();

                // Check for updates
                Task.Run(() =>
                {
                    try
                    {
                        string latest = Constants.LatestPluginVersion();
                        if (Constants.PluginVersion != latest && !String.IsNullOrWhiteSpace(latest))
                        {
                            MessageBox.Show("There is Code::Stats plugin update available!\nDownload it from Plugin Admin (if already available there) or GitHub.\nYour version: " + Constants.PluginVersion + "\nLatest: " + latest, "Code::Stats");
                        }
                    }
                    catch { }
                });


                if (string.IsNullOrEmpty(ApiKey))
                {
                    Stats = false;  // Disable stats reporting for this session/launch
                    PromptApiKey(); // Prompt for API token if not already set
                }

                // setup timer to process queued pulses
                pulseProcessor_tokensource             = new CancellationTokenSource();
                pulseProcessor_httpClientHandler       = new HttpClientHandler();
                pulseProcessor_httpClientHandler.Proxy = GetProxy();
                proxyChangePending    = false;
                pulseProcessor_client = new HttpClient(pulseProcessor_httpClientHandler);
                timer.Interval        = pulseFrequency;
                timer.Elapsed        += ProcessPulses;
                timer.Start();

                if (Stats)
                {
                    ReportStats();
                }

                Logger.Info(string.Format("Finished initializing Code::Stats v{0}", Constants.PluginVersion));
            }
            catch (Exception ex)
            {
                Logger.Error("Error Initializing Code::Stats", ex);
            }
        }
        private static void InitializeAsync()
        {
            if (System.Net.ServicePointManager.SecurityProtocol != 0)
            {
                // If the value is not set to 0 (SystemDefault), disable old protocols and make sure TLS 1.3, 1.2, 1.1 are enabled
                System.Net.ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
                System.Net.ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls;
                System.Net.ServicePointManager.SecurityProtocol |= (SecurityProtocolType)12288 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
            }

            try
            {
                // Delete existing log file to save space
                Logger.Delete();
            }
            catch { }

            Logger.Info($"Initializing Code::Stats v{Constants.PluginVersion}");

            try
            {
                currentPulse = new Pulse();
                Logger.Info("Initialing settings form...");
                // Settings Form
                _settingsForm = new CodeStats.Forms.SettingsForm();
                _settingsForm.OnSettingsSaved += SettingsFormOnConfigSaved;
                Logger.Info("Initialized settings form");                 // it takes 5 seconds to get here from Initializing Code::Stats message...

                // Load config file
                codeStatsSettings = CodeStatsSettingsProvider.GetSingleton();
                GetSettings(true);

                Logger.Debug("Loaded config");

                LoadExtensionMapping();


                if (String.IsNullOrEmpty(codeStatsSettings.ApiKey))
                {
                    PromptApiKey();                     // Prompt for API token if not already set
                }

                // setup timer to process queued pulses
                pulseProcessor_tokensource       = new CancellationTokenSource();
                pulseProcessor_httpClientHandler = new HttpClientHandler
                {
                    Proxy = GetProxy()
                };
                proxyChangePending    = false;
                pulseProcessor_client = new HttpClient(pulseProcessor_httpClientHandler);
                timer.Interval        = pulseFrequency;
                timer.Elapsed        += ProcessPulses;
                timer.Start();


                Logger.Info($"Finished initializing Code::Stats v{Constants.PluginVersion}");
            }
            catch (Exception ex)
            {
                Logger.Error("Error Initializing Code::Stats", ex);
            }
        }