Beispiel #1
0
        static void Main(string[] args)
        {
            // prepare the client for access
            apiClient = new Client("guest", "guest", WdsfEndpoint.Sandbox);

            Console.Write("Enter competition ID:");
            int competitionId;

            if (!int.TryParse(Console.ReadLine(), out competitionId))
            {
                Console.WriteLine("Not a valid competition ID");
                Console.ReadKey();
                return;
            }

            CompetitionDetail competition = apiClient.GetCompetition(competitionId);

            Console.WriteLine(
                "Registering for competition {0} {1} {2} in {3}-{4} on {5}",
                competition.CompetitionType,
                competition.AgeClass,
                competition.Discipline,
                competition.Location,
                competition.Country,
                competition.Date);

            // prepare the person filter
            Dictionary <string, string> personFilter = new Dictionary <string, string>()
            {
                { FilterNames.Person.NameOrMin, string.Empty },
                { FilterNames.Person.Type, "Adjudicator,Chairman" }
            };

            do
            {
                // ask for an official name and list all possible matches
                ListPersons(personFilter);

                // choose one officials from the list
                PersonDetail selectedPerson = ChoosePerson();

                // and save the person as a new official
                Uri newOfficialUri = SavePerson(competition, selectedPerson);

                if (newOfficialUri != null)
                {
                    // get the newly created official to display it
                    OfficialDetail official = apiClient.Get <OfficialDetail>(newOfficialUri);

                    Console.WriteLine("Added official '{0}' to competition with ID:{1}.", official.Person, official.Id);
                }

                Console.Write("Add more? [Y]es/[N]o :");
            } while (Console.ReadKey().Key == ConsoleKey.Y);

            // show all registered officials of this competition
            ListAllOfficials(competition);

            Console.ReadKey();
        }
Beispiel #2
0
        private static Uri SaveParticipant(CompetitionDetail competition, CoupleDetail selectedCouple)
        {
            Uri newParticipantUri = null;

            do
            {
                // choose start number
                Console.Write("Enter start number: ");
                string startNumber = Console.ReadLine();
                int    startNumberValue;
                int.TryParse(startNumber, out startNumberValue);

                ParticipantCoupleDetail participant = new ParticipantCoupleDetail()
                {
                    CompetitionId = competition.Id,
                    CoupleId      = selectedCouple.Id,
                    StartNumber   = startNumberValue
                };

                try
                {
                    newParticipantUri = apiClient.SaveCoupleParticipant(participant);
                }
                catch (ApiException ex)
                {
                    Console.WriteLine(ex.InnerException.Message);
                    continue;
                }
            } while (false);

            return(newParticipantUri);
        }
Beispiel #3
0
        private static string GetAllowedAgeGroups(CompetitionDetail competition)
        {
            // find out what age classes are allowed to dance in this competition
            string[] allAllowedAgeGroups = apiClient
                                           .GetAges()
                                           .Where(a => a.AllowedToDanceIn.Contains(competition.AgeClass))
                                           .Select(a => a.Name)
                                           .ToArray();

            return(string.Join(",", allAllowedAgeGroups));
        }
Beispiel #4
0
        public bool UpdateCompetition(CompetitionDetail competition)
        {
            if (competition == null)
            {
                throw new ArgumentNullException("competition");
            }

            // not used for updating
            competition.Links = null;

            return(UpdateResource <CompetitionDetail>(competition, string.Format("competition/{0}", competition.Id)));
        }
Beispiel #5
0
        ///<inheritdoc/>
        public bool UpdateCompetition(CompetitionDetail competition)
        {
            if (competition == null)
            {
                throw new ArgumentNullException(nameof(competition));
            }

            // not used for updating
            competition.Links = null;

            return(UpdateResource(competition, "competition/" + competition.Id));
        }
Beispiel #6
0
        private static List <Official> GetAllAdjudicators(CompetitionDetail competition)
        {
            // get the url for the list of adjudicators of the competition.

            Uri officialsUri = competition.Links
                               .Where(l => l.Rel == ResourceRelation.CompetitionOfficials)
                               .Select(l => new Uri(l.HRef))
                               .FirstOrDefault();

            ListOfOfficial allOfficials = apiClient.Get <ListOfOfficial>(officialsUri);

            return(new List <Official>(allOfficials));
        }
Beispiel #7
0
        private static List <ParticipantCouple> GetAllParticipants(CompetitionDetail competition)
        {
            // get the url for a list of participants of the competition.

            Uri officialsUri = competition.Links
                               .Where(l => l.Rel.StartsWith(ResourceRelation.CompetitionParticipants))
                               .Select(l => new Uri(l.HRef))
                               .FirstOrDefault();

            ListOfCoupleParticipant allParticipants = apiClient.Get <ListOfCoupleParticipant>(officialsUri);

            return(new List <ParticipantCouple>(allParticipants));
        }
Beispiel #8
0
        private static void ListAllOfficials(CompetitionDetail competition)
        {
            IList <Official> allOfficials = apiClient.GetOfficials(competition.Id);

            if (allOfficials.Count != 0)
            {
                Console.WriteLine();
                Console.WriteLine("Officials registered so far:");
                foreach (Official official in allOfficials)
                {
                    Console.WriteLine("{0}: {1}", official.Name, official.Nationality);
                }
            }
        }
