示例#1
0
 public Task <string[]> ListKeySuffixes(
     Session session,
     string prefix,
     PageRef <string> pageRef,
     SortDirection sortDirection         = SortDirection.Ascending,
     CancellationToken cancellationToken = default)
 => Store.ListKeySuffixes(session, prefix, pageRef, sortDirection, cancellationToken);
示例#2
0
    public static IQueryable <T> TakePage <T, TKey>(
        this IQueryable <T> source,
        Expression <Func <T, TKey> > keySelector,
        PageRef <TKey> pageRef,
        SortDirection keySortDirection = SortDirection.Ascending)
    {
        if (pageRef.After.IsSome(out var after))
        {
            var pItem    = keySelector.Parameters[0];
            var cAfter   = Expression.Constant(after);
            var cIntZero = Expression.Constant(0);

            var tComparer        = typeof(Comparer <TKey>);
            var pComparerDefault = tComparer.GetProperty(
                nameof(Comparer <TKey> .Default),
                BindingFlags.Public | BindingFlags.Static);
            var mCompare = tComparer.GetMethod(
                nameof(Comparer <TKey> .Default.Compare),
                new[] { typeof(TKey), typeof(TKey) });

            var eCompare = Expression.Call(
                Expression.Property(null, pComparerDefault !),
                mCompare !,
                keySelector.Body, cAfter);
            var eBody =
                keySortDirection == SortDirection.Ascending
                    ? Expression.GreaterThan(eCompare, cIntZero)
                    : Expression.LessThan(eCompare, cIntZero);
            source = source.Where(Expression.Lambda <Func <T, bool> >(eBody, pItem));
        }
        return(source.Take(pageRef.Count));
    }
示例#3
0
 public static IQueryable <T> OrderByAndTakePage <T, TKey>(
     this IQueryable <T> source,
     Expression <Func <T, TKey> > keySelector,
     PageRef <TKey> pageRef,
     SortDirection keySortDirection = SortDirection.Ascending)
 => source
 .OrderBy(keySelector, keySortDirection)
 .TakePage(keySelector, pageRef, keySortDirection);
示例#4
0
 public static IEnumerable <T> OrderByAndTakePage <T, TKey>(
     this IEnumerable <T> source,
     Func <T, TKey> keySelector,
     PageRef <TKey> pageRef,
     SortDirection keySortDirection = SortDirection.Ascending)
 => source
 .OrderBy(keySelector, keySortDirection)
 .TakePage(keySelector, pageRef, keySortDirection);
 public Task <string[]> ListKeySuffixes(
     Session?session,
     string prefix,
     PageRef <string> pageRef,
     SortDirection sortDirection         = SortDirection.Ascending,
     CancellationToken cancellationToken = default)
 {
     session ??= SessionResolver.Session;
     return(Store.ListKeySuffixes(session, prefix, pageRef, sortDirection, cancellationToken));
 }
