예제 #1
0
        public async Task GivenMultiLinkRecord_WhenFullLifeCycle_ShouldComplete()
        {
            TestWebsiteHost host = await TestApplication.DefaultHost.GetHost();

            const string testPrefix = "test01-";

            await DeleteAll(host, testPrefix);

            const int    max         = 100;
            const string redirectUrl = "http://localhost:5003/Document";

            IReadOnlyList <LinkRecord> records = Enumerable.Range(0, max)
                                                 .Select(x => new LinkRecord
            {
                Id          = $"{testPrefix}lnk_{x}",
                RedirectUrl = redirectUrl,
                Owner       = $"Owner_{x}",
            })
                                                 .ToArray();

            foreach (var item in records)
            {
                await host.PathFinderClient.Link.Set(item);
            }

            BatchSet <LinkRecord> list = await host.PathFinderClient.Link.List(new QueryParameters { Id = testPrefix }).ReadNext();

            list.Should().NotBeNull();
            list.Records.Count.Should().Be(max);

            records
            .Zip(list.Records, (o, i) => (o, i))
            .All(x => x.o == x.i)
            .Should().BeTrue();
        }
예제 #2
0
 /// <summary>
 /// Applied after RemoveBatch runs.
 /// </summary>
 internal static void Postfix(BatchSet __instance)
 {
     if (__instance.batches.Count < 1)
     {
         var key  = __instance.key;
         var inst = KAnimBatchManager.Instance();
         if (inst != null && inst.batchSets.Remove(key))
         {
             // Destroy from the batch manager
             IList <KAnimBatchManager.BatchSetInfo> toPurge;
             int n;
             if (key.materialType == MaterialType.UI)
             {
                 toPurge = inst.uiBatchSets;
             }
             else
             {
                 toPurge = inst.culledBatchSetInfos;
             }
             n = toPurge.Count;
             for (int i = 0; i < n; i++)
             {
                 if (toPurge[i].batchSet == __instance)
                 {
                     toPurge.RemoveAt(i);
                     break;
                 }
             }
         }
     }
 }
예제 #3
0
        //[Fact]
        public async Task GivenMultiLinkRecord_WhenFullLifeCycle_ShouldComplete()
        {
            TestWebsiteHost host = await TestApplication.DevHost.GetHost();

            await DeleteAllLink(host);

            int half = TestData.RandomNames.Count / 2;
            IReadOnlyList <LinkRecord> records = TestData.RandomNames.Take(half)
                                                 .Zip(TestData.RandomNames.Skip(half), (name, site) => (name, site))
                                                 .Select((x, i) => new LinkRecord
            {
                Id          = $"link_{x.name}",
                RedirectUrl = $"http://{x.site}/Document",
                Owner       = $"l-Owner_{i % 5}",
                Tags        = Enumerable.Range(0, i % 3)
                              .Select(x => new KeyValue($"Key_{x}", $"Value_{x}"))
                              .ToList(),
            })
                                                 .ToArray();

            foreach (var item in records)
            {
                await host.PathFinderClient.Link.Set(item);
            }

            BatchSet <LinkRecord> list = await host.PathFinderClient.Link.List(QueryParameters.Default).ReadNext();

            list.Should().NotBeNull();
            list.Records.Count.Should().Be(half);

            records
            .Zip(list.Records, (o, i) => (o, i))
            .All(x => x.o == x.i)
            .Should().BeTrue();
        }
    public void Register(KAnimConverter.IAnimConverter controller)
    {
        if (!isReady)
        {
            Debug.LogError($"Batcher isnt finished setting up, controller [{controller.GetName()}] is registering too early.");
        }
        BatchKey batchKey = BatchKey.Create(controller);
        Vector2I vector2I = ControllerToChunkXY(controller);

        if (!batchSets.TryGetValue(batchKey, out BatchSet value))
        {
            value = new BatchSet(GetBatchGroup(new BatchGroupKey(batchKey.groupID)), batchKey, vector2I);
            batchSets[batchKey] = value;
            if (value.key.materialType == KAnimBatchGroup.MaterialType.UI)
            {
                uiBatchSets.Add(new BatchSetInfo
                {
                    batchSet   = value,
                    isActive   = false,
                    spatialIdx = vector2I
                });
            }
            else
            {
                culledBatchSetInfos.Add(new BatchSetInfo
                {
                    batchSet   = value,
                    isActive   = false,
                    spatialIdx = vector2I
                });
            }
        }
        value.Add(controller);
    }
