// //mixali min frikaris afto einai gia na grouparis kodika //arxizi me #region <name> //lai telion me #endregion // public PersonManagement() { //auto anoigei to parathiro sto kentro tis othonis WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; //here should be the loading of the locations and clubs and countries InitializeComponent(); athleteConnection = new AthleteConnection(); judgeConnection = new JudgeConnection(); // //NOTE // //mixali listeners vaze katefthian apo to xaml oxi karfota mesa ston kodika // //athleteFirstName.TextChanged += new TextChangedEventHandler(athleteFirstName_TextChanged); //prostetoume cities oses theloume countryConnection = new CountryConnection(); this.countries = countryConnection.GetCountries(); foreach (DataRow dr in countries.Tables[0].Rows) { cmbACountryChooses.Items.Add(dr[1].ToString()); cmbJCountryChooses.Items.Add(dr[1].ToString()); } cmbACountryChooses.SelectedIndex = 0; cmbJCountryChooses.SelectedIndex = 0; this.athleteUpdateCities("CY"); //9th dan - 10th dan- Wide Red optional as Sensei Ilija Yorga himself wore a Black Belt, Master's title //6th dan - 8th dan - White and Red, Master's title //1st dan - 5th dan - Black //1st kyu - Brown (at least 25 Month of traning or more) //2nd kyu - Blue (at least 18 Month of traning or more) //3rd kyu - Green (at least 15 Month of traning or more) //4th kyu - Orange (at least 9 Month of traning or more) //5th kyu - Yellow (at least 7 Month of traning or more) //6th kyu - White (at least 5 Month of traning or more) //prosthetoume athlete_rank cmbAthleteRankChooses.Items.Add("White - 6th kyu"); cmbAthleteRankChooses.Items.Add("Yellow - 5th kyu"); cmbAthleteRankChooses.Items.Add("Orange - 4th kyu"); cmbAthleteRankChooses.Items.Add("Green - 3th kyu"); cmbAthleteRankChooses.Items.Add("Blue - 2nd kyu"); cmbAthleteRankChooses.Items.Add("Brown - 1st kyu"); cmbAthleteRankChooses.Items.Add("Black - 1st dan"); cmbAthleteRankChooses.Items.Add("Black - 2nd dan"); cmbAthleteRankChooses.Items.Add("Black - 3th dan"); cmbAthleteRankChooses.Items.Add("Black - 4th dan"); cmbAthleteRankChooses.Items.Add("Black - 5th dan"); cmbAthleteRankChooses.Items.Add("White/Red - 6th dan"); cmbAthleteRankChooses.Items.Add("White/Red - 7th dan"); cmbAthleteRankChooses.Items.Add("White/Red - 8th dan"); cmbAthleteRankChooses.Items.Add("Red - 9th dan"); cmbAthleteRankChooses.Items.Add("Red - 10th dan"); cmbAthleteRankChooses.SelectedIndex = 0; //prosthetoume judge class cmbJudgeRankChooses.Items.Add("White - 6th kyu"); cmbJudgeRankChooses.Items.Add("Yellow - 5th kyu"); cmbJudgeRankChooses.Items.Add("Orange - 4th kyu"); cmbJudgeRankChooses.Items.Add("Green - 3th kyu"); cmbJudgeRankChooses.Items.Add("Blue - 2nd kyu"); cmbJudgeRankChooses.Items.Add("Brown - 1st kyu"); cmbJudgeRankChooses.Items.Add("Black - 1st dan"); cmbJudgeRankChooses.Items.Add("Black - 2nd dan"); cmbJudgeRankChooses.Items.Add("Black - 3th dan"); cmbJudgeRankChooses.Items.Add("Black - 4th dan"); cmbJudgeRankChooses.Items.Add("Black - 5th dan"); cmbJudgeRankChooses.Items.Add("White/Red - 6th dan"); cmbJudgeRankChooses.Items.Add("White/Red - 7th dan"); cmbJudgeRankChooses.Items.Add("White/Red - 8th dan"); cmbJudgeRankChooses.Items.Add("Red - 9th dan"); cmbJudgeRankChooses.Items.Add("Red - 10th dan"); cmbJudgeRankChooses.SelectedIndex = 0; //prosthetoume clubs this.clubs = clubConnection.GetClubs(); foreach (DataRow dr in clubs.Tables[0].Rows) { cmbAClubChooses.Items.Add(dr[1]); } cmbAClubChooses.SelectedIndex = 0; //cmbAClubChooses.Items.Add("Pro Kata Club (P.K.C.)"); //cmbAClubChooses.Items.Add("Allo Club"); //prosthetoume judge classes cmbJClassChooses.Items.Add("A"); cmbJClassChooses.Items.Add("B"); cmbJClassChooses.SelectedIndex = 0; }
static internal int ReadAthleteConnectionsForAthlete(StravaXApi stravaXApi, string[] args) { int ret = -1; Console.WriteLine("Read athlete connections with Strava-X-API."); String AthleteId = null; var p = new OptionSet() { { "a|athleteid=", v => { AthleteId = v; } }, }; p.Parse(args); if (AthleteId == null) { p.WriteOptionDescriptions(Console.Out); throw new ArgumentException("missing athlete id"); } try { stravaXApi.signIn(); AthleteShort AthleteMasterShort; using (StravaXApiContext db = new StravaXApiContext()) { AthleteMasterShort = db.AthleteShortDB.Find(AthleteId); if (AthleteMasterShort == null) { AthleteMasterShort = new AthleteShort(); // create a dummy master AthleteMasterShort.AthleteId = AthleteId; // [TODO] other parameters should be retrieved with selenium AthleteMasterShort = db.AthleteShortDB.Add(AthleteMasterShort).Entity; db.SaveChanges(); } else { // Eagerly Loading prevent the list to be loaded at creation // https://docs.microsoft.com/de-de/ef/ef6/querying/related-data db.Entry(AthleteMasterShort).Collection(p => p.Connections).Load(); Console.WriteLine($"Athlete {AthleteMasterShort.AthleteId} allready enterred with {AthleteMasterShort.Connections.Count} connections {string.Join(',',AthleteMasterShort.Connections)}"); } string FollowType = "following"; var AthleteShortList = stravaXApi.getConnectedAthetes(AthleteMasterShort, FollowType); Console.WriteLine($"Athlete {AthleteId} has {AthleteShortList.Count} connections"); foreach (AthleteShort _AthleteShort in AthleteShortList) { AthleteShort AthleteShortfromDb; // Console.WriteLine($"JSON={ActivityShort.SerializePrettyPrint(ActivityShort)}"); AthleteShortfromDb = db.AthleteShortDB.Find(_AthleteShort.AthleteId); if (AthleteShortfromDb == null) { // add athlete to the db if need. AthleteShortfromDb = db.AthleteShortDB.Add(_AthleteShort).Entity; } else { Console.WriteLine($"{AthleteShortfromDb.AthleteId} allready in database"); } Console.WriteLine($"Enterred Activities: {db.AthleteShortDB.OrderBy(b => b.AthleteId).Count()}"); // such the connected athlete with they id. AthleteConnection _ConnectedAthleteShort = AthleteMasterShort.Connections.FirstOrDefault(a => a.ToId.Equals(_AthleteShort.AthleteId)); if (_ConnectedAthleteShort == null) { // add connection if needed. AthleteConnection ac = new AthleteConnection(); ac.FromId = AthleteMasterShort.AthleteId; ac.ToId = AthleteShortfromDb.AthleteId; ac.Type = FollowType; ac.ConnectionState = ((ConnectedAthlete)_AthleteShort).ConnectionState; AthleteMasterShort.Connections.Add(ac); Console.WriteLine($"athlete {AthleteMasterShort.AthleteId} has {AthleteMasterShort.Connections.Count} connection(s). Added: {_AthleteShort.AthleteId}"); } else { Console.WriteLine($"athlete {AthleteMasterShort.AthleteId} already connected to {_AthleteShort.AthleteId} with {AthleteMasterShort.Connections.Count} connection(s)"); } } db.SaveChanges(); Console.WriteLine($"total read = {AthleteShortList.Count}"); Console.WriteLine($"total stored = {db.AthleteShortDB.OrderBy(b => b.AthleteId).Count()}"); AthleteShortList.Clear(); } using (StravaXApiContext db = new StravaXApiContext()) { AthleteMasterShort = db.AthleteShortDB.Find(AthleteId); if (AthleteMasterShort == null) { AthleteMasterShort = new AthleteShort(); // create a dummy master AthleteMasterShort.AthleteId = AthleteId; // [TODO] other parameters should be retrieved with selenium AthleteMasterShort = db.AthleteShortDB.Add(AthleteMasterShort).Entity; db.SaveChanges(); } else { // Eagerly Loading prevent the list to be loaded at creation // https://docs.microsoft.com/de-de/ef/ef6/querying/related-data db.Entry(AthleteMasterShort).Collection(p => p.Connections).Load(); Console.WriteLine($"Athlete {AthleteMasterShort.AthleteId} allready enterred with {AthleteMasterShort.Connections.Count} connections {string.Join(',',AthleteMasterShort.Connections)}"); } string FollowType = "followers"; var AthleteShortList = stravaXApi.getConnectedAthetes(AthleteMasterShort, FollowType); Console.WriteLine($"Athlete {AthleteId} has {AthleteShortList.Count} connections"); foreach (AthleteShort _AthleteShort in AthleteShortList) { AthleteShort AthleteShortfromDb; // Console.WriteLine($"JSON={ActivityShort.SerializePrettyPrint(ActivityShort)}"); AthleteShortfromDb = db.AthleteShortDB.Find(_AthleteShort.AthleteId); if (AthleteShortfromDb == null) { // add athlete to the db if need. AthleteShortfromDb = db.AthleteShortDB.Add(_AthleteShort).Entity; } else { Console.WriteLine($"{AthleteShortfromDb.AthleteId} allready in database"); } Console.WriteLine($"Enterred Activities: {db.AthleteShortDB.OrderBy(b => b.AthleteId).Count()}"); // such the connected athlete with they id. AthleteConnection _ConnectedAthleteShort = AthleteMasterShort.Connections.FirstOrDefault(a => a.ToId.Equals(_AthleteShort.AthleteId)); if (_ConnectedAthleteShort == null) { // add connection if needed. AthleteConnection ac = new AthleteConnection(); ac.FromId = AthleteMasterShort.AthleteId; ac.ToId = AthleteShortfromDb.AthleteId; ac.Type = FollowType; AthleteMasterShort.Connections.Add(ac); Console.WriteLine($"athlete {AthleteMasterShort.AthleteId} has {AthleteMasterShort.Connections.Count} connection(s). Added: {_AthleteShort.AthleteId}"); } else { Console.WriteLine($"athlete {AthleteMasterShort.AthleteId} already connected to {_AthleteShort.AthleteId} with {AthleteMasterShort.Connections.Count} connection(s)"); } } db.SaveChanges(); Console.WriteLine($"total read = {AthleteShortList.Count}"); Console.WriteLine($"total stored = {db.AthleteShortDB.OrderBy(b => b.AthleteId).Count()}"); AthleteShortList.Clear(); } ret = 0; } catch (Exception e) { Console.WriteLine($"ERROR:{e.ToString()}"); ret = 1; } finally { stravaXApi.Dispose(); } return(ret); }