public SysTrayApp(ConfigFileProvider configFileProvider, ProcessProvider processProvider, IISProvider iisProvider, EnvironmentProvider environmentProvider) { _configFileProvider = configFileProvider; _processProvider = processProvider; _iisProvider = iisProvider; _environmentProvider = environmentProvider; }
private static void ConfigureDotNetForFirstTimeUse( INuGetCacheSentinel nugetCacheSentinel, CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator) { using (PerfTrace.Current.CaptureTiming()) { var nugetPackagesArchiver = new NuGetPackagesArchiver(); var environmentProvider = new EnvironmentProvider(); var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true); var nugetConfig = new NuGetConfig(cliFallbackFolderPathCalculator); var nugetCachePrimer = new NuGetCachePrimer( nugetPackagesArchiver, nugetCacheSentinel, nugetConfig, cliFallbackFolderPathCalculator); var dotnetConfigurer = new DotnetFirstTimeUseConfigurer( nugetCachePrimer, nugetCacheSentinel, environmentProvider); dotnetConfigurer.Configure(); } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var provider = new EnvironmentProvider <EnvConfig>(); var values = provider.Values; Console.WriteLine(values.AspNetCoreEnvironment); Console.WriteLine(values.MyEnvString); Console.WriteLine(values.MyEnvInt); Console.WriteLine(values.MyEnvBool); Console.WriteLine(values.MyEnvDouble); Console.WriteLine(string.Join(", ", values.MyEnvStringArray)); Console.WriteLine(string.Join(", ", values.MyEnvStringList)); Console.WriteLine(string.Join(", ", values.MyEnvStringEnumerable)); Console.WriteLine(string.Join(", ", values.MyEnvIntArray)); Console.WriteLine(string.Join(", ", values.MyEnvIntList)); Console.WriteLine(string.Join(", ", values.MyEnvIntEnumerable)); Console.WriteLine(string.Join(", ", values.MyEnvIntDictionary)); Console.WriteLine(string.Join(", ", values.MyEnvIntStrDictionary)); Console.WriteLine(values.MyNullList is null ? "I should be null and i'm null" : "Something goes wrong"); }
public static CompositeCommandResolver Create() { var environment = new EnvironmentProvider(); var packagedCommandSpecFactory = new PackagedCommandSpecFactoryWithCliRuntime(); var publishedPathCommandSpecFactory = new PublishPathCommandSpecFactory(); var platformCommandSpecFactory = default(IPlatformCommandSpecFactory); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); } else { platformCommandSpecFactory = new GenericPlatformCommandSpecFactory(); } return(CreateDefaultCommandResolver( environment, packagedCommandSpecFactory, platformCommandSpecFactory, publishedPathCommandSpecFactory)); }
public Telemetry( IFirstTimeUseNoticeSentinel sentinel, string sessionId, bool blockThreadInitialization = false, IEnvironmentProvider environmentProvider = null, int senderCount = 3) { if (DisabledForTests) { return; } if (environmentProvider == null) { environmentProvider = new EnvironmentProvider(); } Enabled = !environmentProvider.GetEnvironmentVariableAsBool(TelemetryOptout, false) && PermissionExists(sentinel); if (!Enabled) { return; } // Store the session ID in a static field so that it can be reused CurrentSessionId = sessionId ?? Guid.NewGuid().ToString(); _senderCount = senderCount; if (blockThreadInitialization) { InitializeTelemetry(); } else { //initialize in task to offload to parallel thread _trackEventTask = Task.Run(() => InitializeTelemetry()); } }
public static IEnvironmentPath CreateEnvironmentPath( bool hasSuperUserAccess = false, IEnvironmentProvider environmentProvider = null) { if (environmentProvider == null) { environmentProvider = new EnvironmentProvider(); } IEnvironmentPath environmentPath = new DoNothingEnvironmentPath(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { environmentPath = new WindowsEnvironmentPath( CliFolderPathCalculator.ToolsShimPath, Reporter.Output, environmentProvider); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && hasSuperUserAccess) { environmentPath = new LinuxEnvironmentPath( CliFolderPathCalculator.ToolsShimPathInUnix, Reporter.Output, environmentProvider, new FileWrapper()); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && hasSuperUserAccess) { environmentPath = new OsxBashEnvironmentPath( executablePath: CliFolderPathCalculator.ToolsShimPathInUnix, reporter: Reporter.Output, environmentProvider: environmentProvider, fileSystem: new FileWrapper()); } return(environmentPath); }
private static void ConfigureDotNetForFirstTimeUse( INuGetCacheSentinel nugetCacheSentinel, IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, CliFolderPathCalculator cliFolderPathCalculator, bool hasSuperUserAccess) { var environmentProvider = new EnvironmentProvider(); using (PerfTrace.Current.CaptureTiming()) { var nugetPackagesArchiver = new NuGetPackagesArchiver(); var environmentPath = EnvironmentPathFactory.CreateEnvironmentPath(cliFolderPathCalculator, hasSuperUserAccess, environmentProvider); var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true); var nugetCachePrimer = new NuGetCachePrimer( nugetPackagesArchiver, nugetCacheSentinel, cliFolderPathCalculator); var aspnetCertificateGenerator = new AspNetCoreCertificateGenerator(); var dotnetConfigurer = new DotnetFirstTimeUseConfigurer( nugetCachePrimer, nugetCacheSentinel, firstTimeUseNoticeSentinel, aspNetCertificateSentinel, aspnetCertificateGenerator, toolPathSentinel, environmentProvider, Reporter.Output, cliFolderPathCalculator.CliFallbackFolderPath, environmentPath); dotnetConfigurer.Configure(); } }
public void It_prefers_EXE_over_CMD_when_two_command_candidates_exist_and_using_WindowsExePreferredCommandSpecFactory() { var environment = new EnvironmentProvider(new [] { ".exe", ".cmd" }, new[] { s_testDirectory }); var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory); CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testDirectory, "extensionPreferenceCommand", ".exe"); CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testDirectory, "extensionPreferenceCommand", ".cmd"); var commandResolverArguments = new CommandResolverArguments() { CommandName = "extensionPreferenceCommand", CommandArguments = null }; var result = pathCommandResolver.Resolve(commandResolverArguments); result.Should().NotBeNull(); var commandFile = Path.GetFileName(result.Path); commandFile.Should().Be("extensionPreferenceCommand.exe"); }
private ICommandResolver GetProjectDependenciesCommandResolver(NuGetFramework framework) { var environment = new EnvironmentProvider(); if (framework.IsDesktop()) { IPlatformCommandSpecFactory platformCommandSpecFactory = null; if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); } else { platformCommandSpecFactory = new GenericPlatformCommandSpecFactory(); } return(new OutputPathCommandResolver(environment, platformCommandSpecFactory)); } else { var packagedCommandSpecFactory = new PackagedCommandSpecFactory(); return(new ProjectDependenciesCommandResolver(environment, packagedCommandSpecFactory)); } }
static CoreTest() { //Delete old db files var oldDbFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories); foreach (var file in oldDbFiles) { try { File.Delete(file); } catch { } } //Delete App_data folder var appData = new EnvironmentProvider().GetAppDataPath(); if (Directory.Exists(appData)) { Directory.Delete(appData, true); } TestDbHelper.CreateDataBaseTemplate(); }
public AppShutdownJob(EnvironmentProvider environmentProvider, ProcessProvider processProvider, ServiceProvider serviceProvider) { _environmentProvider = environmentProvider; _processProvider = processProvider; _serviceProvider = serviceProvider; }
internal static int ProcessArgs(string[] args, TimeSpan startupTime, ITelemetry telemetryClient = null) { Dictionary <string, double> performanceData = new Dictionary <string, double>(); PerformanceLogEventSource.Log.BuiltInCommandParserStart(); Stopwatch parseStartTime = Stopwatch.StartNew(); var parseResult = Parser.Instance.Parse(args); // Avoid create temp directory with root permission and later prevent access in non sudo // This method need to be run very early before temp folder get created // https://github.com/dotnet/sdk/issues/20195 SudoEnvironmentDirectoryOverride.OverrideEnvironmentVariableToTmp(parseResult); performanceData.Add("Parse Time", parseStartTime.Elapsed.TotalMilliseconds); PerformanceLogEventSource.Log.BuiltInCommandParserStop(); using (IFirstTimeUseNoticeSentinel disposableFirstTimeUseNoticeSentinel = new FirstTimeUseNoticeSentinel()) { IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel = disposableFirstTimeUseNoticeSentinel; IAspNetCertificateSentinel aspNetCertificateSentinel = new AspNetCertificateSentinel(); IFileSentinel toolPathSentinel = new FileSentinel( new FilePath( Path.Combine( CliFolderPathCalculator.DotnetUserProfileFolderPath, ToolPathSentinelFileName))); if (parseResult.GetValueForOption(Parser.DiagOption) && parseResult.IsDotnetBuiltInCommand()) { Environment.SetEnvironmentVariable(CommandContext.Variables.Verbose, bool.TrueString); CommandContext.SetVerbose(true); Reporter.Reset(); } if (parseResult.HasOption(Parser.VersionOption) && parseResult.IsTopLevelDotnetCommand()) { CommandLineInfo.PrintVersion(); return(0); } else if (parseResult.HasOption(Parser.InfoOption) && parseResult.IsTopLevelDotnetCommand()) { CommandLineInfo.PrintInfo(); return(0); } else { PerformanceLogEventSource.Log.FirstTimeConfigurationStart(); var environmentProvider = new EnvironmentProvider(); bool generateAspNetCertificate = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", defaultValue: true); bool telemetryOptout = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", defaultValue: false); bool addGlobalToolsToPath = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_ADD_GLOBAL_TOOLS_TO_PATH", defaultValue: true); bool nologo = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_NOLOGO", defaultValue: false); ReportDotnetHomeUsage(environmentProvider); var isDotnetBeingInvokedFromNativeInstaller = false; if (parseResult.CommandResult.Command.Name.Equals(Parser.InstallSuccessCommand.Name)) { aspNetCertificateSentinel = new NoOpAspNetCertificateSentinel(); firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel(); toolPathSentinel = new NoOpFileSentinel(exists: false); isDotnetBeingInvokedFromNativeInstaller = true; } var dotnetFirstRunConfiguration = new DotnetFirstRunConfiguration( generateAspNetCertificate: generateAspNetCertificate, telemetryOptout: telemetryOptout, addGlobalToolsToPath: addGlobalToolsToPath, nologo: nologo); ConfigureDotNetForFirstTimeUse( firstTimeUseNoticeSentinel, aspNetCertificateSentinel, toolPathSentinel, isDotnetBeingInvokedFromNativeInstaller, dotnetFirstRunConfiguration, environmentProvider, performanceData); PerformanceLogEventSource.Log.FirstTimeConfigurationStop(); } PerformanceLogEventSource.Log.TelemetryRegistrationStart(); if (telemetryClient == null) { telemetryClient = new Telemetry.Telemetry(firstTimeUseNoticeSentinel); } TelemetryEventEntry.Subscribe(telemetryClient.TrackEvent); TelemetryEventEntry.TelemetryFilter = new TelemetryFilter(Sha256Hasher.HashWithNormalizedCasing); PerformanceLogEventSource.Log.TelemetryRegistrationStop(); } if (CommandContext.IsVerbose()) { Console.WriteLine($"Telemetry is: {(telemetryClient.Enabled ? "Enabled" : "Disabled")}"); } PerformanceLogEventSource.Log.TelemetrySaveIfEnabledStart(); performanceData.Add("Startup Time", startupTime.TotalMilliseconds); TelemetryEventEntry.SendFiltered(Tuple.Create(parseResult, performanceData)); PerformanceLogEventSource.Log.TelemetrySaveIfEnabledStop(); int exitCode; if (parseResult.CanBeInvoked()) { PerformanceLogEventSource.Log.BuiltInCommandStart(); exitCode = parseResult.Invoke(); PerformanceLogEventSource.Log.BuiltInCommandStop(); } else { PerformanceLogEventSource.Log.ExtensibleCommandResolverStart(); var resolvedCommand = CommandFactoryUsingResolver.Create( "dotnet-" + parseResult.GetValueForArgument(Parser.DotnetSubCommand), args.GetSubArguments(), FrameworkConstants.CommonFrameworks.NetStandardApp15); PerformanceLogEventSource.Log.ExtensibleCommandResolverStop(); PerformanceLogEventSource.Log.ExtensibleCommandStart(); var result = resolvedCommand.Execute(); PerformanceLogEventSource.Log.ExtensibleCommandStop(); exitCode = result.ExitCode; } PerformanceLogEventSource.Log.TelemetryClientFlushStart(); telemetryClient.Flush(); PerformanceLogEventSource.Log.TelemetryClientFlushStop(); return(exitCode); }
public TvDbProvider(EnvironmentProvider environmentProvider) { _environmentProvider = environmentProvider; _handler = new TvdbHandler(new XmlCacheProvider(_environmentProvider.GetCacheFolder()), TVDB_APIKEY); }
public LogProvider(IDatabase database, DiskProvider diskProvider, EnvironmentProvider environmentProvider) { _database = database; _diskProvider = diskProvider; _environmentProvider = environmentProvider; }
static void RunWebTest(string[] args) { //params 1 = test assembly string testAssembly = string.Empty; if (args.Length > 1) { testAssembly = args[1]; } else { Console.WriteLine("You need to specify an assembly."); return; } //params 2 = test name string testName = string.Empty; if (args.Length > 2) { testName = args[2]; } else { Console.WriteLine("You need to specify a test."); return; } //params 3 = environments Dictionary <int, TestEnvironment> Environments = new Dictionary <int, TestEnvironment>(); if (args.Length > 3) { IEnumerable <TestEnvironment> prEnv = EnvironmentProvider.GetEnvironments(); foreach (string s in GetStrings(args[3])) { foreach (TestEnvironment fenv in prEnv.Where(a => a.ID.Equals(int.Parse(s)))) { if (!Environments.ContainsKey(fenv.ID)) { Console.WriteLine(string.Format("Adding '{0}' Environment.", fenv.Name)); Environments.Add(fenv.ID, fenv); } } } } // params 4 = systems // params 5 = sites // will look for sites by system unless systems is an empty string then it looks for them by site Dictionary <int, TestSite> Sites = new Dictionary <int, TestSite>(); IEnumerable <TestSite> prSites = SiteProvider.GetEnabledSites(); if (args.Length > 4 && !string.IsNullOrEmpty(args[4])) { foreach (string s in GetStrings(args[4])) { foreach (TestSite fsite in prSites.Where(a => a.SystemID.Equals(int.Parse(s)))) { if (!Sites.ContainsKey(fsite.ID)) { Console.WriteLine(string.Format("Adding '{0}' Site.", fsite.Name)); Sites.Add(fsite.ID, fsite); } } } } if (args.Length > 5) { foreach (string s in GetStrings(args[5])) { foreach (TestSite fsite in prSites.Where(a => a.ID.Equals(int.Parse(s)))) { if (!Sites.ContainsKey(fsite.ID)) { Console.WriteLine(string.Format("Adding '{0}' Site.", fsite.Name)); Sites.Add(fsite.ID, fsite); } } } } //setup for testing CoreExtensions.Host.InitializeService(); //get the test suite TestSuite suite = TestUtility.GetTestSuite(testAssembly); IEnumerable <TestFixture> Fixtures = suite.GetFixtures().Where(a => a.ClassName.EndsWith(string.Format(".{0}", testName))); if (!Fixtures.Any()) { Console.WriteLine("There were no Test Fixtures found. Make sure the class has the [TestFixture] attribute."); return; } TestFixture tf = Fixtures.First(); WebTestManager manager = new WebTestManager(new WebConsoleTestHandler()); manager.RunTest(tf, Environments.Values, Sites.Values); }
internal static int ProcessArgs(string[] args, TimeSpan startupTime, ITelemetry telemetryClient = null) { Dictionary <string, double> performanceData = new Dictionary <string, double>(); PerformanceLogEventSource.Log.BuiltInCommandParserStart(); Stopwatch parseStartTime = Stopwatch.StartNew(); var parseResult = Parser.Instance.Parse(args); performanceData.Add("Parse Time", parseStartTime.Elapsed.TotalMilliseconds); PerformanceLogEventSource.Log.BuiltInCommandParserStop(); using (IFirstTimeUseNoticeSentinel disposableFirstTimeUseNoticeSentinel = new FirstTimeUseNoticeSentinel()) { IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel = disposableFirstTimeUseNoticeSentinel; IAspNetCertificateSentinel aspNetCertificateSentinel = new AspNetCertificateSentinel(); IFileSentinel toolPathSentinel = new FileSentinel( new FilePath( Path.Combine( CliFolderPathCalculator.DotnetUserProfileFolderPath, ToolPathSentinelFileName))); if (parseResult.ValueForOption <bool>(Parser.DiagOption) && parseResult.IsDotnetBuiltInCommand()) { Environment.SetEnvironmentVariable(CommandContext.Variables.Verbose, bool.TrueString); CommandContext.SetVerbose(true); Reporter.Reset(); } if (parseResult.HasOption(Parser.VersionOption) && parseResult.IsTopLevelDotnetCommand()) { CommandLineInfo.PrintVersion(); return(0); } else if (parseResult.HasOption(Parser.InfoOption) && parseResult.IsTopLevelDotnetCommand()) { CommandLineInfo.PrintInfo(); return(0); } else if (parseResult.HasOption("-h") && parseResult.IsTopLevelDotnetCommand()) { HelpCommand.PrintHelp(); return(0); } else if (parseResult.Directives.Count() > 0) { return(parseResult.Invoke()); } else { PerformanceLogEventSource.Log.FirstTimeConfigurationStart(); var environmentProvider = new EnvironmentProvider(); bool generateAspNetCertificate = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", defaultValue: true); bool telemetryOptout = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", defaultValue: false); bool addGlobalToolsToPath = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_ADD_GLOBAL_TOOLS_TO_PATH", defaultValue: true); bool nologo = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_NOLOGO", defaultValue: false); ReportDotnetHomeUsage(environmentProvider); var isDotnetBeingInvokedFromNativeInstaller = false; if (parseResult.CommandResult.Command.Name.Equals(Parser.InstallSuccessCommand.Name)) { aspNetCertificateSentinel = new NoOpAspNetCertificateSentinel(); firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel(); toolPathSentinel = new NoOpFileSentinel(exists: false); isDotnetBeingInvokedFromNativeInstaller = true; } var dotnetFirstRunConfiguration = new DotnetFirstRunConfiguration( generateAspNetCertificate: generateAspNetCertificate, telemetryOptout: telemetryOptout, addGlobalToolsToPath: addGlobalToolsToPath, nologo: nologo); ConfigureDotNetForFirstTimeUse( firstTimeUseNoticeSentinel, aspNetCertificateSentinel, toolPathSentinel, isDotnetBeingInvokedFromNativeInstaller, dotnetFirstRunConfiguration, environmentProvider, performanceData); PerformanceLogEventSource.Log.FirstTimeConfigurationStop(); } PerformanceLogEventSource.Log.TelemetryRegistrationStart(); if (telemetryClient == null) { telemetryClient = new Telemetry.Telemetry(firstTimeUseNoticeSentinel); } TelemetryEventEntry.Subscribe(telemetryClient.TrackEvent); TelemetryEventEntry.TelemetryFilter = new TelemetryFilter(Sha256Hasher.HashWithNormalizedCasing); PerformanceLogEventSource.Log.TelemetryRegistrationStop(); } if (CommandContext.IsVerbose()) { Console.WriteLine($"Telemetry is: {(telemetryClient.Enabled ? "Enabled" : "Disabled")}"); } PerformanceLogEventSource.Log.TelemetrySaveIfEnabledStart(); performanceData.Add("Startup Time", startupTime.TotalMilliseconds); TelemetryEventEntry.SendFiltered(Tuple.Create(parseResult, performanceData)); PerformanceLogEventSource.Log.TelemetrySaveIfEnabledStop(); var topLevelCommands = new string[] { "dotnet", parseResult.RootSubCommandResult() }.Concat(Parser.DiagOption.Aliases); int exitCode; if (parseResult.CommandResult.Command.Name.Equals("dotnet") && string.IsNullOrEmpty(parseResult.ValueForArgument <string>(Parser.DotnetSubCommand))) { exitCode = 0; } else if (BuiltInCommandsCatalog.Commands.TryGetValue(parseResult.RootSubCommandResult(), out var builtIn)) { PerformanceLogEventSource.Log.BuiltInCommandStart(); exitCode = builtIn.Command(args.Where(t => !topLevelCommands.Contains(t)).ToArray()); PerformanceLogEventSource.Log.BuiltInCommandStop(); } else { PerformanceLogEventSource.Log.ExtensibleCommandResolverStart(); var resolvedCommand = CommandFactoryUsingResolver.Create( "dotnet-" + parseResult.ValueForArgument <string>(Parser.DotnetSubCommand), args.Where(t => !topLevelCommands.Contains(t)).ToArray(), FrameworkConstants.CommonFrameworks.NetStandardApp15); PerformanceLogEventSource.Log.ExtensibleCommandResolverStop(); PerformanceLogEventSource.Log.ExtensibleCommandStart(); var result = resolvedCommand.Execute(); PerformanceLogEventSource.Log.ExtensibleCommandStop(); exitCode = result.ExitCode; } PerformanceLogEventSource.Log.TelemetryClientFlushStart(); telemetryClient.Flush(); PerformanceLogEventSource.Log.TelemetryClientFlushStop(); return(exitCode); }
public BackupProvider(EnvironmentProvider environmentProvider) { _environmentProvider = environmentProvider; }
internal static int ProcessArgs(string[] args, ITelemetry telemetryClient = null) { // CommandLineApplication is a bit restrictive, so we parse things ourselves here. Individual apps should use CLA. var success = true; var command = string.Empty; var lastArg = 0; TopLevelCommandParserResult topLevelCommandParserResult = TopLevelCommandParserResult.Empty; using (IFirstTimeUseNoticeSentinel disposableFirstTimeUseNoticeSentinel = new FirstTimeUseNoticeSentinel()) { IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel = disposableFirstTimeUseNoticeSentinel; IAspNetCertificateSentinel aspNetCertificateSentinel = new AspNetCertificateSentinel(); IFileSentinel toolPathSentinel = new FileSentinel( new FilePath( Path.Combine( CliFolderPathCalculator.DotnetUserProfileFolderPath, ToolPathSentinelFileName))); for (; lastArg < args.Length; lastArg++) { if (IsArg(args[lastArg], "d", "diagnostics")) { Environment.SetEnvironmentVariable(CommandContext.Variables.Verbose, bool.TrueString); CommandContext.SetVerbose(true); } else if (IsArg(args[lastArg], "version")) { PrintVersion(); return(0); } else if (IsArg(args[lastArg], "info")) { PrintInfo(); return(0); } else if (IsArg(args[lastArg], "h", "help") || args[lastArg] == "-?" || args[lastArg] == "/?") { HelpCommand.PrintHelp(); return(0); } else if (args[lastArg].StartsWith("-", StringComparison.OrdinalIgnoreCase)) { Reporter.Error.WriteLine($"Unknown option: {args[lastArg]}"); success = false; } else { // It's the command, and we're done! command = args[lastArg]; if (string.IsNullOrEmpty(command)) { command = "help"; } var environmentProvider = new EnvironmentProvider(); bool generateAspNetCertificate = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true); bool skipFirstRunExperience = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false); bool telemetryOptout = environmentProvider.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", false); ReportDotnetHomeUsage(environmentProvider); topLevelCommandParserResult = new TopLevelCommandParserResult(command); var hasSuperUserAccess = false; if (IsDotnetBeingInvokedFromNativeInstaller(topLevelCommandParserResult)) { aspNetCertificateSentinel = new NoOpAspNetCertificateSentinel(); firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel(); toolPathSentinel = new NoOpFileSentinel(exists: false); hasSuperUserAccess = true; // When running through a native installer, we want the cache expansion to happen, so // we need to override this. skipFirstRunExperience = false; } var dotnetFirstRunConfiguration = new DotnetFirstRunConfiguration( generateAspNetCertificate: generateAspNetCertificate, skipFirstRunExperience: skipFirstRunExperience, telemetryOptout: telemetryOptout); ConfigureDotNetForFirstTimeUse( firstTimeUseNoticeSentinel, aspNetCertificateSentinel, toolPathSentinel, hasSuperUserAccess, dotnetFirstRunConfiguration, environmentProvider); break; } } if (!success) { HelpCommand.PrintHelp(); return(1); } if (telemetryClient == null) { telemetryClient = new Telemetry.Telemetry(firstTimeUseNoticeSentinel); } TelemetryEventEntry.Subscribe(telemetryClient.TrackEvent); TelemetryEventEntry.TelemetryFilter = new TelemetryFilter(Sha256Hasher.HashWithNormalizedCasing); } IEnumerable <string> appArgs = (lastArg + 1) >= args.Length ? Enumerable.Empty <string>() : args.Skip(lastArg + 1).ToArray(); if (CommandContext.IsVerbose()) { Console.WriteLine($"Telemetry is: {(telemetryClient.Enabled ? "Enabled" : "Disabled")}"); } TelemetryEventEntry.SendFiltered(topLevelCommandParserResult); int exitCode; if (BuiltInCommandsCatalog.Commands.TryGetValue(topLevelCommandParserResult.Command, out var builtIn)) { var parseResult = Parser.Instance.ParseFrom($"dotnet {topLevelCommandParserResult.Command}", appArgs.ToArray()); if (!parseResult.Errors.Any()) { TelemetryEventEntry.SendFiltered(parseResult); } exitCode = builtIn.Command(appArgs.ToArray()); } else { CommandResult result = CommandFactoryUsingResolver.Create( "dotnet-" + topLevelCommandParserResult.Command, appArgs, FrameworkConstants.CommonFrameworks.NetStandardApp15) .Execute(); exitCode = result.ExitCode; } return(exitCode); }
private static bool IsEnabledByEnvironment() { var environmentProvider = new EnvironmentProvider(); return(environmentProvider.GetEnvironmentVariableAsBool("DOTNET_ENABLE_PERSISTENCE_CHANNEL_DEBUG_OUTPUT", false)); }
public HealthController(EnvironmentProvider environmentProvider, IDatabase database) { _environmentProvider = environmentProvider; _database = database; }
public void ThatBuildChangeScriptWorks() { DateTime dateTime = new DateTime(2014, 09, 17, 17, 42, 55); TimeProvider.Current = new MockTimeProvider(dateTime); MockEnvironmentProvider mockEnvironmentProvider = new MockEnvironmentProvider(); mockEnvironmentProvider.SetUserName("userName"); EnvironmentProvider.Current = mockEnvironmentProvider; string changeScriptHeader = "Change Script Header -- CurrentVersion = $(CurrentVersion);Current DateTime = $(CurrentDateTime);Current User = $(CurrentUser)"; string scriptHeader = "Script Header -- Script Name = $(ScriptName);Script Id = $(ScriptId);Script Description = $(ScriptDescription)"; string scriptFooter = "Script Footer -- String Name = $(ScriptName);Script Id = $(ScriptId)"; string changeScriptFooter = "Change Script Footer -- Current DateTime = $(CurrentDateTime)"; string undoToken = "--//@Undo"; ScriptService constructorTest = new ScriptService(); Mock <IDatabaseService> databaseServiceMock = new Mock <IDatabaseService>(MockBehavior.Strict); Mock <IFileService> fileServiceMock = new Mock <IFileService>(MockBehavior.Strict); // Database service mock setup databaseServiceMock.Setup(d => d.GetScriptFromFile(DatabaseScriptEnum.ChangeScriptHeader)) .Returns(changeScriptHeader); databaseServiceMock.Setup(d => d.GetScriptFromFile(DatabaseScriptEnum.ScriptHeader)).Returns(scriptHeader); databaseServiceMock.Setup(d => d.GetScriptFromFile(DatabaseScriptEnum.ScriptFooter)).Returns(scriptFooter); databaseServiceMock.Setup(d => d.GetScriptFromFile(DatabaseScriptEnum.ChangeScriptFooter)) .Returns(changeScriptFooter); databaseServiceMock.Setup(d => d.GetScriptFromFile(DatabaseScriptEnum.UndoToken)).Returns(undoToken); // file Service mock setup fileServiceMock.Setup(f => f.GetFileContents(It.IsAny <string>(), It.IsAny <bool>())) .Returns( (string s, bool b) => { ScriptFile file = new ScriptFile(); file.Parse(fileServiceMock.Object, s); if (file.Id % 2 == 0) { return(file.Description + undoToken + "Undo text."); } return(file.Description); }); IDictionary <decimal, IScriptFile> changes = this.GetChanges(); Mock <IConfigurationService> configurationService = new Mock <IConfigurationService>(); configurationService.Setup(c => c.DatabaseService).Returns(databaseServiceMock.Object); IScriptService scriptService = new ScriptService( fileServiceMock.Object, new TokenReplacer(new ConfigurationService()), configurationService.Object); string result = scriptService.BuildChangeScript(changes); TimeProvider.ResetToDefault(); EnvironmentProvider.ResetToDefault(); Approvals.Verify(result); }
public Connection(EnvironmentProvider environmentProvider) { _environmentProvider = environmentProvider; }
public void It_wraps_command_with_CMD_EXE_when_command_has_CMD_Extension_and_using_WindowsExePreferredCommandSpecFactory() { var environment = new EnvironmentProvider(new[] { ".cmd" }); var platformCommandSpecFactory = new WindowsExePreferredCommandSpecFactory(); var pathCommandResolver = new PathCommandResolver(environment, platformCommandSpecFactory); var testCommandPath = CommandResolverTestUtils.CreateNonRunnableTestCommand(s_testProjectDirectory, "cmdWrapCommand", ".cmd"); var commandResolverArguments = new CommandResolverArguments() { CommandName = "cmdWrapCommand", CommandArguments = null }; var result = pathCommandResolver.Resolve(commandResolverArguments); result.Should().NotBeNull(); var commandFile = Path.GetFileName(result.Path); commandFile.Should().Be("cmd.exe"); result.Args.Should().Contain(testCommandPath); }
public SharedController(EnvironmentProvider environmentProvider, RootDirProvider rootDirProvider) { _environmentProvider = environmentProvider; _rootDirProvider = rootDirProvider; }
/// <summary> /// Sets up the form /// </summary> protected void Page_Load(object sender, EventArgs e) { //setup for testing CoreExtensions.Host.InitializeService(); //get the test suite TestSuite suite = TestUtility.GetTestSuite(Constants.DefaultWebTestAssembly); //get dictionaries for forms and querying foreach (TestMethod tm in suite.GetMethods()) { Methods.Add(tm.TestName.FullName, tm); } foreach (TestFixture tf in suite.GetFixtures()) { Fixtures.Add(tf.ClassName, tf); } foreach (TestEnvironment t in EnvironmentProvider.GetEnvironments().OrderBy(a => a.Name)) { Environments.Add(t.ID, t); } foreach (TestSystem tsys in SystemProvider.GetSystems().OrderBy(a => a.Name)) { Systems.Add(tsys.ID, tsys); } foreach (TestSite ts in SiteProvider.GetEnabledSites().OrderBy(a => a.SystemID).ThenBy(a => a.Name)) { try { Sites.Add(ts.ID, ts); } catch (ArgumentException aex) { throw new ArgumentException(string.Format("This key has already been added: {0}-{1}", ts.SystemID, ts.Name)); } } ltlResults.Text = string.Empty; //reset output ltlError.Text = string.Empty; ltlLog.Text = string.Empty; if (!IsPostBack) //setup form { foreach (KeyValuePair <string, TestFixture> kvp in Fixtures) { ListItem li = new ListItem(TestUtility.GetClassName(kvp.Value.ClassName), kvp.Value.TestName.FullName); cblTests.Items.Add(li); } foreach (KeyValuePair <int, TestEnvironment> ekvp in Environments) { ListItem li = new ListItem(ekvp.Value.Name, ekvp.Key.ToString()); cblEnv.Items.Add(li); } foreach (KeyValuePair <int, TestSystem> sykvp in Systems) { ListItem li = new ListItem(sykvp.Value.Name, sykvp.Value.Name); cblSystems.Items.Add(li); } foreach (KeyValuePair <int, TestSite> skvp in Sites) { ListItem li = new ListItem(string.Format("{1}<span class='systemName'>{0}</span>", Systems[skvp.Value.SystemID].Name, skvp.Value.Name), skvp.Key.ToString()); li.Attributes.Add("class", Systems[skvp.Value.SystemID].Name); cblSites.Items.Add(li); } } else { foreach (ListItem li in cblSites.Items) //css classes get lost on postback { li.Attributes.Add("class", Systems[Sites[int.Parse(li.Value)].SystemID].Name); } } }
public SyslogMessage() { EnvironmentProvider = new EnvironmentProvider(); }