public async Task <ParsedItem> ParseItem(string itemText) { await languageProvider.FindAndSetLanguage(itemText); try { itemText = new ItemNameTokenizer().CleanString(itemText); var item = new ParsedItem { ItemText = itemText }; ParseHeader(ref item, ref itemText); ParseProperties(ref item, ref itemText); ParseSockets(ref item, ref itemText); ParseInfluences(ref item, ref itemText); ParseMods(ref item, ref itemText); return(item); } catch (Exception e) { logger.Error(e, "Could not parse item."); return(null); } }
public Task <ParsingItem> Handle(GetParsingItem request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request.ItemText)) { return(Task.FromResult <ParsingItem>(null)); } var itemText = new ItemNameTokenizer().CleanString(request.ItemText); return(Task.FromResult(new ParsingItem(itemText))); }
public ParserService( ILogger logger, ILanguageProvider languageProvider, IStatDataService statsDataService, IItemDataService itemDataService, IParserPatterns patterns) { this.logger = logger.ForContext(GetType()); this.languageProvider = languageProvider; this.statsDataService = statsDataService; this.itemDataService = itemDataService; this.patterns = patterns; itemNameTokenizer = new ItemNameTokenizer(); }
public Task <Item> Handle(ParseItemCommand request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request.ItemText)) { return(Task.FromResult <Item>(null)); } try { var itemText = new ItemNameTokenizer().CleanString(request.ItemText); var wholeSections = itemText.Split(SEPARATOR_PATTERN, StringSplitOptions.RemoveEmptyEntries); var splitSections = wholeSections .Select(block => newLinePattern .Split(block) .Where(line => line != "") .ToArray() ) .ToArray(); var parsingItem = new ParsingItem(wholeSections, splitSections, request.ItemText); var itemHeader = itemMetadataProvider.Parse(parsingItem, GetRarity(parsingItem.Rarity)); if (itemHeader == null || (string.IsNullOrEmpty(itemHeader.Name) && string.IsNullOrEmpty(itemHeader.Type))) { throw new NotSupportedException("Item not found."); } var item = new Item { Name = itemHeader.Name, Type = itemHeader.Type, Rarity = itemHeader.Rarity, Category = itemHeader.Category, NameLine = parsingItem.NameLine, TypeLine = parsingItem.TypeLine, Text = parsingItem.Text, }; if (item.Rarity == Rarity.Unknown) { item.Rarity = GetRarity(parsingItem.Rarity); } switch (item.Category) { case Category.DivinationCard: case Category.Currency: case Category.Prophecy: break; case Category.Gem: ParseGem(item, parsingItem); break; case Category.Map: ParseMap(item, parsingItem); ParseMods(item, parsingItem); break; default: ParseEquipmentProperties(item, parsingItem); ParseMods(item, parsingItem); ParseSockets(item); ParseInfluences(item, parsingItem); break; } return(Task.FromResult(item)); } catch (Exception e) { logger.LogError(e, "Could not parse item."); return(Task.FromResult <Item>(null)); } }