private void ConvertRow(Row row, string data) { //This method is responsible for initiating parsing of //row section. A new instance of row parser is created //by passing the current data and row information RowParser rowParser = new RowParser(dataReader, data, row); //invoke the writer band start method dataWriter.WriteStartRow(row, rowParser.Data); //invoke row parser if (rowParser.Parse() == false) { //if there is no matching data found based on row identifier //then bypass the column processing and invoke //the writer row end method dataWriter.WriteEndRow(row); return; } //initiate the column parsing ColumnParser colParser = new ColumnParser(dataReader); //iterate through individual columns //and process the column level information foreach (Column col in row.Columns) { colParser.Data = data; colParser.CellsAttribute = col; ConvertCol(row, col, data, colParser); } //invoke the writer row end method dataWriter.WriteEndRow(row); }
public void Parse_ValidInput_ReturnsRow( string input, string band, int pcl, float txPower, float targetPower, float minPower, float maxPower, bool isPassed) { var result = _cut.Parse(input); Assert.NotNull(result); Assert.Equal(band, result.Band); Assert.Equal(pcl, result.Pcl); Assert.Equal(txPower, result.TxPower); Assert.Equal(targetPower, result.TargetPower); Assert.Equal(minPower, result.MinPower); Assert.Equal(maxPower, result.MaxPower); Assert.Equal(isPassed, result.IsPassed); }
/// <summary> /// Checks the response. /// </summary> /// <param name="res">The resource.</param> /// <exception cref="MKCommandException"></exception> /// <exception cref="MikrotikDotNet.Exceptions.MKCommandException"></exception> private void checkResponse(List <string> res) { var firstRow = res[0]; if (firstRow.StartsWith("!trap") || firstRow.StartsWith("!fatal")) { var rowData = RowParser.Parse(firstRow); var exMessage = ""; //if (MKResponseParser.HasField("category", firstRow)) CommandFailureTypes errorCategory = CommandFailureTypes.GeneralFailure; if (rowData.ContainsKey("category")) { var cat = int.Parse(rowData["category"]); exMessage = "Category: " + (CommandFailureTypes)cat; errorCategory = (CommandFailureTypes)cat; } exMessage += "\n" + rowData["message"]; throw new MKCommandException(exMessage, errorCategory); } res.Remove("!done"); }
public IList <InvolvedRow> GetInvolvedRows([NotNull] IRow errorRow) { return(RowParser.Parse(GetString(errorRow, AttributeRole.ErrorObjects))); }
private ParseFileResult ParseDataFile(Configuration configuration, byte[] csvBytes) { var csvText = ReadTextFromBytes(configuration, csvBytes); var rowParser = new RowParser(configuration, ResultsAppender, LocationInfo); var(prefaceLines, dataRowReader) = ExtractPrefaceLines(configuration, csvText); rowParser.AddPrefaceLines(prefaceLines); if (!rowParser.IsPrefaceValid()) { return(ParseFileResult.CannotParse()); } var dataRowCount = 0; using (var reader = dataRowReader) { var separator = configuration.Separator ?? DefaultFieldSeparator; var fieldParser = GetCsvParser(reader, separator); while (!fieldParser.EndOfData) { rowParser.LineNumber = rowParser.PrefaceLineCount + fieldParser.LineNumber; string[] fields = null; try { fields = fieldParser.ReadFields(); } catch (Exception) { if (dataRowCount == 0) { // We'll hit this when the plugin tries to parse a text file that is not CSV, like a JSON document. return(ParseFileResult.CannotParse()); } } if (fields == null) { continue; } if (fields.Length > 0 && fields.All(string.IsNullOrEmpty)) { continue; } if (fields.Length > 0 && !string.IsNullOrEmpty(configuration.CommentLinePrefix) && fields[0].StartsWith(configuration.CommentLinePrefix)) { continue; } if (dataRowCount == 0 && configuration.IsHeaderRowRequired) { try { if (rowParser.IsHeaderFullyParsed(fields)) { ++dataRowCount; } continue; } catch (Exception exception) { // Most CSV files have a header. // So a problem mapping the header is a strong indicator that this CSV file is not intended for us. if (exception is AllHeadersMissingException) { // When all headers are missing, then we should exit without logging anything special. // We'll just let the other plugins have a turn } else { // Some of the headers matched, so log a warning before returning CannotParse. // This might be the only hint in the log that the configuration is incorrect. Log.Info($"Partial headers detected: {exception.Message}"); } return(ParseFileResult.CannotParse()); } } if (IsFooterDetected(configuration, () => string.Join(separator, fields))) { break; } try { rowParser.Parse(fields); } catch (Exception exception) { if (!ResultsAppender.AnyResultsAppended) { throw; } Log.Error($"Ignoring invalid CSV row: {exception.Message}"); } ++dataRowCount; } if (dataRowCount == 0) { if (configuration.NoDataRowsExpected) { // When all the data comes from the preface, then this will parse the preface context rowParser.Parse(new string[0]); } else { // No rows were parsed. if (rowParser.RemainingHeaderLines > 0) { return(ParseFileResult.CannotParse("No matching header row was detected.")); } return(ParseFileResult.CannotParse()); } } Log.Info($"Configuration='{configuration.Id}' Priority={configuration.Priority} parsed {ResultsAppender.SummaryInfo()}."); return(ParseFileResult.SuccessfullyParsedAndDataValid()); } }
public AllowedError CreateAllowedError( [NotNull] IssueDatasetWriter issueWriter, [NotNull] IRow errorRow) { Assert.ArgumentNotNull(issueWriter, nameof(issueWriter)); Assert.ArgumentNotNull(errorRow, nameof(errorRow)); int?qualityConditionId = issueWriter.Get <int>( errorRow, AttributeRole.ErrorConditionId); if (qualityConditionId == null) { _msg.WarnFormat( "Error object <oid> {0} in {1} has no quality condition id", errorRow.OID, issueWriter.DatasetName); return(null); } QualityCondition qualityCondition; if (!_qualityConditionsById.TryGetValue((int)qualityConditionId, out qualityCondition)) { return(null); } IGeometry geometry = null; var errorFeature = errorRow as IFeature; if (errorFeature != null) { geometry = errorFeature.Shape.Envelope; geometry.SnapToSpatialReference(); } string involvedObjectsString = issueWriter.GetString( errorRow, AttributeRole.ErrorObjects); IList <InvolvedRow> involvedRows = RowParser.Parse(involvedObjectsString); string description = issueWriter.GetString(errorRow, AttributeRole.ErrorDescription); // explicit storage of ConditionVersion for later comparison (context change determination) // because condition.Version is read-only (VersionedEntity) int?conditionVersion = null; if (issueWriter.HasAttribute(AttributeRole.ErrorQualityConditionVersion)) { conditionVersion = issueWriter.Get <int>(errorRow, AttributeRole.ErrorQualityConditionVersion); } // Date of creation attribute is expected DateTime?dateOfCreation = issueWriter.Get <DateTime>( errorRow, AttributeRole.DateOfCreation); if (dateOfCreation == null) { _msg.WarnFormat( "Date of creation field is null for allowed error row <oid> {0} in {1}. It will be disregarded.", errorRow.OID, issueWriter.DatasetName); return(null); } return(new AllowedError(qualityCondition, conditionVersion, geometry, description, involvedRows, issueWriter.Table, errorRow.OID, (DateTime)dateOfCreation, _datasetResolver)); }