示例#6
0
        public async Task ComplexTest()
        {
            var kvs = Services.GetRequiredService <IKeyValueStore>();
            await kvs.Set("1/2", "12");

            (await kvs.Count("1")).Should().Be(1);
            (await kvs.ListKeySuffixes("1", 100)).Length.Should().Be(1);
            (await kvs.Count("1/2")).Should().Be(1);
            (await kvs.ListKeySuffixes("1/2", 100)).Length.Should().Be(1);
            (await kvs.Count("1/2/3a")).Should().Be(0);
            (await kvs.ListKeySuffixes("1/2/3a", 100)).Length.Should().Be(0);

            await kvs.Set("1/2/3a", "123");

            (await kvs.Count("1")).Should().Be(2);
            (await kvs.ListKeySuffixes("1", 100)).Length.Should().Be(2);
            (await kvs.Count("1/2")).Should().Be(2);
            (await kvs.ListKeySuffixes("1/2", 100)).Length.Should().Be(2);
            (await kvs.Count("1/2/3a")).Should().Be(1);
            (await kvs.ListKeySuffixes("1/2/3a", 100)).Length.Should().Be(1);

            await kvs.Set("1/2/3b", "123");

            (await kvs.Count("1")).Should().Be(3);
            (await kvs.ListKeySuffixes("1", 100)).Length.Should().Be(3);
            (await kvs.Count("1/2")).Should().Be(3);
            (await kvs.ListKeySuffixes("1/2", 100)).Length.Should().Be(3);
            (await kvs.Count("1/2/3a")).Should().Be(1);
            (await kvs.ListKeySuffixes("1/2/3a", 100)).Length.Should().Be(1);

            (await kvs.ListKeySuffixes("1", 3))
            .Should().BeEquivalentTo("/2", "/2/3a", "/2/3b");
            (await kvs.ListKeySuffixes("1", 2))
            .Should().BeEquivalentTo("/2", "/2/3a");
            (await kvs.ListKeySuffixes("1", PageRef.New(2, "1/2")))
            .Should().BeEquivalentTo("/2/3a", "/2/3b");
            (await kvs.ListKeySuffixes("1", PageRef.New(2, "1/2/3b"), SortDirection.Descending))
            .Should().BeEquivalentTo("/2/3a", "/2");
            (await kvs.ListKeySuffixes("1", PageRef.New(1, "1/2/3b"), SortDirection.Descending))
            .Should().BeEquivalentTo("/2/3a");
            (await kvs.ListKeySuffixes("1", PageRef.New(0, "1/2/3b"), SortDirection.Descending))
            .Should().BeEquivalentTo();

            await kvs.RemoveMany(new[] { "1/2/3c", "1/2/3b" });

            (await kvs.Count("1")).Should().Be(2);
            (await kvs.ListKeySuffixes("1", 100)).Length.Should().Be(2);
            (await kvs.Count("1/2")).Should().Be(2);
            (await kvs.ListKeySuffixes("1/2", 100)).Length.Should().Be(2);
            (await kvs.Count("1/2/3a")).Should().Be(1);
            (await kvs.ListKeySuffixes("1/2/3a", 100)).Length.Should().Be(1);

            await kvs.SetMany(new[] {
示例#7
0
        public virtual async Task <Todo[]> List(Session session, PageRef <string> pageRef, CancellationToken cancellationToken = default)
        {
            await PseudoGetAllItems(session);

            var todos = _store.AsEnumerable();

            if (pageRef.AfterKey != null)
            {
                todos = todos.Where(i => string.CompareOrdinal(i.Id, pageRef.AfterKey) > 0);
            }
            todos = todos.Take(pageRef.Count);
            return(todos.ToArray());
        }
示例#8
0
 public static IEnumerable <T> TakePage <T, TKey>(
     this IEnumerable <T> source,
     Func <T, TKey> keySelector,
     PageRef <TKey> pageRef,
     SortDirection keySortDirection = SortDirection.Ascending)
 {
     if (pageRef.After.IsSome(out var after))
     {
         var comparer = Comparer <TKey> .Default;
         if (keySortDirection == SortDirection.Ascending)
         {
             source = source.Where(i => comparer.Compare(keySelector(i), after) > 0);
         }
         else
         {
             source = source.Where(i => comparer.Compare(keySelector(i), after) < 0);
         }
     }
     return(source.Take(pageRef.Count));
 }
示例#9
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Value.Length != 0)
            {
                hash ^= Value.GetHashCode();
            }
            if (Text.Length != 0)
            {
                hash ^= Text.GetHashCode();
            }
            if (confidence_ != null)
            {
                hash ^= Confidence.GetHashCode();
            }
            if (boundingBox_ != null)
            {
                hash ^= BoundingBox.GetHashCode();
            }
            if (Type != global::Ssn.Type.Candidate.Types.Type.Unknown)
            {
                hash ^= Type.GetHashCode();
            }
            if (PageRef != 0)
            {
                hash ^= PageRef.GetHashCode();
            }
            if (modelMetadata_ != null)
            {
                hash ^= ModelMetadata.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
示例#10
0
 public Task <Todo[]> List(Session?session, PageRef <string> pageRef, CancellationToken cancellationToken = default)
 {
     session ??= _sessionResolver.Session;
     return(_todoService.List(session, pageRef, cancellationToken));
 }
示例#11
0
文件: Program.cs 项目: gnoso/razordb
        static void Main(string[] args)
        {
            Console.WriteLine("RazorDB Utility\n");

            if (args.Length == 0) {
                Console.WriteLine("Commands:");
                Console.WriteLine("\tdump-journal  <basedir> <version>");
                Console.WriteLine("\tdump-table <basedir> <level> <version>");
                Console.WriteLine("\tdump-manifest <manifest file> ");
                Console.WriteLine("\tdump-manifest-all <basedir>");
                Console.WriteLine("\tsplit-manifest <basedir>");
                Console.WriteLine("\tcheck-each-table <basedir>");
                Console.WriteLine("\tcheck-database <basedir>");
                Console.WriteLine("\tremove-orphans <basedir>");
                Console.WriteLine("\tremove-page <basedir> <level> <version>");
            } else {
                switch (args[0].ToLower()) {
                    case "dump-journal":
                        if (args.Length < 3) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            DumpJournal(args[1], int.Parse(args[2]));
                        }
                        break;
                    case "dump-table":
                        if (args.Length < 4) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            DumpFile(args[1], int.Parse(args[2]), int.Parse(args[3]));
                        }
                        break;
                    case "dump-manifest":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            var mf = new Manifest(args[1]);
                            mf.Logger = msg => Console.WriteLine(msg);
                            mf.LogContents();
                        }
                        break;
                    case "dump-manifest-all":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            var dummyMf = Manifest.NewDummyManifest();
                            dummyMf.Logger = msg => Console.WriteLine(msg);
                            foreach (var mf in Manifest.ReadAllManifests(args[1])) {
                                mf.LogContents(dummyMf);
                            }
                        }
                        break;
                    case "split-manifest":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            var dummyMf = Manifest.NewDummyManifest();
                            dummyMf.Logger = msg => Console.WriteLine(msg);
                            int ct = 0;
                            foreach (var mf in Manifest.ReadAllManifests(args[1])) {
                                using (var bw = new BinaryWriter(new FileStream(Path.Combine(args[1], "S" + ct.ToString() + ".mf"), FileMode.CreateNew, FileAccess.Write, FileShare.None, 40096))) {
                                    mf.WriteManifestContents(bw);
                                }
                                ct++;
                            }
                        }
                        break;
                    case "check-each-table":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            CheckBlockTableFiles(args[1]);
                        }
                        break;
                    case "check-database":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            CheckDatabase(args[1]);
                        }
                        break;
                    case "remove-orphans":
                        if (args.Length < 2) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            RemoveOrphanedTables(args[1]);
                        }
                        break;
                    case "remove-page":
                        if (args.Length < 4) {
                            Console.WriteLine("Invalid parameters");
                        } else {
                            var pageRef = new PageRef { Level = int.Parse(args[2]), Version = int.Parse(args[3]) };
                            var mf = new Manifest(args[1]);
                            mf.ModifyPages(new List<PageRecord>(), new List<PageRef> { { pageRef } });
                        }
                        break;
                    default:
                        Console.WriteLine("Unknown command: {0}", args[0]);
                        break;
                }
            }
        }