예제 #5
0
        public async Task List(string nameSpace, CancellationToken token)
        {
            nameSpace.VerifyNotEmpty(nameof(nameSpace));

            using IDisposable scope = _logger.BeginScope(new { Command = nameof(List), Namespace = nameSpace });

            BatchSetCursor <string> batch = _artifactClient.List(null !);
            int index = 0;

            var list = new List <string>
            {
                $"Listing artifacts from Namespace {nameSpace}...",
                "",
            };

            while (true)
            {
                BatchSet <string> batchSet = await batch.ReadNext(token);

                if (batchSet.IsEndSignaled)
                {
                    break;
                }

                batchSet.Records.ForEach(x => list.Add($"({index++}) {nameSpace + "/" + x}"));
            }

            list.Add($"Completed, {index} listed");

            _logger.LogInformation(list.Aggregate(string.Empty, (a, x) => a += x + Environment.NewLine));
        }
 public GivingRealm(PlanningCenterOptions options, PlanningCenterToken token)
 {
     Funds          = new FundSet(options, token);
     PaymentSources = new PaymentSourceSet(options, token);
     Donations      = new DonationSet(options, token);
     Batches        = new BatchSet(options, token);
 }
예제 #7
0
    private async Task Delete(DocumentId documentId, bool shouldExist)
    {
        ContractClient client = TestApplication.GetContractClient();

        var query = new QueryParameter()
        {
            Filter    = documentId.Id.Split('/').Reverse().Skip(1).Reverse().Join("/"),
            Recursive = false,
        };

        BatchSet <string> searchList = await client.Search(query).ReadNext();

        searchList.Should().NotBeNull();
        bool exists = searchList.Records.Any(x => x.EndsWith(documentId.Path));

        if (!shouldExist && !exists)
        {
            return;
        }
        exists.Should().BeTrue();

        (await client.Delete(documentId)).Should().BeTrue();

        searchList = await client.Search(query).ReadNext();

        searchList.Should().NotBeNull();
        searchList.Records.Any(x => x.EndsWith(documentId.Path)).Should().BeFalse();
    }
예제 #8
0
    public async Task GivenNoContract_WhenCreated_ShouldVerify()
    {
        ContractClient client = TestApplication.GetContractClient();

        var documentId = new DocumentId("test/unit-tests-smart/contract1");

        var query = new QueryParameter()
        {
            Filter    = "test/unit-tests-smart",
            Recursive = false,
        };

        IReadOnlyList <string> search = (await client.Search(query).ReadNext()).Records;

        if (search.Any(x => x == (string)documentId))
        {
            await client.Delete(documentId);
        }

        var blkHeader = new BlkHeader
        {
            PrincipalId = "dev/user/[email protected]",
            DocumentId  = (string)documentId,
            Creator     = "test",
            Description = "test description",
        };

        await client.Create(blkHeader);

        BlockChainModel model = await client.Get(documentId);

        model.Should().NotBeNull();
        model.Blocks.Should().NotBeNull();
        model.Blocks.Count.Should().Be(2);

        model.Blocks[0].Should().NotBeNull();
        model.Blocks[0].IsValid().Should().BeTrue();

        model.Blocks[1].Should().NotBeNull();
        model.Blocks[1].IsValid().Should().BeTrue();
        model.Blocks[1].DataBlock.Should().NotBeNull();
        model.Blocks[1].DataBlock.BlockType.Should().Be(typeof(BlkHeader).Name);

        bool isValid = await client.Validate(model);

        isValid.Should().BeTrue();


        BatchSet <string> searchList = await client.Search(query).ReadNext();

        searchList.Should().NotBeNull();
        searchList.Records.Any(x => x.EndsWith(documentId.Path)).Should().BeTrue();

        (await client.Delete(documentId)).Should().BeTrue();

        searchList = await client.Search(query).ReadNext();

        searchList.Should().NotBeNull();
        searchList.Records.Any(x => x.EndsWith(documentId.Path)).Should().BeFalse();
    }
