﻿using System;
using System.IO;
using System.Net;
using System.Windows.Forms;
using Bloom.Api;
using Bloom.Book;
using Bloom.MiscUI;
using Bloom.Publish;
using Bloom.Utils;
using SIL.IO;

namespace Bloom.web.controllers
{
	public class ProgressDialogApi
	{
		private static Action _cancelHandler;
		public static void SetCancelHandler(Action cancelHandler)
		{
			_cancelHandler = cancelHandler;
		}

		public void RegisterWithApiHandler(BloomApiHandler apiHandler)
		{
			apiHandler.RegisterEndpointLegacy("progress/cancel", Cancel, false, false);
			apiHandler.RegisterEndpointHandler("progress/closed", BrowserProgressDialog.HandleProgressDialogClosed, false);
			apiHandler.RegisterEndpointHandler("progress/ready", BrowserProgressDialog.HandleProgressReady, false);
		}

		private void Cancel(ApiRequest request)
		{
			// if it's null, and that causes a throw, well... that *is* an error situation
			_cancelHandler();
			request.PostSucceeded();
		}
	}
}

﻿using System;
using System.IO;
using System.Net;
using System.Windows.Forms;
using Bloom.Api;
using Bloom.Book;
using Bloom.MiscUI;
using Bloom.Publish;
using Bloom.Utils;
using SIL.IO;

namespace Bloom.web.controllers
{
	public class ProgressDialogApi
	{
		private static Action _cancelHandler;
		public static void SetCancelHandler(Action cancelHandler)
		{
			_cancelHandler = cancelHandler;
		}

		public void RegisterWithApiHandler(BloomApiHandler apiHandler)
		{
			apiHandler.RegisterEndpointLegacy("progress/cancel", Cancel, false, false);
			apiHandler.RegisterEndpointHandler("progress/closed", BrowserProgressDialog.HandleProgressDialogClosed, false);
			// Doesn't need sync because all it does is set a flag, which nothing else modifies.
			// Mustn't need sync because we may be processing another request (e.g., creating a TC) when we launch the dialog
			// that we want to know is ready to receive messages.
			apiHandler.RegisterEndpointHandler("progress/ready", BrowserProgressDialog.HandleProgressReady, false, false);
		}

		private void Cancel(ApiRequest request)
		{
			// if it's null, and that causes a throw, well... that *is* an error situation
			_cancelHandler();
			request.PostSucceeded();
		}
	}
}

Allow progress dialog ready API call to proceed without sync (BL-11484)
Allow progress dialog ready API call to proceed without sync (BL-11484)

