// Get additional assemblies from azure storage
        private async Task <IEnumerable <Assembly> > GetDependencyAssembliesFromStorageAsync()
        {
            IEnumerable <Assembly> additionalAssemblies = new List <Assembly>();
            var mefStorageAccountName = Settings.MefStorageAccountName;
            var mefContainerName      = Settings.MefContainerName;

            if (string.IsNullOrEmpty(mefStorageAccountName) || string.IsNullOrEmpty(mefContainerName))
            {
                return(additionalAssemblies);
            }

            var mefBlobDirectory = Settings.MefBlobDirectory;

            BlobStorageMSI blobStorage = new BlobStorageMSI(mefStorageAccountName);

            var dlls = blobStorage.GetCloudBlockBlobs(mefContainerName, mefBlobDirectory);

            foreach (var blob in dlls)
            {
                if (blob.Name.EndsWith(".dll"))
                {
                    using (var strm = new MemoryStream())
                    {
                        await blob.DownloadToStreamAsync(strm);

                        byte[] asseblyBytes = strm.ToArray();
                        var    assembly     = Assembly.Load(asseblyBytes);
                        additionalAssemblies = additionalAssemblies.Append(assembly);
                    }
                }
            }
            return(additionalAssemblies);
        }
Exemplo n.º 2
0
        // Get additional assemblies from azure storage
        private async Task <IEnumerable <Assembly> > GetDependencyAssembliesFromStorageAsync()
        {
            IEnumerable <Assembly> additionalAssemblies = new List <Assembly>();
            var mefStorageAccountName = ServiceFabricUtil.GetServiceFabricConfigSetting("MefStorageAccountName").Result.ToString();
            var mefContainerName      = ServiceFabricUtil.GetServiceFabricConfigSetting("MefContainerName").Result.ToString();

            if (string.IsNullOrEmpty(mefStorageAccountName) || string.IsNullOrEmpty(mefContainerName))
            {
                return(additionalAssemblies);
            }

            var mefBlobDirectory = ServiceFabricUtil.GetServiceFabricConfigSetting("MefBlobDirectory").Result.ToString();

            BlobStorageMSI blobStorage = new BlobStorageMSI(mefStorageAccountName);

            var dlls = blobStorage.GetCloudBlockBlobs(mefContainerName, mefBlobDirectory);

            // Configure and create a logger instance
            var logger = _loggerFactory.CreateLogger <Startup>();

            foreach (var blob in dlls)
            {
                if (blob.Name.EndsWith(".dll"))
                {
                    using (var strm = new MemoryStream())
                    {
                        await blob.DownloadToStreamAsync(strm);

                        byte[] asseblyBytes = strm.ToArray();
                        try
                        {
                            var assembly = Assembly.Load(asseblyBytes);
                            additionalAssemblies = additionalAssemblies.Append(assembly);
                        }
                        catch (BadImageFormatException be)
                        {
                            // Do nothing and skip the assembly to load as it might be a native assembly
                            logger.LogError(be, "Unable to load Assembly: {0} from the StorageAccount", blob.Name);
                        }
                    }
                }
            }
            return(additionalAssemblies);
        }