internal static Address FromApi(ApiAddress address)
 => Address.Create(address.Country,
                   address.City,
                   address.Street,
                   address.Number,
                   address.DisplayAddress1,
                   address.DisplayAddress2);
        private void EditLeague(object sender, RoutedEventArgs e)
        {
            league.Name   = Name.Text;
            league.Rating = int.Parse(Rating.Text);
            //league.RaceTypes = RaceTypes.SelectedItem;

            RestService restService = new RestService(ApiAddress.Address(), "/League", token);

            restService.Put <string, League>(league.LID, league);
            MainWindow mainWindow = new MainWindow();

            mainWindow.GetLeagueListNames();
            this.Close();
        }
        private void EditTeam(object sender, RoutedEventArgs e)
        {
            team.TName   = TName.Text;
            team.Created = int.Parse(Created.Text);
            team.Country = Country.Text;


            RestService restService = new RestService(ApiAddress.Address(), "/Team", token);

            restService.Put <string, Team>(team.TID, team);
            MainWindow mainWindow = new MainWindow();

            mainWindow.GetLeagueListNames();
            this.Close();
        }
Exemple #4
0
        private void EditDriver(object sender, RoutedEventArgs e)
        {
            driver.DName      = DName.Text;
            driver.BornYear   = int.Parse(BornYear.Text);
            driver.CountryB   = CountryB.Text;
            driver.RaceNumber = int.Parse(RaceNumber.Text);

            RestService restService = new RestService(ApiAddress.Address(), "/Driver", token);

            restService.Put <string, Driver>(driver.DID, driver);

            MainWindow mainWindow = new MainWindow();

            mainWindow.GetLeagueListNames();
            this.Close();
        }
Exemple #5
0
        /// <summary>
        /// Gets next API address (until the end of list).
        /// </summary>
        /// <param name="address">Address</param>
        /// <returns>Next API address</returns>
        public static ApiAddress GetNextAddress(string address)
        {
            ApiAddress apiAddress = ADDRESSES.Find(item => item.Address == address);

            if (apiAddress == null)
            {
                throw new APICommunicationException("Connection error (and no backup server available for " + address + ")");
            }
            // Remove the broken address
            ADDRESSES.Remove(apiAddress);

            // If there are anymore else take the first
            if (ADDRESSES.Count > 0)
            {
                return(ADDRESSES[0]);
            }

            throw new APICommunicationException("Connection error (and no more backup servers available)");
        }
        private void AddTeam(object sender, RoutedEventArgs e)
        {
            Team team = new Team()
            {
                TName   = TName.Text,
                Created = int.Parse(Created.Text),
                Country = Country.Text,
                //Engine = Engine.SelectedItem,
                LID    = league.LID,
                League = league
            };

            RestService restService = new RestService(ApiAddress.Address(), "/Team", token);

            restService.Post <Team>(team);
            MainWindow mainWindow = new MainWindow();

            mainWindow.GetLeagueListNames();
            this.Close();
        }
        /// <summary>
        /// Gets the ID of an address in Address Service - if the address does not already exist, address service can use
        /// the address sent in the query string to Post a new address. The official Address entry will always accopany a success response.
        /// NOTE: This Method uses a try catch that may result in the use of dummy data! Should be removed before public deployment.
        /// </summary>
        /// <param name="item">A model of an Address</param>
        /// <returns>A model of the formal Address entry in Address Services Database, including it GUID</returns>
        public async Task <ApiAddress> GetAddressAsync(ApiAddress item)
        {
            try
            {
                var queryString = "?"
                                  + "street=" + item.Street + "&"
                                  + "city=" + item.City + "&"
                                  + "state=" + item.State + "&"
                                  + "zipCode=" + item.ZipCode + "&"
                                  + "country=" + item.Country;

                using var response = await SendRequestAsync <ApiAddress>(HttpMethod.Get, "api/Address" + queryString);

                response.EnsureSuccessStatusCode();

                return(await ReadResponseBodyAsync <ApiAddress>(response));
            }
            catch
            {
                item.AddressId = Guid.NewGuid();
                return(item);
            }
        }
Exemple #8
0
        /// <summary>
        /// Gets backup server of given broken server.
        /// </summary>
        /// <param name="server">Broken server</param>
        /// <returns>Backup server</returns>
        public static SpecificServer GetBackup(Server server)
        {
            ApiAddress address = GetNextAddress(server.URI);

            return(new SpecificServer(address.Address, server.Port, server.Secure, address.Name));
        }
Exemple #9
0
        /// <summary>
        /// Gets backup server of given broken server.
        /// </summary>
        /// <param name="server">Broken server</param>
        /// <returns>Backup server</returns>
        public static Server GetBackup(Server server)
        {
            ApiAddress address = GetNextAddress(server.Address);

            return(new Server(address.Address, server.MainPort, server.StreamingPort, server.Secure, address.Name));
        }