Exemple #1
0
        public override Table VisitOrder_item(QueryParser.Order_itemContext context)
        {
            int Comparer(TableRow row1, TableRow row2)
            {
                var env1 = new Environment(row1, _table.Columns);
                var expr1 = new CondExprVisitor(_zmi, env1).Visit(context.cond_expr());
                var env2 = new Environment(row2, _table.Columns);
                var expr2 = new CondExprVisitor(_zmi, env2).Visit(context.cond_expr());
                var result = expr1.Zip(expr2).Bind(p =>
                {
                    var res = new NullsVisitor(p).VisitNulls(context.nulls());
                    if (res == 0)
                        return new OrderVisitor(p).VisitOrder(context.order()).Just();
                    return res.Just();
                });
                return result.Match(i => i, () => 0);
            }

            _table.Sort(Compare.By<TableRow>(Comparer));
            return _table;
        }
Exemple #2
0
        internal static Dictionary <string, string> FindAssetPathsForLineIDs(IEnumerable <string> lineIDs, string assetsFolderPath)
        {
            // Find _all_ files in this director that are not .meta files
            var allFiles = Directory.EnumerateFiles(assetsFolderPath, "*", SearchOption.AllDirectories)
                           .Where(path => path.EndsWith(".meta") == false);

            // Match files with those whose filenames contain a line ID
            var matchedFilesAndPaths = lineIDs.GroupJoin(
                // the elements we're matching lineIDs to
                allFiles,
                // the key for lineIDs (being strings, it's just the line
                // ID itself)
                lineID => lineID,
                // the key for assets (the filename without the path)
                assetPath => Path.GetFileName(assetPath),
                // the way we produce the result (a key-value pair)
                (lineID, assetPaths) =>
            {
                if (assetPaths.Count() > 1)
                {
                    Debug.LogWarning($"Line {lineID} has {assetPaths.Count()} possible assets.\n{string.Join(", ", assetPaths)}");
                }
                return(new { lineID, assetPaths });
            },
                // the way we test to see if two elements should be joined
                // (does the filename contain the line ID?)
                Compare.By <string>((fileName, lineID) =>
            {
                var lineIDWithoutPrefix = lineID.Replace("line:", "");
                return(Path.GetFileNameWithoutExtension(fileName).Equals(lineIDWithoutPrefix));
            })
                )
                                       // Discard any pair where no asset was found
                                       .Where(pair => pair.assetPaths.Count() > 0)
                                       .ToDictionary(entry => entry.lineID, entry => entry.assetPaths.FirstOrDefault());

            return(matchedFilesAndPaths);
        }
 public static IEnumerable <T> DistinctBy <T, TIdentity>(this IEnumerable <T> source, Func <T, TIdentity> identitySelector)
 {
     return(source.Distinct(Compare.By(identitySelector)));
 }