private void readDataFeatures(IFMEOReader fmeReader, ref int featureCount) { // Initialize counters int numFeatures = 0; // Now, read all the different features IFMEOFeature fmeFeature = m_fmeSession.CreateFeature(); while (fmeReader.Read(fmeFeature)) { // Log the feature to the log file m_fmeLogFile.LogFeature(fmeFeature, FMEOMessageLevel.Inform, -1); // Increment feature count numFeatures++; // For every feature, we will put it into m_featureTypeDictionary insertIntoFeatureTypeDictionary(fmeFeature); // Check if we need to update status bar if ((numFeatures % m_kUpdateInterval) == 0) { updateStatusBar("Read " + numFeatures.ToString() + " features..."); } // Create a new feature for the next read fmeFeature = m_fmeSession.CreateFeature(); } fmeFeature.Dispose(); featureCount = numFeatures; }
/// <summary> Returns the value of the specified attribute or expression as String. </summary> private static string GetOrResolveAttributeValue(IFMEOFeature feature, string value) { if (value != null && value.Length > 0) { if (value.StartsWith("@")) { value = feature.GetOrResolveAttributeAsString(value); if (value != null && value.StartsWith("@")) { value = null; } } else { value = feature.GetAttributeAsString(value); } } return(value); }
private void insertIntoFeatureTypeDictionary(IFMEOFeature pFeature) { string currFeatureType = pFeature.FeatureType; // First, we check for where to put the feature inside m_featureTypeDictionary // Check to see if an entry for currFeatureType already exists if (!m_featureTypeDictionary.ContainsKey(currFeatureType)) { // We must create a new entry to the m_featureTypeDictionary IFMEOFeatureVectorOnDisk newVectorOnDisk = m_fmeSession.CreateFeatureVectorOnDisk(m_kMaxFeatureInMemory); // Add the new entry to the dictionary m_featureTypeDictionary.Add(currFeatureType, newVectorOnDisk); } // Now, we put the feature into the proper IFMEOFeatureVectorOnDisk IFMEOFeatureVectorOnDisk currVectorOnDisk = m_featureTypeDictionary[currFeatureType]; currVectorOnDisk.Append(pFeature); }
/// <summary> Process the specified Feature. </summary> public override IEnumerable <KeyValuePair <string, IFMEOFeature> > ProcessFeature(string inputTag, IFMEOFeature feature) { // Depending on how we have chosen to process features in this factory we could: // a) Process and output each feature immediately or // b) Process and store features into a list, then when all features have been collected, process and output them. // Under a) the bulk of the work occurs in this function since features are output immediately as soon as they are done processing. // Under b) the bulk of the work occurs in the close() function. if (feature != null) { StringBuilder sb = new StringBuilder(); sb.Append("## " + GetType().Name + " - Processing Feature, Attributes=["); foreach (string attrib in feature.GetAllAttributeNames()) { sb.Append(attrib).Append("='").Append(feature.GetAttributeAsString(attrib)).Append("', "); } sb.Length -= 2; sb.Append("]"); _bridge.LogFile.LogMessageString(sb.ToString(), FMEOMessageLevel.Inform); // For this sample we output the feature with a specific OutputTag. // For this module the related fmx file defines one unique output tag called "OUTPUT"... yield return(new KeyValuePair <string, IFMEOFeature>("OUTPUT", feature)); // But we can use the '_bridge.OutputTags' member to query the available collection of output tags... // foreach (string outputTag in _bridge.OutputTags) yield return new KeyValuePair<string,IFMEOFeature>(outputTag, feature); } yield break; }
/// <summary> Process the specified Feature. </summary> public override IEnumerable <KeyValuePair <string, IFMEOFeature> > ProcessFeature(string inputTag, IFMEOFeature feature) { if (feature != null) { string lvalue = GetOrResolveAttributeValue(feature, _lhandKeyword); string rvalue = _rhandKeyword; if (_rvalueHash.Count == 0) { rvalue = GetOrResolveAttributeValue(feature, _rhandKeyword); } bool ok = false; // First checks and validations. if (lvalue == null) { ok = _operatorEnum == OperatorEnum.IsMissing; goto gotoReturnFeature; } lvalue = FixQuotedEmptyString(lvalue); rvalue = FixQuotedEmptyString(rvalue); // Compare the attribute value. switch (_operatorEnum) { case OperatorEnum.HasAvalidValue: ok = lvalue != null && lvalue.Length > 0; break; case OperatorEnum.IsMissing: ok = lvalue == null; break; case OperatorEnum.NotEqual: ok = _rvalueHash.Count > 0 ? !_rvalueHash.ContainsKey(lvalue) : !rvalue.Equals(lvalue); break; case OperatorEnum.BeginsWith: { if (_rvalueHash.Count > 0) { foreach (string rv in _rvalueHash.Keys) { if (lvalue.StartsWith(rv)) { ok = true; break; } } } else { ok = lvalue.StartsWith(rvalue); } break; } case OperatorEnum.EndsWith: { if (_rvalueHash.Count > 0) { foreach (string rv in _rvalueHash.Keys) { if (lvalue.EndsWith(rv)) { ok = true; break; } } } else { ok = lvalue.EndsWith(rvalue); } break; } case OperatorEnum.Less: { double doubleValue = double.Parse(lvalue, s_englishCultureInfo); if (_rvalueList.Count > 0) { foreach (double rv in _rvalueList) { if (doubleValue < rv) { ok = true; break; } } } else { double rv = double.Parse(rvalue, s_englishCultureInfo); ok = doubleValue < rv; } break; } case OperatorEnum.LessOrEqual: { double doubleValue = double.Parse(lvalue, s_englishCultureInfo); if (_rvalueList.Count > 0) { foreach (double rv in _rvalueList) { if (doubleValue <= rv) { ok = true; break; } } } else { double rv = double.Parse(rvalue, s_englishCultureInfo); ok = doubleValue <= rv; } break; } case OperatorEnum.Greater: { double doubleValue = double.Parse(lvalue, s_englishCultureInfo); if (_rvalueList.Count > 0) { foreach (double rv in _rvalueList) { if (doubleValue > rv) { ok = true; break; } } } else { double rv = double.Parse(rvalue, s_englishCultureInfo); ok = doubleValue > rv; } break; } case OperatorEnum.GreaterOrEqual: { double doubleValue = double.Parse(lvalue, s_englishCultureInfo); if (_rvalueList.Count > 0) { foreach (double rv in _rvalueList) { if (doubleValue >= rv) { ok = true; break; } } } else { double rv = double.Parse(rvalue, s_englishCultureInfo); ok = doubleValue >= rv; } break; } default: ok = _rvalueHash.Count > 0 ? _rvalueHash.ContainsKey(lvalue) : rvalue.Equals(lvalue); break; } gotoReturnFeature: yield return(new KeyValuePair <string, IFMEOFeature>(ok ? "PASSED" : "FAILED", feature)); } yield break; }