예제 #9
0
        public async Task GivenFakePackage_WhenFullLifeCycle_ShouldPass()
        {
            TestWebsiteHost host = TestApplication.GetHost();

            const string payload = "This is a test";
            string       id      = "fake1";

            byte[] bytes = Encoding.UTF8.GetBytes(payload);

            ArticlePayload articlePayload = bytes.ToArticlePayload((ArticleId)id);

            await host.ArticleClient.Set(articlePayload);

            ArticlePayload?readPayload = await host.ArticleClient.Get((ArticleId)id);

            readPayload.Should().NotBeNull();

            (articlePayload == readPayload).Should().BeTrue();

            string payloadText = Encoding.UTF8.GetString(readPayload !.ToBytes());

            payloadText.Should().Be(payload);

            BatchSet <string> searchList = await host.ArticleClient.List(QueryParameters.Default).ReadNext();

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.StartsWith(id)).Should().BeTrue();

            (await host.ArticleClient.Delete((ArticleId)id)).Should().BeTrue();

            searchList = await host.ArticleClient.List(QueryParameters.Default).ReadNext();

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.StartsWith(id)).Should().BeFalse();
        }
예제 #10
0
        private async Task DeleteAll(TestWebsiteHost host, string prefix)
        {
            BatchSet <MetadataRecord> list = await host.PathFinderClient.Metadata.List(new QueryParameters { Id = prefix }).ReadNext();

            foreach (var item in list.Records)
            {
                (await host.PathFinderClient.Metadata.Delete(item.Id)).Should().BeTrue(item.Id);
            }
        }
예제 #11
0
    public async Task <BatchSet <DatalakePathItem> > Search(QueryParameter queryParameter, CancellationToken token)
    {
        queryParameter = queryParameter with {
            Container = _container
        };
        BatchSet <DatalakePathItem> batch = await _artifactClient.Search(queryParameter).ReadNext(token);

        return(batch);
    }
예제 #12
0
        private async Task DeleteAllMetadata(TestWebsiteHost host)
        {
            BatchSet <MetadataRecord> list = await host.PathFinderClient.Metadata.List(QueryParameters.Default).ReadNext();

            foreach (var item in list.Records)
            {
                await host.PathFinderClient.Metadata.Delete(item.Id);
            }
        }
예제 #13
0
        private async Task <BatchSet <T> > Start(CancellationToken token)
        {
            _logger.LogTrace($"{nameof(Start)}: Query={_queryParameter}");

            Current = await Post(_queryParameter);

            _getFunc = Continue;

            return(Current);
        }
예제 #14
0
        public async Task <IReadOnlyList <LinkRecord> > List(QueryParameters queryParameters)
        {
            HttpResponseMessage response = await _httpClient.PostAsJsonAsync("api/link/list", queryParameters);

            response.EnsureSuccessStatusCode();

            BatchSet <LinkRecord> result = (await response.Content.ReadFromJsonAsync <BatchSet <LinkRecord> >()).VerifyNotNull("No response");

            return(result.Records);
        }
