当前位置: 首页>>代码示例>>C#>>正文


C# LockFile.LockOperation方法代码示例

本文整理汇总了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);
        }
开发者ID:Walk4Muscle,项目名称:kudu,代码行数:35,代码来源:LockFileTests.cs

示例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;
            }
        }
开发者ID:shibayan,项目名称:kudu,代码行数:65,代码来源:Program.cs


注:本文中的Kudu.Core.Infrastructure.LockFile.LockOperation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。