public CounterInfo(CounterInfo c)
 {
     foreach (KeyValuePair <string, CounterRelation> entry in c.BestAgainst)
     {
         CounterRelation cr = new CounterRelation(entry.Value);
         BestAgainst[entry.Key] = cr;
     }
     foreach (KeyValuePair <string, CounterRelation> entry in c.BestWith)
     {
         CounterRelation cr = new CounterRelation(entry.Value);
         BestWith[entry.Key] = cr;
     }
     foreach (KeyValuePair <string, CounterRelation> entry in c.IsCounteredBy)
     {
         CounterRelation cr = new CounterRelation(entry.Value);
         IsCounteredBy[entry.Key] = cr;
     }
 }
Ejemplo n.º 2
0
        string persistCsvData(string region, string rank)
        {
            string msg = "";
            string regionFolderPath        = StaticValue.getRegionRankDirectory(region, rank),
                   overallDataPath         = string.Format("{0}\\{1}", regionFolderPath, StaticValue.csv_overallChampionsInfo),
                   championCounterDataPath = string.Format("{0}\\{1}", regionFolderPath, StaticValue.csv_championCounter);

            if (File.Exists(overallDataPath) && File.Exists(championCounterDataPath))
            {
                StaticValue.allChampions.Clear();
                FileStream      stream_overall    = new FileStream(overallDataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                TextFieldParser csvReader_overall = new TextFieldParser(stream_overall);
                csvReader_overall.SetDelimiters(new string[] { "," });

                FileStream      stream_counter    = new FileStream(championCounterDataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                TextFieldParser csvReader_counter = new TextFieldParser(stream_counter);
                csvReader_counter.SetDelimiters(new string[] { "," });

                csvReader_overall.ReadFields(); //header
                csvReader_counter.ReadFields(); //header

                string[] filed_counter = null;
                while (!csvReader_overall.EndOfData)
                {
                    string[] filed    = csvReader_overall.ReadFields();
                    Champion champion = new Champion();
                    champion.Name = filed[0];
                    string   championName = champion.Name;
                    string[] lanes        = filed[2].Split(';');
                    for (int i = 0; i < lanes.Count(); i++)
                    {
                        champion.Lanes.Add(StaticValue.mapLane(lanes[i]));
                    }
                    champion.WinRate = Convert.ToDouble(filed[3]);
                    champion.BanRate = Convert.ToDouble(filed[4]);

                    CounterInfo counterInfo = new CounterInfo();
                    if (filed_counter != null)
                    {
                        CounterRelation cf = new CounterRelation();
                        cf.ChampionName = filed_counter[2];
                        cf.Lane         = StaticValue.mapLane(filed_counter[3]);
                        cf.Rate         = Convert.ToDouble(filed_counter[4]);
                        switch (filed_counter[1])
                        {
                        case "best against":
                            counterInfo.BestAgainst[cf.ChampionName] = cf;
                            break;

                        case "is countered by":
                            counterInfo.IsCounteredBy[cf.ChampionName] = cf;
                            break;

                        case "best with":
                            counterInfo.BestWith[cf.ChampionName] = cf;
                            break;
                        }
                    }
                    while (!csvReader_counter.EndOfData && championName == champion.Name)
                    {
                        filed_counter = csvReader_counter.ReadFields();
                        championName  = filed_counter[0];
                        if (championName == champion.Name)
                        {
                            CounterRelation cf = new CounterRelation();
                            cf.ChampionName = filed_counter[2];
                            cf.Lane         = StaticValue.mapLane(filed_counter[3]);
                            cf.Rate         = Convert.ToDouble(filed_counter[4]);
                            switch (filed_counter[1])
                            {
                            case "best against":
                                counterInfo.BestAgainst[cf.ChampionName] = cf;
                                break;

                            case "is countered by":
                                counterInfo.IsCounteredBy[cf.ChampionName] = cf;
                                break;

                            case "best with":
                                counterInfo.BestWith[cf.ChampionName] = cf;
                                break;
                            }
                            filed_counter = null;
                        }
                    }
                    champion.counterInfo = counterInfo;
                    StaticValue.allChampions.Add(champion);
                }
                msg = "Data has been persisted into memory";
            }
            else
            {
                msg = "No CSV file has been crawlered for the selected rank and region.";
            }
            return(msg);
        }
 public CounterRelation(CounterRelation c)
 {
     ChampionName = c.ChampionName;
     Lane         = c.Lane;
     Rate         = c.Rate;
 }