예제 #15
0
        public async Task GivenMultiLinkRecord_WhenManuallyPaged_ShouldComplete()
        {
            TestWebsiteHost host = await TestApplication.DefaultHost.GetHost();

            const string testPrefix = "metadata-test02-";

            await DeleteAll(host, testPrefix);

            const int max      = 100;
            const int pageSize = 10;

            IReadOnlyList <MetadataRecord> records = Enumerable.Range(0, max)
                                                     .Select(x => new MetadataRecord
            {
                Id         = $"{testPrefix}meta_{x}",
                Properties = new[]
                {
                    new KeyValue("key1", "value1"),
                    new KeyValue("key2", "value2"),
                },
            })
                                                     .ToArray();

            foreach (var item in records)
            {
                await host.PathFinderClient.Metadata.Set(item);
            }

            var aggList = new List <MetadataRecord>();

            int index = 0;

            while (aggList.Count < max)
            {
                BatchSet <MetadataRecord> list = await host.PathFinderClient.Metadata.List(new QueryParameters { Id = testPrefix, Index = index, Count = pageSize }).ReadNext();

                list.Should().NotBeNull();
                list.Records.Count.Should().Be(pageSize);

                index += list.Records.Count;
                aggList.AddRange(list.Records);
            }

            aggList.Count.Should().Be(max);

            records
            .Zip(aggList, (o, i) => (o, i))
            .All(x => x.o == x.i)
            .Should().BeTrue();

            BatchSet <MetadataRecord> finalList = await host.PathFinderClient.Metadata.List(new QueryParameters { Id = testPrefix, Index = index, Count = pageSize }).ReadNext();

            finalList.Should().NotBeNull();
            finalList.Records.Count.Should().Be(0);
        }
예제 #16
0
            /// <summary>
            /// Applied after Deactivate runs.
            /// </summary>
            internal static void Postfix(KAnimBatch __instance, BatchSet newBatchSet)
            {
                int id = __instance.id;

                if (newBatchSet == null && __instance.materialType != MaterialType.UI &&
                    visualizers.TryGetValue(id, out KAnimMeshRenderer renderer) &&
                    renderer != null)
                {
                    renderer.Deactivate();
                }
            }
예제 #17
0
        private async Task <BatchSet <T> > Continue(CancellationToken token)
        {
            _logger.LogTrace($"{nameof(Continue)}: Query={_queryParameters}");

            QueryParameters queryParameters = _queryParameters.WithIndex(Current !.NextIndex);

            Current = await Post(queryParameters);

            _getFunc = Continue;
            return(Current);
        }
예제 #18
0
        public async Task <IActionResult> Search([FromBody] QueryParameter queryParameter, CancellationToken token)
        {
            if (!queryParameter.Container.IsEmpty())
            {
                return(BadRequest(_noContainer));
            }

            BatchSet <DatalakePathItem> response = await _service.Search(queryParameter, token);

            return(Ok(response));
        }
예제 #19
0
        public async Task GivenMultiLinkRecord_WhenManuallyPaged_ShouldComplete()
        {
            TestWebsiteHost host = await TestApplication.DefaultHost.GetHost();

            const string testPrefix = "test02-";

            await DeleteAll(host, testPrefix);

            const int    max         = 100;
            const int    pageSize    = 10;
            const string redirectUrl = "http://localhost:5003/Document";

            IReadOnlyList <LinkRecord> records = Enumerable.Range(0, max)
                                                 .Select(x => new LinkRecord
            {
                Id          = $"{testPrefix}lnk_{x}",
                RedirectUrl = redirectUrl
            })
                                                 .ToArray();

            foreach (var item in records)
            {
                await host.PathFinderClient.Link.Set(item);
            }

            var aggList = new List <LinkRecord>();

            int index = 0;

            while (aggList.Count < max)
            {
                BatchSet <LinkRecord> list = await host.PathFinderClient.Link.List(new QueryParameters { Id = testPrefix, Index = index, Count = pageSize }).ReadNext();

                list.Should().NotBeNull();
                list.Records.Count.Should().Be(pageSize);

                index += list.Records.Count;
                aggList.AddRange(list.Records);
            }

            aggList.Count.Should().Be(max);

            records
            .Zip(aggList, (o, i) => (o, i))
            .All(x => x.o == x.i)
            .Should().BeTrue();

            BatchSet <LinkRecord> finalList = await host.PathFinderClient.Link.List(new QueryParameters { Id = testPrefix, Index = index, Count = pageSize }).ReadNext();

            finalList.Should().NotBeNull();
            finalList.Records.Count.Should().Be(0);
        }