Beispiel #9
0
        private static void ListAllParticipants(CompetitionDetail competition)
        {
            IList <ParticipantCouple> allParticipants = apiClient.GetCoupleParticipants(competition.Id);

            if (allParticipants.Count != 0)
            {
                Console.WriteLine();
                Console.WriteLine("Couples registered so far:");
                foreach (ParticipantCouple participant in allParticipants)
                {
                    Console.WriteLine("{0, 5}: {1,-40} - {2}", participant.StartNumber, participant.Couple, participant.Country);
                }
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            // prepare the client for access
            apiClient = new Client("guest", "guest", WdsfEndpoint.Sandbox);

            Console.Write("Enter competition ID:");
            int competitionId;

            if (!int.TryParse(Console.ReadLine(), out competitionId))
            {
                Console.WriteLine("Not a valid competition ID");
                Console.ReadKey();
                return;
            }

            CompetitionDetail competition = apiClient.GetCompetition(competitionId);

            Link participantsReference = competition.Links.First(l => l.Rel.StartsWith(ResourceRelation.CompetitionParticipants));

            switch (participantsReference.Rel.Replace(ResourceRelation.CompetitionParticipants, string.Empty))
            {
            case ".team":
            {
                ListTeams(participantsReference);
                break;
            }

            case ".couple":
            {
                ListCouples(participantsReference);
                break;
            }

            case ".single":
            {
                ListSingles(participantsReference);
                break;
            }

            default:
            {
                Console.WriteLine("Unkown participant type received");
                break;
            }
            }

            Console.ReadKey();
        }
Beispiel #11
0
        private static Uri SavePerson(CompetitionDetail competition, PersonDetail selectedPerson)
        {
            Uri newOfficialUri = null;

            do
            {
                Console.Write("Enter adjudicator char or [nothing] for Chairman: ");
                string adjudicatorChar = Console.ReadLine();

                OfficialDetail official = new OfficialDetail()
                {
                    CompetitionId = competition.Id,
                    Min           = selectedPerson.Min
                };

                if (adjudicatorChar == string.Empty ||
                    adjudicatorChar.Contains("nothing"))
                {
                    official.Task = "Chairman";
                }
                else
                {
                    official.Task            = "Adjudicator";
                    official.AdjudicatorChar = adjudicatorChar;
                }

                try
                {
                    newOfficialUri = apiClient.SaveOfficial(official);
                }
                catch (ApiException ex)
                {
                    Console.WriteLine(ex.InnerException.Message);
                    return(null);
                }
            } while (false);

            return(newOfficialUri);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            // prepare the client for access
            apiClient = new Client("guest", "guest", WdsfEndpoint.Sandbox);

            Console.Write("Enter competition ID:");
            int competitionId;

            if (!int.TryParse(Console.ReadLine(), out competitionId))
            {
                Console.WriteLine("Not a valid competition ID");
                Console.ReadKey();
                return;
            }

            CompetitionDetail competition = apiClient.GetCompetition(competitionId);

            Console.WriteLine(
                "Registering for competition {0} {1} {2} in {3}-{4} on {5}",
                competition.CompetitionType,
                competition.AgeClass,
                competition.Discipline,
                competition.Location,
                competition.Country,
                competition.Date);

            Console.WriteLine("Starting registration.");
            competition.Status = "Registering";
            if (!apiClient.UpdateCompetition(competition))
            {
                Console.WriteLine(string.Format("Failed to start registration. {0}", apiClient.LastApiMessage));
                Console.ReadKey();
                return;
            }

            // we want to list only couples that are allowed to participate in this competition
            string allAllowedAgeGroups = GetAllowedAgeGroups(competition);

            // prepare the couple filter
            Dictionary <string, string> coupleFilter = new Dictionary <string, string>()
            {
                { FilterNames.Couple.NameOrMin, string.Empty },
                { FilterNames.Couple.Division, competition.Division },
                { FilterNames.Couple.AgeGroup, allAllowedAgeGroups }
            };

            do
            {
                // ask for an athlete name and list all possible couples
                ListCouples(coupleFilter);

                // choose one couple id from the list
                CoupleDetail selectedCouple = ChooseCouple();

                // and save the couple as a new participant
                Uri newParticipantUri = SaveParticipant(competition, selectedCouple);

                // get the newly created participant to display it
                ParticipantCoupleDetail participant = apiClient.Get <ParticipantCoupleDetail>(newParticipantUri);

                Console.WriteLine("Added couple '{0}' to competition with ID:{1}.", participant.Name, participant.Id);
                Console.Write("An more? [Y]es/[N]o :");
            } while (Console.ReadKey().Key == ConsoleKey.Y);

            Console.WriteLine("Closing registration.");
            competition.Status = "RegistrationClosed";
            if (!apiClient.UpdateCompetition(competition))
            {
                Console.WriteLine(string.Format("Failed to close registration. {0}", apiClient.LastApiMessage));
                Console.ReadKey();
                return;
            }

            // show all registered participants of this competition
            ListAllParticipants(competition);

            Console.ReadKey();
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            // prepare the client for access
            apiClient = new Client("guest", "guest", WdsfEndpoint.Sandbox);

            Console.Write("Enter competition ID:");
            int competitionId;

            if (!int.TryParse(Console.ReadLine(), out competitionId))
            {
                Console.WriteLine("Not a valid competition ID");
                Console.ReadKey();
                return;
            }

            CompetitionDetail competition = apiClient.GetCompetition(competitionId);

            Console.WriteLine(
                "Closing competition {0} {1} {2} in {3}-{4} on {5}",
                competition.CompetitionType,
                competition.AgeClass,
                competition.Discipline,
                competition.Location,
                competition.Country,
                competition.Date);

            competition.Status = "Closed";

            try
            {
                if (!apiClient.UpdateCompetition(competition))
                {
                    Console.WriteLine(string.Format("Failed to close the competition. {0}", apiClient.LastApiMessage));
                    Console.ReadKey();
                    return;
                }

                // we have to get the competition again to retreive the WRL coefficient
                competition = apiClient.GetCompetition(competitionId);
                Console.WriteLine(string.Format("The competitions coefficient is: {0}", competition.Coefficient));

                // find the URL that contains all participants
                Uri allParticipantsUri = competition.Links
                                         .Where(l => l.Rel.StartsWith(ResourceRelation.CompetitionParticipants))
                                         .Select(l => new Uri(l.HRef))
                                         .FirstOrDefault();

                Console.WriteLine("Results:");
                Console.WriteLine(string.Format("{0,3} {1,4} {2,6} {3,-40} {4}", "Rank", "#", "Points", "Name", "Country"));

                ListOfCoupleParticipant participants = apiClient.Get <ListOfCoupleParticipant>(allParticipantsUri);
                foreach (ParticipantCouple participant in participants)
                {
                    ParticipantCoupleDetail p = apiClient.GetCoupleParticipant(participant.Id);
                    Console.WriteLine(string.Format("{0,3}. {1,4} {2,6} {3,-40} {4}", p.Rank, p.StartNumber, p.Points, p.Name, p.Country));
                }
            }
            catch (ApiException ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }

            Console.ReadKey();
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            // prepare the client for access
            apiClient = new Client("guest", "guest", WdsfEndpoint.Sandbox);

            Console.Write("Enter competition ID:");
            int competitionId;

            if (!int.TryParse(Console.ReadLine(), out competitionId))
            {
                Console.WriteLine("Not a valid competition ID");
                Console.ReadKey();
                return;
            }

            CompetitionDetail competition = apiClient.GetCompetition(competitionId);

            Console.WriteLine("Loading officials.");
            List <Official> adjudicators = GetAllAdjudicators(competition);

            if (adjudicators.Count == 0)
            {
                Console.WriteLine("No officials found. Can not add results!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Loading participants.");
            List <ParticipantCouple> participants = GetAllParticipants(competition);

            if (participants.Count == 0)
            {
                Console.WriteLine("No participants found. Can not add results!");
                Console.ReadKey();
                return;
            }


            // one couple did not show up so we set it to "Noshow"
            ParticipantCouple missingParticipant = participants.First();

            Console.WriteLine(string.Format("Setting 'No-Show' for participant: {0}", missingParticipant.Couple));
            ParticipantCoupleDetail missing = apiClient.GetCoupleParticipant(missingParticipant.Id);

            missing.Status = "Noshow";
            try
            {
                Console.WriteLine("Saving participant.");
                if (!apiClient.UpdateCoupleParticipant(missing))
                {
                    Console.WriteLine(string.Format("Could not update participant: {0}", apiClient.LastApiMessage));
                }
            }
            catch (ApiException ex)
            {
                Console.WriteLine(ex.InnerException.Message);
                Console.ReadKey();
                return;
            }

            // we just simulate the ranking here. Your application would follow the scating rules to determine the ranking
            int rank = 1;

            foreach (ParticipantCouple participant in participants.Skip(1))
            {
                Console.WriteLine(string.Format("Setting scores for participant: {0}", participant.Couple));
                ParticipantCoupleDetail coupleParticipant = apiClient.GetCoupleParticipant(participant.Id);
                FillResults(coupleParticipant, adjudicators);
                coupleParticipant.Rank = rank.ToString();

                try
                {
                    Console.WriteLine("Saving participant.");
                    if (!apiClient.UpdateCoupleParticipant(coupleParticipant))
                    {
                        Console.WriteLine(string.Format("Could not update participant: {0}", apiClient.LastApiMessage));
                    }
                }
                catch (ApiException ex)
                {
                    Console.WriteLine(ex.InnerException.Message);
                    Console.ReadKey();
                    return;
                }

                rank++;
            }

            Console.WriteLine("Setting competition status to processing.");
            competition.Status = "Processing";
            apiClient.UpdateCompetition(competition);

            Console.WriteLine("Done.");
            Console.ReadKey();
        }