From 2674f027a473d2ed70c9b68b40daed8520c504c7 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 22 Sep 2017 11:01:31 -0700 Subject: [PATCH] Adding check on promote and wait buffers during import --- Ardvark/Aardvark.csproj | 25 +++--- Ardvark/Domain/Processes.cs | 34 +++++++- Ardvark/Program.cs | 84 ++++++++++++-------- Ardvark/ViewModels/ImportViewModel.cs | 1 + Ardvark/ViewModels/PromoteStatusViewModel.cs | 18 +++++ Ardvark/packages.config | 2 +- 6 files changed, 119 insertions(+), 45 deletions(-) create mode 100644 Ardvark/ViewModels/PromoteStatusViewModel.cs diff --git a/Ardvark/Aardvark.csproj b/Ardvark/Aardvark.csproj index 00ea8d4..67bd4e3 100644 --- a/Ardvark/Aardvark.csproj +++ b/Ardvark/Aardvark.csproj @@ -56,15 +56,20 @@ Ardvark_TemporaryKey.pfx - true + false false + + LocalIntranet + + + Properties\app.manifest + - - ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll - True + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll @@ -92,6 +97,7 @@ + @@ -100,14 +106,11 @@ Always Designer - - App.config - - - App.config - - + + Designer + + diff --git a/Ardvark/Domain/Processes.cs b/Ardvark/Domain/Processes.cs index 5ce65cd..109d404 100644 --- a/Ardvark/Domain/Processes.cs +++ b/Ardvark/Domain/Processes.cs @@ -135,10 +135,11 @@ namespace Aardvark.Domain { importViewModel.ImportResponseViewModel = result; importViewModel.Success = true; - importViewModel.Message = "Import succeeded for '" + zipPath + "'"; + importViewModel.Message = "Import succeeded for '" + zipPath + "'"; + importViewModel.PromoteJobId = result.promoteJobId; } else - { + { importViewModel.ImportResponseViewModel = null; importViewModel.Success = false; importViewModel.Message = response.ReasonPhrase; @@ -183,5 +184,34 @@ namespace Aardvark.Domain return response; } } + + /// + /// get the promote status of specific promote job id + /// + /// + /// PromoteStatusViewModel + public PromoteStatusViewModel GetPromoteStatus(string promoteJobId) + { + PromoteStatusViewModel vm = null; + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_apiurl); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _login); + + HttpResponseMessage response = client.GetAsync("_apis/work/processAdmin/processes/status/" + promoteJobId).Result; + + if (response.IsSuccessStatusCode) + { + vm = response.Content.ReadAsAsync().Result; + } + + response.Dispose(); + + return vm; + } + } } } diff --git a/Ardvark/Program.cs b/Ardvark/Program.cs index e4365e8..fabd389 100644 --- a/Ardvark/Program.cs +++ b/Ardvark/Program.cs @@ -8,6 +8,7 @@ using System.IO; using System.IO.Compression; using Aardvark.ViewModels; using Aardvark.Domain; +using System.Threading; namespace ImportExportProcessExamples { @@ -118,7 +119,7 @@ namespace ImportExportProcessExamples Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Importing Project"); - ImportSingle(_source); + var i = ImportSingle(_source); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Done"); @@ -433,30 +434,15 @@ namespace ImportExportProcessExamples else { return; - } - + } + + var status = 0; + foreach (var item in list) { - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Importing process '" + item.ZipFilePath + "': "); + status = ImportSingle(item.ZipFilePath); - ImportViewModel vm = process.ImportSingleProcessRESTCall(item.ZipFilePath); - - if (!vm.Success) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Error: " + vm.Message); - - foreach (var result in vm.validationResults) - { - Console.WriteLine("Line " + result.line + " : " + result.description); - } - } - else - { - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("Success"); - } + if (status == 0) break; } process = null; @@ -511,29 +497,29 @@ namespace ImportExportProcessExamples process = null; } - private static void ImportSingle(string zipFile) + private static int ImportSingle(string zipFile) { if (!File.Exists(zipFile)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error: Invlaid argument, zip file not found"); - return; + return 0; } Processes process = new Processes(_appConfig); Console.ForegroundColor = ConsoleColor.White; - Console.Write("Importing process '" + zipFile + "': "); + Console.Write("importing process '" + zipFile + "': "); - ImportViewModel vm = process.ImportSingleProcessRESTCall(zipFile); + ImportViewModel importVm = process.ImportSingleProcessRESTCall(zipFile); - if (!vm.Success) + if (!importVm.Success) { Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Error: " + vm.Message); + Console.WriteLine("Error: " + importVm.Message); Console.WriteLine(""); - foreach (var item in vm.validationResults) + foreach (var item in importVm.validationResults) { Console.WriteLine("Line " + item.line + " : " + item.description); } @@ -543,10 +529,46 @@ namespace ImportExportProcessExamples Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Success"); - - } + Console.ForegroundColor = ConsoleColor.White; + Console.Write("checking promote status..."); + + PromoteStatusViewModel promoteStatusVm = new PromoteStatusViewModel() { complete = 0 }; + + do + { + //check the status of the promote job + promoteStatusVm = process.GetPromoteStatus(importVm.PromoteJobId); + + Console.Write("."); + + if (promoteStatusVm == null) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Error: promote json package is empty"); + break; + } + + Thread.Sleep(10000); + } + while (promoteStatusVm.complete == 0); + + Thread.Sleep(10000); + + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Success"); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("adding a buffer to promote process (this may take a couple minutes): "); + + Thread.Sleep(120000); + + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Success"); + } process = null; + + return 1; } public static void ShowHelp() diff --git a/Ardvark/ViewModels/ImportViewModel.cs b/Ardvark/ViewModels/ImportViewModel.cs index 02166d7..9abcbe1 100644 --- a/Ardvark/ViewModels/ImportViewModel.cs +++ b/Ardvark/ViewModels/ImportViewModel.cs @@ -11,6 +11,7 @@ namespace Aardvark.ViewModels public ImportResponseViewModel ImportResponseViewModel { get; set; } = null; public string Message { get; set; } public bool Success { get; set; } = false; + public string PromoteJobId { get; set; } = "0"; public Validationresult[] validationResults { get; set; } } } diff --git a/Ardvark/ViewModels/PromoteStatusViewModel.cs b/Ardvark/ViewModels/PromoteStatusViewModel.cs new file mode 100644 index 0000000..d0e3555 --- /dev/null +++ b/Ardvark/ViewModels/PromoteStatusViewModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Aardvark.ViewModels +{ + public class PromoteStatusViewModel + { + public string id { get; set; } + public int complete { get; set; } + public int pending { get; set; } + public int remainingRetries { get; set; } + public bool successful { get; set; } + public string message { get; set; } + } +} diff --git a/Ardvark/packages.config b/Ardvark/packages.config index ba19ad6..6e7da69 100644 --- a/Ardvark/packages.config +++ b/Ardvark/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file