示例#1
0
        /// <summary>
        /// This method returns the competition objects from cache
        /// </summary>
        public static ObservableCollection <CompetitionClass> LoadEvents()
        {
            if (Preferences.ContainsKey("compKeys"))
            {
                string[] keys = Preferences.Get("compKeys", "").Split(';');

                ObservableCollection <CompetitionClass> competitions = new ObservableCollection <CompetitionClass>();
                List <string> openedList = new List <string>();

                foreach (string key in keys)
                {
                    if (!openedList.Contains(key))
                    {
                        openedList.Add(key);
                        CompetitionClass comp = LoadEvent(key);
                        if (comp != null)
                        {
                            competitions.Add(comp);
                        }
                    }
                }
                return(competitions);
            }
            return(new ObservableCollection <CompetitionClass>());
        }
示例#2
0
        async private void competitions_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            try
            {
                if (!isOpening)
                {
                    isOpening = true;
                    KeyValuePair <string, string> pair = (KeyValuePair <string, string>)e.Item;
                    CompetitionClass competition       = DownloadData.getEventSpecific(pair.Key);
                    eventsNotLocal.Remove(pair.Key);
                    if (competition.matchesList.Count != 0)
                    {
                        competition.name = pair.Value;
                        eventsListObj.Add(competition);
                        CacheData.CacheOneEvent(competition);
                        await Navigation.PushAsync(new MatchList(competition)).ConfigureAwait(false);

                        Navigation.RemovePage(this);
                    }
                    else
                    {
                        await DisplayAlert("Error", DataConstants.EmptyCompetition, "Sksksk").ConfigureAwait(true);

                        isOpening = false;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
示例#3
0
        public RankingGeneral(CompetitionClass competition)
        {
            InitializeComponent();
            comp = competition;
            r    = new Ranker(comp);

            rankPicker.ItemsSource = DataConstants.rankPickerText;
        }
示例#4
0
 public MatchList(CompetitionClass competition)
 {
     InitializeComponent();
     Competition            = competition;
     Title                  = competition.name;
     lastMatch              = -1;
     lastSelect             = -1;
     Matches.RefreshCommand = RefreshCommand;
 }
示例#5
0
        public static void DeleteOneEvent(CompetitionClass comp)
        {
            string keys = Preferences.Get("compKeys", "");

            if (keys.Contains(comp.eventKey))
            {
                int    compKeyInd = keys.IndexOf(comp.eventKey);
                string newKeys    = keys.Substring(0, compKeyInd) + keys.Substring(compKeyInd + comp.eventKey.Length + 1);
                Preferences.Set("compKeys", newKeys);
                Preferences.Remove(comp.eventKey);
            }
        }
示例#6
0
 /// <summary>
 /// Stores one eventKey
 /// </summary>
 /// <param name="comp"></param>
 private static void CacheOneEventKey(CompetitionClass comp)
 {
     if (Preferences.ContainsKey("compKeys"))
     {
         string keys = Preferences.Get("compKeys", "");
         if (!keys.Contains(comp.eventKey))
         {
             Preferences.Set("compKeys", Preferences.Get("compKeys", "") + comp.eventKey + ";");
         }
     }
     else
     {
         Preferences.Set("compKeys", comp.eventKey + ";");
     }
 }
示例#7
0
        /// <summary>
        /// Return the MatchEventClass object from a given eventKey, pulling from Shrey's server
        /// </summary>
        /// <param name="eventKey"></param>
        /// <returns></returns>
        public static CompetitionClass getEventSpecific(string eventKey)
        {
            try
            {
                string response;
                int    c = 0;

                do
                {
                    RestRequest request = new RestRequest("/event/matches");
                    request.AddJsonBody("{\"event_key\": \"" + eventKey + "\",\"comp_level\": \"qm\",\"uses_sets\": false}");
                    response = client.Post(request).Content;

                    c++; // I need to hide a reference somewhere you know (copy-and-pasted)

                    if (c > 3)
                    {
                        return(new CompetitionClass());
                    }
                } while (String.IsNullOrEmpty(response));

                CompetitionClass competition = new CompetitionClass();

                competition.eventKey = eventKey;

                JObject a = JObject.Parse(response);

                for (int i = 1; i <= a.Count; i++)
                {
                    JToken s      = a[i + ""];
                    Match  aMatch = new Match();
                    aMatch.number = i;
                    string         daList       = s.ToString();
                    BlueRedJObject allianceInfo = JsonConvert.DeserializeObject <BlueRedJObject>(daList);
                    int[]          blues        = allianceInfo.blue.ToArray();
                    int[]          reds         = allianceInfo.red.ToArray();
                    aMatch.setAlliance(true, blues);
                    aMatch.setAlliance(false, reds);
                    competition.matchesList.Add(aMatch);
                }
                return(competition);
            }
            catch (Exception e)
            {
                throw e.InnerException;
            }
        }
示例#8
0
        /// <summary>
        /// Get all the information object in the competition
        /// </summary>
        /// <param name="comp"> the competition </param>
        /// <returns> the list of ScoutedInfo objects paired with the team number </returns>
        public static Dictionary <ScoutedInfo, int> getInformations(CompetitionClass comp)
        {
            Dictionary <ScoutedInfo, int> infos = new Dictionary <ScoutedInfo, int>();

            foreach (Match m in comp.matchesList)
            {
                if (m.isFilled)
                {
                    for (int i = 0; i < 6; i++)
                    {
                        if (m.TeamsScouted[i] != null)
                        {
                            int teamNum = i < 2 ? m.blueAlliance[i] : m.redAlliance[i - 3];
                            infos.Add(m.TeamsScouted[i], teamNum);
                        }
                    }
                }
            }
            return(infos);
        }
示例#9
0
        public AddNewMatch(CompetitionClass competition)
        {
            InitializeComponent();

            if (competition.matchesList.Count == 0)
            {
                throw new MissingMemberException();
            }

            comp = competition;

            for (int i = 0; i < 6; i++)
            {
                Button btn = new Button
                {
                    BackgroundColor = Color.Gold,
                    TextColor       = Color.White,
                    BorderColor     = Color.Orange,
                    BorderWidth     = 2,
                    Text            = DataConstants.canSelect,
                    StyleId         = i + ""
                };
                btn.Clicked += DynamicClickedEvent;
                buttons.Add(btn);
                if (i < 3)
                {
                    PrematchGrid.Children.Add(btn, 1, i + 1);
                }
                else
                {
                    PrematchGrid.Children.Add(btn, 2, i - 2);
                }
            }

            if (lastMatch >= 1 && lastMatch <= comp.matchesList.Count && lastSelect >= 0)
            {
                @continue.IsVisible = true;
            }
        }
        /// <summary>
        /// attempt to merge outside data with inside data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async private void importConfirm(object sender, EventArgs e)
        {
            try
            {
                List <string> oldCompKeys = new List <string>();
                foreach (CompetitionClass comp in eventsListObj)
                {
                    oldCompKeys.Add(comp.eventKey);
                }
                ObservableCollection <CompetitionClass> newComps =
                    JsonConvert.DeserializeObject <ObservableCollection <CompetitionClass> >(importTextEditor.Text);

                string choice = "";

                foreach (CompetitionClass comp in newComps)
                {
                    if (oldCompKeys.Contains(comp.eventKey))
                    {
                        CompetitionClass oldComp = eventsListObj[oldCompKeys.IndexOf(comp.eventKey)];
                        for (int num = 0; num < comp.matchesList.Count; num++)
                        {
                            for (int pos = 0; pos < 6; pos++)
                            {
                                if (comp.matchesList[num].TeamsScouted[pos] != null)
                                {
                                    if (oldComp.matchesList[num].TeamsScouted[pos] != null)
                                    {
                                        if (choice.Length == 0)
                                        {
                                            choice = await DisplayActionSheet(
                                                "Conflict file at " + comp.name + " match No." + (num + 1),
                                                "Ignore all", null, "Overwrite", "Overwrite all", "Ignore")
                                                     .ConfigureAwait(true);

                                            switch (choice)
                                            {
                                            case "Overwrite":
                                                oldComp.matchesList[num].TeamsScouted[pos] = comp.matchesList[num].TeamsScouted[pos];
                                                choice = "";
                                                break;

                                            case "Ignore":
                                                choice = "";
                                                break;

                                            default:
                                                break;
                                            }
                                        }
                                        if (choice == "Overwrite all")
                                        {
                                            oldComp.matchesList[num].TeamsScouted[pos] = comp.matchesList[num].TeamsScouted[pos];
                                        }
                                    }
                                    else
                                    {
                                        oldComp.matchesList[num].TeamsScouted[pos] = comp.matchesList[num].TeamsScouted[pos];
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        eventsListObj.Add(comp);
                        CacheData.CacheOneEvent(comp);
                    }
                }
            }
            catch (Exception)
            {
                DisplayAlert("ERROR", "Invalid Format!", "sksksk");
            }
            importTextEditor.Text = "";
        }
示例#11
0
 /// <summary>
 /// Cache individual competition
 /// </summary>
 /// <param name="comp"></param>
 public static void CacheOneEvent(CompetitionClass comp)
 {
     CacheEvent(comp);
     CacheOneEventKey(comp);
 }
示例#12
0
 /// <summary>
 /// Cache only one competition to storage
 /// </summary>
 /// <param name="comp"></param>
 private static void CacheEvent(CompetitionClass comp)
 {
     Preferences.Set(comp.eventKey, JsonConvert.SerializeObject(comp));
 }
        internal static async Task PublishAsync(CompetitionClass results)
        {
            var payload = JsonConvert.SerializeObject(results);

            await PublishAsync($"Results/Class/{results.ShortName}", payload);
        }
示例#14
0
 public Ranker(CompetitionClass competition)
 {
     infs = getInformations(competition);
 }
示例#15
0
 public EventRankings(CompetitionClass competition)
 {
     InitializeComponent();
 }