예제 #1
0
        static void Main()
        {
            //Starting visual and text styles
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(true);

            SetApplicationExceptions(); //Set for logging events when the application shuts down

            ILogger.AddToLog(ResourceInformation.ApplicationName, "Running main form now!");

            //Initialize CefSharp
            VoidCef.InitializeCefSharp();

            //Initialize settings manager
            Settings.SettingsManager.InitializeValues();

            OpenForm(); //Opens a new borwser window

            //Checks if the application exist
            var exists = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1;

            if (exists)
            {
                ILogger.AddToLog(ResourceInformation.ApplicationName, "Detected another instance of the browser open! Sending client package and closing browser...");

                //New TCP client to send data to local server
                TcpClient client = new TcpClient(); client.Connect("localhost", 6189);
                client.Client.Send(Encoding.UTF8.GetBytes("newpage"));

                //Closing application and client
                client.Close();
                Application.Exit();
            }

            InitializeInvokeObject(); //Initialize the invoke object for the start of the application.

            //Check if there is an active internet connection
            if (!CheckInternet.CheckForInternetConnection())
            {
                ILogger.AddToLog("ERROR", "Connection to the internet was not found!");
                MessageBox.Show("Connection to the internet was not found! this browser is currently closing.", ResourceInformation.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            InitializeLocalServer(); //Loads the local server used to open a new form when a new application is open.

            InitializeStripe();      //Initialize the stripe API

            //Initializing History
            IHistory.LoadFromFile();

            StartFormTimer();                                         //Starts a timer to check when no forms are open

            Settings.Settings.downloadItem.InitializeDownloadItems(); //Initialize download items from local storage.

            Thread thread = new Thread(new ThreadStart(() =>
            {
                //Initializes server connections
                ServerConnections.InitializeServerConnections();
            }));

            thread.Start();

            //Running the application loop.
            Application.Run();
        }