Ejemplo n.º 1
0
        static void Add(string featureId, Type subFeaturesEnumType)
        {
            var feature = new FeatureMetadata()
            {
                Id = featureId, SubFeatures = new Dictionary <int, SubFeatureMetadata>()
            };

            var values = subFeaturesEnumType.GetEnumValues();
            var names  = subFeaturesEnumType.GetEnumNames();

            for (int i = 0; i < values.Length; ++i)
            {
                var member = subFeaturesEnumType.GetMember(names[i]).First();
                feature.SubFeatures[Convert.ToInt32(values.GetValue(i))] = new SubFeatureMetadata()
                {
                    Feature = feature,
                    Id      = i,
                    Name    = names[i],
                    IsKnownObsoleteCodepath = member.GetCustomAttributes(typeof(ObsoleteCodepathAttribute), false).FirstOrDefault() != null,
                    IsRareCodepath          = member.GetCustomAttributes(typeof(RareCodepathAttribute), false).FirstOrDefault() != null,
                };
            }
            feature.SubFeatures.Remove(0);             // 0 (None) is reserved to mean "not a feature"

            data.Add(featureId, feature);
        }
Ejemplo n.º 2
0
 public void HandleUsedFeatures(Schema.Session session, string usedFeatures)
 {
     foreach (var featureStr in (usedFeatures ?? "").Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
     {
         var featureMatch = featureRegex.Match(featureStr);
         if (!featureMatch.Success)
         {
             Errors.Add("bad feature string: " + featureStr);
             continue;
         }
         var featureId = featureMatch.Groups[1].Value;
         var feature   = new Schema.Feature()
         {
             Session = session,
             Meta    = FeatureMetadata.FromId(featureId)
         };
         if (feature.Meta == null)
         {
             Errors.Add("unknown feature: " + featureId);
             continue;
         }
         session.Features.Add(feature);
         foreach (var subFeatureStr in featureMatch.Groups[3].Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
         {
             var subFeatureMatch = subFeatureRegex.Match(subFeatureStr);
             if (!subFeatureMatch.Success)
             {
                 Errors.Add("bad subfeature string: " + subFeatureStr);
                 continue;
             }
             SubFeatureMetadata sfm;
             if (!feature.Meta.SubFeatures.TryGetValue(int.Parse(subFeatureMatch.Groups[1].Value), out sfm))
             {
                 Errors.Add("unkonwn subfeature string: " + subFeatureMatch.Groups[1].Value);
                 continue;
             }
             var subFeature = new Schema.SubFeature()
             {
                 Feature  = feature,
                 Meta     = sfm,
                 UseCount = int.Parse(subFeatureMatch.Groups[2].Value)
             };
             SubFeatures.Add(subFeature);
             feature.SubFeatures.Add(subFeature);
         }
     }
 }