protected void SaveVhdAndAssertContent(BlobHandle destination, FileInfo localFile, int? numThread, string storageKey, bool overwrite, bool deleteBlob, bool deleteLocal)
        {
            try
            {
                Console.WriteLine("Downloading a VHD from {0} to {1}...", destination.Blob.Uri.ToString(), localFile.FullName);
                DateTime startTime = DateTime.Now;
                VhdDownloadContext result = vmPowershellCmdlets.SaveAzureVhd(destination.Blob.Uri, localFile, numThread, storageKey, overwrite);
                Console.WriteLine("Downloading completed in {0} seconds.", (DateTime.Now - startTime).TotalSeconds);

                string calculateMd5Hash = CalculateContentMd5(File.OpenRead(result.LocalFilePath.FullName));

                Assert.IsTrue(VerifyMD5hash(destination, calculateMd5Hash));

                if (deleteBlob)
                {
                    destination.Blob.Delete();
                }

                if (deleteLocalFileIfPassed && deleteLocal)
                {
                    File.Delete(localFile.FullName);
                }
            }
            catch (Exception e)
            {
                if (deleteLocalFileIfFailed && deleteLocal)
                {
                    File.Delete(localFile.FullName);
                }
                Assert.Fail(e.InnerException.ToString());
            }
        }
        public void Initialize()
        {
            pass = true;
            testStartTime = DateTime.Now;
            storageAccountKey = vmPowershellCmdlets.GetAzureStorageAccountKey(defaultAzureSubscription.CurrentStorageAccountName);  

            // Set the source blob
            blobHandle = Utilities.GetBlobHandle(vhdBlobLocation, storageAccountKey.Primary);            
        }
        private static AssemblyReferenceInformation FormatAssemblyInfo(this MetadataReader metadataReader, string name, StringHandle cultureHandle, BlobHandle publicKeyTokenHandle, Version version)
        {
            var culture = cultureHandle.IsNil
                ? "neutral"
                : metadataReader.GetString(cultureHandle);

            var publicKeyToken = publicKeyTokenHandle.IsNil
                ? "null"
                : metadataReader.FormatPublicKeyToken(publicKeyTokenHandle);

            return new AssemblyReferenceInformation(name, version, culture, publicKeyToken);
        }
 protected static void SaveVhd(BlobHandle destination, FileInfo locFile, string storageKey, int? numThread = null, bool overwrite = false)
 {
     try
     {
         Console.WriteLine("Downloading a VHD from {0} to {1}...", destination.Blob.Uri.ToString(), locFile.FullName);
         DateTime startTime = DateTime.Now;
         vmPowershellCmdlets.SaveAzureVhd(destination.Blob.Uri, locFile, numThread, storageKey, overwrite);
         Console.WriteLine("Downloading completed in {0} seconds.", (DateTime.Now - startTime).TotalSeconds);
     }
     catch (Exception e)
     {
         Assert.Fail(e.InnerException.ToString());
     }
 }
Beispiel #5
0
        internal ImportDefinition(
            ImportDefinitionKind kind,
            BlobHandle alias = default(BlobHandle),
            AssemblyReferenceHandle assembly = default(AssemblyReferenceHandle),
            Handle typeOrNamespace = default(Handle))
        {
            Debug.Assert(
                typeOrNamespace.IsNil ||
                typeOrNamespace.Kind == HandleKind.Blob ||
                typeOrNamespace.Kind == HandleKind.TypeDefinition ||
                typeOrNamespace.Kind == HandleKind.TypeReference ||
                typeOrNamespace.Kind == HandleKind.TypeSpecification);

            _kind = kind;
            _alias = alias;
            _assembly = assembly;
            _typeOrNamespace = typeOrNamespace;
        }
        private static RuntimeAssemblyName CreateRuntimeAssemblyNameFromMetadata(
            MetadataReader reader,
            StringHandle name,
            Version version,
            StringHandle culture,
            BlobHandle publicKeyOrToken,
            AssemblyFlags assemblyFlags)
        {
            AssemblyNameFlags assemblyNameFlags = AssemblyNameFlags.None;
            if (0 != (assemblyFlags & AssemblyFlags.PublicKey))
                assemblyNameFlags |= AssemblyNameFlags.PublicKey;
            if (0 != (assemblyFlags & AssemblyFlags.Retargetable))
                assemblyNameFlags |= AssemblyNameFlags.Retargetable;
            int contentType = ((int)assemblyFlags) & 0x00000E00;
            assemblyNameFlags |= (AssemblyNameFlags)contentType;

            return new RuntimeAssemblyName(
                name.GetString(reader),
                version,
                culture.GetString(reader),
                assemblyNameFlags,
                reader.GetBlobContent(publicKeyOrToken).ToArray()
                );
        }
