Esempio n. 1
0
 private Task <T> AirplaneSvcOperationAsync <T>(Func <Task <T> > operation, string errorMessage, params object[] args)
 {
     return(ErrorHandlingPolicy.ExecuteNetworkCallAsync(operation, (Exception ex, TimeSpan waitDuration) => {
         logger_.LogWarning(LoggingEvents.AirplaneSvcOpFailed, ex, FailedNetworkOperationErrorMessage(errorMessage), args);
         return Task.CompletedTask;
     }));
 }
        public async Task RequestErrorPolicySuppressesCancellationExceptions()
        {
            // These two should not throw and the test should pass
            await ErrorHandlingPolicy.ExecuteRequestAsync(() => { throw new OperationCanceledException(); });

            await ErrorHandlingPolicy.ExecuteRequestAsync(() => { throw new TaskCanceledException(); });
        }
 public void ResetToDefault()
 {
     lock (LOCK)
     {
         this.logger              = null;
         this.loggingPolicy       = default(LoggingPolicy);
         this.errorHandlingPolicy = default(ErrorHandlingPolicy);
     }
 }
        public static IAppBuilder UseIMOwin(this IAppBuilder app, BehaviorRouter behaviorRouter, IMOwinFilterCollection filters, IContentFormatter contentFormatter, ErrorHandlingPolicy errorHandlingPolicy)
        {
            var option = new IMOwinOptions(behaviorRouter, contentFormatter, filters)
            {
                ErrorHandlingPolicy = errorHandlingPolicy,
            };

            return UseIMOwin(app, option);
        }
Esempio n. 5
0
        public Task <IEnumerable <string> > GetFlyingAirplaneCallSigns()
        {
            try {
                return(ErrorHandlingPolicy.ExecuteRequestAsync(async() => {
                    var flyingAirplaneCallSigns = await TableStorageOperationAsync(
                        () => flyingAirplanesTable_.GetFlyingAirplaneCallSignsAsync(shutdownTokenSource_.Token),
                        "Could not get call signs of all flying airplanes",
                        nameof(FlyingAirplanesTable.GetFlyingAirplaneCallSignsAsync));

                    return flyingAirplaneCallSigns;
                }));
            }
            catch (Exception ex) {
                logger_.LogError(LoggingEvents.AirplaneCallSignEnumerationFalied, ex,
                                 "Unexpected error occurred when getting call signs of all flying airplanes");
                throw;
            }
        }
Esempio n. 6
0
        public Task StartNewFlight(FlightPlan flightPlan)
        {
            FlightPlan.Validate(flightPlan, includeFlightPath: false);

            try
            {
                return(ErrorHandlingPolicy.ExecuteRequestAsync(async() =>
                {
                    var flyingAirplaneCallSigns = await TableStorageOperationAsync(
                        () => flyingAirplanesTable_.GetFlyingAirplaneCallSignsAsync(shutdownTokenSource_.Token),
                        null,
                        nameof(FlyingAirplanesTable.GetFlyingAirplaneCallSignsAsync));
                    if (flyingAirplaneCallSigns.Contains(flightPlan.CallSign, StringComparer.OrdinalIgnoreCase))
                    {
                        // In real life airplanes can have multiple flight plans filed, just for different times. But here we assume there can be only one flight plan per airplane
                        throw new InvalidOperationException($"The airplane {flightPlan.CallSign} is already flying");
                        // CONSIDER forcing execution of the new flight plan here, instead of throwing an error.
                    }

                    flightPlan.FlightPath = Dispatcher.ComputeFlightPath(flightPlan.DeparturePoint, flightPlan.Destination);

                    // The actual creation of the flight will be queued and handled by the time passage routine to ensure that there are no races
                    // during new world state calculation
                    newFlightQueue_.Enqueue(flightPlan);

                    if (logger_.IsEnabled(LogLevel.Information))
                    {
                        flightPlan.AddUniverseInfo();
                        logger_.LogInformation(
                            LoggingEvents.NewFlightCreated,
                            "New flight created from {DeparturePoint} to {Destination} for {CallSign}. Clearance is {FlightPath}",
                            flightPlan.DeparturePoint.Name,
                            flightPlan.Destination.Name,
                            flightPlan.CallSign,
                            flightPlan.FlightPath.Select(fix => fix.Name).Aggregate(string.Empty, (current, fixName) => current + " " + fixName));
                    }
                }));
            }
            catch (Exception ex)
            {
                logger_.LogError(LoggingEvents.StartingNewFlightFailed, ex, "Unexpected error occurred when starting new flight");
                throw;
            }
        }