示例#12
0
        static void Main(string[] args)
        {
            Console.WriteLine("RazorDB Utility\n");

            if (args.Length == 0)
            {
                Console.WriteLine("Commands:");
                Console.WriteLine("\tdump-journal  <basedir> <version>");
                Console.WriteLine("\tdump-table <basedir> <level> <version>");
                Console.WriteLine("\tdump-manifest <manifest file> ");
                Console.WriteLine("\tdump-manifest-all <basedir>");
                Console.WriteLine("\tsplit-manifest <basedir>");
                Console.WriteLine("\tcheck-each-table <basedir>");
                Console.WriteLine("\tcheck-database <basedir>");
                Console.WriteLine("\tremove-orphans <basedir>");
                Console.WriteLine("\tremove-page <basedir> <level> <version>");
            }
            else
            {
                switch (args[0].ToLower())
                {
                case "dump-journal":
                    if (args.Length < 3)
                    {
                        Console.WriteLine("Invalid parameters");
                    }
                    else
                    {
                        DumpJournal(args[1], int.Parse(args[2]));
                    }
                    break;

                case "dump-table":
                    if (args.Length < 4)
                    {
                        Console.WriteLine("Invalid parameters");
                    }
                    else
                    {
                        DumpFile(args[1], int.Parse(args[2]), int.Parse(args[3]));
                    }
                    break;

                case "dump-manifest":
                    if (args.Length < 2)
                    {
                        Console.WriteLine("Invalid parameters");
                    }
                    else
                    {
                        var mf = new Manifest(args[1]);
                        mf.Logger = msg => Console.WriteLine(msg);
                        mf.LogContents();
                    }
                    break;

                case "dump-manifest-all":
                    if (args.Length < 2)
                    {
                        Console.WriteLine("Invalid parameters");
                    }
                    else
                    {
                        var dummyMf = Manifest.NewDummyManifest();
                        dummyMf.Logger = msg => Console.WriteLine(msg);
                        foreach (var mf in Manifest.ReadAllManifests(args[1]))
                        {
                            mf.LogContents(dummyMf);
                        }
                    }
                    break;

                case "split-manifest":
                    if (args.Length < 2)
                    {
                        Console.WriteLine("Invalid parameters");
                    }
                    else
                    {
                        var dummyMf = Manifest.NewDummyManifest();
                        dummyMf.Logger = msg => Console.WriteLine(msg);
                        int ct = 0;
                        foreach (var mf in Manifest.ReadAllManifests(args[1]))
                        {
                            using (var bw = new BinaryWriter(new FileStream(Path.Combine(args[1], "S" + ct.ToString() + ".mf"), FileMode.CreateNew, FileAccess.Write, FileShare.None, 40096))) {
                                mf.WriteManifestContents(bw);
                            }
                            ct++;
                        }
                    }
                    break;

                case "check-each-table":
                    if (args.Length < 2)
                    {
                        Console.WriteLine("Invalid parameters");
                    }
                    else
                    {
                        CheckBlockTableFiles(args[1]);
                    }
                    break;

                case "check-database":
                    if (args.Length < 2)
                    {
                        Console.WriteLine("Invalid parameters");
                    }
                    else
                    {
                        CheckDatabase(args[1]);
                    }
                    break;

                case "remove-orphans":
                    if (args.Length < 2)
                    {
                        Console.WriteLine("Invalid parameters");
                    }
                    else
                    {
                        RemoveOrphanedTables(args[1]);
                    }
                    break;

                case "remove-page":
                    if (args.Length < 4)
                    {
                        Console.WriteLine("Invalid parameters");
                    }
                    else
                    {
                        var pageRef = new PageRef {
                            Level = int.Parse(args[2]), Version = int.Parse(args[3])
                        };
                        var mf = new Manifest(args[1]);
                        mf.ModifyPages(new List <PageRecord>(), new List <PageRef> {
                            { pageRef }
                        });
                    }
                    break;

                default:
                    Console.WriteLine("Unknown command: {0}", args[0]);
                    break;
                }
            }
        }
 public Task <Todo[]> List(Session session, PageRef <string> pageRef, CancellationToken cancellationToken = default)
 => _todos.List(session, pageRef, cancellationToken);
示例#14
0
    public virtual async Task <Todo[]> List(Session session, PageRef <string> pageRef, CancellationToken cancellationToken = default)
    {
        await PseudoGetAllItems(session);

        return(_store.OrderByAndTakePage(i => i.Id, pageRef).ToArray());
    }