Exemplo n.º 1
0
        public InvokeResult <IEnumerable <MunroModel> > GetMunrosByQuery(
            IEnumerable <HillCategory> hillCategories = null,
            SortDirectionType heightSortDirectionType = SortDirectionType.None,
            SortDirectionType nameSortDirectionType   = SortDirectionType.None,
            double?heightMinMetres = null,
            double?heightMaxMetres = null,
            int?limit = null)
        => _invokeHandler.Invoke(() =>
        {
            var queryResult = this.CreateMunrosQuery(
                hillCategories,
                heightSortDirectionType,
                nameSortDirectionType,
                heightMinMetres,
                heightMaxMetres);

            if (!queryResult.IsSuccess)
            {
                return(InvokeResult <IEnumerable <MunroModel> > .Fail(queryResult.Code));
            }

            var munros = _munrosRepository.GetAll();

            var result =
                _munroService.GetMunrosByQuery(munros, queryResult.Result.conditions, queryResult.Result.sorts,
                                               limit);
            return(result);
        });
Exemplo n.º 2
0
        public void StartJob(JobQueueItemEntity jobQueueItemEntity)
        {
            if (IsWorking)
            {
                return;
            }
            IsWorking = true;
            CancellationTokenSource = new CancellationTokenSource();
            IEnumerable <object> returnObjects = null;

            var typ   = _nodeConfiguration.HandlerAssembly.GetType(jobQueueItemEntity.Type);
            var deSer = JsonConvert.DeserializeObject(jobQueueItemEntity.Serialized,
                                                      typ);
            //-----------------------------------------------------
            // Clear faulted timer.
            //-----------------------------------------------------
            var faultedTimer =
                _trySendJobFaultedStatusToManagerTimer as TrySendJobFaultedToManagerTimer;

            if (faultedTimer != null)
            {
                faultedTimer.AggregateExceptionToSend = null;
                faultedTimer.ErrorOccured             = null;
            }

            //----------------------------------------------------
            // Define task.
            //----------------------------------------------------

            Task = new Task(() =>
            {
                _handler.Invoke(deSer,
                                CancellationTokenSource,
                                SendJobProgressToManager,
                                ref returnObjects);
            },
                            CancellationTokenSource.Token);

            Task.ContinueWith(t =>
            {
                switch (t.Status)
                {
                case TaskStatus.RanToCompletion:

                    SetNodeStatusTimer(_trySendJobDoneStatusToManagerTimer,
                                       _currentMessageToProcess);

                    if (returnObjects != null)
                    {
                        SpinWait.SpinUntil(() => _currentMessageToProcess == null);
                        LoopReturnObjects(returnObjects);
                    }

                    break;


                case TaskStatus.Canceled:

                    SetNodeStatusTimer(_trySendJobCanceledStatusToManagerTimer,
                                       _currentMessageToProcess);

                    if (returnObjects != null)
                    {
                        SpinWait.SpinUntil(() => _currentMessageToProcess == null);
                        LoopReturnObjects(returnObjects);
                    }

                    break;


                case TaskStatus.Faulted:
                    if (faultedTimer != null)
                    {
                        faultedTimer.AggregateExceptionToSend = t.Exception;
                        faultedTimer.ErrorOccured             = DateTime.UtcNow;
                    }

                    if (t.Exception != null)
                    {
                        Logger.ErrorWithLineNumber("Failed",
                                                   t.Exception);
                    }

                    SetNodeStatusTimer(_trySendJobFaultedStatusToManagerTimer,
                                       _currentMessageToProcess);

                    if (returnObjects != null)
                    {
                        SpinWait.SpinUntil(() => _currentMessageToProcess == null);
                        LoopReturnObjects(returnObjects);
                    }

                    break;
                }
            }, TaskContinuationOptions.LongRunning);

            Task.Start();
        }
Exemplo n.º 3
0
 public void DisplayInfoWindow()
 {
     _invokeHandler.Invoke(DisplayWindow);
 }