本文整理汇总了C#中Kudu.Core.Deployment.DeploymentContext类的典型用法代码示例。如果您正苦于以下问题:C# DeploymentContext类的具体用法?C# DeploymentContext怎么用?C# DeploymentContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeploymentContext类属于Kudu.Core.Deployment命名空间,在下文中一共展示了DeploymentContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public Task Build(DeploymentContext context)
{
var tcs = new TaskCompletionSource<object>();
ILogger innerLogger = context.Logger.Log(Resources.Log_PreparingFiles);
try
{
using (context.Tracer.Step("Copying files to output directory"))
{
// Copy to the output path and use the previous manifest if there
DeploymentHelper.CopyWithManifest(_sourcePath, context.OutputPath, context.PreviousMainfest);
}
using (context.Tracer.Step("Building manifest"))
{
// Generate a manifest from those build artifacts
context.ManifestWriter.AddFiles(_sourcePath);
}
// Log the copied files from the manifest
innerLogger.LogFileList(context.ManifestWriter.GetPaths());
}
catch (Exception ex)
{
context.Tracer.TraceError(ex);
context.GlobalLogger.Log(ex);
innerLogger.Log(ex);
tcs.SetException(ex);
// Bail out early
return tcs.Task;
}
try
{
// Download node packages
DownloadNodePackages(context);
AddIISNodeConfig(context);
tcs.SetResult(null);
}
catch (Exception ex)
{
context.Tracer.TraceError(ex);
// HACK: Log an empty error to the global logger (post receive hook console output).
// The reason we don't log the real exception is because the 'live output' when downloding
// npm packages has already been captured.
context.GlobalLogger.LogError();
tcs.SetException(ex);
}
return tcs.Task;
}
示例2: Build
public override Task Build(DeploymentContext context)
{
ILogger buildLogger = context.Logger.Log(Resources.Log_BuildingSolution, Path.GetFileName(SolutionPath));
try
{
string propertyString = GetPropertyString();
if (!String.IsNullOrEmpty(propertyString))
{
propertyString = " /p:" + propertyString;
}
using (context.Tracer.Step("Running msbuild on solution"))
{
// Build the solution first
string log = ExecuteMSBuild(context.Tracer, @"""{0}"" /verbosity:m /nologo{1}", SolutionPath, propertyString);
buildLogger.Log(log);
}
return BuildProject(context);
}
catch (Exception ex)
{
context.Tracer.TraceError(ex);
buildLogger.Log(ex);
var tcs = new TaskCompletionSource<object>();
tcs.SetException(ex);
return tcs.Task;
}
}
示例3: BuildProject
protected override Task BuildProject(DeploymentContext context)
{
var tcs = new TaskCompletionSource<object>();
var innerLogger = context.Logger.Log("Using website project {0}.", _projectPath);
try
{
using (context.Profiler.Step("Copying files to output directory"))
{
// Copy to the output path
DeploymentHelper.CopyWithManifest(_projectPath, context.OutputPath, context.PreviousMainfest);
}
using (context.Profiler.Step("Building manifest"))
{
// Generate the manifest from the project path
context.ManifestWriter.AddFiles(_projectPath);
}
innerLogger.Log("Done.");
tcs.SetResult(null);
}
catch (Exception e)
{
innerLogger.Log("Copying website failed.", LogEntryType.Error);
innerLogger.Log(e);
tcs.SetException(e);
}
return tcs.Task;
}
示例4: BuildProject
protected override Task BuildProject(DeploymentContext context)
{
var tcs = new TaskCompletionSource<object>();
ILogger copyLogger = context.Logger.Log(Resources.Log_PreparingFiles);
try
{
using (context.Tracer.Step("Copying files to output directory"))
{
// Copy to the output path
DeploymentHelper.CopyWithManifest(_projectPath, context.OutputPath, context.PreviousMainfest);
}
using (context.Tracer.Step("Building manifest"))
{
// Generate the manifest from the project path
context.ManifestWriter.AddFiles(_projectPath);
}
// Log the copied files from the manifest
copyLogger.LogFileList(context.ManifestWriter.GetPaths());
tcs.SetResult(null);
}
catch (Exception ex)
{
context.Tracer.TraceError(ex);
copyLogger.Log(ex);
tcs.SetException(ex);
}
return tcs.Task;
}
示例5: DownloadNodePackages
/// <summary>
/// Download node packages as part of the deployment
/// </summary>
private void DownloadNodePackages(ILogger logger, DeploymentContext context)
{
// Check to see if there's a package.json file
string packagePath = Path.Combine(context.OutputPath, PackageJsonFile);
if (!File.Exists(packagePath))
{
// If the package.json file doesn't exist then don't bother to run npm install
return;
}
using (context.Profiler.Step("Downloading node packages"))
{
var npm = new NpmExecutable(context.OutputPath);
if (!npm.IsAvailable)
{
logger.Log("NPM not installed or couldn't be located. Skipping package installation.");
return;
}
// Set the npm proxy settings based on the default settings
var proxy = WebRequest.DefaultWebProxy;
var httpProxyUrl = proxy.GetProxy(new Uri("http://registry.npmjs.org/"));
var httpsProxyUrl = proxy.GetProxy(new Uri("https://registry.npmjs.org/"));
if (httpProxyUrl != null)
{
npm.EnvironmentVariables["HTTP_PROXY"] = httpProxyUrl.ToString();
}
if (httpsProxyUrl != null)
{
npm.EnvironmentVariables["HTTPS_PROXY"] = httpsProxyUrl.ToString();
}
// Use the temp path as the user profile path in case we don't have the right
// permission set. This normally happens under IIS as a restricted user (ApplicationPoolIdentity).
string npmUserProfile = Path.Combine(_tempPath, "npm");
npm.EnvironmentVariables["USERPROFILE"] = npmUserProfile;
npm.EnvironmentVariables["LocalAppData"] = npmUserProfile;
npm.EnvironmentVariables["AppData"] = npmUserProfile;
try
{
// Use the http proxy since https is failing for some reason
npm.Execute("config set registry \"http://registry.npmjs.org/\"");
}
catch(Exception ex)
{
// This fails if it's already set
Debug.WriteLine(ex.Message);
}
// Run install on the output directory
string log = npm.Execute(context.Profiler, "install").Item1;
logger.Log(log);
}
}
示例6: DownloadNodePackages
/// <summary>
/// Download node packages as part of the deployment
/// </summary>
private void DownloadNodePackages(ILogger logger, DeploymentContext context)
{
// Check to see if there's a package.json file
string packagePath = Path.Combine(context.OutputPath, PackageJsonFile);
if (!File.Exists(packagePath))
{
// If the package.json file doesn't exist then don't bother to run npm install
return;
}
using (context.Profiler.Step("Downloading node packages"))
{
var npm = new NpmExecutable(context.OutputPath);
if (!npm.IsAvailable)
{
logger.Log(Resources.Log_NpmNotInstalled);
return;
}
// Set the npm proxy settings based on the default settings
var proxy = WebRequest.DefaultWebProxy;
var httpUrl = new Uri("http://registry.npmjs.org/");
var httpsUrl = new Uri("https://registry.npmjs.org/");
var proxyHttpProxyUrl = proxy.GetProxy(httpUrl);
var proxyHttpsProxyUrl = proxy.GetProxy(httpsUrl);
if (proxyHttpProxyUrl != httpUrl)
{
npm.EnvironmentVariables["HTTP_PROXY"] = proxyHttpProxyUrl.ToString();
}
if (proxyHttpsProxyUrl != httpsUrl)
{
npm.EnvironmentVariables["HTTPS_PROXY"] = proxyHttpsProxyUrl.ToString();
}
try
{
// Use the http proxy since https is failing for some reason
npm.Execute("config set registry \"http://registry.npmjs.org/\"");
}
catch (Exception ex)
{
// This fails if it's already set
Debug.WriteLine(ex.Message);
}
// Run install on the output directory
string log = npm.Execute(context.Profiler, "install").Item1;
logger.Log(log);
}
}
示例7: Build
public Task Build(DeploymentContext context)
{
var tcs = new TaskCompletionSource<object>();
ILogger innerLogger = context.Logger.Log(Resources.Log_CopyingFiles);
try
{
using (context.Tracer.Step("Copying files to output directory"))
{
// Copy to the output path and use the previous manifest if there
DeploymentHelper.CopyWithManifest(_sourcePath, context.OutputPath, context.PreviousMainfest);
}
using (context.Tracer.Step("Building manifest"))
{
// Generate a manifest from those build artifacts
context.ManifestWriter.AddFiles(_sourcePath);
}
// Log the copied files from the manifest
innerLogger.LogFileList(context.ManifestWriter.GetPaths());
}
catch (Exception ex)
{
context.Tracer.TraceError(ex);
innerLogger.Log(ex);
tcs.SetException(ex);
// Bail out early
return tcs.Task;
}
try
{
// Download node packages
DownloadNodePackages(context);
tcs.SetResult(null);
}
catch (Exception ex)
{
context.Tracer.TraceError(ex);
tcs.SetException(ex);
}
return tcs.Task;
}
示例8: Build
public Task Build(DeploymentContext context)
{
var tcs = new TaskCompletionSource<object>();
ILogger customLogger = context.Logger.Log("Running custom deployment...");
Executable exe = GetExecutable();
exe.EnvironmentVariables[SourcePath] = _repositoryPath;
exe.EnvironmentVariables[TargetPath] = context.OutputPath;
// Populate the enviornment with the build propeties
foreach (var property in _propertyProvider.GetProperties())
{
exe.EnvironmentVariables[property.Key] = property.Value;
}
// Add the msbuild path and git path to the %PATH% so more tools are available
var toolsPaths = new[] {
Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()),
Path.GetDirectoryName(PathUtility.ResolveGitPath())
};
exe.AddToPath(toolsPaths);
try
{
string output = exe.ExecuteWithConsoleOutput(context.Tracer, String.Empty).Item1;
customLogger.Log(output);
tcs.SetResult(null);
}
catch (Exception ex)
{
context.Tracer.TraceError(ex);
// HACK: Log an empty error to the global logger (post receive hook console output).
// The reason we don't log the real exception is because the 'live output' running
// msbuild has already been captured.
context.GlobalLogger.LogError();
customLogger.Log(ex);
tcs.SetException(ex);
}
return tcs.Task;
}
示例9: HandleAutoSwap
public async Task HandleAutoSwap(string currentDeploymetId, DeploymentContext context)
{
ITracer tracer = context.Tracer;
if (!IsAutoSwapEnabled())
{
tracer.Trace("AutoSwap is not enabled");
return;
}
string jwtToken = System.Environment.GetEnvironmentVariable(Constants.SiteRestrictedJWT);
if (string.IsNullOrWhiteSpace(jwtToken))
{
tracer.Trace("Jwt token is null");
return;
}
// active deployment is always a success deployment
string lastDeploymentId = _deploymentStatusManager.ActiveDeploymentId;
if (string.Equals(currentDeploymetId, lastDeploymentId, StringComparison.OrdinalIgnoreCase))
{
tracer.Trace("Deployment haven't changed, no need for auto swap: {0}", lastDeploymentId);
return;
}
try
{
FileSystemHelpers.WriteAllTextToFile(_autoSwapLockFilePath, String.Empty);
}
catch (Exception ex)
{
tracer.TraceError(ex);
}
string operationId = "AUTOSWAP" + Guid.NewGuid();
var queryStrings = HttpUtility.ParseQueryString(string.Empty);
queryStrings["slot"] = _autoSwapSlotName;
queryStrings["operationId"] = operationId;
var client = new OperationClient(context.Tracer);
await client.PostAsync<string>("/operations/autoswap?" + queryStrings.ToString());
context.Logger.Log("Requesting auto swap to slot - '{0}' operation id - '{1}' deployment id - '{2}'".FormatInvariant(_autoSwapSlotName, operationId, currentDeploymetId));
}
示例10: Build
public override Task Build(DeploymentContext context)
{
ILogger buildLogger = context.Logger.Log(Resources.Log_BuildingSolution, Path.GetFileName(SolutionPath));
try
{
string propertyString = GetPropertyString();
if (!String.IsNullOrEmpty(propertyString))
{
propertyString = " /p:" + propertyString;
}
string extraArguments = GetMSBuildExtraArguments();
using (context.Tracer.Step("Running msbuild on solution"))
{
// Build the solution first
string log = ExecuteMSBuild(context.Tracer, @"""{0}"" /verbosity:m /nologo{1} {2}", SolutionPath, propertyString, extraArguments);
buildLogger.Log(log);
}
return BuildProject(context);
}
catch (Exception ex)
{
context.Tracer.TraceError(ex);
// HACK: Log an empty error to the global logger (post receive hook console output).
// The reason we don't log the real exception is because the 'live output' running
// msbuild has already been captured.
context.GlobalLogger.Log(String.Empty, LogEntryType.Error);
buildLogger.Log(ex);
var tcs = new TaskCompletionSource<object>();
tcs.SetException(ex);
return tcs.Task;
}
}
示例11: Build
public override Task Build(DeploymentContext context)
{
var tcs = new TaskCompletionSource<object>();
var innerLogger = context.Logger.Log("Building web project {0}.", Path.GetFileName(_projectPath));
try
{
string buildTempPath = Path.Combine(_tempPath, "builds", Guid.NewGuid().ToString());
string log = null;
using (context.Profiler.Step("Running msbuild on project file"))
{
log = BuildProject(context.Profiler, buildTempPath);
}
using (context.Profiler.Step("Copying files to output directory"))
{
// Copy to the output path and use the previous manifest if there
DeploymentHelper.CopyWithManifest(buildTempPath, context.OutputPath, context.PreviousMainfest);
}
using (context.Profiler.Step("Building manifest"))
{
// Generate a manifest from those build artifacts
context.ManifestWriter.AddFiles(buildTempPath);
}
innerLogger.Log(log);
tcs.SetResult(null);
}
catch (Exception ex)
{
innerLogger.Log("Building web project failed.", LogEntryType.Error);
innerLogger.Log(ex);
tcs.SetException(ex);
}
return tcs.Task;
}
示例12: Build
public Task Build(DeploymentContext context)
{
var tcs = new TaskCompletionSource<object>();
var innerLogger = context.Logger.Log("Copying files.");
innerLogger.Log("Copying files to {0}.", context.OutputPath);
try
{
using (context.Profiler.Step("Copying files to output directory"))
{
// Copy to the output path and use the previous manifest if there
DeploymentHelper.CopyWithManifest(_sourcePath, context.OutputPath, context.PreviousMainfest);
}
// Download node packages
DownloadNodePackages(innerLogger, context);
using (context.Profiler.Step("Building manifest"))
{
// Generate a manifest from those build artifacts
context.ManifestWriter.AddFiles(_sourcePath);
}
innerLogger.Log("Done.");
tcs.SetResult(null);
}
catch (Exception ex)
{
innerLogger.Log("Copying files failed.");
innerLogger.Log(ex);
tcs.SetException(ex);
}
return tcs.Task;
}
示例13: Build
/// <summary>
/// Builds and deploys a particular changeset. Puts all build artifacts in a deployments/{id}
/// </summary>
private void Build(string id, ITracer tracer, IDisposable deployStep)
{
if (String.IsNullOrEmpty(id))
{
throw new ArgumentException();
}
ILogger logger = null;
DeploymentStatusFile currentStatus = null;
IDisposable buildStep = null;
try
{
logger = GetLogger(id);
ILogger innerLogger = logger.Log(Resources.Log_PreparingDeployment, TrimId(id));
currentStatus = OpenStatusFile(id);
currentStatus.Complete = false;
currentStatus.StartTime = DateTime.Now;
currentStatus.Status = DeployStatus.Building;
currentStatus.StatusText = String.Format(CultureInfo.CurrentCulture, Resources.Status_BuildingAndDeploying, id);
currentStatus.Save(_fileSystem);
ReportStatus(id);
ISiteBuilder builder = null;
try
{
builder = _builderFactory.CreateBuilder(tracer, innerLogger);
}
catch (Exception ex)
{
_globalLogger.Log(ex);
tracer.TraceError(ex);
innerLogger.Log(ex);
MarkFailed(currentStatus);
ReportStatus(id);
deployStep.Dispose();
return;
}
buildStep = tracer.Step("Building");
var context = new DeploymentContext
{
ManifestWriter = GetDeploymentManifestWriter(id),
PreviousMainfest = GetActiveDeploymentManifestReader(),
Tracer = tracer,
Logger = logger,
GlobalLogger = _globalLogger,
OutputPath = _environment.DeploymentTargetPath,
};
builder.Build(context)
.Then(() =>
{
// End the build step
buildStep.Dispose();
// Run post deployment steps
FinishDeployment(id, tracer, deployStep);
})
.Catch(ex =>
{
// End the build step
buildStep.Dispose();
MarkFailed(currentStatus);
ReportStatus(id);
// End the deploy step
deployStep.Dispose();
});
}
catch (Exception ex)
{
tracer.TraceError(ex);
logger.LogUnexpetedError();
if (buildStep != null)
{
buildStep.Dispose();
}
deployStep.Dispose();
}
}
示例14: Build
/// <summary>
/// Builds and deploys a particular changeset. Puts all build artifacts in a deployments/{id}
/// </summary>
private void Build(string id, ITracer tracer, IDisposable deployStep)
{
if (String.IsNullOrEmpty(id))
{
throw new ArgumentException("The id parameter is null or empty", "id");
}
ILogger logger = null;
IDeploymentStatusFile currentStatus = null;
IDisposable buildStep = null;
try
{
logger = GetLogger(id);
ILogger innerLogger = logger.Log(Resources.Log_PreparingDeployment, TrimId(id));
currentStatus = _status.Open(id);
currentStatus.Complete = false;
currentStatus.StartTime = DateTime.Now;
currentStatus.Status = DeployStatus.Building;
currentStatus.StatusText = String.Format(CultureInfo.CurrentCulture, Resources.Status_BuildingAndDeploying, id);
currentStatus.Save();
ISiteBuilder builder = null;
try
{
builder = _builderFactory.CreateBuilder(tracer, innerLogger);
}
catch (Exception ex)
{
// If we get a TargetInvocationException, use the inner exception instead to avoid
// useless 'Exception has been thrown by the target of an invocation' messages
var targetInvocationException = ex as System.Reflection.TargetInvocationException;
if (targetInvocationException != null)
{
ex = targetInvocationException.InnerException;
}
_globalLogger.Log(ex);
tracer.TraceError(ex);
innerLogger.Log(ex);
currentStatus.MarkFailed();
deployStep.Dispose();
return;
}
buildStep = tracer.Step("Building");
var context = new DeploymentContext
{
ManifestWriter = GetDeploymentManifestWriter(id),
PreviousManifest = GetActiveDeploymentManifestReader(),
Tracer = tracer,
Logger = logger,
GlobalLogger = _globalLogger,
OutputPath = _environment.WebRootPath,
};
context.NextManifestFilePath = context.ManifestWriter.ManifestFilePath;
if (context.PreviousManifest == null)
{
// In the first deployment we want the wwwroot directory to be cleaned, we do that using a manifest file
// That has the expected content of a clean deployment (only one file: hostingstart.html)
// This will result in KuduSync cleaning this file.
context.PreviousManifest = new DeploymentManifest(Path.Combine(_environment.ScriptPath, Constants.FirstDeploymentManifestFileName));
}
context.PreviousManifestFilePath = context.PreviousManifest.ManifestFilePath;
builder.Build(context)
.Then(() =>
{
// End the build step
buildStep.Dispose();
// Run post deployment steps
FinishDeployment(id, deployStep);
})
.Catch(ex =>
{
// End the build step
buildStep.Dispose();
currentStatus.MarkFailed();
// End the deploy step
deployStep.Dispose();
return ex.Handled();
});
//.........这里部分代码省略.........
示例15: Build
public override Task Build(DeploymentContext context)
{
var tcs = new TaskCompletionSource<object>();
string buildTempPath = Path.Combine(_tempPath, Guid.NewGuid().ToString());
ILogger buildLogger = context.Logger.Log(Resources.Log_BuildingWebProject, Path.GetFileName(_projectPath));
try
{
using (context.Tracer.Step("Running msbuild on project file"))
{
string log = BuildProject(context.Tracer, buildTempPath);
// Log the details of the build
buildLogger.Log(log);
}
}
catch (Exception ex)
{
context.Tracer.TraceError(ex);
// HACK: Log an empty error to the global logger (post receive hook console output).
// The reason we don't log the real exception is because the 'live output' running
// msbuild has already been captured.
context.GlobalLogger.LogError();
buildLogger.Log(ex);
tcs.SetException(ex);
return tcs.Task;
}
ILogger copyLogger = context.Logger.Log(Resources.Log_PreparingFiles);
try
{
using (context.Tracer.Step("Copying files to output directory"))
{
// Copy to the output path and use the previous manifest if there
DeploymentHelper.CopyWithManifest(buildTempPath, context.OutputPath, context.PreviousMainfest);
}
using (context.Tracer.Step("Building manifest"))
{
// Generate a manifest from those build artifacts
context.ManifestWriter.AddFiles(buildTempPath);
}
// Log the copied files from the manifest
copyLogger.LogFileList(context.ManifestWriter.GetPaths());
tcs.SetResult(null);
}
catch (Exception ex)
{
context.Tracer.TraceError(ex);
context.GlobalLogger.Log(ex);
copyLogger.Log(ex);
tcs.SetException(ex);
}
finally
{
// Clean up the build artifacts after copying them
CleanBuild(context.Tracer, buildTempPath);
}
return tcs.Task;
}