private static String PollTaskForResult(IXenConnection connection, ref Session session, HTTP.FuncBool cancellingDelegate, XenRef <Task> task) { //Program.AssertOffEventThread(); task_status_type status; do { if (cancellingDelegate != null && cancellingDelegate()) { throw new XenAdmin.CancelledException(); } System.Threading.Thread.Sleep(500); status = (task_status_type)Task.DoWithSessionRetry(connection, ref session, (Task.TaskStatusOp)Task.get_status, task.opaque_ref); }while (status == task_status_type.pending || status == task_status_type.cancelling); if (cancellingDelegate != null && cancellingDelegate()) { throw new XenAdmin.CancelledException(); } if (status == task_status_type.failure) { throw new Failure(Task.get_error_info(session, task)); } else { return(Task.get_result(session, task)); } }
private static String PollTaskForResult(IXenConnection connection, ref Session session, HTTP.FuncBool cancellingDelegate, XenRef<Task> task, bool timeout = false) { //Program.AssertOffEventThread(); task_status_type status; int tries = POLL_FOR_TASK_RESULT_TIMEOUT / POLL_FOR_TASK_RESULT_SLEEP_INTERVAL; do { if (cancellingDelegate != null && cancellingDelegate()) throw new XenAdmin.CancelledException(); System.Threading.Thread.Sleep(POLL_FOR_TASK_RESULT_SLEEP_INTERVAL); tries--; status = (task_status_type)Task.DoWithSessionRetry(connection, ref session, (Task.TaskStatusOp)Task.get_status, task.opaque_ref); } while ((status == task_status_type.pending || status == task_status_type.cancelling) && (!timeout || tries > 0)); if (cancellingDelegate != null && cancellingDelegate()) throw new XenAdmin.CancelledException(); if (status == task_status_type.failure) { throw new Failure(Task.get_error_info(session, task)); } else { return Task.get_result(session, task); } }
public static String Get(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, bool timeout, HTTP.DataCopiedDelegate dataRxDelegate, IXenConnection connection, XenRef <Task> task, ref Session session, string path, string hostname, Delegate f, params object[] p) { log.DebugFormat("HTTP GETTING file from {0} to {1}", hostname, path); // Cannot use ref param in anonymous method, so save it here and restore it later Session _session = session; HTTP.DataCopiedDelegate dataCopiedDelegate = delegate(long bytes) { if (progressDelegate != null) { int progress = (int)(100 * (double)Task.DoWithSessionRetry(connection, ref _session, (Task.TaskProgressOp)Task.get_progress, task.opaque_ref)); progressDelegate(progress); } if (dataRxDelegate != null) { dataRxDelegate(bytes); } }; HTTP.FuncBool cancellingDelegate2 = (HTTP.FuncBool) delegate() { return(XenAdminConfigManager.Provider.ForcedExiting || cancellingDelegate != null && cancellingDelegate()); }; try { List <object> args = new List <object>(); args.Add(dataCopiedDelegate); args.Add(cancellingDelegate2); args.Add(XenAdminConfigManager.Provider.GetProxyTimeout(timeout)); args.Add(hostname); args.Add(XenAdminConfigManager.Provider.GetProxyFromSettings(connection)); args.Add(path); args.Add(task.opaque_ref); // task_id args.AddRange(p); f.DynamicInvoke(args.ToArray()); } catch (Exception e) { log.Debug($"Caught exception doing HTTP GET from {hostname} to {path}", e); if (e is WebException && e.InnerException is IOException && Win32.GetHResult(e.InnerException as IOException) == Win32.ERROR_DISK_FULL) { throw e.InnerException; } else if (e is CancelledException || e.InnerException is CancelledException) { throw new XenAdmin.CancelledException(); } else if (e.InnerException.Message == "Received error code HTTP/1.1 403 Forbidden\r\n from the server") { // RBAC Failure List <Role> roles = connection.Session.Roles; roles.Sort(); throw new Exception(String.Format(Messages.RBAC_HTTP_FAILURE, roles[0].FriendlyName()), e); } else { throw e.InnerException; } } return(PollTaskForResult(connection, ref session, cancellingDelegate2, task)); }