Esempio n. 1
0
 public EngineEnvironmentSettings(ITemplateEngineHost host, Func <IEngineEnvironmentSettings, ISettingsLoader> settingsLoaderFactory, string hiveLocation)
 {
     Host           = host;
     Paths          = new DefaultPathInfo(this, hiveLocation);
     Environment    = new DefaultEnvironment();
     SettingsLoader = settingsLoaderFactory(this);
 }
Esempio n. 2
0
        /// <summary>
        /// Creates the instance.
        /// </summary>
        /// <param name="host">caller <see cref="ITemplateEngineHost"/>.</param>
        /// <param name="virtualizeConfiguration">if true, settings will be stored in memory and will be disposed with instance.</param>
        /// <param name="loadDefaultComponents">if true, the default components (providers, installers, generator) will be loaded. Same as calling <see cref="LoadDefaultComponents()"/> after instance is created.</param>
        /// <param name="hostSettingsLocation">the file path to store host specific settings. Use null for default location.
        /// Note: this parameter changes only directory of host and host version specific settings. Global settings path remains unchanged.</param>
        public Bootstrapper(ITemplateEngineHost host, bool virtualizeConfiguration, bool loadDefaultComponents = true, string?hostSettingsLocation = null)
        {
            _host = host ?? throw new ArgumentNullException(nameof(host));

            if (string.IsNullOrWhiteSpace(hostSettingsLocation))
            {
                _engineEnvironmentSettings = new EngineEnvironmentSettings(host, virtualizeSettings: virtualizeConfiguration);
            }
            else
            {
                string       hostSettingsDir        = Path.Combine(hostSettingsLocation, host.HostIdentifier);
                string       hostVersionSettingsDir = Path.Combine(hostSettingsLocation, host.HostIdentifier, host.Version);
                IEnvironment environment            = new DefaultEnvironment();
                IPathInfo    pathInfo = new DefaultPathInfo(environment, host, hostSettingsDir: hostSettingsDir, hostVersionSettingsDir: hostVersionSettingsDir);
                _engineEnvironmentSettings = new EngineEnvironmentSettings(
                    host,
                    virtualizeSettings: virtualizeConfiguration,
                    environment: environment,
                    pathInfo: pathInfo);
            }

            _templateCreator         = new TemplateCreator(_engineEnvironmentSettings);
            _templatePackagesManager = new Edge.Settings.TemplatePackageManager(_engineEnvironmentSettings);
            if (loadDefaultComponents)
            {
                LoadDefaultComponents();
            }
        }
Esempio n. 3
0
        public void CustomHiveLocationTest(string?hiveLocation)
        {
            var environment = A.Fake <IEnvironment>();

            A.CallTo(() => environment.GetEnvironmentVariable("HOME")).Returns("/home/path");
            A.CallTo(() => environment.GetEnvironmentVariable("USERPROFILE")).Returns("C:\\users\\user");

            var host = A.Fake <ITemplateEngineHost>();

            A.CallTo(() => host.HostIdentifier).Returns("hostID");
            A.CallTo(() => host.Version).Returns("1.0.0");

            var envSettings = A.Fake <IEngineEnvironmentSettings>();

            A.CallTo(() => envSettings.Host).Returns(host);
            A.CallTo(() => envSettings.Environment).Returns(environment);

            var pathInfo = new DefaultPathInfo(envSettings, hiveLocation);

            var homeFolder     = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "C:\\users\\user" : "/home/path";
            var expectedGlobal = string.IsNullOrWhiteSpace(hiveLocation)
                ? Path.Combine(homeFolder, ".templateengine")
                : Path.Combine(hiveLocation);
            var expectedHost = string.IsNullOrWhiteSpace(hiveLocation)
                ? Path.Combine(homeFolder, ".templateengine", "hostID")
                : Path.Combine(hiveLocation, "hostID");
            var expectedHostVesrion = string.IsNullOrWhiteSpace(hiveLocation)
                ? Path.Combine(homeFolder, ".templateengine", "hostID", "1.0.0")
                : Path.Combine(hiveLocation, "hostID", "1.0.0");

            Assert.Equal(homeFolder, pathInfo.UserProfileDir);
            Assert.Equal(expectedGlobal, pathInfo.GlobalSettingsDir);
            Assert.Equal(expectedHost, pathInfo.HostSettingsDir);
            Assert.Equal(expectedHostVesrion, pathInfo.HostVersionSettingsDir);
        }
Esempio n. 4
0
        public void DefaultLocationTest()
        {
            var environment = A.Fake <IEnvironment>();

            A.CallTo(() => environment.GetEnvironmentVariable("HOME")).Returns("/home/path");
            A.CallTo(() => environment.GetEnvironmentVariable("USERPROFILE")).Returns("C:\\users\\user");

            var host = A.Fake <ITemplateEngineHost>();

            A.CallTo(() => host.HostIdentifier).Returns("hostID");
            A.CallTo(() => host.Version).Returns("1.0.0");

            var pathInfo = new DefaultPathInfo(environment, host);

            var homeFolder = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "C:\\users\\user" : "/home/path";

            Assert.Equal(homeFolder, pathInfo.UserProfileDir);
            Assert.Equal(Path.Combine(homeFolder, ".templateengine"), pathInfo.GlobalSettingsDir);
            Assert.Equal(Path.Combine(homeFolder, ".templateengine", "hostID"), pathInfo.HostSettingsDir);
            Assert.Equal(Path.Combine(homeFolder, ".templateengine", "hostID", "1.0.0"), pathInfo.HostVersionSettingsDir);
        }
Esempio n. 5
0
        public void CustomLocationTest(string?global, string?hostDir, string?hostVersion)
        {
            var environment = A.Fake <IEnvironment>();

            A.CallTo(() => environment.GetEnvironmentVariable("HOME")).Returns("/home/path");
            A.CallTo(() => environment.GetEnvironmentVariable("USERPROFILE")).Returns("C:\\users\\user");

            var host = A.Fake <ITemplateEngineHost>();

            A.CallTo(() => host.HostIdentifier).Returns("hostID");
            A.CallTo(() => host.Version).Returns("1.0.0");

            var pathInfo = new DefaultPathInfo(environment, host, global, hostDir, hostVersion);

            var homeFolder         = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "C:\\users\\user" : "/home/path";
            var defaultGlobal      = Path.Combine(homeFolder, ".templateengine");
            var defaultHost        = Path.Combine(homeFolder, ".templateengine", "hostID");
            var defaultHostVesrion = Path.Combine(homeFolder, ".templateengine", "hostID", "1.0.0");

            Assert.Equal(homeFolder, pathInfo.UserProfileDir);
            Assert.Equal(string.IsNullOrWhiteSpace(global) ? defaultGlobal : global, pathInfo.GlobalSettingsDir);
            Assert.Equal(string.IsNullOrWhiteSpace(hostDir) ? defaultHost : hostDir, pathInfo.HostSettingsDir);
            Assert.Equal(string.IsNullOrWhiteSpace(hostVersion) ? defaultHostVesrion : hostVersion, pathInfo.HostVersionSettingsDir);
        }
Esempio n. 6
0
 static EngineEnvironmentSettings()
 {
     Host  = new DefaultTemplateEngineHost(DefaultLocale);
     Paths = new DefaultPathInfo();
 }