本文整理汇总了C#中IApplicationEnvironment类的典型用法代码示例。如果您正苦于以下问题:C# IApplicationEnvironment类的具体用法?C# IApplicationEnvironment怎么用?C# IApplicationEnvironment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IApplicationEnvironment类属于命名空间,在下文中一共展示了IApplicationEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public static void Register(CommandLineApplication cmdApp, IApplicationEnvironment appEnvironment)
{
cmdApp.Command("scan", c => {
c.Description = "Scan a directory tree and produce a JSON array of source units";
var repoName = c.Option ("--repo <REPOSITORY_URL>", "The URI of the repository that contains the directory tree being scanned", CommandOptionType.SingleValue);
var subdir = c.Option ("--subdir <SUBDIR_PATH>", "The path of the current directory (in which the scanner is run), relative to the root directory of the repository being scanned", CommandOptionType.SingleValue);
c.HelpOption("-?|-h|--help");
c.OnExecute(() => {
var repository = repoName.Value();
var dir = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), subdir.Value()));
//Console.WriteLine($"Repository: {repository}");
//Console.WriteLine($"Directory: {dir}");
var sourceUnits = new List<SourceUnit>();
foreach(var proj in Scan(dir))
{
//Console.WriteLine($"Found project: {proj.Name} ({proj.Version}, {proj.CompilerServices})");
sourceUnits.Add(SourceUnit.FromProject(proj, dir));
}
//Console.Error.Write($"Current dir: {Environment.CurrentDirectory}\n");
Console.WriteLine(JsonConvert.SerializeObject(sourceUnits, Formatting.Indented));
return 0;
});
});
}
示例2: Startup
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Setup configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsEnvironment("Development"))
{
// This reads the configuration keys from the secret store.
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
// this file name is ignored by gitignore
// so you can create it and use on your local dev machine
// remember last config source added wins if it has the same settings
builder.AddJsonFile("appsettings.local.overrides.json", optional: true);
// most common use of environment variables would be in azure hosting
// since it is added last anything in env vars would trump the same setting in previous config sources
// so no risk of messing up settings if deploying a new version to azure
builder.AddEnvironmentVariables();
Configuration = builder.Build();
//env.MapPath
appBasePath = appEnv.ApplicationBasePath;
}
示例3: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env)
{
var ksi = app.ServerFeatures.Get<IKestrelServerInformation>();
ksi.NoDelay = true;
loggerFactory.AddConsole(LogLevel.Error);
app.UseKestrelConnectionLogging();
app.Run(async context =>
{
Console.WriteLine("{0} {1}{2}{3}",
context.Request.Method,
context.Request.PathBase,
context.Request.Path,
context.Request.QueryString);
Console.WriteLine($"Method: {context.Request.Method}");
Console.WriteLine($"PathBase: {context.Request.PathBase}");
Console.WriteLine($"Path: {context.Request.Path}");
Console.WriteLine($"QueryString: {context.Request.QueryString}");
var connectionFeature = context.Connection;
Console.WriteLine($"Peer: {connectionFeature.RemoteIpAddress?.ToString()} {connectionFeature.RemotePort}");
Console.WriteLine($"Sock: {connectionFeature.LocalIpAddress?.ToString()} {connectionFeature.LocalPort}");
var content = $"Hello world!{Environment.NewLine}Received '{Args}' from command line.";
context.Response.ContentLength = content.Length;
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync(content);
});
}
示例4: Startup
public Startup(
IHostingEnvironment env,
IApplicationEnvironment appEnv)
{
_env = env;
// Setup configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
// standard config file
.AddJsonFile("config.json")
// environment specific config.<environment>.json file
.AddJsonFile($"config.{env.EnvironmentName}.json", true /* override if exists */)
// standard Windows environment variables
.AddEnvironmentVariables();
if (env.IsDevelopment())
{
// this one adds not using directive to keep it secret, only a dnx reference
// the focus is not on Secrets but on User, so these are User specific settings
// we can also make it available only for developers
builder.AddUserSecrets();
}
Configuration = builder.Build();
}
示例5: PublishMarkdownAsync
/// <summary>
/// Publishes the markdown as a file.
/// </summary>
/// <param name="markdown">Content in Markdown format.</param>
/// <param name="env"><see cref="IApplicationEnvironment"/> instance.</param>
/// <returns>Returns the Markdown file path in a virtual path format.</returns>
public async Task<string> PublishMarkdownAsync(string markdown, IApplicationEnvironment env)
{
if (string.IsNullOrWhiteSpace(markdown))
{
throw new ArgumentNullException(nameof(markdown));
}
if (env == null)
{
throw new ArgumentNullException(nameof(env));
}
var filename = "markdown.md";
var markdownpath = $"{this._settings.MarkdownPath}/{filename}";
var filepath = this._fileHelper.GetDirectory(env, this._settings.MarkdownPath);
filepath = Path.Combine(new[] { filepath, filename });
var written = await this._fileHelper.WriteAsync(filepath, markdown).ConfigureAwait(false);
if (!written)
{
throw new PublishFailedException("Markdown not published");
}
return markdownpath;
}
示例6: Configure
public void Configure(IApplicationBuilder app, IApplicationEnvironment env)
{
app.UseIISPlatformHandler();
app.UseDeveloperExceptionPage();
var certFile = env.ApplicationBasePath + "\\idsrv3test.pfx";
app.Map("/identity", idsrvApp =>
{
idsrvApp.UseIdentityServer(new IdentityServerOptions
{
SiteName = "Embedded IdentityServer",
SigningCertificate = new X509Certificate2(certFile, "idsrv3test"),
Factory = new IdentityServerServiceFactory()
.UseInMemoryUsers(Users.Get())
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get()),
AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions
{
EnableLocalLogin = false,
IdentityProviders = ConfigureIdentityProviders,
SignInMessageThreshold = 5
}
});
});
app.UseCors("mypolicy");
app.UseMvc();
}
示例7: Startup
public Startup(IHostingEnvironment hostingEnvironment, IApplicationEnvironment applicationEnvironment)
{
Configuration = new ConfigurationBuilder()
.SetBasePath(applicationEnvironment.ApplicationBasePath)
.AddJsonFile("config.json")
.Build();
}
示例8: TestApplicationEnvironment
public TestApplicationEnvironment(IApplicationEnvironment originalAppEnvironment,
string appBasePath, string appName)
{
_originalAppEnvironment = originalAppEnvironment;
_applicationBasePath = appBasePath;
_appName = appName;
}
示例9: Startup
public Startup(IApplicationEnvironment env)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("config.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
}
示例10: TransitApiController
/// <summary>
/// Dependency-injected application settings which are then passed on to other components.
/// </summary>
public TransitApiController(IApplicationEnvironment appEnv)
{
_repository = new MemoryTransitRepository(appEnv.ApplicationBasePath);
_client = new TransitClient();
_getCurrentTime = () => TimeZoneInfo.ConvertTime(DateTimeOffset.Now, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"));
}
示例11: ApplicationSettings
public ApplicationSettings(IApplicationEnvironment appEnv, IHostingEnvironment env)
{
_appEnv = appEnv;
_env = env;
BasePath = Path.GetFullPath(Path.Combine(_appEnv.ApplicationBasePath, "../"));
}
示例12: Register
public static void Register(CommandLineApplication cmdApp, IApplicationEnvironment appEnv, IRuntimeEnvironment runtimeEnv)
{
if (runtimeEnv.OperatingSystem == "Windows")
{
_dnuPath = new Lazy<string>(FindDnuWindows);
}
else
{
_dnuPath = new Lazy<string>(FindDnuNix);
}
cmdApp.Command("depresolve", c => {
c.Description = "Perform a combination of parsing, static analysis, semantic analysis, and type inference";
c.HelpOption("-?|-h|--help");
c.OnExecute(async () => {
//System.Diagnostics.Debugger.Launch();
var jsonIn = await Console.In.ReadToEndAsync();
var sourceUnit = JsonConvert.DeserializeObject<SourceUnit>(jsonIn);
var dir = Path.Combine(Directory.GetCurrentDirectory(), sourceUnit.Dir);
var deps = await DepResolve(dir);
var result = new List<Resolution>();
foreach(var dep in deps)
{
result.Add(Resolution.FromLibrary(dep));
}
Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
return 0;
});
});
}
示例13: CompilationEngineContext
public CompilationEngineContext(IApplicationEnvironment applicationEnvironment,
IAssemblyLoadContext defaultLoadContext,
CompilationCache cache) :
this(applicationEnvironment, defaultLoadContext, cache, NoopWatcher.Instance, new ProjectGraphProvider())
{
}
示例14: Startup
public Startup(IApplicationEnvironment appEnv)
{
_configurationRoot = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.Build();
}
示例15: GetCompilationSettings
/// <summary>
/// Parses the <see cref="ICompilerOptions"/> for the current executing application and returns a
/// <see cref="CompilationSettings"/> used for Roslyn compilation.
/// </summary>
/// <param name="compilerOptionsProvider">
/// A <see cref="ICompilerOptionsProvider"/> that reads compiler options.
/// </param>
/// <param name="applicationEnvironment">
/// The <see cref="IApplicationEnvironment"/> for the executing application.
/// </param>
/// <param name="configuration">
/// The configuration name to use for compilation.
/// </param>
/// <returns>The <see cref="CompilationSettings"/> for the current application.</returns>
public static CompilationSettings GetCompilationSettings(
this ICompilerOptionsProvider compilerOptionsProvider,
IApplicationEnvironment applicationEnvironment,
string configuration)
{
if (compilerOptionsProvider == null)
{
throw new ArgumentNullException(nameof(compilerOptionsProvider));
}
if (applicationEnvironment == null)
{
throw new ArgumentNullException(nameof(applicationEnvironment));
}
if (string.IsNullOrEmpty(configuration))
{
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(configuration));
}
return compilerOptionsProvider.GetCompilerOptions(
applicationEnvironment.ApplicationName,
applicationEnvironment.RuntimeFramework,
configuration)
.ToCompilationSettings(applicationEnvironment.RuntimeFramework, applicationEnvironment.ApplicationBasePath);
}