Пример #1
0
        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));
            }
        }
Пример #2
0
        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);
            }
        }