The elements of installation configuration that the standard library understands.
        internal static void Init(string assemblyFolderPath, Type globalInitializerType, string appName, bool isClientSideApp, ref string initializationLog)
        {
            EwlFolderPath = Environment.GetEnvironmentVariable("{0}FolderPath".FormatWith(EwlStatics.EwlInitialism.EnglishToPascal())) ??
                            @"C:\{0}".FormatWith(EwlStatics.EwlName);

            initializationLog += Environment.NewLine + "About to load machine config";

            // Load machine configuration.
            var machineConfigFilePath = EwlStatics.CombinePaths(EwlFolderPath, "Machine Configuration.xml");

            if (File.Exists(machineConfigFilePath))
            {
                // Do not perform schema validation since the schema file won't be available on non-development machines.
                try {
                    MachineConfiguration = XmlOps.DeserializeFromFile <MachineConfiguration>(machineConfigFilePath, false);
                }
                catch {
                    // The alt file allows us to smoothly transition all machines in the case of schema changes that break deserialization.
                    var altFilePath = EwlStatics.CombinePaths(EwlFolderPath, "Machine Configuration Alt.xml");
                    if (!File.Exists(altFilePath))
                    {
                        throw;
                    }
                    MachineConfiguration = XmlOps.DeserializeFromFile <MachineConfiguration>(altFilePath, false);
                }
            }

            initializationLog += Environment.NewLine + "About to initialize stack trace";

            // Assume the first assembly up the call stack that is not this assembly is the application assembly.
            var stackFrames = new StackTrace().GetFrames();

            if (stackFrames == null)
            {
                throw new ApplicationException("No stack trace available.");
            }
            AppAssembly = stackFrames.Select(frame => frame.GetMethod().DeclaringType.Assembly).First(assembly => assembly != Assembly.GetExecutingAssembly());

            initializationLog += Environment.NewLine + "Stack trace initialized";

            // Determine the installation path and load configuration information.
            string installationPath;
            bool   isDevelopmentInstallation;

            if (NetTools.IsWebApp())
            {
                initializationLog += Environment.NewLine + "Is a web app";

                installationPath          = EwlStatics.CombinePaths(HttpRuntime.AppDomainAppPath, "..");
                isDevelopmentInstallation = !InstallationConfiguration.InstalledInstallationExists(installationPath);
            }
            else
            {
                initializationLog += Environment.NewLine + "Is not a web app";

                // Assume this is an installed installation. If this assumption turns out to be wrong, consider it a development installation. Installed executables are
                // one level below the installation folder.
                installationPath          = EwlStatics.CombinePaths(assemblyFolderPath.Any() ? assemblyFolderPath : Path.GetDirectoryName(AppAssembly.Location), "..");
                isDevelopmentInstallation = !InstallationConfiguration.InstalledInstallationExists(installationPath);
                if (isDevelopmentInstallation)
                {
                    installationPath = EwlStatics.CombinePaths(installationPath, "..", "..");                       // Visual Studio puts executables inside bin\Debug.
                }
            }
            initializationLog        += Environment.NewLine + "Successfully determined installation path";
            InstallationConfiguration = new InstallationConfiguration(installationPath, isDevelopmentInstallation);
            initializationLog        += Environment.NewLine + "Successfully loaded installation configuration";

            ConfigurationStatics.globalInitializerType = globalInitializerType;
            SystemGeneralProvider = GetSystemLibraryProvider("General") as SystemGeneralProvider;
            if (SystemGeneralProvider == null)
            {
                throw new ApplicationException("General provider not found in system");
            }

            AppName         = appName;
            IsClientSideApp = isClientSideApp;
        }
 public ExistingInstallationLogic( GeneralInstallationLogic generalInstallationLogic, InstallationConfiguration runtimeConfiguration )
 {
     this.generalInstallationLogic = generalInstallationLogic;
     this.runtimeConfiguration = runtimeConfiguration;
 }
        internal static void Init(
            bool useRelativeInstallationPath, Type globalInitializerType, string appName, bool isClientSideProgram, ref string initializationLog)
        {
            RedStaplerFolderPath = Environment.GetEnvironmentVariable("RedStaplerFolderPath") ?? @"C:\Red Stapler";

            initializationLog += Environment.NewLine + "About to load machine config";

            // Load machine configuration.
            var machineConfigXmlFilePath = EwlStatics.CombinePaths(RedStaplerFolderPath, "Machine Configuration.xml");

            if (File.Exists(machineConfigXmlFilePath))
            {
                // Do not perform schema validation since the schema file won't be available on non-development machines.
                MachineConfiguration = XmlOps.DeserializeFromFile <MachineConfiguration>(machineConfigXmlFilePath, false);
            }

            initializationLog += Environment.NewLine + "About to initialize stack trace";

            // Assume the first assembly up the call stack that is not this assembly is the application assembly.
            var stackFrames = new StackTrace().GetFrames();

            if (stackFrames == null)
            {
                throw new ApplicationException("No stack trace available.");
            }
            AppAssembly = stackFrames.Select(frame => frame.GetMethod().DeclaringType.Assembly).First(assembly => assembly != Assembly.GetExecutingAssembly());

            initializationLog += Environment.NewLine + "Stack trace initialized";

            // Determine the installation path and load configuration information.
            string installationPath;
            bool   isDevelopmentInstallation;

            if (NetTools.IsWebApp())
            {
                initializationLog += Environment.NewLine + "Is a web app";

                installationPath          = EwlStatics.CombinePaths(HttpRuntime.AppDomainAppPath, "..");
                isDevelopmentInstallation = !InstallationConfiguration.InstalledInstallationExists(installationPath);
            }
            else
            {
                initializationLog += Environment.NewLine + "Is not a web app";

                // Assume this is an installed installation. If this assumption turns out to be wrong, consider it a development installation. Installed executables are
                // one level below the installation folder.
                if (useRelativeInstallationPath)
                {
                    installationPath = "..";
                }
                else
                {
                    var assemblyFolderPath = Path.GetDirectoryName(AppAssembly.Location);
                    installationPath = EwlStatics.CombinePaths(assemblyFolderPath, "..");
                }
                isDevelopmentInstallation = !InstallationConfiguration.InstalledInstallationExists(installationPath);
                if (isDevelopmentInstallation)
                {
                    installationPath = EwlStatics.CombinePaths(installationPath, "..", "..");                       // Visual Studio puts executables inside bin\Debug.
                }
            }
            initializationLog        += Environment.NewLine + "Successfully determined installation path";
            InstallationConfiguration = new InstallationConfiguration(MachineIsStandbyServer, installationPath, isDevelopmentInstallation);
            initializationLog        += Environment.NewLine + "Successfully loaded installation configuration";

            ConfigurationStatics.globalInitializerType = globalInitializerType;
            SystemGeneralProvider = GetSystemLibraryProvider("General") as SystemGeneralProvider;
            if (SystemGeneralProvider == null)
            {
                throw new ApplicationException("General provider not found in system");
            }

            AppName             = appName;
            IsClientSideProgram = isClientSideProgram;
        }