public TreePathStreamedBlob(TreeID rootTreeID, CanonicalBlobPath path, IStreamedBlob blob)
     : this(new TreeBlobPath(rootTreeID, path), blob)
 {
 }
Ejemplo n.º 2
0
 public StreamedBlobResult(IStreamedBlob blob)
 {
     this.blob = blob;
 }
 public TreePathStreamedBlob(TreeBlobPath treePath, IStreamedBlob blob)
 {
     this.TreeBlobPath = treePath;
     this.StreamedBlob = blob;
 }
Ejemplo n.º 4
0
 public TreePathStreamedBlob(TreeID rootTreeID, CanonicalBlobPath path, IStreamedBlob blob)
     : this(new TreeBlobPath(rootTreeID, path), blob)
 {
 }
Ejemplo n.º 5
0
 public TreePathStreamedBlob(TreeBlobPath treePath, IStreamedBlob blob)
 {
     this.TreeBlobPath = treePath;
     this.StreamedBlob = blob;
 }
Ejemplo n.º 6
0
 protected void assertTranslated(TestContext tc, IStreamedBlob bl, TreeID rootid, string expected, params SemanticWarning[] expectedWarnings)
 {
     var item = new TreePathStreamedBlob(rootid, (CanonicalBlobPath)"/test", bl);
     assertTranslated(tc, item, expected, expectedWarnings);
 }
Ejemplo n.º 7
0
 protected void assumeFail(TestContext tc, IStreamedBlob bl, TreeID rootid, IVO.CMS.SemanticError[] expectedErrors, SemanticWarning[] expectedWarnings)
 {
     var item = new TreePathStreamedBlob(rootid, (CanonicalBlobPath)"/test", bl);
     assumeFail(tc, item, expectedErrors, expectedWarnings);
 }
Ejemplo n.º 8
0
        async Task DemonstrateHashing()
        {
            var db = getDataContext();

            IBlobRepository   blrepo = new BlobRepository(db);
            ITreeRepository   trrepo = new TreeRepository(db);
            ICommitRepository cmrepo = new CommitRepository(db);
            IRefRepository    rfrepo = new RefRepository(db);

            // Create a sample set of blobs:
            Blob readmeBlob;
            ImmutableContainer <BlobID, Blob> blobs = new ImmutableContainer <BlobID, Blob>(
                bl => bl.ID,
                readmeBlob = new Blob.Builder(pContents: Encoding.UTF8.GetBytes(@"Hello world"))
                );

            Console.Out.WriteAsync(String.Format("Blob {0} = \"{1}\"" + Environment.NewLine, readmeBlob.ID.ToString(firstLength: 7), Encoding.UTF8.GetString(readmeBlob.Contents)));
            // Persist them:
            var persistingBlobs = blrepo.PersistBlobs(blobs);

            // Create an initial tree:
            Tree trRoot;
            ImmutableContainer <TreeID, Tree> trees = new ImmutableContainer <TreeID, Tree>(
                tr => tr.ID,
                new Tree[] {
                trRoot = new Tree.Builder(
                    pTrees: new List <TreeTreeReference>(0),
                    pBlobs: new List <TreeBlobReference> {
                    new TreeBlobReference.Builder(pName: "README", pBlobID: readmeBlob.ID)
                }
                    )
            }
                );

            // Dump the tree:
            RecursivePrint(trRoot.ID, trees);

            // Now wait for the blob persistence to complete:
            await persistingBlobs;
            // Persist our tree now:
            var   persistTrees = trrepo.PersistTree(trRoot.ID, trees);
            await persistTrees;

            // Let's make a commit out of all that:
            Commit cm1 = new Commit.Builder(
                pParents:       new List <CommitID>(0),
                pTreeID:        trRoot.ID,
                pCommitter:     @"James Dunne <*****@*****.**>",
                pDateCommitted: DateTimeOffset.Now,
                pMessage:       "Initial commit."
                );

            // Persist that commit:
            Console.Out.WriteAsync(String.Format("Persisting commit {0}..." + Environment.NewLine, cm1.ID.ToString(firstLength: 7)));
            await cmrepo.PersistCommit(cm1);

            // Let's create a ref to point to it:
            await rfrepo.DestroyRefByName("demo/HEAD");

            await rfrepo.PersistRef(new Ref.Builder(pName: "demo/HEAD", pCommitID: cm1.ID));

            await Console.Out.WriteAsync(String.Format("Pointed demo/HEAD to commit {0}" + Environment.NewLine, cm1.ID.ToString(firstLength: 7)));

            // Now let's create a new blob with some revised contents: (adding a period at the end)
            Blob readmeBlob2;

            blobs = new ImmutableContainer <BlobID, Blob>(
                bl => bl.ID,
                readmeBlob2 = new Blob.Builder(Encoding.UTF8.GetBytes(@"Hello world."))
                );
            var persistBlobs2 = blrepo.PersistBlobs(blobs);

            // Make a new tree out of the old tree:
            Tree.Builder trRoot2b = new Tree.Builder(trRoot);
            // Point README to the new BlobID:
            trRoot2b.Blobs[0] = new TreeBlobReference.Builder(trRoot2b.Blobs[0])
            {
                BlobID = readmeBlob2.ID
            };

            // Freeze our Tree.Builder to a Tree:
            Tree trRoot2;

            trees = new ImmutableContainer <TreeID, Tree>(tr => tr.ID, trRoot2 = trRoot2b);

            // Wait for the blobs to persist:
            await persistBlobs2;
            // Now persist the new tree:
            await trrepo.PersistTree(trRoot2.ID, trees);

            // Load a streamed blob:
            IStreamedBlob strbl = await blrepo.GetStreamedBlob(readmeBlob.ID);

            await strbl.ReadStream(blsr =>
            {
                Console.WriteLine("blob is {0} length", blsr.Length);

                byte[] dum = new byte[8040];
                int count  = 8040;

                try
                {
                    while ((count = blsr.Read(dum, 0, 8040)) > 0)
                    {
                        for (int i = 0; i < (count / 40) + ((count % 40) > 0 ? 1 : 0); ++i)
                        {
                            Console.WriteLine(dum.ToHexString(i * 40, Math.Min(count - (i * 40), 40)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex.ToString());
                }
            });
        }