Beispiel #7
0
 public ImmutableArray<byte> GetBlobContent(BlobHandle handle)
 {
     // TODO: We can skip a copy for virtual blobs.
     byte[] bytes = GetBlobBytes(handle);
     return ImmutableArrayInterop.DangerousCreateFromUnderlyingArray(ref bytes);
 }
 public void AddCustomDebugInformation(EntityHandle parent, GuidHandle kind, BlobHandle value)
 {
     _customDebugInformationTable.Add(new CustomDebugInformationRow
     {
         Parent = (uint)CodedIndex.ToHasCustomDebugInformation(parent),
         Kind = kind,
         Value = value
     });
 }
        public LocalConstantHandle AddLocalConstant(StringHandle name, BlobHandle signature)
        {
            _localConstantTable.Add(new LocalConstantRow
            {
                Name = name,
                Signature = signature
            });

            return MetadataTokens.LocalConstantHandle(_localConstantTable.Count);
        }
        public DocumentHandle AddDocument(BlobHandle name, GuidHandle hashAlgorithm, BlobHandle hash, GuidHandle language)
        {
            _documentTable.Add(new DocumentRow
            {
                Name = name,
                HashAlgorithm = hashAlgorithm,
                Hash = hash,
                Language = language
            });

            return MetadataTokens.DocumentHandle(_documentTable.Count);
        }
 public void AddAssemblyFile(
     StringHandle name,
     BlobHandle hashValue,
     bool containsMetadata)
 {
     _fileTable.Add(new FileTableRow
     {
         FileName = name,
         Flags = containsMetadata ? 0u : 1u,
         HashValue = hashValue
     });
 }
        public MethodDefinitionHandle AddMethodDefinition(
            MethodAttributes attributes, 
            MethodImplAttributes implAttributes,
            StringHandle name,
            BlobHandle signature,
            int bodyOffset,
            ParameterHandle paramList)
        {
            _methodDefTable.Add(new MethodRow
            {
                Flags = (ushort)attributes,
                ImplFlags = (ushort)implAttributes,
                Name = name,
                Signature = signature,
                BodyOffset = bodyOffset,
                ParamList = (uint)MetadataTokens.GetRowNumber(paramList)
            });

            return MetadataTokens.MethodDefinitionHandle(_methodDefTable.Count);
        }
Beispiel #13
0
 public BlobReader GetBlobReader(BlobHandle handle)
 {
     return BlobHeap.GetBlobReader(handle);
 }
