Пример #1
0
        public static int Run(string[] args)
        {
            var sessionId =
                Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);

            // senderCount: 0 to disable sender.
            // When senders in different process running at the same
            // time they will read from the same global queue and cause
            // sending duplicated events. Disable sender to reduce it.
            var telemetry = new Telemetry(new FirstTimeUseNoticeSentinel(),
                                          sessionId,
                                          senderCount: 0);
            var logger = new TelemetryLogger(null);

            if (telemetry.Enabled)
            {
                logger = new TelemetryLogger((name, props, measures) =>
                {
                    if (telemetry.Enabled)
                    {
                        telemetry.TrackEvent($"template/{name}", props, measures);
                    }
                });
            }

            return(New3Command.Run(CommandName, CreateHost(), logger, FirstRun, args));
        }
Пример #2
0
        public static int Main(string[] args)
        {
            bool emitTimings    = args.Any(x => string.Equals(x, "--debug:emit-timings", StringComparison.OrdinalIgnoreCase));
            bool debugTelemetry = args.Any(x => string.Equals(x, "--debug:emit-telemetry", StringComparison.OrdinalIgnoreCase));

            return(New3Command.Run(CommandName, CreateHost(emitTimings), new TelemetryLogger(null, debugTelemetry), FirstRun, args));
        }
        public static int Main(string[] args)
        {
            bool emitTimings    = args.Any(x => string.Equals(x, "--debug:emit-timings", StringComparison.OrdinalIgnoreCase));
            bool debugTelemetry = args.Any(x => string.Equals(x, "--debug:emit-telemetry", StringComparison.OrdinalIgnoreCase));

            bool disableSdkTemplates       = args.Any(x => string.Equals(x, "--debug:disable-sdk-templates", StringComparison.OrdinalIgnoreCase));
            DefaultTemplateEngineHost host = CreateHost(emitTimings, disableSdkTemplates);

            bool debugAuthoring = args.Any(x => string.Equals(x, "--trace:authoring", StringComparison.OrdinalIgnoreCase));
            bool debugInstall   = args.Any(x => string.Equals(x, "--trace:install", StringComparison.OrdinalIgnoreCase));

            if (debugAuthoring)
            {
                AddAuthoringLogger(host);
                AddInstallLogger(host);
            }
            else if (debugInstall)
            {
                AddInstallLogger(host);
            }

            var callbacks = new New3Callbacks();

            return(New3Command.Run(CommandName, host, new TelemetryLogger(null, debugTelemetry), callbacks, args));
        }
Пример #4
0
        public void NupkgReinstallDoesntRemoveTemplates()
        {
            const string nupkgToInstallName = "TestNupkgInstallTemplate.0.0.1.nupkg";
            const string checkTemplateName  = "nupkginstall";   // this is the short name of the template in the nupkg that gets installed.

            ITemplateEngineHost host = CreateHostWithVirtualizedHive(HostIdentifier, HostVersion);

            Assert.NotNull(host);

            ITelemetryLogger telemetryLogger = new TelemetryLogger(null, false);
            int initializeResult             = New3Command.Run(CommandName, host, telemetryLogger, null, new string[] { });

            Assert.Equal(0, initializeResult);

            string codebase      = typeof(NupkgInstallTests).GetTypeInfo().Assembly.CodeBase;
            Uri    cb            = new Uri(codebase);
            string asmPath       = cb.LocalPath;
            string dir           = Path.GetDirectoryName(asmPath);
            string pathToInstall = Path.Combine(dir, "TemplateInstallTests", "TestTemplates", nupkgToInstallName);

            Assert.True(File.Exists(pathToInstall), $"directory didnt exist: {pathToInstall}");

            string[] installArgs = new[]
            {
                "--install",
                pathToInstall
            };

            // install the test pack
            int firstInstallResult = New3Command.Run(CommandName, host, telemetryLogger, null, installArgs);

            Assert.Equal(0, firstInstallResult);

            EngineEnvironmentSettings environemnt    = new EngineEnvironmentSettings(host, x => new SettingsLoader(x));
            SettingsLoader            settingsLoader = (SettingsLoader)environemnt.SettingsLoader;
            IHostSpecificDataLoader   hostDataLoader = new MockHostSpecificDataLoader();

            // check that the template was installed from the first install.
            IReadOnlyCollection <ITemplateMatchInfo> allTemplates = TemplateListResolver.PerformAllTemplatesQuery(settingsLoader.UserTemplateCache.TemplateInfo, hostDataLoader);

            Assert.Contains(checkTemplateName, allTemplates.Select(t => t.Info.ShortName));

            // install the same test pack again
            int secondInstallResult = New3Command.Run(CommandName, host, telemetryLogger, null, installArgs);

            Assert.Equal(0, secondInstallResult);

            settingsLoader.Reload();

            // check that the template is still installed after the second install.
            IReadOnlyCollection <ITemplateMatchInfo> allTemplatesAfterSecondInstall = TemplateListResolver.PerformAllTemplatesQuery(settingsLoader.UserTemplateCache.TemplateInfo, hostDataLoader);

            Assert.Contains(checkTemplateName, allTemplatesAfterSecondInstall.Select(t => t.Info.ShortName));
        }
