InitializeLogger() public static method

Initialise Logger if it's enabled.
public static InitializeLogger ( ) : void
return void
        public static bool SetSebClientConfiguration()
        {
            SEBClientInfo.IsNewOS = false;
            SEBClientInfo.ExplorerShellWasKilled = false;
            SEBClientInfo.UserNameRegistryFlags  = new char[100];
            SEBClientInfo.RegistryFlags          = new char[50];
            SEBClientInfo.UserSid       = new char[512];
            SEBClientInfo.UserName      = "";
            SEBClientInfo.HostName      = "localhost";
            SEBClientInfo.HostIpAddress = "127.0.0.1";
            SEBClientInfo.PortNumber    = 57016;
            SEBClientInfo.SendInterval  = 100;
            SEBClientInfo.RecvTimeout   = 100;
            SEBClientInfo.NumMessages   = 3;
            SEBClientInfo.SetSebPaths();
            byte[]        sebSettings   = (byte[])null;
            StringBuilder stringBuilder = new StringBuilder();

            try
            {
                sebSettings = File.ReadAllBytes(SEBClientInfo.SebClientSettingsProgramDataFile);
            }
            catch (Exception ex)
            {
                stringBuilder.Append("Could not load SebClientSettigs.seb from the Program Data directory").Append(ex == null ? (string)null : ex.GetType().ToString()).Append(ex.Message);
            }
            if (sebSettings == null)
            {
                try
                {
                    sebSettings = File.ReadAllBytes(SEBClientInfo.SebClientSettingsAppDataFile);
                }
                catch (Exception ex)
                {
                    stringBuilder.Append("Could not load SebClientSettigs.seb from the Roaming Application Data directory. ").Append(ex == null ? (string)null : ex.GetType().ToString()).Append(ex.Message);
                }
            }
            if (!SEBSettings.StoreDecryptedSebClientSettings(sebSettings))
            {
                return(false);
            }
            SEBClientInfo.InitializeLogger();
            Logger.AddError(stringBuilder.ToString(), (object)null, (Exception)null, (string)null);
            SEBClientInfo.UserName = Environment.UserName;
            int num = 1;

            Logger.AddInformation(new StringBuilder("User Name: ").Append(SEBClientInfo.UserName).Append(" Host Name: ").Append(SEBClientInfo.HostName).Append(" Port Number: ").Append(SEBClientInfo.PortNumber).Append(" Send Interval: ").Append(SEBClientInfo.SendInterval).Append(" Recv Timeout: ").Append(SEBClientInfo.RecvTimeout).Append(" Num Messages: ").Append(SEBClientInfo.NumMessages).Append(" SebClientConfigFileDirectory: ").Append(SEBClientInfo.SebClientSettingsAppDataDirectory).Append(" SebClientConfigFile: ").Append(SEBClientInfo.SebClientSettingsAppDataFile).ToString(), (object)null, (Exception)null, (string)null);
            return(num != 0);
        }
        /// ----------------------------------------------------------------------------------------
        /// <summary>
        /// Decrypt, parse and use new SEB settings
        /// </summary>
        /// ----------------------------------------------------------------------------------------
        public static bool StoreDecryptedSEBSettings(byte[] sebData)
        {
            DictObj          sebPreferencesDict;
            string           sebFilePassword       = null;
            bool             passwordIsHash        = false;
            X509Certificate2 sebFileCertificateRef = null;

            sebPreferencesDict = DecryptSEBSettings(sebData, false, ref sebFilePassword, ref passwordIsHash, ref sebFileCertificateRef);
            if (sebPreferencesDict == null)
            {
                return(false);                            //Decryption didn't work, we abort
            }
            Logger.AddInformation("Reconfiguring");
            // Reset SEB, close third party applications
            SEBClientInfo.SebWindowsClientForm.closeSebClient = false;
            Logger.AddInformation("Attempting to CloseSEBForm for reconfiguration");
            SEBClientInfo.SebWindowsClientForm.CloseSEBForm();
            Logger.AddInformation("Succesfully CloseSEBForm for reconfiguration");
            SEBClientInfo.SebWindowsClientForm.closeSebClient = true;
            //SEBClientInfo.SebWindowsClientForm.Close();
            //SEBClientInfo.SebWindowsClientForm.Dispose();

            // We need to check if setting for createNewDesktop changed
            SEBClientInfo.CreateNewDesktopOldValue = (bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, SEBSettings.KeyCreateNewDesktop);

            if ((int)sebPreferencesDict[SEBSettings.KeySebConfigPurpose] == (int)SEBSettings.sebConfigPurposes.sebConfigPurposeStartingExam)
            {
                ///
                /// If these SEB settings are ment to start an exam
                ///

                Logger.AddInformation("Reconfiguring to start an exam");
                /// If these SEB settings are ment to start an exam

                // Store decrypted settings
                Logger.AddInformation("Attempting to StoreSebClientSettings");
                SEBSettings.StoreSebClientSettings(sebPreferencesDict);
                Logger.AddInformation("Successfully StoreSebClientSettings");

                // Set the flag that SEB is running in exam mode now
                SEBClientInfo.examMode = true;

                //Re-initialize logger
                SEBClientInfo.InitializeLogger();

                // Check if SEB is running on the standard desktop and the new settings demand to run in new desktop (createNewDesktop = true)
                // or the other way around!
                if (SEBClientInfo.CreateNewDesktopOldValue != (bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, SEBSettings.KeyCreateNewDesktop))
                {
                    // If it did, SEB needs to quit and be restarted manually for the new setting to take effekt
                    if (SEBClientInfo.CreateNewDesktopOldValue == false)
                    {
                        SEBMessageBox.Show(SEBUIStrings.settingsRequireNewDesktop, SEBUIStrings.settingsRequireNewDesktopReason, MessageBoxIcon.Error, MessageBoxButtons.OK);
                    }
                    else
                    {
                        SEBMessageBox.Show(SEBUIStrings.settingsRequireNotNewDesktop, SEBUIStrings.settingsRequireNotNewDesktopReason, MessageBoxIcon.Error, MessageBoxButtons.OK);
                    }

                    //SEBClientInfo.SebWindowsClientForm.closeSebClient = true;
                    SEBClientInfo.SebWindowsClientForm.ExitApplication();
                }

                // Re-Initialize SEB according to the new settings
                Logger.AddInformation("Attemting to InitSEBDesktop for reconfiguration");
                if (!SebWindowsClientMain.InitSEBDesktop())
                {
                    return(false);
                }
                Logger.AddInformation("Sucessfully InitSEBDesktop for reconfiguration");
                // Re-open the main form
                //SEBClientInfo.SebWindowsClientForm = new SebWindowsClientForm();
                //SebWindowsClientMain.singleInstanceController.SetMainForm(SEBClientInfo.SebWindowsClientForm);

                //return if initializing SEB with openend preferences was successful
                Logger.AddInformation("Attempting to OpenSEBForm for reconfiguration");
                var ret = SEBClientInfo.SebWindowsClientForm.OpenSEBForm();
                Logger.AddInformation("Successfully OpenSEBForm for reconfiguration");
                return(ret);
            }
            else
            {
                ///
                /// If these SEB settings are ment to configure a client
                ///

                Logger.AddInformation("Reconfiguring to configure a client");
                /// If these SEB settings are ment to configure a client

                // Check if we have embedded identities and import them into the Windows Certifcate Store
                ListObj embeddedCertificates = (ListObj)sebPreferencesDict[SEBSettings.KeyEmbeddedCertificates];
                for (int i = embeddedCertificates.Count - 1; i >= 0; i--)
                {
                    // Get the Embedded Certificate
                    DictObj embeddedCertificate = (DictObj)embeddedCertificates[i];
                    // Is it an identity?
                    if ((int)embeddedCertificate[SEBSettings.KeyType] == 1)
                    {
                        // Store the identity into the Windows Certificate Store
                        SEBProtectionController.StoreCertificateIntoStore((byte[])embeddedCertificate[SEBSettings.KeyCertificateData]);
                    }
                    // Remove the identity from settings, as it should be only stored in the Certificate Store and not in the locally stored settings file
                    embeddedCertificates.RemoveAt(i);
                }

                // Store decrypted settings
                SEBSettings.StoreSebClientSettings(sebPreferencesDict);

                //Re-initialize logger
                SEBClientInfo.InitializeLogger();

                // Write new settings to the localapp directory
                SEBSettings.WriteSebConfigurationFile(SEBClientInfo.SebClientSettingsAppDataFile, "", false, null, SEBSettings.sebConfigPurposes.sebConfigPurposeConfiguringClient);

                // Re-Initialize SEB desktop according to the new settings
                if (!SebWindowsClientMain.InitSEBDesktop())
                {
                    return(false);
                }

                if (SEBClientInfo.SebWindowsClientForm.OpenSEBForm())
                {
                    // Activate SebWindowsClient so the message box gets focus
                    //SEBClientInfo.SebWindowsClientForm.Activate();

                    // Check if setting for createNewDesktop changed
                    if (SEBClientInfo.CreateNewDesktopOldValue != (bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, SEBSettings.KeyCreateNewDesktop))
                    {
                        // If it did, SEB needs to quit and be restarted manually for the new setting to take effekt
                        SEBMessageBox.Show(SEBUIStrings.sebReconfiguredRestartNeeded, SEBUIStrings.sebReconfiguredRestartNeededReason, MessageBoxIcon.Warning, MessageBoxButtons.OK);
                        //SEBClientInfo.SebWindowsClientForm.closeSebClient = true;
                        SEBClientInfo.SebWindowsClientForm.ExitApplication();
                    }

                    if (SEBMessageBox.Show(SEBUIStrings.sebReconfigured, SEBUIStrings.sebReconfiguredQuestion, MessageBoxIcon.Question, MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        //SEBClientInfo.SebWindowsClientForm.closeSebClient = true;
                        SEBClientInfo.SebWindowsClientForm.ExitApplication();
                    }

                    return(true); //reading preferences was successful
                }
                else
                {
                    return(false);
                }
            }
        }
        public static bool StoreDecryptedSEBSettings(byte[] sebData)
        {
            string                      sebFilePassword       = (string)null;
            bool                        passwordIsHash        = false;
            X509Certificate2            sebFileCertificateRef = (X509Certificate2)null;
            Dictionary <string, object> settingsDict          = SEBConfigFileManager.DecryptSEBSettings(sebData, false, ref sebFilePassword, ref passwordIsHash, ref sebFileCertificateRef);

            if (settingsDict == null)
            {
                return(false);
            }
            Logger.AddInformation("Reconfiguring", (object)null, (Exception)null, (string)null);
            SEBClientInfo.SebWindowsClientForm.closeSebClient = false;
            Logger.AddInformation("Attempting to CloseSEBForm for reconfiguration", (object)null, (Exception)null, (string)null);
            SEBClientInfo.SebWindowsClientForm.CloseSEBForm();
            Logger.AddInformation("Succesfully CloseSEBForm for reconfiguration", (object)null, (Exception)null, (string)null);
            SEBClientInfo.SebWindowsClientForm.closeSebClient = true;
            SEBClientInfo.CreateNewDesktopOldValue            = (bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, "createNewDesktop");
            if ((int)settingsDict["sebConfigPurpose"] == 0)
            {
                Logger.AddInformation("Reconfiguring to start an exam", (object)null, (Exception)null, (string)null);
                Logger.AddInformation("Attempting to StoreSebClientSettings", (object)null, (Exception)null, (string)null);
                SEBSettings.StoreSebClientSettings(settingsDict);
                Logger.AddInformation("Successfully StoreSebClientSettings", (object)null, (Exception)null, (string)null);
                SEBClientInfo.examMode = true;
                SEBClientInfo.InitializeLogger();
                if (SEBClientInfo.CreateNewDesktopOldValue != (bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, "createNewDesktop"))
                {
                    if (!SEBClientInfo.CreateNewDesktopOldValue)
                    {
                        int num1 = (int)SEBMessageBox.Show(SEBUIStrings.settingsRequireNewDesktop, SEBUIStrings.settingsRequireNewDesktopReason, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
                    }
                    else
                    {
                        int num2 = (int)SEBMessageBox.Show(SEBUIStrings.settingsRequireNotNewDesktop, SEBUIStrings.settingsRequireNotNewDesktopReason, MessageBoxIcon.Hand, MessageBoxButtons.OK, false);
                    }
                    SEBClientInfo.SebWindowsClientForm.ExitApplication(true);
                }
                Logger.AddInformation("Attemting to InitSEBDesktop for reconfiguration", (object)null, (Exception)null, (string)null);
                if (!SebWindowsClientMain.InitSEBDesktop())
                {
                    return(false);
                }
                Logger.AddInformation("Sucessfully InitSEBDesktop for reconfiguration", (object)null, (Exception)null, (string)null);
                Logger.AddInformation("Attempting to OpenSEBForm for reconfiguration", (object)null, (Exception)null, (string)null);
                int num = SEBClientInfo.SebWindowsClientForm.OpenSEBForm() ? 1 : 0;
                Logger.AddInformation("Successfully OpenSEBForm for reconfiguration", (object)null, (Exception)null, (string)null);
                return(num != 0);
            }
            Logger.AddInformation("Reconfiguring to configure a client", (object)null, (Exception)null, (string)null);
            List <object> objectList = (List <object>)settingsDict["embeddedCertificates"];

            for (int index = objectList.Count - 1; index >= 0; --index)
            {
                Dictionary <string, object> dictionary = (Dictionary <string, object>)objectList[index];
                if ((int)dictionary["type"] == 1)
                {
                    SEBProtectionController.StoreCertificateIntoStore((byte[])dictionary["certificateData"]);
                }
                objectList.RemoveAt(index);
            }
            SEBSettings.StoreSebClientSettings(settingsDict);
            SEBClientInfo.InitializeLogger();
            SEBSettings.WriteSebConfigurationFile(SEBClientInfo.SebClientSettingsAppDataFile, "", false, (X509Certificate2)null, SEBSettings.sebConfigPurposes.sebConfigPurposeConfiguringClient, false);
            if (!SebWindowsClientMain.InitSEBDesktop() || !SEBClientInfo.SebWindowsClientForm.OpenSEBForm())
            {
                return(false);
            }
            if (SEBClientInfo.CreateNewDesktopOldValue != (bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, "createNewDesktop"))
            {
                int num = (int)SEBMessageBox.Show(SEBUIStrings.sebReconfiguredRestartNeeded, SEBUIStrings.sebReconfiguredRestartNeededReason, MessageBoxIcon.Exclamation, MessageBoxButtons.OK, false);
                SEBClientInfo.SebWindowsClientForm.ExitApplication(true);
            }
            if (SEBMessageBox.Show(SEBUIStrings.sebReconfigured, SEBUIStrings.sebReconfiguredQuestion, MessageBoxIcon.Question, MessageBoxButtons.YesNo, false) == DialogResult.No)
            {
                SEBClientInfo.SebWindowsClientForm.ExitApplication(true);
            }
            return(true);
        }