Esempio n. 7
0
        public Task <int?> GetFlightCountAsync()
        {
            try {
                return(ErrorHandlingPolicy.ExecuteRequestAsync(async() => {
                    int?count = await TableStorageOperationAsync(
                        () => flyingAirplanesTable_.GetFlyingAirplaneCountAsync(shutdownTokenSource_.Token),
                        "Could not get the count of flying airplanes",
                        nameof(FlyingAirplanesTable.GetFlyingAirplaneCountAsync)
                        );

                    // Add airplanes scheduled to dispatch.
                    count += newFlightQueue_.Count;

                    return count;
                }));
            }
            catch (Exception ex) {
                logger_.LogError(LoggingEvents.AirplaneCountFailed, ex, "Unexpected error occurred when getting count of flying airplanes");
                throw;
            }
        }
 public async Task RequestErrorPolicyIgnoresNonCancellationExceptions()
 {
     await Assert.ThrowsExceptionAsync <Exception>(() => ErrorHandlingPolicy.ExecuteRequestAsync(() => { throw new Exception(); }));
 }
Esempio n. 9
0
        public IScheduler CreateScheduler()
        {
            Func <DateTime> now = () => DateTime.Now;

            var eventStream                = new EventStream(_eventSinks, _exceptionLogger, now);
            var recoverableAction          = new RecoverableAction(this, eventStream);
            var delegatingPersistenceStore = new DelegatingPersistenceStore(_persistenceProvider);
            var jobMutation                = new JobMutator(eventStream, delegatingPersistenceStore);

            var queueConfiguration = new JobQueueFactory(
                delegatingPersistenceStore, this, eventStream, recoverableAction, jobMutation).Create();

            var router       = new JobRouter(queueConfiguration);
            var methodBinder = new MethodBinder();

            var continuationDispatcher = new ContinuationDispatcher(router, jobMutation,
                                                                    delegatingPersistenceStore, recoverableAction);
            var activityToContinuationConverter = new ActivityToContinuationConverter(now);

            var runningTransition = new RunningTransition(jobMutation);
            var failedTransition  = new FailedTransition(this, jobMutation, now);
            var endTransition     = new EndTransition(delegatingPersistenceStore, jobMutation,
                                                      continuationDispatcher);

            var continuationLiveness = new ContinuationLiveness(delegatingPersistenceStore, continuationDispatcher);

            var coordinator = new JobCoordinator(eventStream, recoverableAction);

            var waitingForChildrenTransition = new WaitingForChildrenTransition(
                delegatingPersistenceStore,
                continuationDispatcher,
                activityToContinuationConverter,
                recoverableAction,
                jobMutation);

            var changeState = new StatusChanger(eventStream, runningTransition, failedTransition,
                                                endTransition, waitingForChildrenTransition, jobMutation);

            var failedJobQueue = new FailedJobQueue(this, delegatingPersistenceStore, now, eventStream, router);

            var errorHandlingPolicy = new ErrorHandlingPolicy(this, coordinator, changeState,
                                                              failedJobQueue, recoverableAction);

            var exceptionFilterDispatcher = new ExceptionFilterDispatcher(eventStream);

            var jobDispatcher = new Dispatcher.Dispatcher(_dependencyResolver,
                                                          coordinator,
                                                          errorHandlingPolicy,
                                                          methodBinder,
                                                          eventStream,
                                                          recoverableAction,
                                                          changeState,
                                                          continuationLiveness,
                                                          exceptionFilterDispatcher);

            var jobPumps =
                queueConfiguration
                .ActivitySpecificQueues
                .Values
                .Select(q => new JobPump(jobDispatcher, eventStream, q))
                .ToList();

            jobPumps.Add(new JobPump(jobDispatcher, eventStream, queueConfiguration.Default));

            return(new Scheduler(
                       queueConfiguration,
                       this,
                       delegatingPersistenceStore,
                       now,
                       failedJobQueue,
                       recoverableAction,
                       router,
                       activityToContinuationConverter,
                       jobPumps,
                       jobMutation));
        }