Пример #5
0
        static int Main(string[] args)
        {
            VerificationLookup["dir_exists"]            = CheckDirectoryExists;
            VerificationLookup["file_exists"]           = CheckFileExists;
            VerificationLookup["dir_does_not_exist"]    = CheckDirectoryDoesNotExist;
            VerificationLookup["file_does_not_exist"]   = CheckFileDoesNotExist;
            VerificationLookup["file_contains"]         = CheckFileContains;
            VerificationLookup["file_does_not_contain"] = CheckFileDoesNotContain;

            string[] passthroughArgs = new string[args.Length - 2];

            for (int i = 0; i < passthroughArgs.Length; ++i)
            {
                passthroughArgs[i] = args[i + 2];
            }

            string verificationsFile         = args[0];
            string outputPath                = args[1];
            string verificationsFileContents = File.ReadAllText(verificationsFile);
            JArray verifications             = JArray.Parse(verificationsFileContents);
            ITemplateEngineHost host         = CreateHost();
            string profileDir                = Environment.ExpandEnvironmentVariables("%USERPROFILE%");

            if (string.IsNullOrWhiteSpace(profileDir))
            {
                profileDir = Environment.ExpandEnvironmentVariables("$HOME");
            }
            if (string.IsNullOrWhiteSpace(profileDir))
            {
                Console.Error.WriteLine("Could not determine home directory");
                return(0);
            }

            host.VirtualizeDirectory(Path.Combine(profileDir, ".templateengine"));
            host.VirtualizeDirectory(outputPath);

            int result = New3Command.Run(CommandName, host, FirstRun, passthroughArgs);

            bool verificationsPassed = false;

            try
            {
                verificationsPassed = RunVerifications(verifications, host.FileSystem, outputPath);
            }
            catch (Exception ex)
            {
                verificationsPassed = false;
                Console.Error.WriteLine(ex.ToString());
            }

            return(result != 0 ? result : verificationsPassed ? 0 : 1);
        }
Пример #6
0
        public static int Run(string[] args)
        {
            var sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
            var telemetry = new Telemetry(new NuGetCacheSentinel(new CliFallbackFolderPathCalculator()), sessionId);
            var logger    = new TelemetryLogger((name, props, measures) =>
            {
                if (telemetry.Enabled)
                {
                    telemetry.TrackEvent(name, props, measures);
                }
            });

            return(New3Command.Run(CommandName, CreateHost(), logger, FirstRun, args));
        }
Пример #7
0
        public static int Run(string[] args)
        {
            var sessionId =
                Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
            var telemetry = new Telemetry(new FirstTimeUseNoticeSentinel(), sessionId);
            var logger    = new TelemetryLogger(null);

            if (telemetry.Enabled)
            {
                logger = new TelemetryLogger((name, props, measures) =>
                {
                    if (telemetry.Enabled)
                    {
                        telemetry.TrackEvent($"template/{name}", props, measures);
                    }
                });
            }

            return(New3Command.Run(CommandName, CreateHost(), logger, FirstRun, args));
        }
Пример #8
0
        static int Main(string[] args)
        {
            VerificationLookup["dir_exists"] = CheckDirectoryExists;
            VerificationLookup["file_exists"] = CheckFileExists;
            VerificationLookup["dir_does_not_exist"] = CheckDirectoryDoesNotExist;
            VerificationLookup["file_does_not_exist"] = CheckFileDoesNotExist;
            VerificationLookup["file_contains"] = CheckFileContains;
            VerificationLookup["file_does_not_contain"] = CheckFileDoesNotContain;

            int batteryCount = int.Parse(args[0], CultureInfo.InvariantCulture);
            string[] passthroughArgs = new string[args.Length - 2 - batteryCount];
            string outputPath = args[batteryCount + 1];

            for(int i = 0; i < passthroughArgs.Length; ++i)
            {
                passthroughArgs[i] = args[i + 2 + batteryCount];
            }

            string home = "%USERPROFILE%";

            if (Path.DirectorySeparatorChar == '/')
            {
                home = "%HOME%";
            }

            ITemplateEngineHost host = CreateHost();
            string profileDir = Environment.ExpandEnvironmentVariables(home);

            if (string.IsNullOrWhiteSpace(profileDir))
            {
                Console.Error.WriteLine("Could not determine home directory");
                return 0;
            }

            string hivePath = Path.Combine(profileDir, ".tetestharness");
            host.VirtualizeDirectory(hivePath);
            host.VirtualizeDirectory(outputPath);

            int result = New3Command.Run(CommandName, host, new TelemetryLogger(null), FirstRun, passthroughArgs, hivePath);
            bool verificationsPassed = false;

            for (int i = 0; i < batteryCount; ++i)
            {
                string verificationsFile = args[i + 1];
                string verificationsFileContents = File.ReadAllText(verificationsFile);
                JArray verifications = JArray.Parse(verificationsFileContents);

                try
                {
                    verificationsPassed = RunVerifications(verifications, host.FileSystem, outputPath);
                }
                catch (Exception ex)
                {
                    verificationsPassed = false;
                    Console.Error.WriteLine(ex.ToString());
                }
            }

            Console.Error.WriteLine(" ");
            Console.Error.WriteLine("Output Files:");
            foreach (string fileName in host.FileSystem.EnumerateFiles(outputPath, "*", SearchOption.AllDirectories))
            {
                Console.Error.WriteLine(fileName.Substring(outputPath.Length));
            }

            return result != 0 ? result : verificationsPassed ? 0 : 1;
        }
Пример #9
0
 public static int Run(string[] args)
 {
     return(New3Command.Run(CommandName, CreateHost(), FirstRun, args));
 }
Пример #10
0
 public static int Run(string[] args)
 {
     return(New3Command.Run(CommandName, CreateHost(), new TelemetryLogger(null), FirstRun, args));
 }