Beispiel #14
0
 public byte[] GetBlobBytes(BlobHandle handle)
 {
     return BlobHeap.GetBytes(handle);
 }
        private void AssertContentMD5(string destination, bool deleteBlob)
        {
            string downloadedFile = DownloadToFile(destination);

            var calculateMd5Hash = CalculateContentMd5(File.OpenRead(downloadedFile));

            BlobUri blobUri2;
            Assert.IsTrue(BlobUri.TryParseUri(new Uri(destination), out blobUri2));
            var blobHandle = new BlobHandle(blobUri2, storageAccountKey.Primary);

            Assert.AreEqual(calculateMd5Hash, blobHandle.Blob.Properties.ContentMD5);

            if (deleteBlob)
            {
                blobHandle.Blob.Delete();
            }
        }
 public void AddFieldDefinition(
     FieldAttributes attributes,
     StringHandle name,
     BlobHandle signature)
 {
     _fieldTable.Add(new FieldDefRow
     {
         Flags = (ushort)attributes,
         Name = name,
         Signature = signature
     });
 }
        public void AddMarshallingDescriptor(
            EntityHandle parent,
            BlobHandle descriptor)
        {
            uint codedIndex = (uint)CodedIndex.ToHasFieldMarshal(parent);

            // the table is required to be sorted by Parent:
            _fieldMarshalTableNeedsSorting |= codedIndex < _fieldMarshalTableLastParent;
            _fieldMarshalTableLastParent = codedIndex;

            _fieldMarshalTable.Add(new FieldMarshalRow
            {
                Parent = codedIndex,
                NativeType = descriptor
            });
        }
 public void AddAssembly(
     StringHandle name, 
     Version version,
     StringHandle culture,
     BlobHandle publicKey,
     AssemblyFlags flags,
     AssemblyHashAlgorithm hashAlgorithm)
 {
     _assemblyTable.Add(new AssemblyRow
     {
         Flags = (ushort)flags,
         HashAlgorithm = (uint)hashAlgorithm,
         Version = version,
         AssemblyKey = publicKey,
         AssemblyName = name,
         AssemblyCulture = culture
     });
 }
        public MemberReferenceHandle AddMemberReference(
            EntityHandle parent,
            StringHandle name,
            BlobHandle signature)
        {
            _memberRefTable.Add(new MemberRefRow
            {
                Class = (uint)CodedIndex.ToMemberRefParent(parent),
                Name = name,
                Signature = signature
            });

            return MetadataTokens.MemberReferenceHandle(_memberRefTable.Count);
        }
        public AssemblyReferenceHandle AddAssemblyReference(
            StringHandle name,
            Version version,
            StringHandle culture,
            BlobHandle publicKeyOrToken,
            AssemblyFlags flags,
            BlobHandle hashValue)
        {
            _assemblyRefTable.Add(new AssemblyRefTableRow
            {
                Name = name,
                Version = version,
                Culture = culture,
                PublicKeyToken = publicKeyOrToken,
                Flags = (uint)flags,
                HashValue = hashValue
            });

            return MetadataTokens.AssemblyReferenceHandle(_assemblyRefTable.Count);
        }
        public void AddDeclarativeSecurityAttribute(
            EntityHandle parent,
            DeclarativeSecurityAction action,
            BlobHandle permissionSet)
        {
            uint parentCodedIndex = (uint)CodedIndex.ToHasDeclSecurity(parent);

            // the table is required to be sorted by Parent:
            _declSecurityTableNeedsSorting |= parentCodedIndex < _declSecurityTableLastParent;
            _declSecurityTableLastParent = parentCodedIndex;

            _declSecurityTable.Add(new DeclSecurityRow
            {
                Parent = parentCodedIndex,
                Action = (ushort)action,
                PermissionSet = permissionSet
            });
        }
 public void AddTypeSpecification(BlobHandle signature)
 {
     _typeSpecTable.Add(new TypeSpecRow
     {
         Signature = signature
     });
 }
 public void AddMethodDebugInformation(DocumentHandle document, BlobHandle sequencePoints)
 {
     _methodDebugInformationTable.Add(new MethodDebugInformationRow
     {
         Document = (uint)MetadataTokens.GetRowNumber(document),
         SequencePoints = sequencePoints
     });
 }
 public void AddStandaloneSignature(BlobHandle signature)
 {
     _standAloneSigTable.Add(new StandaloneSigRow
     {
         Signature = signature
     });
 }
        public ImportScopeHandle AddImportScope(ImportScopeHandle parentScope, BlobHandle imports)
        {
            _importScopeTable.Add(new ImportScopeRow
            {
                Parent = (uint)MetadataTokens.GetRowNumber(parentScope),
                Imports = imports
            });

            return MetadataTokens.ImportScopeHandle(_importScopeTable.Count);
        }
 public void AddProperty(PropertyAttributes attributes, StringHandle name, BlobHandle signature)
 {
     _propertyTable.Add(new PropertyRow
     {
         PropFlags = (ushort)attributes,
         Name = name,
         Type = signature
     });
 }
Beispiel #27
0
 public byte[] GetBlobBytes(BlobHandle handle)
 {
     return BlobStream.GetBytes(handle);
 }
        public void AddCustomAttribute(EntityHandle parent, EntityHandle constructor, BlobHandle value)
        {
            uint parentCodedIndex = (uint)CodedIndex.ToHasCustomAttribute(parent);

            // the table is required to be sorted by Parent:
            _customAttributeTableNeedsSorting |= parentCodedIndex < _customAttributeTableLastParent;
            _customAttributeTableLastParent = parentCodedIndex;

            _customAttributeTable.Add(new CustomAttributeRow
            {
                Parent = parentCodedIndex,
                Type = (uint)CodedIndex.ToCustomAttributeType(constructor),
                Value = value
            });
        }
Beispiel #29
0
 public BlobReader GetBlobReader(BlobHandle handle)
 {
     return BlobStream.GetBlobReader(handle);
 }
 public void AddMethodSpecification(EntityHandle method, BlobHandle instantiation)
 {
     _methodSpecTable.Add(new MethodSpecRow
     {
         Method = (uint)CodedIndex.ToMethodDefOrRef(method),
         Instantiation = instantiation
     });
 }