本文整理汇总了C#中Kudu.Core.Infrastructure.LockFile.LockOperation方法的典型用法代码示例。如果您正苦于以下问题:C# LockFile.LockOperation方法的具体用法?C# LockFile.LockOperation怎么用?C# LockFile.LockOperation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kudu.Core.Infrastructure.LockFile
的用法示例。
在下文中一共展示了LockFile.LockOperation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LockFileConcurrentTest
public void LockFileConcurrentTest()
{
// Mock
var file = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var lockFile = new LockFile(file, NullTracerFactory.Instance);
int count = 10;
int threads = 2;
int totals = 0;
// Test
var result = Parallel.For(0, threads, i =>
{
for (int j = 0; j < count; ++j)
{
lockFile.LockOperation(() =>
{
// simulate get/set
int val = totals;
Thread.Sleep(0);
totals = val + 1;
using (var reader = new StreamReader(FileSystemHelpers.OpenFile(file, FileMode.Open, FileAccess.Read, FileShare.Write)))
{
Assert.Contains("at Kudu.Core.Test.LockFileTests", reader.ReadToEnd());
}
}, TimeSpan.FromSeconds(60));
}
});
// Assert
Assert.True(result.IsCompleted);
Assert.Equal(count * threads, totals);
FileSystemHelpers.DeleteFileSafe(file);
}
示例2: Main
private static int Main(string[] args)
{
// Turn flag on in app.config to wait for debugger on launch
if (ConfigurationManager.AppSettings["WaitForDebuggerOnStart"] == "true")
{
while (!Debugger.IsAttached)
{
System.Threading.Thread.Sleep(100);
}
}
if (System.Environment.GetEnvironmentVariable(SettingsKeys.DisableDeploymentOnPush) == "1")
{
return 0;
}
if (args.Length < 2)
{
System.Console.WriteLine("Usage: kudu.exe appRoot wapTargets [deployer]");
return 1;
}
// The post receive hook launches the exe from sh and intereprets newline differently.
// This fixes very wacky issues with how the output shows up in the console on push
System.Console.Error.NewLine = "\n";
System.Console.Out.NewLine = "\n";
string appRoot = args[0];
string wapTargets = args[1];
string deployer = args.Length == 2 ? null : args[2];
IEnvironment env = GetEnvironment(appRoot);
ISettings settings = new XmlSettings.Settings(GetSettingsPath(env));
IDeploymentSettingsManager settingsManager = new DeploymentSettingsManager(settings);
// Setup the trace
TraceLevel level = settingsManager.GetTraceLevel();
ITracer tracer = GetTracer(env, level);
ITraceFactory traceFactory = new TracerFactory(() => tracer);
// Calculate the lock path
string lockPath = Path.Combine(env.SiteRootPath, Constants.LockPath);
string deploymentLockPath = Path.Combine(lockPath, Constants.DeploymentLockFile);
IOperationLock deploymentLock = new LockFile(deploymentLockPath, traceFactory);
if (deploymentLock.IsHeld)
{
return PerformDeploy(appRoot, wapTargets, deployer, lockPath, env, settingsManager, level, tracer, traceFactory, deploymentLock);
}
// Cross child process lock is not working on linux via mono.
// When we reach here, deployment lock must be HELD! To solve above issue, we lock again before continue.
try
{
return deploymentLock.LockOperation(() =>
{
return PerformDeploy(appRoot, wapTargets, deployer, lockPath, env, settingsManager, level, tracer, traceFactory, deploymentLock);
}, "Performing deployment", TimeSpan.Zero);
}
catch (LockOperationException)
{
return -1;
}
}