<commit_before>﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using DesktopAnalytics;
using Glyssen.Dialogs;
using Glyssen.Properties;
using Glyssen.Shared;
using Glyssen.Utilities;
using GlyssenEngine;
using GlyssenEngine.Utilities;
using GlyssenFileBasedPersistence;
using L10NSharp;
using L10NSharp.UI;
using Paratext.Data;
using Paratext.Data.Users;
using PtxUtils;
using PtxUtils.Progress;
using SIL.Extensions;
using SIL.IO;
using SIL.Reporting;
using SIL.Windows.Forms.i18n;
using SIL.Windows.Forms.Reporting;
using SIL.WritingSystems;
using static System.Char;
using static System.String;
using Resources = Glyssen.Properties.Resources;

namespace Glyssen
{
	static class Program
	{
		private const string kOldProductName = "Protoscript Generator";

		// From https://stackoverflow.com/questions/73515/how-to-tell-if-net-code-is-being-run-by-visual-studio-designer
		/// <summary>
		/// <para>If false, we can assume that something like the Designer or Designer Serializer is trying to run the code.</para>
		/// <para>Basically, this is an alternative to Control.DesignMode that works better.</para>
 		/// </summary>
		public static bool IsRunning { get; set; }

		public static IEnumerable<ErrorMessageInfo> CompatibleParatextProjectLoadErrors => ScrTextCollection.ErrorMessages.Where(e => e.ProjecType != ProjectType.Resource && !e.ProjecType.IsNoteType());
		private static List<Exception> _pendingExceptionsToReportToAnalytics = new List<Exception>();

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			IsRunning = true;

			if (GetRunningGlyssenProcessCount() > 1)
			{
				ErrorReport.NotifyUserOfProblem("There is another copy of Glyssen already running. This instance of Glyssen will now shut down.");
				return;
			}

			GlyssenInfo.Product = Application.ProductName;
			MessageModal.Default = new WinFormsMessageBox();
			GlyssenEngine.ErrorHandling.NonFatalErrorHandler.Default = new WinFormsErrorAnalytics();

			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);

			//bring in settings from any previous version
			if (Settings.Default.NeedUpgrade)
			{
				//see http://stackoverflow.com/questions/3498561/net-applicationsettingsbase-should-i-call-upgrade-every-time-i-load
				Settings.Default.Upgrade();
				Settings.Default.Reload();
				Settings.Default.NeedUpgrade = false;
				Settings.Default.Save();
			}

			SetUpErrorHandling();

			UserInfo userInfo = new UserInfo { UILanguageCode = Settings.Default.UserInterfaceLanguage };
			bool sldrIsInitialized = false;

			Logger.Init();
			Trace.Listeners.Add(new LogFileTraceListener());

