public ParsingResult(ResultLevel level, string message, object value, IDataSourceLocation dataSourceLocation) { _level = level; _message = message; _value = value; _dataSourceLocation = dataSourceLocation; }
public IResult Parse(IDataToImport dataToImport, IDataSourceLocation dataSourceLocation, Type type) { if (!(dataSourceLocation is XMLDataSourceLocation)) { return(new ParsingResult(ResultLevel.FATAL, dataSourceLocation.GetType().ToString() + " is not supported by XML Node Parser", null, dataSourceLocation)); } if (!(dataToImport is XMLDataToImport)) { return(new ParsingResult(ResultLevel.FATAL, dataToImport.GetType().ToString() + " is not supported by XML Node Parser", null, dataSourceLocation)); } var castedDataToImport = dataToImport as XMLDataToImport; var castedDataSourceLocation = dataSourceLocation as XMLDataSourceLocation; try { var rawData = GetRawDataValue(castedDataSourceLocation, castedDataToImport); var parsedValue = ParseRawValue(type, rawData); return(new ParsingResult(ResultLevel.INFO, "Parsing value successfully", parsedValue, dataSourceLocation)); } catch (Exception e) { return(new ParsingResult(ResultLevel.FATAL, "Exception caught: " + e, null, dataSourceLocation)); } }
public IResult Parse(IDataToImport dataToImport, IDataSourceLocation dataSourceLocation, Type type) { if (!(dataSourceLocation is XMLDataSourceLocation)) { return new ParsingResult(ResultLevel.FATAL, dataSourceLocation.GetType().ToString() + " is not supported by XML Node Parser", null, dataSourceLocation); } if (!(dataToImport is XMLDataToImport)) { return new ParsingResult(ResultLevel.FATAL, dataToImport.GetType().ToString() + " is not supported by XML Node Parser", null, dataSourceLocation); } var castedDataToImport = dataToImport as XMLDataToImport; var castedDataSourceLocation = dataSourceLocation as XMLDataSourceLocation; try { var rawData = GetRawDataValue(castedDataSourceLocation, castedDataToImport); var parsedValue = ParseRawValue(type, rawData); return new ParsingResult(ResultLevel.INFO, "Parsing value successfully", parsedValue, dataSourceLocation); } catch (Exception e) { return new ParsingResult(ResultLevel.FATAL, "Exception caught: " + e, null, dataSourceLocation); } }
public IResult Parse(IDataToImport dataToImport, IDataSourceLocation dataSourceLocation, Type type) { var castedDataToImport = dataToImport as JSONDataToImport; var castedJObject = castedDataToImport.Data as JObject; var castedDataSourceLocation = dataSourceLocation as JSONDataSourceLocation; var locationPath = castedDataSourceLocation.Path; if (castedDataSourceLocation.IsArray) { var rawValues = castedJObject.SelectTokens(locationPath).Values<string>(); var valueParser = _parserFactory.GetValueParser(type); var parsedValue = from value in rawValues select valueParser.Parse(value); return new ParsingResult(ResultLevel.INFO, "Parse value from " + dataToImport.ToString() + " successfully, the value is " + parsedValue.ToString(), parsedValue.ToList(), castedDataSourceLocation); } else { var rawValue = (castedJObject.SelectTokens(locationPath).ElementAt(castedDataSourceLocation.Index.Value) as JValue).Value; var valueParser = _parserFactory.GetValueParser(type); var parsedValue = valueParser.Parse(rawValue); return new ParsingResult(ResultLevel.INFO, "Parse value from " + dataToImport.ToString() + " successfully " + parsedValue, parsedValue, castedDataSourceLocation); } }
public IExtractedDataset <T> Extract <T>(IDataToImport dataToImport) where T : new() { var extractedDataset = new ExtractedDataset <T>(_thresholdLevel); var validatedDataToImportResult = ValidateDataToImport(dataToImport); extractedDataset.AddParsingResults(validatedDataToImportResult.Item2); if (!validatedDataToImportResult.Item1) { //format not valid, return return(extractedDataset); } var results = new List <IResult>(); var model = new T(); IDataSourceLocation currentLocation = null; foreach (var configuration in _extractConfigurations) { if (configuration is SimpleXMLExtractConfiguration) { currentLocation = new XMLDataSourceLocation(((SimpleXMLExtractConfiguration)configuration).ElementName, ((SimpleXMLExtractConfiguration)configuration).AttributeName); } results.AddRange(((SimpleXMLExtractConfiguration)configuration).ExtractData(model, dataToImport, currentLocation)); } var parsingResult = new ParsingResult(ResultLevel.DEBUG, "Extract data from single row success", model, null); results.Add(parsingResult); extractedDataset.AddParsingResults(results); return(extractedDataset); }
public IResult Parse(IDataToImport dataToImport, IDataSourceLocation dataSourceLocation, Type type) { if (!(dataSourceLocation is CSVDataSourceLocation)) { return new ParsingResult(ResultLevel.FATAL, dataSourceLocation.GetType().ToString() + " is not supported by CSV Cell Parser", null, null); } if (!(dataToImport is CSVDataToImport)) { return new ParsingResult(ResultLevel.FATAL, dataToImport.GetType().ToString() + " is not supported by CSV Cell Parser", null, null); } var castedDataToImport = dataToImport as CSVDataToImport; var castedDataSourceLocation = dataSourceLocation as CSVDataSourceLocation; try { var rawData = GetRawDataValue(castedDataSourceLocation, castedDataToImport); var parsedValue = ParseRawValue(type, rawData); return new ParsingResult(ResultLevel.INFO, "Parsing value successfully", parsedValue, castedDataSourceLocation); } catch (IndexOutOfRangeException) { return new ParsingResult(ResultLevel.FATAL, "Index is out of range", null, castedDataSourceLocation); } }
public IResult Parse(IDataToImport dataToImport, IDataSourceLocation dataSourceLocation, Type type) { var castedDataToImport = dataToImport as JSONDataToImport; var castedJObject = castedDataToImport.Data as JObject; var castedDataSourceLocation = dataSourceLocation as JSONDataSourceLocation; var locationPath = castedDataSourceLocation.Path; if (castedDataSourceLocation.IsArray) { var rawValues = castedJObject.SelectTokens(locationPath).Values <string>(); var valueParser = _parserFactory.GetValueParser(type); var parsedValue = from value in rawValues select valueParser.Parse(value); return(new ParsingResult(ResultLevel.INFO, "Parse value from " + dataToImport.ToString() + " successfully, the value is " + parsedValue.ToString(), parsedValue.ToList(), castedDataSourceLocation)); } else { var rawValue = (castedJObject.SelectTokens(locationPath).ElementAt(castedDataSourceLocation.Index.Value) as JValue).Value; var valueParser = _parserFactory.GetValueParser(type); var parsedValue = valueParser.Parse(rawValue); return(new ParsingResult(ResultLevel.INFO, "Parse value from " + dataToImport.ToString() + " successfully " + parsedValue, parsedValue, castedDataSourceLocation)); } }
public IResult Parse(IDataToImport dataToImport, IDataSourceLocation dataSourceLocation, Type type) { if (!(dataSourceLocation is CSVDataSourceLocation)) { return(new ParsingResult(ResultLevel.FATAL, dataSourceLocation.GetType().ToString() + " is not supported by CSV Cell Parser", null, null)); } if (!(dataToImport is CSVDataToImport)) { return(new ParsingResult(ResultLevel.FATAL, dataToImport.GetType().ToString() + " is not supported by CSV Cell Parser", null, null)); } var castedDataToImport = dataToImport as CSVDataToImport; var castedDataSourceLocation = dataSourceLocation as CSVDataSourceLocation; try { var rawData = GetRawDataValue(castedDataSourceLocation, castedDataToImport); var parsedValue = ParseRawValue(type, rawData); return(new ParsingResult(ResultLevel.INFO, "Parsing value successfully", parsedValue, castedDataSourceLocation)); } catch (IndexOutOfRangeException) { return(new ParsingResult(ResultLevel.FATAL, "Index is out of range", null, castedDataSourceLocation)); } }
public HelixAnalyzerService(XmlNode configNode, IDataSourceLocation dataSourceLocation, ICerberusVariablesReplacer variablesReplacer) : base( variablesReplacer) { _dataSourceLocation = dataSourceLocation; if (configNode == null) { return; } var analyzers = GetAnalyzers(configNode, out var provider); _logProvider = GetLogContainer(configNode); foreach (var node in analyzers) { var ruleProvider = RegisterRules(node); var type = XmlActivator.GetType(node); if (type != null) { provider.Register(type, () => XmlActivator.CreateInstance(type, node, new[] { provider, ruleProvider, _logProvider }), true); if (provider.Resolve(type) is IHelixAnalyzer resolve) { Analyzers.Add(resolve); } } } }
public RainbowConfigurationService(string configPath, IHelixModuleProvider helixModuleProvider, IDataSourceLocation dataSourceLocation, ICerberusVariablesReplacer variablesReplacer) : base(configPath, helixModuleProvider, variablesReplacer) { _helixModuleProvider = helixModuleProvider; _dataSourceLocation = dataSourceLocation; }
public CellValueMatchCriteriaValidationRule(IDataSourceLocation location, ICSVParserFactory parserFactory, Type cellValueType, ICriteria criteria) { _location = location; _parserFactory = parserFactory; _cellValueType = cellValueType; _criteria = criteria; }
public ElementValueMatchCriteriaValidationRule(IDataSourceLocation location, IXMLParserFactory parserFactory, Type elementValueType, ICriteria criteria) { _location = location; _parserFactory = parserFactory; _elementValueType = elementValueType; _criteria = criteria; }
public HtmlLogger(string outputPath, IDataSourceLocation dataSourceLocation) { var path = Path.GetFullPath(outputPath.ToLower().Replace("$(configpath)", dataSourceLocation.Root)); path = path.EndsWith(@"\") ? path : $@"{path}\"; var reporter = new ExtentHtmlReporter(path); // create ExtentReports and attach reporter(s) _extent = new ExtentReports(); _extent.AttachReporter(reporter); }
protected IEnumerable <IResult> ExtractDataForSingleNode <T>(IList <IExtractConfiguration> extractConfigurations, IDataToImport dataToImport) where T : new() { var resultsForSingleNode = new List <IResult>(); var model = new T(); IDataSourceLocation currentLocation = null; foreach (var configuration in _extractConfigurations) { if (configuration is SimpleXMLExtractConfiguration) { currentLocation = new XMLDataSourceLocation(((SimpleXMLExtractConfiguration)configuration).ElementName, ((SimpleXMLExtractConfiguration)configuration).AttributeName); } resultsForSingleNode.AddRange(((SimpleXMLExtractConfiguration)configuration).ExtractData(model, dataToImport, currentLocation)); } var parsingResult = new ParsingResult(ResultLevel.DEBUG, "Extract data from single row success", model, new XMLDataSourceLocation("", "")); resultsForSingleNode.Add(parsingResult); return(resultsForSingleNode); }
public LogDispatcher(XmlNode configNode, IDataSourceLocation dataSourceLocation) : base( new ContainerDefinitionVariablesReplacer()) { var loggerConfigs = configNode.ChildNodes.OfType <XmlElement>().Where(node => node.NodeType == XmlNodeType.Element && node.Name.Equals("logger")); var provider = GetContainer(new ContainerDefinition(configNode as XmlElement)); provider.Register(typeof(IDataSourceLocation), () => dataSourceLocation, true); _loggers = new List <ILogger>(); foreach (var config in loggerConfigs) { var type = Type.GetType(config.Attributes["type"]?.Value ?? throw new InvalidOperationException("Invalid Logger Configuration.")); if (type != null) { var allInterfaces = type.GetInterfaces(); var directInterface = allInterfaces.Except(allInterfaces.SelectMany(t => t.GetInterfaces())); _loggers.Add(provider.Resolve(directInterface.First()) as ILogger); } } }
protected IEnumerable <IResult> ExtractDataForSingleRow <T>(IList <IExtractConfiguration> extractConfigurations, IDataToImport dataSource, int currentRow) where T : new() { var resultsForSingleRow = new List <IResult>(); var model = new T(); IDataSourceLocation currentLocation = null; foreach (var configuration in extractConfigurations.Where(x => x is ISimpleExtractConfiguration).Cast <ISimpleExtractConfiguration>()) { if (configuration is SimpleCSVExtractConfiguration) { currentLocation = new CSVDataSourceLocation(currentRow, ((SimpleCSVExtractConfiguration)configuration).ColumnIndex); } resultsForSingleRow.AddRange(configuration.ExtractData(model, dataSource, currentLocation)); } var parsingResult = new ParsingResult(ResultLevel.DEBUG, "Extract data from single row success", model, new CSVDataSourceLocation(currentRow, 1)); resultsForSingleRow.Add(parsingResult); return(resultsForSingleRow); }
private IEnumerable <IResult> ExtractHeaderFile(object model, IList <IExtractConfiguration> extractConfiguration, IDataToImport xmlDataToImport) { var results = new List <IResult>(); var validatedDataToImportResult = ValidateHeaderFileDataToImport(xmlDataToImport); results.AddRange(validatedDataToImportResult.Item2); IDataSourceLocation currentLocation = null; foreach (var configuration in extractConfiguration.Where(x => x is ISimpleExtractConfiguration)) { if (configuration is SimpleXMLExtractConfiguration) { currentLocation = new XMLDataSourceLocation(((SimpleXMLExtractConfiguration)configuration).ElementName, ((SimpleXMLExtractConfiguration)configuration).AttributeName); } results.AddRange(((SimpleXMLExtractConfiguration)configuration).ExtractData(model, xmlDataToImport, currentLocation)); } return(results); }
public override IEnumerable<IResult> ExtractData(object model, IDataToImport dataToImport, IDataSourceLocation currentLocation) { var results = new List<IResult>(); try { var parsingResult = _parser.Parse(dataToImport, currentLocation, _propertyType) as IParsingResult; _valueAssigner.AssignValue(model, _propertyPath, parsingResult.Value, _propertyType); results.Add(new BaseResult(ResultLevel.DEBUG, string.Format("Extract data from csv file and assign to model {0}", currentLocation.ToString()))); return results; } catch(Exception ex) { results.Add(new BaseResult(ResultLevel.ERROR, string.Format("Extract data from csv file and assign to model fail. {0}", currentLocation.ToString()))); } return results; }
public override IEnumerable <IResult> ExtractData(object model, IDataToImport dataToImport, IDataSourceLocation currentLocation) { if (!(dataToImport is JSONDataToImport)) { throw new ArgumentException("The SimpleJSONExtractConfiguration only accept JSONDataToImport to extract data"); } if (!(currentLocation is JSONDataSourceLocation)) { throw new ArgumentException("The SimpleJSONExtractConfiguration only accept JSONDataSourceLocation to extract data"); } throw new NotImplementedException(); }
public abstract IEnumerable <IResult> ExtractData(object model, IDataToImport dataToImport, IDataSourceLocation currentLocation);
public HelixModuleProvider(IDataSourceLocation dataSourceLocation, string pattern) { _dataSourceLocation = dataSourceLocation; _pattern = pattern; }
public abstract IEnumerable<IResult> ExtractData(object model, IDataToImport dataToImport, IDataSourceLocation currentLocation);
public MappingResult(ResultLevel level, string message, IDataSourceLocation dataSourceLocation) { _level = level; _message = message; _dataSourceLocation = dataSourceLocation; }
public IEnumerable <IResult> ExtractData(object model, IDataToImport dataToImport, IDataSourceLocation locationToParse) { var results = new List <IResult>(); try { var parsingResult = _parser.Parse(dataToImport, locationToParse, _propertyType) as IParsingResult; _valueAssigner.AssignValue(model, _propertyPath, parsingResult.Value, _propertyType); results.Add(new BaseResult(ResultLevel.DEBUG, string.Format("Extract data from xml file and assign to model {0}", locationToParse.ToString()))); return(results); } catch (Exception ex) { results.Add(new BaseResult(ResultLevel.ERROR, string.Format("Extract data from xml file and assign to model fail. {0}", locationToParse.ToString()))); } return(results); }