public override Task RunAsync(CancellationToken cancellationToken)
 {
     return(Task.Factory.
            StartNew(
                () =>
     {
         using (var shutdownFile = ShutdownFile.CreateRandom(
                    new DirectoryInfo(
                        Path.GetDirectoryName(_startInfo.FileName))))
         {
             _startInfo.UseShellExecute = false;
             _startInfo.EnvironmentVariables[WorkerRoleShutdownFileEnvironmentVariableName] = shutdownFile.FullName;
             using (var process = Process.Start(_startInfo))
             {
                 cancellationToken.WaitHandle.WaitOne();
                 shutdownFile.Notify();
                 if (!process.WaitForExit(Convert.ToInt32(_waitForExitTimeout.TotalMilliseconds)))
                 {
                     process.Kill();
                 }
             }
         }
     },
                cancellationToken,
                TaskCreationOptions.LongRunning,
                TaskScheduler.Default));
 }
示例#2
0
 public void CreateRandomHasExpectedResult()
 {
     using (var sut = ShutdownFile.CreateRandom(new DirectoryInfo(Environment.CurrentDirectory)))
     {
         Assert.That(Path.GetDirectoryName(sut.FullName), Is.EqualTo(Environment.CurrentDirectory));
         Assert.That(Path.GetFileName(sut.FullName), Is.Not.EqualTo(Path.GetFileName(_sut.FullName)));
     }
 }
示例#3
0
 public void CreateRandomDirectoryCanNotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() => ShutdownFile.CreateRandom(null));
 }
示例#4
0
 public void SetUp()
 {
     _sut = ShutdownFile.CreateRandom(new DirectoryInfo(Environment.CurrentDirectory));
 }