示例#1
0
        public static void ImportFeatureContainer(Stream reader, string fullpath, string source, OGLContext context, IEnumerable <String> path)
        {
            String        cat = context.Config.Features_Directory;
            List <String> p   = new List <string>()
            {
                cat
            };

            p.AddRange(path);
            for (int i = 1; i < p.Count; i++)
            {
                cat = String.Join("/", p.Take(i));
            }
            FeatureContainer cont  = FeatureContainer.Serializer.Deserialize(reader) as FeatureContainer;
            List <Feature>   feats = cont.Features;

            if (!context.FeatureContainers.ContainsKey(cat))
            {
                context.FeatureContainers.Add(cat, new List <FeatureContainer>());
            }
            cont.FileName = fullpath;
            cont.category = cat;
            cont.Name     = Path.GetFileNameWithoutExtension(fullpath);
            cont.Source   = source;
            context.FeatureContainers[cat].Add(cont);
            foreach (Feature feat in feats)
            {
                feat.Source = cont.Source;
                foreach (Keyword kw in feat.Keywords)
                {
                    kw.check();
                }
                feat.Category = cat;
                if (!context.FeatureCategories.ContainsKey(cat))
                {
                    context.FeatureCategories.Add(cat, new List <Feature>());
                }
                Feature other = context.FeatureCategories[cat].Where(ff => string.Equals(ff.Name, feat.Name, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                if (other != null)
                {
                    other.ShowSource = true;
                    feat.ShowSource  = true;
                }
                context.FeatureCategories[cat].Add(feat);
                if (cat.Equals("Feats/Boons", StringComparison.OrdinalIgnoreCase))
                {
                    if (context.BoonsSimple.ContainsKey(feat.Name))
                    {
                        context.BoonsSimple[feat.Name].ShowSource = true;
                        feat.ShowSource = true;
                    }
                    else
                    {
                        context.BoonsSimple.Add(feat.Name, feat);
                    }
                    if (context.Boons.ContainsKey(feat.Name + " " + ConfigManager.SourceSeperator + " " + feat.Source))
                    {
                        ConfigManager.LogError("Duplicate Boon: " + feat.Name + " " + ConfigManager.SourceSeperator + " " + feat.Source);
                    }
                    else
                    {
                        context.Boons[feat.Name + " " + ConfigManager.SourceSeperator + " " + feat.Source] = feat;
                    }
                }
            }
            foreach (Feature feat in feats)
            {
                context.Features.Add(feat);
            }
        }
示例#2
0
        public List <Feature> GetFeatureCollection(string expression, int copy = 0)
        {
            while (FeatureCollections.Count <= copy)
            {
                FeatureCollections.Add(new Dictionary <string, List <Feature> >(StringComparer.OrdinalIgnoreCase));
            }
            int c = copy - 1;

            while (copies.Count <= c)
            {
                copies.Add(FeatureContainer.MakeCopy(Features));
            }
            List <Feature> features = Features;

            if (c >= 0)
            {
                features = copies[c];
            }
            if (expression == null || expression == "")
            {
                expression = "Category = 'Feats'";
            }
            if (expression == "Boons")
            {
                expression = "Category = 'Boons'";
            }
            if (FeatureCollections[copy].ContainsKey(expression))
            {
                return(new List <Feature>(FeatureCollections[copy][expression]));
            }
            try
            {
                Expression ex      = new Expression(FixQuotes(expression));
                Feature    current = null;
                ex.EvaluateParameter += delegate(string name, ParameterArgs args)
                {
                    name = name.ToLowerInvariant();
                    if (name == "category")
                    {
                        args.Result = current.Category;
                    }
                    else if (name == "level")
                    {
                        args.Result = current.Level;
                    }
                    else if (name == "name")
                    {
                        args.Result = current.Name.ToLowerInvariant();
                    }
                    else if (name == "source")
                    {
                        args.Result = current.Source.ToLowerInvariant();
                    }
                    else if (current.Keywords.Count > 0 && current.Keywords.Exists(k => k.Name == name))
                    {
                        args.Result = true;
                    }
                    else
                    {
                        args.Result = false;
                    }
                };
                List <Feature> res = new List <Feature>();
                foreach (Feature f in features)
                {
                    current = f;
                    object o = ex.Evaluate();
                    if (o is Boolean && (Boolean)o)
                    {
                        res.Add(current);
                    }
                }
                res.Sort();
                FeatureCollections[copy][expression] = res;
                return(res);
            }
            catch (Exception e)
            {
                ConfigManager.LogError("Error while evaluating expression " + expression, e);
                return(new List <Feature>());
            }
        }