protected CloudBlockBlob GetBlob(IFileQuery qryFile) { CloudBlobContainer objAzureContainer = AzureBlobClient.GetContainerReference(Settings.CDNStorageBucket); CloudBlockBlob blockBlob = objAzureContainer.GetBlockBlobReference(GetCDNPath(qryFile, false)); return(blockBlob); }
private static void Setup() { var credentials = FileClient.ReadLines("../../../../azure-credentials.txt"); AzureBlobClient.Setup( accountName: credentials[0], accountKey: credentials[1], containerName: "test" ); }
public void WriteAndRead() { TestInitialize($"{GetType().Name}.{nameof(WriteAndRead)}"); Setup(); var testFileName = "test.xml"; using (var fileStream = FileClient.OpenRead("../../Kit.Tests.csproj")) AzureBlobClient.WriteFrom(testFileName, fileStream); using (var blobStream = AzureBlobClient.OpenRead(testFileName)) FileClient.WriteFrom(testFileName, blobStream); }
public FileStorageService(IUnityContainer container, ISaphirCloudBoxDataContextManager dataContextManager, BlobSettings blobSettings, AzureBlobClient azureBlobClient, IPermissionHelper permissionHelper, IUserService userService) : base(container, dataContextManager) { _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _blobSettings = blobSettings ?? throw new ArgumentNullException(nameof(blobSettings)); _azureBlobClient = azureBlobClient ?? throw new ArgumentNullException(nameof(azureBlobClient)); _permissionHelper = permissionHelper ?? throw new ArgumentNullException(nameof(permissionHelper)); }
public Task OnExecuteAsync(CommandLineApplication app) { var showHelp = string.IsNullOrWhiteSpace(BlobName) || string.IsNullOrWhiteSpace(FileToUpload) || string.IsNullOrWhiteSpace(ContainerName) || string.IsNullOrWhiteSpace(ConnectionString); if (showHelp) { app.ShowHelp(); return(Task.CompletedTask); } var blobClient = new AzureBlobClient(ConnectionString, ContainerName, _logger); return(blobClient.UploadBlobAsync(BlobName, FileToUpload)); }
public Task OnExecuteAsync(CommandLineApplication app) { var showHelp = string.IsNullOrWhiteSpace(BlobName) || string.IsNullOrWhiteSpace(ContainerName) || string.IsNullOrWhiteSpace(ConnectionString) || string.IsNullOrWhiteSpace(DownloadFilePath); if (showHelp) { app.ShowHelp(); return(Task.CompletedTask); } var blobClient = new AzureBlobClient(ConnectionString, ContainerName, _logger); return(Enum.TryParse <DownloadStrategies>(DownloadStrategy, out var strategy) ? blobClient.DownloadBlobAsync(BlobName, DownloadFilePath, strategy) : blobClient.DownloadBlobAsync(BlobName, DownloadFilePath)); }
public async Task when_put_blob_request_then_response_should_be_ok() { //Given var fakeHttpMessageHandler = new FakeHttpMessageHandler(new HttpResponseMessage(HttpStatusCode.OK)); var httpClient = new HttpClient(fakeHttpMessageHandler); var apiHandler = Substitute.For <IAzureStorageHandler>(); apiHandler.GetRequest(Arg.Is(StorageType.Blob), Arg.Is(HttpMethod.Put), Arg.Any <string>(), Arg.Any <byte[]>()).Returns( x => { return(new HttpRequestMessage(HttpMethod.Put, "http://www.justafake.com/something")); } ); var servant = new AzureBlobClient(apiHandler, httpClient); var content = Encoding.UTF8.GetBytes("arandomstring"); //When var result = await servant.PutBlobAsync("test", "test.jpg", content); //Then result.Equals(true); }
public static async Task Main(string[] Options) { if (Options.Length < 3 || (Options.Length > 0 && Options[0] == "-h")) { Console.WriteLine("Usage: YarnCacher.exe <absolute-path-to-package.json> <azure-storage-access-key> <azure-blob-container-name> <OPTIONAL: absolute-path-to-yarn>"); return; } Console.WriteLine(" *** YarnCacher for Azure @ https://github.com/bl4y/YarnCacher *** "); Console.WriteLine("Fetching Yarn cache directory..."); string YarnCachePath = string.Empty; Process YarnCacheProcess = Process.Start(new ProcessStartInfo("cmd", "/c " + (Options.Length == 4 ? Options[4] : "yarn") + " cache dir") { WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true }); YarnCacheProcess.WaitForExit(); YarnCachePath = YarnCacheProcess.StandardOutput.ReadToEnd().TrimEnd('\r', '\n'); try { Path.GetFullPath(YarnCachePath); } catch { Console.WriteLine(" > Invalid Yarn cache directory. Make sure Yarn is added to PATH or specify Yarn path in arguments. More info: YarnCacher.exe -h"); return; } Console.WriteLine(" > Yarn cache directory: " + YarnCachePath); Console.WriteLine("Generating MD5 hash for package.json..."); string PackagePath = Options[0]; string PackageHash = string.Empty; if (!File.Exists(PackagePath)) { Console.WriteLine(" > Invalid package.json path. Please specify full absolute path, including package.json ."); return; } using (MD5 MD5Instance = MD5.Create()) { using (FileStream Stream = File.OpenRead(PackagePath)) { PackageHash = string.Join(string.Empty, MD5Instance.ComputeHash(Stream).Select(x => x.ToString("x2"))); } } Console.WriteLine(" > Hash: " + PackageHash); string CacheArchivePath = Path.Combine(Path.GetDirectoryName(PackagePath), "yarn-pre-cache-" + PackageHash + ".zip"); Console.WriteLine("Accessing Azure..."); CloudBlobClient AzureBlobClient; CloudBlobContainer AzureBlobContainer; CloudBlockBlob AzureBlockBlob; try { AzureBlobClient = CloudStorageAccount.Parse(Options[1]).CreateCloudBlobClient(); AzureBlobContainer = AzureBlobClient.GetContainerReference(Options[2]); AzureBlockBlob = AzureBlobContainer.GetBlockBlobReference(Path.GetFileName(CacheArchivePath)); } catch (Exception e) { Console.WriteLine(" > Failed to access Azure. Exception message:"); Console.WriteLine(e.Message); return; } Console.WriteLine(" > Connected to Azure."); bool AzureBlockBlobExists = await AzureBlockBlob.ExistsAsync(); if (AzureBlockBlobExists) { Console.WriteLine("Downloading pre-cached archive from Azure..."); await AzureBlockBlob.DownloadToFileAsync(CacheArchivePath, FileMode.CreateNew); Console.WriteLine("Cleaning up..."); DirectoryInfo CacheDirectoryInfo = new DirectoryInfo(YarnCachePath); foreach (FileInfo File in CacheDirectoryInfo.GetFiles()) { File.Delete(); } foreach (DirectoryInfo Directory in CacheDirectoryInfo.GetDirectories()) { Directory.Delete(true); } Console.WriteLine("Uncompressing pre-cached archive..."); ZipFile.ExtractToDirectory(CacheArchivePath, YarnCachePath); File.Delete(CacheArchivePath); } Console.WriteLine("Installing and building Yarn packages..."); Process YarnInstallProcess = Process.Start(new ProcessStartInfo("cmd", "/c " + (Options.Length == 4 ? Options[4] : "yarn") + " install") { WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, WorkingDirectory = Path.GetDirectoryName(PackagePath) }); YarnInstallProcess.WaitForExit(); Console.WriteLine(" > Process output:"); Console.WriteLine(YarnInstallProcess.StandardOutput.ReadToEnd().TrimEnd('\r', '\n')); if (!AzureBlockBlobExists) { Console.WriteLine("Compressing Yarn cache..."); ZipFile.CreateFromDirectory(YarnCachePath, CacheArchivePath); Console.WriteLine("Uploading pre-cached archive to Azure..."); await AzureBlockBlob.UploadFromFileAsync(CacheArchivePath); Console.WriteLine("Cleaning up..."); File.Delete(CacheArchivePath); } Console.WriteLine(" > Finished."); }
static async Task <int> Main(string[] args) { var logCommand = new Command("azlogs", "Download portfolio backend diagnostic log files from an Azure Blob Storage Container") { new Option <int?>("--days", getDefaultValue: () => null, "Only output logs going back this number of days"), new Option <bool>("--today", getDefaultValue: () => false, "Only output logs generated today"), new Option <bool>("--web", getDefaultValue: () => false, "Get web server logs"), new Option <string>("--env", getDefaultValue: () => "LIVE", "The environment to download from. Requires settings for each environment to be configured in appSettings e.g. AzureStorageConnectionString.LIVE & AzureStorageConnectionString.TEST.") }; var fieldDocsCommand = new Command("markdown", "Generate markdown files") { new Option <string>("--file", getDefaultValue: () => "fields", "Generate markdown file for project fields.") }; var rootCommand = new RootCommand("Portfolio utitlies") { logCommand, fieldDocsCommand }; logCommand.Handler = CommandHandler.Create <int?, bool, bool, string>(async(days, today, web, env) => await AzureBlobClient.OutputBlobText(days, today, web, env)); fieldDocsCommand.Handler = CommandHandler.Create <string>(async(file) => await MarkdownGenerator.OutputFile(file)); return(await rootCommand.InvokeAsync(args)); }