예제 #1
0
        public void ContentHashFromMemoization()
        {
            ContentHash contentHash = ContentHashingUtilities.CreateRandom();
            CasHash     hash        = contentHash.FromMemoization();

            Assert.Equal(contentHash.ToHashByteArray(), hash.BaseHash.RawHash.ToByteArray());
        }
예제 #2
0
        public void CasHashToMemoization()
        {
            CasHash     hash        = RandomHelpers.CreateRandomCasHash();
            ContentHash contentHash = hash.ToMemoization();

            Assert.Equal(hash.BaseHash.RawHash.ToByteArray(), contentHash.ToHashByteArray());
        }
예제 #3
0
        internal SymbolFile(
            Func <string, bool> symlinkTester,
            Client bxlClient,
            string filePath,
            string fileId,
            ContentHash hash,
            IEnumerable <IDebugEntryData> debugEntries)
        {
            Contract.Requires(symlinkTester != null);
            Contract.Requires(bxlClient != null);
            Contract.Requires(!string.IsNullOrEmpty(filePath));
            Contract.Requires(!string.IsNullOrEmpty(fileId));
            Contract.Requires(hash.IsValid);
            // It's not clear whether the symbol endpoint can play nicely with dedup hashes, so locking it down to VSO0 for now.
            Contract.Requires(hash.HashType == HashType.Vso0, "support only VSO0 hashes (for now)");

            if (debugEntries != null)
            {
                var blobIdentifier = new BlobIdentifier(hash.ToHashByteArray());
                Contract.Assert(debugEntries.All(e => e.BlobIdentifier == blobIdentifier));
                m_debugEntries = new List <IDebugEntryData>(debugEntries);
            }

            m_symlinkTester = symlinkTester;
            m_bxlClient     = bxlClient;
            FullFilePath    = Path.GetFullPath(filePath);
            m_file          = FileId.Parse(fileId);
            Hash            = hash;
        }
예제 #4
0
        public void ToHashBytesArray(HashType hashType)
        {
            var length      = HashInfoLookup.Find(hashType).ByteLength;
            var bytes       = Enumerable.Range(0, length).Select(i => (byte)i).ToArray();
            var contentHash = new ContentHash(hashType, bytes);
            var exported    = contentHash.ToHashByteArray();

            Assert.Equal(bytes, exported);
        }
예제 #5
0
        /// <summary>
        /// Adds a content hash to the fingerprint stream without adding a type prefix.
        /// </summary>
        protected void AddInnerHash(ContentHash contentHash)
        {
            var bytes = contentHash.ToHashByteArray();

            Contract.Assert(bytes.Length == ContentHashingUtilities.HashInfo.ByteLength);

            for (int i = 0; i < ContentHashingUtilities.HashInfo.ByteLength; i++)
            {
                AddInnerByte(bytes[i]);
            }
        }
예제 #6
0
        /// <nodoc/>
        public void SetDebugEntries(List <DebugEntryData> entries)
        {
            Contract.Requires(entries != null);

            // check that either all entries are missing the blobId, or all the entries have the same blobId and that blobId matches this file
            var blobIdentifier = new BlobIdentifier(Hash.ToHashByteArray());

            Contract.Assert(entries.All(e => e.BlobIdentifier == null) || entries.All(e => e.BlobIdentifier == blobIdentifier));

            // ensure that BlobIdentifier is not null
            // here we 'trust' that the debug entries are from the current symbol file
            entries.ForEach(entry => entry.BlobIdentifier = blobIdentifier);
            m_debugEntries = new List <IDebugEntryData>(entries);
        }
예제 #7
0
        public Task <Possible <CasHash, Failure> > AddToCasAsync(Stream inputStream, CasHash?hash, UrgencyHint urgencyHint, Guid activityId)
        {
            Contract.Requires(!IsClosed);
            Contract.Requires(inputStream != null);
            Contract.Assert(!m_readOnly);

            return(Task.Run <Possible <CasHash, Failure> >(() =>
            {
                using (var memoryStream = new MemoryStream())
                {
                    // TODO: Use CloudStore HashingStream when it can work with MemoryStream destination.
                    inputStream.CopyTo(memoryStream);
                    byte[] buffer = memoryStream.ToArray();

                    ContentHash contentHash = ContentHashingUtilities.HashBytes(buffer);
                    CasHash casHash = new CasHash(contentHash.ToHashByteArray());
                    Cache.CasStorage.TryAdd(casHash, buffer);
                    m_pinnedToCas.TryAdd(casHash, 0);

                    return casHash;
                }
            }));
        }
예제 #8
0
 private static string GetContentHashString(ContentHash contentHash)
 {
     return(Convert.ToBase64String(contentHash.ToHashByteArray()));
 }
예제 #9
0
        internal SymbolFile(
            Func <string, bool> symlinkTester,
            Client bxlClient,
            string filePath,
            string fileId,
            ContentHash hash,
            IEnumerable <DebugEntryData> debugEntries)
        {
            Contract.Requires(symlinkTester != null);
            Contract.Requires(bxlClient != null);
            Contract.Requires(!string.IsNullOrEmpty(filePath));
            Contract.Requires(!string.IsNullOrEmpty(fileId));
            Contract.Requires(debugEntries == null || debugEntries.All(de => de.BlobIdentifier == null));

            // It's not clear whether the symbol endpoint can play nicely with dedup hashes, so locking it down to VSO0 for now.
            Contract.Requires(hash.HashType == HashType.Vso0, "support only VSO0 hashes (for now)");

            m_symlinkTester = symlinkTester;
            m_bxlClient     = bxlClient;
            FullFilePath    = Path.GetFullPath(filePath);
            m_file          = FileId.Parse(fileId);
            Hash            = hash;

            if (debugEntries != null)
            {
                var blobIdentifier = new Microsoft.VisualStudio.Services.BlobStore.Common.BlobIdentifier(Hash.ToHashByteArray());

                var entries = new List <DebugEntryData>(debugEntries);
                entries.ForEach(entry => entry.BlobIdentifier = blobIdentifier);
                m_debugEntries = entries;
            }
        }