예제 #20
0
        public async Task GivenMultiLinkRecord_WhenSearchedBothIdAndRedirectUrl_ShouldComplete()
        {
            // Arrange
            TestWebsiteHost host = await TestApplication.SearchHost.GetHost();

            // Act
            BatchSet <LinkRecord> list = await host.PathFinderClient.Link.List(new QueryParameters { Id = "Z", RedirectUrl = "sa" }).ReadNext();

            // Assert
            list.Should().NotBeNull();
            list.Records.Should().NotBeNull();
            list.Records.Count.Should().Be(5);
        }
예제 #21
0
        public async Task <IActionResult> List([FromBody] QueryParameter queryParameter)
        {
            IReadOnlyList <string> list = await _acticleStoreService.List(queryParameter);

            var result = new BatchSet <string>
            {
                QueryParameter = queryParameter,
                NextIndex      = queryParameter.Index + queryParameter.Count,
                Records        = list.ToArray(),
            };

            return(Ok(result));
        }
예제 #22
0
    public async Task <IActionResult> Search([FromBody] QueryParameter queryParameter, CancellationToken token)
    {
        IReadOnlyList <DatalakePathItem> list = await _identityService.Search(queryParameter);

        var result = new BatchSet <DatalakePathItem>
        {
            QueryParameter = queryParameter,
            NextIndex      = queryParameter.Index + queryParameter.Count,
            Records        = list.ToArray(),
        };

        return(Ok(result));
    }
예제 #23
0
        public async Task GivenMultiLinkRecord_WhenSearchedAllFields_ShouldComplete()
        {
            // Arrange
            TestWebsiteHost host = await TestApplication.SearchHost.GetHost();

            // Act
            BatchSet <MetadataRecord> list = await host.PathFinderClient.Metadata.List(new QueryParameters { Id = "Z", Owner = "3", Tag = "2" }).ReadNext();

            // Assert
            list.Should().NotBeNull();
            list.Records.Should().NotBeNull();
            list.Records.Count.Should().Be(11);
        }
예제 #24
0
        public async Task <IActionResult> List([FromBody] QueryParameters listParameters)
        {
            IReadOnlyList <LinkRecord> list = await _linkPathService.List(listParameters);

            var result = new BatchSet <LinkRecord>
            {
                QueryParameters = listParameters,
                NextIndex       = listParameters.Index + listParameters.Count,
                Records         = list.ToArray(),
            };

            return(Ok(result));
        }
예제 #25
0
        public async Task GivenMultiLinkRecord_WhenSearchForTag_ShouldComplete()
        {
            // Arrange
            TestWebsiteHost host = await TestApplication.SearchHost.GetHost();

            // Act
            BatchSet <LinkRecord> list = await host.PathFinderClient.Link.List(new QueryParameters { Tag = "1" }).ReadNext();

            // Assert
            list.Should().NotBeNull();
            list.Records.Should().NotBeNull();
            list.Records.Count.Should().Be(16);
        }
예제 #26
0
        public async Task <IActionResult> List([FromBody] QueryParameters listParameters)
        {
            BatchSet <MetadataRecord> list = await _metadataService.List(listParameters);

            var result = new BatchSet <MetadataRecord>
            {
                QueryParameters = listParameters,
                NextIndex       = listParameters.Index + listParameters.Count,
                Records         = list.Records.ToArray(),
            };

            return(Ok(result));
        }
        public async Task <IActionResult> List([FromBody] QueryParameters listParameters)
        {
            IReadOnlyList <string> list = await _contactRequestStore.List(listParameters);

            var result = new BatchSet <string>
            {
                QueryParameters = listParameters,
                NextIndex       = listParameters.Index + listParameters.Count,
                Records         = list.ToArray(),
            };

            return(Ok(result));
        }
