PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Kudu.Web/Controllers/DeploymentsController.cs

https://github.com/moacap/kudu
C# | 126 lines | 101 code | 24 blank | 1 comment | 8 complexity | 29a80eef6645ce44971682bc66fe4c76 MD5 | raw file
Possible License(s): Apache-2.0
  1. using System.Linq;
  2. using System.Net;
  3. using System.Threading.Tasks;
  4. using System.Web.Mvc;
  5. using Kudu.Client.Deployment;
  6. using Kudu.Client.Infrastructure;
  7. using Kudu.Contracts.Infrastructure;
  8. using Kudu.Web.Infrastructure;
  9. using Kudu.Web.Models;
  10. using Mvc.Async;
  11. namespace Kudu.Web.Controllers
  12. {
  13. public class DeploymentsController : TaskAsyncController
  14. {
  15. private readonly IApplicationService _applicationService;
  16. private readonly ICredentialProvider _credentialProvider;
  17. public DeploymentsController(IApplicationService applicationService,
  18. ICredentialProvider credentialProvider)
  19. {
  20. _applicationService = applicationService;
  21. _credentialProvider = credentialProvider;
  22. }
  23. protected override void OnActionExecuting(ActionExecutingContext filterContext)
  24. {
  25. ViewBag.tab = "deployments";
  26. base.OnActionExecuting(filterContext);
  27. }
  28. public Task<ActionResult> Index(string slug)
  29. {
  30. IApplication application = _applicationService.GetApplication(slug);
  31. if (application == null)
  32. {
  33. return HttpNotFoundAsync();
  34. }
  35. ICredentials credentials = _credentialProvider.GetCredentials();
  36. RemoteDeploymentManager deploymentManager = application.GetDeploymentManager(credentials);
  37. // TODO: Do this in parallel
  38. return deploymentManager.GetResultsAsync().Then(results =>
  39. {
  40. return application.GetRepositoryInfo(credentials).Then(repositoryInfo =>
  41. {
  42. var appViewModel = new ApplicationViewModel(application);
  43. appViewModel.RepositoryInfo = repositoryInfo;
  44. appViewModel.Deployments = results.ToList();
  45. ViewBag.slug = slug;
  46. ViewBag.appName = appViewModel.Name;
  47. return (ActionResult)View(appViewModel);
  48. });
  49. });
  50. }
  51. public Task<ActionResult> Deploy(string slug, string id, bool? clean)
  52. {
  53. IApplication application = _applicationService.GetApplication(slug);
  54. if (application == null)
  55. {
  56. return HttpNotFoundAsync();
  57. }
  58. ICredentials credentials = _credentialProvider.GetCredentials();
  59. RemoteDeploymentManager deploymentManager = application.GetDeploymentManager(credentials);
  60. return deploymentManager.DeployAsync(id, clean ?? false)
  61. .ContinueWith(task =>
  62. {
  63. return (ActionResult)RedirectToAction("Index", new { slug });
  64. });
  65. }
  66. public Task<ActionResult> Log(string slug, string id)
  67. {
  68. IApplication application = _applicationService.GetApplication(slug);
  69. if (application == null)
  70. {
  71. return HttpNotFoundAsync();
  72. }
  73. ICredentials credentials = _credentialProvider.GetCredentials();
  74. RemoteDeploymentManager deploymentManager = application.GetDeploymentManager(credentials);
  75. return deploymentManager.GetLogEntriesAsync(id).Then(entries =>
  76. {
  77. ViewBag.slug = slug;
  78. ViewBag.appName = application.Name;
  79. ViewBag.id = id;
  80. return (ActionResult)View(entries);
  81. });
  82. }
  83. public Task<ActionResult> Details(string slug, string id, string logId)
  84. {
  85. IApplication application = _applicationService.GetApplication(slug);
  86. if (application == null)
  87. {
  88. return HttpNotFoundAsync();
  89. }
  90. ICredentials credentials = _credentialProvider.GetCredentials();
  91. RemoteDeploymentManager deploymentManager = application.GetDeploymentManager(credentials);
  92. return deploymentManager.GetLogEntryDetailsAsync(id, logId).Then(entries =>
  93. {
  94. ViewBag.slug = slug;
  95. ViewBag.appName = application.Name;
  96. ViewBag.id = id;
  97. ViewBag.verbose = true;
  98. return (ActionResult)View("Log", entries);
  99. });
  100. }
  101. }
  102. }