Example #1
0
        private async Task GenerateItemSetByChampion(ChampionViewModel champion, LoLMode mode, CancellationToken cancelToken)
        {
            // Create a unique instance of BuildSource to be thread safe
            // I'm afraid of having corruption with a shared "Document" property if I use a single shared instance
            IBuildSource buildSource = (T)Activator.CreateInstance(typeof(T));
            await buildSource.InitAsync(champion.Name, mode);

            if (!buildSource.IsValidContent())
            {
                throw new InvalidOperationException("Invalid content");
            }

            LoLItemSetViewModel itemSetViewModel = ItemSetUtil.CreateItemSetPerChampion(buildSource, champion, mode, Configuration.ShowSkillsOrder);

            if (itemSetViewModel == null)
            {
                throw new InvalidOperationException("LoLItemSetViewModel is null");
            }

            // Create Item set JSON file into LoL directory
            string itemSetDir = LoLPathUtil.CreateItemSetDirectory(Configuration.LoLDirectory, champion.Name);

            string itemSetFileName     = ItemSetUtil.GetFormattedItemSetFileName(buildSource, mode, Configuration.ApplicationPrefixName);
            string itemSetAbsolutePath = Path.Combine(itemSetDir, itemSetFileName);

            await FileUtil.CreateJsonFileAsync(itemSetAbsolutePath, itemSetViewModel, cancelToken);
        }
Example #2
0
 private string GetUrl(LoLMode mode, string championName)
 {
     return(mode switch
     {
         LoLMode.Classic => $"https://www.op.gg/champion/{championName}",
         LoLMode.ARAM => $"https://na.op.gg/aram/{championName}/statistics",
         _ => throw new NotSupportedException()
     });
Example #3
0
 /// <summary>
 /// Either returns champion position if LoLMode = classic (SR),
 /// Else, the mode itself (ex. "ARAM")
 /// </summary>
 /// <param name="source"></param>
 /// <param name="mode"></param>
 /// <returns></returns>
 public static string FormatChampionInfoByMode(IBuildSource source, LoLMode mode)
 {
     return(mode switch
     {
         LoLMode.Classic => EnumUtil.ToString <ChampionPosition>(source.GetChampionPosition()),
         LoLMode.ARAM => "ARAM",
         _ => throw new NotSupportedException()
     });
Example #4
0
        /// <summary>
        /// Returns formatted Item set file name with JSON extension
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string GetFormattedItemSetFileName(IBuildSource source, LoLMode mode, string appPrefix)
        {
            string sourceName    = source.GetSourceName();
            string sourceVersion = source.GetVersion();
            // Either show champion position as info, or LoL mode if not classic
            string championInfo = LoLModeUtil.FormatChampionInfoByMode(source, mode);

            return($"{appPrefix}_{sourceName}v{sourceVersion}_{championInfo}.json");
        }
Example #5
0
        public async Task InitAsync(string championName, LoLMode mode = LoLMode.Classic)
        {
            Task <HtmlDocument>      fetchHtmlTask     = FetchHtmlAsync(championName, mode);
            Task <SelectorViewModel> fetchSelectorTask = FetchSelectorDataAsync();

            await Task.WhenAll(fetchHtmlTask, fetchSelectorTask);

            Document = fetchHtmlTask.Result;
            Selector = fetchSelectorTask.Result;
        }
Example #6
0
        private static string GetPageTitle(IBuildSource source, LoLMode mode, ChampionViewModel champion)
        {
            string sourceName    = source.GetSourceName();
            string championName  = champion.Name;
            string championInfo  = LoLModeUtil.FormatChampionInfoByMode(source, mode);
            string sourceVersion = source.GetVersion();

            // Example for classic mode: OPGG - Annie Middle - v11.07
            // Example for ARAM mode: OPGG - Annie ARAM - v11.07
            return($"{sourceName} - {championName} {championInfo} - v{sourceVersion}");
        }
Example #7
0
 public static LoLItemSetViewModel CreateItemSetPerChampion(IBuildSource source, ChampionViewModel champion, LoLMode mode, bool showSkillsOrder)
 {
     return(new LoLItemSetViewModel()
     {
         Title = GetPageTitle(source, mode, champion),
         Map = LoLModeUtil.GetMapNameByMode(mode),
         AssociatedChampions = new List <int> {
             champion.Id
         },
         Blocks = CreateBlockItems(source, showSkillsOrder)
     });
 }