public IEnumerable <string> Analyze(IEnumerable <Tuple <int, InputType, IEnumerable <string>, string> > contents) { ICollection <string> analyzedResponses = new Collection <string>(); if (contents != null && contents.Any()) { foreach (Tuple <int, InputType, IEnumerable <string>, string> content in contents) { int lineNumber = content.Item1; InputType typeOfInput = content.Item2; IEnumerable <string> products = content.Item3; string productValue = content.Item4; SLogger.LogInfoFormat("Analyzing line number {0}.", lineNumber); try { Tuple <int, IEnumerable <string>, string> contentToInterpret = new Tuple <int, IEnumerable <string>, string>(lineNumber, products, productValue); switch (typeOfInput) { case InputType.ProductData: { if (products == null || !products.Any()) { SLogger.LogWarn("No products found to analyze. Skipping product data intrepretation..."); continue; } this.productDataInterpreter.Interpret(contentToInterpret); } break; case InputType.Query: { string queryResponse = this.queryInterpreter.Interpret(contentToInterpret); analyzedResponses.Add(queryResponse); } break; default: throw new InvalidOperationException("Invalid InputType Enum."); } } catch (Exception ex) { SLogger.LogErrorFormat(ex, "Exception found when Analyzing line: {0}.", lineNumber); } } } return(analyzedResponses); }
public string GetProductValue(string content, int lineNumber) { if (string.IsNullOrEmpty(content) || string.IsNullOrWhiteSpace(content)) { SLogger.LogWarnFormat("Line number {0} does not have a valid product value. Skipping...", lineNumber); return(string.Empty); } int creditsIndex = -1; if (this.DoesContentContainArabicNumerals(content, out creditsIndex) && creditsIndex > 0) { // Assuming that Credits is the last text in the content. if (!(content.Reverse().ToString().StartsWith(CREDITS_TEXT.Reverse().ToString()))) { SLogger.LogWarn("Credits text is not the last word of the content. Skipping..."); return(string.Empty); } // Assuming that Credits are linked to Arabic Numerals int number = 0; string numberString = content.Substring(0, creditsIndex - 1).Trim(); int.TryParse(numberString, out number); string error = this.validator.Validate(number); if (!string.IsNullOrEmpty(error)) { SLogger.LogWarnFormat("Validation issue found for arabic numeric value: {0} \nError: {1} on Line Number: {2}. Skipping...", numberString, error, lineNumber); return(string.Empty); } return(number.ToString()); } else { // Else, the value is in Roman numeral representation string romanNumeral = content.Trim(); string error = this.validator.Validate(content.Trim()); if (!string.IsNullOrEmpty(error)) { SLogger.LogWarnFormat("Validation issue found for roman numberal: {0} \nError: {1} on Line Number: {2}. Skipping...", romanNumeral, error, lineNumber); return(string.Empty); } return(romanNumeral); } }