public void CommitTransaction() { if (_needToPay > 0) { throw new InvalidOperationException("Where is the money, Lebowski?"); // Somehow exception may not be caught in try-catch inside Program.Main } _payments.ForEach(payment => { if (!payment.IsSuccessful.HasValue) { IFailablePayment failablePayment = (IFailablePayment)payment; failablePayment.TryCommit(); if (!failablePayment.IsSuccessful.Value) { OnPaymentFailed?.Invoke(payment); return; } } }); }
private static void InitConnection(API.AuthenticationInfo e) { // var handler = new Handler(Looper.MainLooper); hubConnection = new HubConnection(Resources.APIBaseAddress, true); if (hubConnection.Headers.ContainsKey("Authorization")) { hubConnection.Headers["Authorization"] = $"Bearer {e.AccessToken}"; } else { hubConnection.Headers.Add("Authorization", $"Bearer {e.AccessToken}"); } coreHub = hubConnection.CreateHubProxy("CoreHub"); coreHub.On("OnReservationPaid", (long id) => { handler.Post(() => OnReservationPaid?.Invoke(null, id)); }); coreHub.On("OnReservationRefunded", (long id) => { handler.Post(() => OnReservationRefunded?.Invoke(null, id)); }); coreHub.On("OnReservationPaymentFailed", (long id) => { handler.Post(() => OnPaymentFailed?.Invoke(null, id)); }); #if DEBUG coreHub.On("OnTest", (int count) => { LogHelpers.Write(nameof(RealtimeNotifications), $"Receive test notification: {count}"); }); #endif hubConnection.Error += (err) => { }; hubConnection.StateChanged += (t) => { if (!connectionTimer.Enabled) { connectionTimer.Start(); } if (t.NewState == ConnectionState.Connected) { LogHelpers.Write(nameof(RealtimeNotifications), "Connected to hub successfully!"); } }; // isRegistered = true; hubConnection.Start().ContinueWith(t => { if (t.IsFaulted) { LogHelpers.Write(nameof(RealtimeNotifications), t.Exception.GetBaseException().ToString()); } else { LogHelpers.Write(nameof(RealtimeNotifications), "Connection was successful"); } }); }