Exemplo n.º 1
0
        internal static Transports getAllTransports()
        {
            SqlCommand    cmd           = new SqlCommand("select t.tid, t.name, p.postID from Transport as t left join Posts as p on t.tid = p.tid", Starter.GetConnection());
            SqlDataReader reader        = cmd.ExecuteReader();
            Transports    allTransports = new Transports(); //initialisiere lehre Liste

            Transport currentObject = new Transport();

            currentObject.transportID = 0;

            while (reader.Read())
            {
                if (currentObject.transportID != reader.GetInt32(0))
                {
                    Transport oneTransport = new Transport();
                    currentObject = oneTransport;
                    allTransports.Add(currentObject);
                    currentObject.transportID   = reader.GetInt32(0);
                    currentObject.transportName = reader.GetString(1);
                }


                try
                {
                    currentObject.postIDs.Add(reader.GetInt32(2));
                }
                catch (Exception e)
                {
                }
            }
            return(allTransports);
        }
Exemplo n.º 2
0
        public void AddTransport(string name, int level, double posX, double posY, double width,
                                 double height, double vel)
        {
            Transport transport = new Transport(Transports.Count, name, level, posX, posY, width, height, vel);

            Transports.Add(transport);
        }
    public ServerOptionsViewModel()
    {
        Host = "localhost";
        Port = 1883;
        CommunicationTimeout = 10;

        Transports.Add(new TransportViewModel("TCP", Transport.TCP));
        Transports.Add(new TransportViewModel("WebSocket", Transport.WebSocket));
        Transports.SelectedItem = Transports.FirstOrDefault() !;

        TlsVersions.Add(new TlsVersionViewModel("no TLS", SslProtocols.None));
        TlsVersions.Add(new TlsVersionViewModel("TLS 1.0", SslProtocols.Tls));
        TlsVersions.Add(new TlsVersionViewModel("TLS 1.1", SslProtocols.Tls11));
        TlsVersions.Add(new TlsVersionViewModel("TLS 1.2", SslProtocols.Tls12));
        TlsVersions.Add(new TlsVersionViewModel("TLS 1.3", SslProtocols.Tls13));

        TlsVersions.SelectedItem = TlsVersions.FirstOrDefault() !;
    }
Exemplo n.º 4
0
        private async Task <ClientWebSocket> OpenTransport(long?key = 0)
        {
            long _key = key.HasValue ? key.Value : await Options.KeyGenerator();

            ClientWebSocket transport = Transports.ContainsKey(_key) ? Transports[_key] : null;

            if (transport != null && transport.State != WebSocketState.Open)
            {
                if (transport.State != WebSocketState.CloseSent && transport.State != WebSocketState.Aborted)
                {
                    try {
                        await transport.CloseOutputAsync(WebSocketCloseStatus.NormalClosure,
                                                         "Reopening socket",
                                                         CancellationToken.None);
                    } catch (Exception e) {
                    }
                }
                Transports.Remove(_key);
                transport.Dispose();
            }
            if (transport == null || transport.State != WebSocketState.Open)
            {
                transport = new ClientWebSocket();
                Uri connectTo = new Uri(Options.BaseConnectionUri, _key.ToString());
                await transport.ConnectAsync(connectTo, CancellationToken.None);

                if (Transports.ContainsKey(_key))
                {
                    Transports[_key] = transport;
                }
                else
                {
                    Transports.Add(_key, transport);
                }
            }
            return(transport);
        }
Exemplo n.º 5
0
        public async Task Init()
        {
            var countries = await _countryService.Get <List <CountryDTO> >(null);

            foreach (var country in countries)
            {
                Countries.Add(country);
            }


            var hotelData    = (await _hotelService.Get <List <HotelDTO> >(null)).OrderByDescending(_ => _.TotalVisits).Take(5);
            var tCompanyData = (await _tCompanyService.Get <List <TransportCompanyDTO> >(null)).OrderByDescending(_ => _.TotalReservations).Take(5);

            foreach (var hotel in hotelData)
            {
                Hotels.Add(hotel);
            }
            foreach (var tcompany in tCompanyData)
            {
                Transports.Add(tcompany);
            }

            int visits       = 0;
            var reservations = await _reservationService.Get <List <ReservationDTO> >(null);

            foreach (var item in reservations)
            {
                visits += item.NumberOfPersons;
            }
            AllTimeVisits = visits;

            //Dictionary<int, int> topOffers = new Dictionary<int, int>();
            //Dictionary<int, int> bestHotels = new Dictionary<int, int>();
            //Dictionary<int, int> bestTransports = new Dictionary<int, int>();

            //#region hotels
            //foreach (var hOffer in hOffers)
            //{
            //    var reservations = (await _reservationService.Get<List<ReservationDTO>>(new ReservationSearchRequest { HotelOfferId = hOffer.Id})).Count;

            //    if (topOffers.ContainsKey(hOffer.HotelId))
            //    {
            //        topOffers[hOffer.HotelId] += reservations;
            //    }
            //    else
            //    {
            //        topOffers.Add(hOffer.HotelId, reservations);
            //    }
            //}
            //var offers = bestOffer(ref topOffers, bestHotels);

            //foreach (var hotel in offers)
            //{
            //    var bestHotel = await _hotelService.GetById<HotelDTO>(hotel.Key);
            //    Hotels.Add(bestHotel);
            //}
            //#endregion



            //#region transports

            //foreach (var tOffer in tOffers)
            //{
            //    var reservations = (await _reservationService.Get<List<ReservationDTO>>(new ReservationSearchRequest {TransportOfferId = tOffer.Id})).Count;

            //    if (topOffers.ContainsKey(tOffer.TransportCompanyId))
            //    {
            //        topOffers[tOffer.TransportCompanyId] += reservations;
            //    }
            //    else
            //    {
            //        topOffers.Add(tOffer.TransportCompanyId, reservations);
            //    }
            //}


            //offers = bestOffer(ref topOffers, bestTransports);

            //foreach (var transport in offers)
            //{
            //    var bestTransport = await _tCompanyService.GetById<TransportCompanyDTO>(transport.Key);
            //    Transports.Add(bestTransport);
            //}
            //#endregion
        }