			GlyssenVersificationTable.Initialize();
			ProgressUtils.Implementation = new ProgressUtilsImpl();
			Alert.Implementation = new AlertImpl(); // Do this before calling Initialize, just in case Initialize tries to display an alert.
			if (ParatextInfo.IsParatextInstalled)
			{
				string userName = null;

				try
				{
					ParatextData.Initialize();
					sldrIsInitialized = true;
					userName = RegistrationInfo.UserName;
					userInfo.Email = RegistrationInfo.EmailAddress;
					foreach (var errMsgInfo in CompatibleParatextProjectLoadErrors.Where(e => e.Reason == UnsupportedReason.Unspecified))
					{
						_pendingExceptionsToReportToAnalytics.Add(errMsgInfo.Exception);
					}
				}
				catch (Exception fatalEx) when (fatalEx is FileLoadException || fatalEx is TypeInitializationException)
				{
					ErrorReport.ReportFatalException(fatalEx);
				}
				catch (Exception ex)
				{
					_pendingExceptionsToReportToAnalytics.Add(ex);
				}

				if (userName != null)
				{
					var split = userName.LastIndexOf(" ", StringComparison.Ordinal);
					if (split > 0)
					{
						userInfo.FirstName = userName.Substring(0, split);
						userInfo.LastName = userName.Substring(split + 1);
					}
					else<commit_msg>PG-1387: Added log entry to not Paratext user name<commit_after>﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using DesktopAnalytics;
using Glyssen.Dialogs;
using Glyssen.Properties;
using Glyssen.Shared;
using Glyssen.Utilities;
using GlyssenEngine;
using GlyssenEngine.Utilities;
using GlyssenFileBasedPersistence;
using L10NSharp;
using L10NSharp.UI;
using Paratext.Data;
using Paratext.Data.Users;
using PtxUtils;
using PtxUtils.Progress;
using SIL.Extensions;
using SIL.IO;
using SIL.Reporting;
using SIL.Windows.Forms.i18n;
using SIL.Windows.Forms.Reporting;
using SIL.WritingSystems;
using static System.Char;
using static System.String;
using Resources = Glyssen.Properties.Resources;

namespace Glyssen
{
	static class Program
	{
		private const string kOldProductName = "Protoscript Generator";

		// From https://stackoverflow.com/questions/73515/how-to-tell-if-net-code-is-being-run-by-visual-studio-designer
		/// <summary>
		/// <para>If false, we can assume that something like the Designer or Designer Serializer is trying to run the code.</para>
		/// <para>Basically, this is an alternative to Control.DesignMode that works better.</para>
 		/// </summary>
		public static bool IsRunning { get; set; }

		public static IEnumerable<ErrorMessageInfo> CompatibleParatextProjectLoadErrors => ScrTextCollection.ErrorMessages.Where(e => e.ProjecType != ProjectType.Resource && !e.ProjecType.IsNoteType());
		private static List<Exception> _pendingExceptionsToReportToAnalytics = new List<Exception>();

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			IsRunning = true;

			if (GetRunningGlyssenProcessCount() > 1)
			{
				ErrorReport.NotifyUserOfProblem("There is another copy of Glyssen already running. This instance of Glyssen will now shut down.");
				return;
			}

			GlyssenInfo.Product = Application.ProductName;
			MessageModal.Default = new WinFormsMessageBox();
			GlyssenEngine.ErrorHandling.NonFatalErrorHandler.Default = new WinFormsErrorAnalytics();

			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);

			//bring in settings from any previous version
			if (Settings.Default.NeedUpgrade)
			{
				//see http://stackoverflow.com/questions/3498561/net-applicationsettingsbase-should-i-call-upgrade-every-time-i-load
				Settings.Default.Upgrade();
				Settings.Default.Reload();
				Settings.Default.NeedUpgrade = false;
				Settings.Default.Save();
			}

			SetUpErrorHandling();

			UserInfo userInfo = new UserInfo { UILanguageCode = Settings.Default.UserInterfaceLanguage };
			bool sldrIsInitialized = false;

			Logger.Init();
			Trace.Listeners.Add(new LogFileTraceListener());

			GlyssenVersificationTable.Initialize();
			ProgressUtils.Implementation = new ProgressUtilsImpl();
			Alert.Implementation = new AlertImpl(); // Do this before calling Initialize, just in case Initialize tries to display an alert.
			if (ParatextInfo.IsParatextInstalled)
			{
				string userName = null;

				try
				{
					ParatextData.Initialize();
					sldrIsInitialized = true;
					userName = RegistrationInfo.UserName;
					Logger.WriteEvent($"Paratext user name: {userName}");
					userInfo.Email = RegistrationInfo.EmailAddress;
					foreach (var errMsgInfo in CompatibleParatextProjectLoadErrors.Where(e => e.Reason == UnsupportedReason.Unspecified))
					{
						_pendingExceptionsToReportToAnalytics.Add(errMsgInfo.Exception);
					}
				}
				catch (Exception fatalEx) when (fatalEx is FileLoadException || fatalEx is TypeInitializationException)
				{
					ErrorReport.ReportFatalException(fatalEx);
				}
				catch (Exception ex)
				{
					_pendingExceptionsToReportToAnalytics.Add(ex);
				}

				if (userName != null)
				{
					var split = userName.LastIndexOf(" ", StringComparison.Ordinal);
					if (split > 0)
					{
						userInfo.FirstName = userName.Substring(0, split);
						userInfo.LastName = userName.Substring(split + 1);
					}
					else
{'fraction_non_alphanumeric': 0.09946885562530179, 'fraction_numerical': 0.005794302269435055, 'mean_word_length': 4.237041719342605, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7203618', 'n_tokens_mistral': 2923, 'n_tokens_neox': 2435, 'n_words': 571}