예제 #28
0
        public async Task GivenRealPackage_WhenFullLifeCycleInFolder_ShouldPass()
        {
            TestWebsiteHost host = TestApplication.GetHost();

            string specFile    = new TestResources().WriteTestData_1();
            string buildFolder = Path.Combine(Path.GetTempPath(), nameof(nBlog), "build", Guid.NewGuid().ToString());

            string packageFile = new ArticlePackageBuilder()
                                 .SetSpecFile(specFile)
                                 .SetBuildFolder(buildFolder)
                                 .SetObjFolder(Path.Combine(buildFolder, "obj"))
                                 .Build();

            byte[]          packageBytes    = File.ReadAllBytes(packageFile);
            ArticlePayload  articlePayload  = packageBytes.ToArticlePayload();
            ArticleManifest articleManifest = packageBytes.ReadManifest();

            await host.ArticleClient.Set(articlePayload);

            ArticlePayload?readPayload = await host.ArticleClient.Get((ArticleId)articlePayload.Id);

            readPayload.Should().NotBeNull();

            ArticleManifest readArticleManifest = articlePayload.ReadManifest();

            articleManifest.ArticleId.Should().Be(readArticleManifest.ArticleId);
            articleManifest.PackageVersion.Should().Be(readArticleManifest.PackageVersion);
            articleManifest.Title.Should().Be(readArticleManifest.Title);
            articleManifest.Summary.Should().Be(readArticleManifest.Summary);
            articleManifest.Author.Should().Be(readArticleManifest.Author);
            articleManifest.ImageFile.Should().Be(readArticleManifest.ImageFile);
            articleManifest.Date.Should().Be(readArticleManifest.Date);
            Enumerable.SequenceEqual(articleManifest.Tags !, readArticleManifest.Tags !).Should().BeTrue();
            Enumerable.SequenceEqual(articleManifest.Categories !, readArticleManifest.Categories !).Should().BeTrue();

            (articlePayload == readPayload).Should().BeTrue();

            BatchSet <string> searchList = await host.ArticleClient.List(QueryParameters.Default).ReadNext();

            searchList.Should().NotBeNull();

            searchList.Records.Any(x => x.StartsWith(articlePayload.Id)).Should().BeTrue();

            (await host.ArticleClient.Delete((ArticleId)articlePayload.Id)).Should().BeTrue();

            searchList = await host.ArticleClient.List(QueryParameters.Default).ReadNext();

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.StartsWith(articlePayload.Id)).Should().BeFalse();
        }
예제 #29
0
    public async Task WriteFile(string file, string path, bool recursive, CancellationToken token)
    {
        file.VerifyNotEmpty(nameof(file));

        using IDisposable scope = _logger.BeginScope(new { Command = nameof(WriteFile), File = file, Path = path, Recursive = recursive });

        _logger.LogInformation($"Reading directory at {path}, recursive={recursive}...");

        var query = new QueryParameter()
        {
            Filter    = path,
            Recursive = recursive,
        };

        BatchSetCursor <DatalakePathItem> batch = _directoryClient.Search(query);

        var list = new List <DirectoryEntry>();

        while (true)
        {
            BatchSet <DatalakePathItem> batchSet = await batch.ReadNext(token);

            if (batchSet.IsEndSignaled)
            {
                break;
            }

            foreach (var entry in batchSet.Records)
            {
                var documentId = new DocumentId(entry.Name);

                DirectoryEntry?directoryEntry = await _directoryClient.Get(documentId, token);

                if (directoryEntry == null)
                {
                    _logger.LogWarning($"Directory entry for {entry.Name} was not found");
                    continue;
                }

                list.Add(directoryEntry);
            }
        }

        string json = Json.Default.SerializeFormat(list);

        File.WriteAllText(path, json);

        _logger.LogInformation($"{list.Count} directory entries written to {file}");
    }
예제 #30
0
        private void AddDeletedDoc(BatchSet bs, BsonDocument doc, SyncLogItem logItem)
        {
            if (bs.DeletedDocuments == null)
            {
                bs.DeletedDocuments = new List <DeletedDocument>();
            }

            //check uploaded anchor- means cliet just uploaded this record and we should not return back
            if (logItem != null && logItem.KeyVersion != null && logItem.KeyVersion.ContainsKey(doc["o"].AsBsonDocument["_id"].AsString))
            {
                return;
            }

            DeletedDocument delDoc = new DeletedDocument();

            delDoc.Key = doc["o"].AsBsonDocument["_id"].AsString;
            bs.DeletedDocuments.Add(delDoc);
        }