コード例 #1
0
        private void NouveauVoyage()
        {
            ConsoleHelper.AfficherEntete("Nouveau Voyage");
            OutilsConsole.CentrerTexte("LISTE DES DESTINATIONS\n ");
            ConsoleHelper.AfficherListe(new DestinationData().GetList(), strategieAffichageDestination);

            var voyage = new Voyage
            {
                DestinationId     = ConsoleSaisie.SaisirEntierObligatoire("Id de la Destination retenue ?"),
                DateAller         = ConsoleSaisie.SaisirDateObligatoire("Date Aller ?"),
                DateRetour        = ConsoleSaisie.SaisirDateObligatoire("Date Retour ?"),
                PlacesDisponibles = ConsoleSaisie.SaisirEntierObligatoire("Places max disponibles ?"),
                PrixParPersonne   = ConsoleSaisie.SaisirDecimalObligatoire("Prix/pers. ?"),
                AgenceVoyageId    = ConsoleSaisie.SaisirEntierObligatoire("Id de l'Agence de Voyage (par défaut 1) ?")
            };
            var voyageService = new VoyageService();

            voyageService.Ajout(voyage);
            if (voyage.Id != 0)
            {
                Console.WriteLine("Le Voyage a été enregistré avec succès");
            }
            else
            {
                Console.WriteLine("Le Voyage n'a pas pu être créé (Erreur de date ou de destination ...)");
            }
        }
コード例 #2
0
        private void SupprimerVoyage()
        {
            ConsoleHelper.AfficherEntete("Suppression d'un Voyage");
            Console.WriteLine("LISTE DES VOYAGES\n");
            ConsoleHelper.AfficherListe(new VoyageData().GetList(), strategieAffichageVoyages);
            var voyageService = new VoyageService();

            var voyageId = ConsoleSaisie.SaisirEntierObligatoire("Id du voyage à supprimer ?");
            var succes   = voyageService.Supprimer(voyageId);

            if (succes == true)
            {
                Console.WriteLine("Le voyage a été supprimé");
            }
            else
            {
                Console.WriteLine("Suppression impossible car dossier client en cours ");
            }
        }
コード例 #3
0
        public ResponseHeaderType SaveOrUpdateVoyage(VoyageRequest request)
        {
            try
            {
                UnityWrapper.ConfiguredContainer.RegisterType <ILoginInformation, WcfLoginInformation>(
                    new UnityOperationContextLifetimeManager(),
                    new InjectionFactory(
                        container =>
                {
                    log.Debug($"Operation context hash: {OperationContext.Current.GetHashCode()} Creating WCFLoginInformation {request.Header.UserName}");
                    return(WcfLoginInformation.Authenticate(request.Header.UserName));
                })
                    );

                LoggedInPersonIDInterceptorUtil.RegisterPersonIdProviderWcfContext(() => new HasLoggedInPersonID
                {
                    LoggedInPersonID   = UnityWrapper.Resolve <ILoginInformation>().ID,
                    UserIdentification = UnityWrapper.Resolve <ILoginInformation>().UserIdentification,
                });

                //This variable delay simulates variances in the time it takes to handle a request in the real application.
                //E.g. some requests take longer to validate since the payload is larger.

                //Note: If this variable delay is removed, the clients will not interfere with each other.
                var delay = (int)(1000 * new Random().NextDouble());
                log.Debug($"Operation context hash: {OperationContext.Current.GetHashCode()} Delaying: {delay}, {request.Header.UserName}");
                Thread.Sleep(delay);

                var user = UnityWrapper.Resolve <ILoginInformation>();
                if (user == null)
                {
                    return(CreateResponse(StatusCodeEnumType.AccessDenied, $"Login failed for user {request.Header.UserName}"));
                }



                var dto = new VoyageService().GetById(request.Body.VoyageID) ?? new DAL.DTO.Classes.Voyage();

                if (!string.IsNullOrWhiteSpace(request.Body.ShipName))
                {
                    dto.ShipName = request.Body.ShipName;
                }

                if (!string.IsNullOrWhiteSpace(request.Body.ToLocation))
                {
                    dto.ToLocation = request.Body.ToLocation;
                }

                if (!string.IsNullOrWhiteSpace(request.Body.FromLocation))
                {
                    dto.FromLocation = request.Body.FromLocation;
                }

                if (request.Body.ETD != default(DateTime))
                {
                    dto.ETD = request.Body.ETD;
                }

                if (request.Body.ETA != default(DateTime))
                {
                    dto.ETA = request.Body.ETA;
                }

                dto = new VoyageService().SaveOrUpdate(dto);

                if (dto.ModifiedByPersonID != user.ID)
                {
                    var modifiedBy = new PersonService().GetById(dto.ModifiedByPersonID.GetValueOrDefault());
                    return(CreateResponse(StatusCodeEnumType.ServerError, $"The voyage with ID {dto.VoyageID} was modified by {modifiedBy.UserIdentification} - not {user.UserIdentification}"));
                }
            }
            catch (Exception ex)
            {
                return(CreateResponse(StatusCodeEnumType.ServerError, ex.Message));
            }

            return(CreateResponse(StatusCodeEnumType.OK));
        }
コード例 #4
0
        private static async Task SpawnWriter(string username, string shipname)
        {
            await Task.Run(() => {
                try
                {
                    log.Info($"Retrieving user account for {username}");
                    var person = new PersonService().GetByUserIdentification(username);
                    if (person == null)
                    {
                        throw new ArgumentException($"No user account exists for {username}");
                    }

                    log.Info($"Creating sample voyage for {username}");
                    var eta = DateTime.Now.AddDays(2);

                    //Create an initial voyage
                    var voyage = new VoyageService().SaveOrUpdate(new DAL.DTO.Classes.Voyage
                    {
                        ShipName         = shipname,
                        FromLocation     = "NOTRD",
                        ToLocation       = "NOBGO",
                        ETA              = eta,
                        ETD              = DateTime.Now.AddHours(1),
                        LoggedInPersonID = person.PersonID
                    });

                    log.Info("Spawning client ...");
                    var client = new TestServiceClient();

                    while (isRunning)
                    {
                        var response = client.SaveOrUpdateVoyage(new WcfService.Schema.VoyageRequest
                        {
                            Header = new WcfService.Schema.RequestHeaderType
                            {
                                UserName = username
                            },
                            Body = new WcfService.Schema.VoyageType
                            {
                                VoyageID          = voyage.VoyageID,
                                VoyageIDSpecified = true,
                                ETA = eta.AddMinutes(1)
                            }
                        });

                        if (response.StatusCode != WcfService.Schema.StatusCodeEnumType.OK)
                        {
                            isRunning = false;                             //Abort further execution
                            log.Error($"{response.StatusCode} - {response.StatusMessage}");
                        }
                        else
                        {
                            log.Debug($"{response.StatusCode}");
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
            });
        }