Ejemplo n.º 1
0
        public Response RequestResumption(ResumptionRequest resumptionRequest)
        {
            try
            {
                var FaultServices = GetFaultCourtService(resumptionRequest.Court_ID);
                if (FaultServices == null || FaultServices.Count == 0)
                {
                    return new Response
                           {
                               ErrorCodes = new List <int> {
                                   ErrorCode.CourtIDNotRegistered
                               }
                           }
                }
                ;
                else if (FaultServices.Count == 1)
                {
                    return(FaultServices.First().RequestResumption(resumptionRequest));
                }
                else
                {
                    /** why can a court has more than one service !!!?
                     * This will call all Services at same time
                     * then will check each one of them if the service response is the one i need
                     * what i need is either the result is true Or it dones't have the NotFoundBussinessID error
                     * if found i will return this response
                     * example:
                     * portsaid , suez, ismalilia
                     * each of them has an initial court
                     * if i request an resumption i will go to the higher court
                     * sadly they added the higer court in the seperate DB (because the higher court has a branch in the city)
                     * so i have 3 primary courts in system which one of them has the original case :(
                     * so i send to all 3 at same time (Parrell so it won't wait until the previous finishs etc...)
                     * and search in them (i like this trick actully)
                     **/
                    List <Task <Response> > serviceTasks = FaultServices.Select(service => service.RequestResumptionAsync(resumptionRequest)).ToList();

                    while (serviceTasks.Count > 0)
                    {
                        Task <Response> serviceTask = GetFirstFinishedTask(serviceTasks);
                        //Remove the task from the unfinished List
                        serviceTasks.Remove(serviceTask);
                        try
                        {
                            var response = serviceTask.Result;
                            if (response.Result || !response.ErrorCodes.Contains(ErrorCode.NotFoundBussinessID))
                            {
                                return(response);
                            }
                        }
                        catch (OperationCanceledException) { }
                        catch (Exception ex)
                        {
                            logger.LogException(ex);
                        }
                    }
                    //if none of the services respond correctly then this id is wrong or correct service isn't registered
                    return(new Response
                    {
                        ErrorCodes = new List <int> {
                            ErrorCode.NotFoundBussinessID
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                logger.LogException(ex);
                return(Response.Failed);
            }
        }
 /// <summary>
 /// Request a Resumption for this Case
 /// </summary>
 /// <param name="resumptionRequest"></param>
 /// <returns></returns>
 public Response RequestResumption(ResumptionRequest resumptionRequest)
 {
     return(ReturnErrorResponse(new List <int> {
         ErrorCode.NotFoundBussinessID
     }));
 }