public void WaitUntilActionsCompleted(HttpListenerContext _Context, Action <string> _ErrorMessageAction = null) { if (ErrorMessageAction == null) { ErrorMessageAction = _ErrorMessageAction; } if (ActionsDictionary.TryRemove(_Context, out ConcurrentQueue <Action_DeliveryEnsurer> DeliveryEnsurerActions)) { var WaitForEvent = new ManualResetEvent(false); BackgroundProcessingQueue.Enqueue(new Tuple <ManualResetEvent, ConcurrentQueue <Action_DeliveryEnsurer> >(WaitForEvent, DeliveryEnsurerActions)); lock (BackgroundProcessingQueueEvent) { try { BackgroundProcessingQueueEvent.Set(); } catch (Exception) { } } try { WaitForEvent.WaitOne(); WaitForEvent.Close(); } catch (Exception) { } } }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> static void Main(string[] args) { //Setup of DI IServiceProvider serviceProvider = new ServiceCollection() .AddSingleton <IConfigurationService, ConfigurationService>() .AddSingleton <ITokenService, TokenService>() .AddSingleton <ICartService, CartService>() .BuildServiceProvider(); ICartService cartService = serviceProvider.GetService <ICartService>(); try { Console.Clear(); Console.Write(Labels.Feedback.EnterAction); string line; while (!Labels.Quit.Equals((line = Console.ReadLine().Trim()))) { Console.Clear(); string[] parameters = line.Split(' '); Func <ICartService, Guid, Guid, uint, bool> action = null; if (parameters.Length < 2 || !ActionsDictionary.TryGetValue(parameters[0], out action) || action == null) { Console.WriteLine(Labels.Feedback.InvalidAction); } else { int length = parameters.Length; Guid cartId, productId; uint amount; Guid.TryParse(length > 1 ? parameters[1] : string.Empty, out cartId); Guid.TryParse(length > 2 ? parameters[2] : string.Empty, out productId); uint.TryParse(length > 3 ? parameters[3] : string.Empty, out amount); bool result = action(cartService, cartId, productId, amount); Console.WriteLine( string.Format(Labels.Feedback.ResultAction, Labels.Feedback.ResultToText(result))); ICartInfo cart; if (result && (cart = cartService.GetCartInfo(cartId)) != null) { Console.WriteLine(JsonConvert.SerializeObject(cart, Formatting.Indented)); Console.WriteLine(); } } Console.Write(Labels.Feedback.EnterAction); } } catch (Exception e) { Console.WriteLine(Labels.Feedback.Error); Console.WriteLine(e.Message); } finally { Console.WriteLine(Labels.Feedback.Exit); } }