From de437610399178f64bcfab51f9a3f184bdeb8566 Mon Sep 17 00:00:00 2001 From: Callum McIntyre Date: Fri, 21 Oct 2016 14:45:35 +0100 Subject: [PATCH] [CA-211267] Add a lightweight polling mechanism to the appliance tasks, to provide an accurate timer For other actions we get a ticking timer in the Events view because they use PollToCompletion, which calls their Changed event every 900ms. These actions don't use PollToCompletion, and didn't regularly call their Changed event - so their timer didn't tick regularly. This change adds a lightweight mechanism to call their changed event every 900ms until they complete. This allows the events page timer to tick every second in the same way as it does for other actions. --- .../Actions/OVFActions/ApplianceAction.cs | 19 +++++++++++++++++++ .../OVFActions/ExportApplianceAction.cs | 3 +++ .../OVFActions/ImportApplianceAction.cs | 3 +++ .../Actions/OVFActions/ImportImageAction.cs | 2 ++ 4 files changed, 27 insertions(+) diff --git a/XenAdmin/Actions/OVFActions/ApplianceAction.cs b/XenAdmin/Actions/OVFActions/ApplianceAction.cs index d9255f48e..98d9aa07e 100644 --- a/XenAdmin/Actions/OVFActions/ApplianceAction.cs +++ b/XenAdmin/Actions/OVFActions/ApplianceAction.cs @@ -29,6 +29,7 @@ * SUCH DAMAGE. */ +using System.Threading; using XenAdmin.Core; using XenAdmin.Network; using XenAPI; @@ -97,5 +98,23 @@ namespace XenAdmin.Actions.OVFActions if (m_transportAction != null) m_transportAction.Cancel = true; } + + protected void InitialiseTicker() + { + System.Threading.Tasks.Task.Run(() => TickUntilCompletion(this)); + } + + private void TickUntilCompletion(ApplianceAction action) + { + int sleepTime = 900; + + while (!action.IsCompleted) + { + action.OnChanged(); + Thread.Sleep(sleepTime); + } + } + + } } diff --git a/XenAdmin/Actions/OVFActions/ExportApplianceAction.cs b/XenAdmin/Actions/OVFActions/ExportApplianceAction.cs index 080eadef9..cfcea029f 100644 --- a/XenAdmin/Actions/OVFActions/ExportApplianceAction.cs +++ b/XenAdmin/Actions/OVFActions/ExportApplianceAction.cs @@ -92,6 +92,9 @@ namespace XenAdmin.Actions.OVFActions { SafeToExit = false; var session = Connection.Session; + + InitialiseTicker(); + var url = session.Url; Uri uri = new Uri(url); diff --git a/XenAdmin/Actions/OVFActions/ImportApplianceAction.cs b/XenAdmin/Actions/OVFActions/ImportApplianceAction.cs index fa0c6b182..350adfacd 100644 --- a/XenAdmin/Actions/OVFActions/ImportApplianceAction.cs +++ b/XenAdmin/Actions/OVFActions/ImportApplianceAction.cs @@ -77,6 +77,9 @@ namespace XenAdmin.Actions.OVFActions protected override void Run() { SafeToExit = false; + + InitialiseTicker(); + if (m_verifySignature) { Description = Messages.VERIFYING_SIGNATURE; diff --git a/XenAdmin/Actions/OVFActions/ImportImageAction.cs b/XenAdmin/Actions/OVFActions/ImportImageAction.cs index d3b6b0760..d270d085c 100644 --- a/XenAdmin/Actions/OVFActions/ImportImageAction.cs +++ b/XenAdmin/Actions/OVFActions/ImportImageAction.cs @@ -73,6 +73,8 @@ namespace XenAdmin.Actions.OVFActions SafeToExit = false; Debug.Assert(m_vmMappings.Count == 1, "There is one VM mapping"); + InitialiseTicker(); + string systemid = m_vmMappings.Keys.ElementAt(0); var mapping = m_vmMappings.Values.ElementAt(0);