public async Task <IActionResult> Create([Bind("Id,Name")] Swallow swallow) { if (!ModelState.IsValid) { string msg = (ModelState.FirstOrDefault(x => x.Value.Errors.Any()).Value.Errors.FirstOrDefault().ErrorMessage).Replace("'", ""); _toastNotification.AddErrorToastMessage(msg); return(View(swallow)); } if (ModelState.IsValid) { var checkExit = _context.Swallow.Where(x => x.Name.ToLower() == swallow.Name.ToLower()).Count(); if (checkExit == 0) { _context.Add(swallow); await _context.SaveChangesAsync(); _toastNotification.AddErrorToastMessage(ResponseMessageUtilities.CREATED_SUCESSFUL); return(RedirectToAction(nameof(Index))); } _toastNotification.AddErrorToastMessage(ResponseMessageUtilities.ITEM_EXIST); return(RedirectToAction(nameof(Index))); } return(View(swallow)); }
private void DoSafeRelease() => Swallow.Everything( () => { if (_cancellation == null) { return; } if (!_cancellation.IsCancellationRequested) { _cancellation.Cancel(false); } _cancellation = null; }, () => { if (_consumer == null) { return; } if (!_consumer.IsCompleted) { _consumer.Wait(WaitForConsumerCompleteMs); } _consumer = null; }, () => { _connection?.Dispose(); _connection = null; });
public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Swallow swallow) { if (!ModelState.IsValid) { string msg = (ModelState.FirstOrDefault(x => x.Value.Errors.Any()).Value.Errors.FirstOrDefault().ErrorMessage).Replace("'", ""); _toastNotification.AddErrorToastMessage(msg); return(View(swallow)); } var CheckExist = _context.Swallow.Where(x => x.Id != swallow.Id && x.Name.ToLower() == swallow.Name.ToLower()).Count(); if (CheckExist == 0) { var model = _context.Swallow.FirstOrDefault(x => x.Id == swallow.Id); model.Name = swallow.Name; await _context.SaveChangesAsync(); _toastNotification.AddSuccessToastMessage(ResponseMessageUtilities.UPDATE_SUCESSFUL); return(RedirectToAction(nameof(Index))); } _toastNotification.AddErrorToastMessage(ResponseMessageUtilities.ITEM_EXIST); return(View(swallow)); }
private void DisposeSubscription(ObSubscription sub) { if (!_subscriptions.TryRemove(sub.Id, out _)) { return; //Most likely, previously removed due to failure } Swallow.Everything(() => sub.Observer.OnCompleted()); }
private void DisposeSubscription(SubscriptionInfo subscriptionInfo) { if (_isDisposed) { return; } Swallow.Everything(() => Unsub(subscriptionInfo)); }
static void Main(string[] args) { Console.WriteLine("接口隔离原则"); Bird bird01 = new Swallow(); Animal bird02 = new BrownKiwi(); Console.WriteLine("end"); Console.ReadKey(); }
private void DoSafeRelease() => Swallow.Everything( () => { if (_cancellation == null) { return; } if (!_cancellation.IsCancellationRequested) { _cancellation.Cancel(false); } _cancellation.Dispose(); _cancellation = null; }, () => { if (_consumer == null) { return; } if (!_consumer.IsCompleted) { _consumer.Wait(WaitForConsumerCompleteMs); } _consumer = null; }, () => { foreach (var key in _outstandingRequests.Keys) { if (_outstandingRequests.TryRemove(key, out var tcs)) { try { tcs.TrySetCanceled(); } catch { // ignored } } } }, () => { _connection?.Dispose(); _connection = null; });
private Subscription CreateMsgOpSubscription(SubscriptionInfo subscriptionInfo, Func <INatsObservable <MsgOp>, IDisposable> subscriptionFactory) { var subscription = Subscription.Create( subscriptionInfo, subscriptionFactory(MsgOpStream.Where(msg => subscriptionInfo.Matches(msg.Subject))), info => Swallow.Everything(() => Unsub(info))); if (!_subscriptions.TryAdd(subscription.SubscriptionInfo.Id, subscription)) { throw NatsException.CouldNotCreateSubscription(subscription.SubscriptionInfo); } return(subscription); }
public void TestAct() { Helpers.TestBlockAction(Agent, Game); Helpers.TestProtectAction(Agent, Game, false); Game.Reset(); Agent = (Swallow)Game.Agents[nameof(Swallow)]; Helpers.TestBlockerKillInteraction(Agent, Game.Agents[nameof(Android)], Game, true, true); Game.Reset(); Agent = (Swallow)Game.Agents[nameof(Swallow)]; Helpers.TestBlockerKillInteraction(Agent, Game.Agents[nameof(Mastermind)], Game, true, true); Game.Reset(); Agent = (Swallow)Game.Agents[nameof(Swallow)]; }
static void Main(string[] args) { Bird christianBird = new RubberDuck(); christianBird.Display(); christianBird.SetFlyBehavior(new YesFly()); christianBird.PerformFly(); christianBird.PerformQuack(); christianBird.Swim(); Bird mortyBird = new Swallow(); mortyBird.Display(); mortyBird.PerformFly(); mortyBird.PerformQuack(); mortyBird.Swim(); }
public void Emit(T value) { foreach (var subscription in _subscriptions) { try { subscription.Value.Observer.OnNext(value); } catch (Exception ex) { Logger.Error("Error in observer while emitting value.", ex); RemoveSubscription(subscription.Key); Swallow.Everything(() => subscription.Value.Observer.OnError(ex)); } } }
public void Emit(T value) { ThrowIfDisposed(); foreach (var subscription in _subscriptions.Values) { try { subscription.Observer.OnNext(value); } catch (Exception ex) { Logger.Error("Error in observer while emitting value. Observer subscription will be removed.", ex); //No invoke of OnError as it's not the producer that is failing. _subscriptions.TryRemove(subscription.Id, out _); Swallow.Everything(() => subscription.Dispose()); } } }
public void TestName() { for (int i = 0; i < 1000; i++) { Agent = new Swallow(); switch (Agent.Gender) { case Gender.Female: Assert.AreEqual("Swallow", Agent.Name); break; case Gender.Male: Assert.AreEqual("Raven", Agent.Name); break; default: throw new NotImplementedException(); } ; } Agent = (Swallow)Game.Agents[nameof(Swallow)]; }
public void Setup() { Game = new(); Agent = (Swallow)Game.Agents[nameof(Swallow)]; }