public static void StatusReport(string report) { string logmsg = string.Format("{0}\n{1}\n", DateTime.Now.ToString(), report); BlobStorage bs = new BlobStorage(); byte[] bytes = Encoding.UTF8.GetBytes(report); bs.put_blob("events", "events.rpt", new Hashtable(), bytes, null); }
public AzureStorage() { var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString"); StorageAccount = CloudStorageAccount.Parse(connectionString); Blob = new BlobStorage(StorageAccount); Table = new TableStorage(StorageAccount); }
public void Test_CanUploadRetrieveDeleteTextBlob() { var storage = new BlobStorage(account, _containerName); Assert.IsTrue(storage.Create()); const string dataContent = "data content"; Assert.IsTrue(storage.UploadText("test.txt", dataContent)); string content = storage.Download("test.txt"); Assert.AreEqual(dataContent, content); Assert.IsTrue(storage.Delete("test.txt")); Assert.IsTrue(storage.Delete()); }
public void ListBlobsInContainerShouldSucceed() { var blobContainerToEnumerage = new BlobStorage(EndpointUrl, ContainerToEnumerate, Account, Key); blobContainerToEnumerage.CreateBlockBlob("restteststringblob", "hello World"); blobContainerToEnumerage.CreateBlockBlob("restteststringblobtwo", "hello World again"); var results = blobContainerToEnumerage.ListBlobsInContainer().ToList<string>(); Assert.True(results.Count == 2); blobContainerToEnumerage.DeleteBlobContainer(); }
public Replicate(CloudStorageAccount source, CloudStorageAccount target, string backupName) { this.Source = new Repository(source); this.Target = new Repository(target); this.Blobs = new BlobStorage(this); if (backupName == null) { this.BackupName = string.Format("{0}{1}{2}", this.backupPrefix, source.Credentials.AccountName, DateTime.UtcNow.Ticks); } else { this.BackupName = backupName; } }
public static void SaveManifestToAzureStorage(AppManifestBase appManifest) { var azureStorageInfo = appManifest.GetAzureStorageInfo(); if (azureStorageInfo == null) { return; } var blobStorage = new BlobStorage(azureStorageInfo.Account, azureStorageInfo.AccountKey, azureStorageInfo.Container); var js = new JavaScriptSerializer(); var json = js.Serialize(appManifest); blobStorage.UploadText(json, "manifest.json"); }
/// <summary> /// Saves sitedefinition.json to Azure storage /// </summary> /// <param name="siteCreator"></param> public static void SaveSiteDefinitionToAzureStorage(SiteDefinition siteCreator) { var azureStorageInfo = siteCreator.GetAzureStorageInfo(); if (azureStorageInfo == null) { return; } var blobStorage = new BlobStorage(azureStorageInfo.Account, azureStorageInfo.AccountKey, azureStorageInfo.Container); var js = new JavaScriptSerializer(); var json = js.Serialize(siteCreator); blobStorage.UploadText(json, "sitedefinition.json"); }
private static object GetWall(string wallId) { var meta = TableStorage.GetEntity <Walls>(Constants.TableNames.Walls, wallId, wallId); string Title = "Untitled Wall"; if (meta == null) { _log.Warning($"The metadata for {wallId} in the Wall table was not found and should exist."); } else { Title = meta.Title; } return(new { BlobStorage.GetWall(wallId).Messages, Title }); }
public bool DeleteExecute() { MessageBoxResult messageresult = MessageBox.Show("Esta seguro que desea eliminar a " + JugadorDelete.Nombre_Completo + " del equipo: " + EquipoJugador.Nombre + '?', "Advertencia", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (messageresult == MessageBoxResult.Yes) { if (!JugadorDelete.Foto.Equals("/Assets/equipodefecto.jpg")) { string[] blobreference = JugadorDelete.Foto.Split('/'); BlobStorage.EliminarImagen(blobreference[blobreference.Length - 1], JugadorDelete); } ApiRest.DeleteteJugador(JugadorDelete.Id); return(true); } return(false); }
public void NonexistingFeedCacheYieldsCachedAndValidIcsAndObj() { var example = "hillside"; var feedurl = BlobStorage.MakeAzureBlobUri("admin", example + ".ics", false).ToString(); Utils.PurgeFeedCacheForHub(calinfo_berkeley.id); AfternoonTeaAt3PMLocal(); // process the hillside example var ics_cached_uri = GetFeedCacheUri(GetFeedIcsCacheName(feedurl)); var cached_ics = Utils.GetCachedFeedText(feedurl); Assert.That(cached_ics != ""); // should exist now var obj_blob_name = Utils.MakeCachedFeedObjName(berkeley_test_hub, feedurl); var es_zoned = Utils.GetFeedObjFromCache(calinfo_berkeley, feedurl); // verify obj exists var es_zoneless = EventStore.ZonedToZoneless(berkeley_test_hub, calinfo_berkeley, es_zoned); HillsideExampleIsCorrectObj(es_zoneless, null, null); // verify obj correct }
// ********************************************************* // Create a new Blob in a Specific Blob Container // ********************************************************* public void CreateBlob(string ContainerName, string FileName, string BlobEndPoint, string Account, string SharedKey) { StorageAccountInfo AccountInfo = new StorageAccountInfo(new Uri(BlobEndPoint), null, Account, SharedKey); var blobStore = BlobStorage.Create(AccountInfo); var container = blobStore.GetBlobContainer(ContainerName); BlobProperties props = new BlobProperties(System.IO.Path.GetFileName(FileName)); BlobContents blobContents = new BlobContents(new System.IO.FileStream(FileName, FileMode.Open)); container.CreateBlob(props, blobContents, true); }
public static ImageService GetImageServiceCached(BlobStorageConfig blobStorageConfig, FileStorageConfig fileStorageConfig, MongoDbConfig mongoDbConfig) { BlobStorage blobStorage = new BlobStorage(blobStorageConfig); FileStorage fileStorage = new FileStorage(fileStorageConfig); CachedBlogStorage cachedBlogStorage = new CachedBlogStorage(blobStorage, fileStorage); ImageProcessor imageProcessor = new ImageProcessor(); //ImageDBManager imageDBManager = new ImageDBManager // (new MediaRecordDatabaseContext()); MediaRecordMongoDatabaseContext mongoDbContext = new MediaRecordMongoDatabaseContext(mongoDbConfig); ImageMongoDbManager imageDBManager = new ImageMongoDbManager(mongoDbContext); Core.ImageService imageService = new Core.ImageService( blobStorageConfig, imageProcessor, cachedBlogStorage, imageDBManager ); return(imageService); }
public void Initialize() { account = new Account("UseDevelopmentStorage=true"); // Let's nuke the container, to have clean tests try { var storage = new BlobStorage(account, _containerName); storage.Container.Delete(); } catch (StorageClientException ex) { // we don't care about the exception here, because in most // cases, it will be because the previous test ran perfectly // and the container doesn't exist } }
public async Task Consume(ConsumeContext <GenerateReport> context) { var message = context.Message; var correlationId = message.CorrelationId; var folderId = message.ParentId; var bucket = message.Models.First().Bucket; var userId = message.UserId; var modelBlobId = message.Models.First().BlobId; var blobInfo = await BlobStorage.GetFileInfo(message.SourceBlobId, message.SourceBucket); if (blobInfo.Metadata["case"].Equals("train one model and fail during the report generation")) { await LoadBlob(context, userId, bucket, "FocusSynthesis_InStock.csv", "application/octet-stream", new Dictionary <string, object>() { { "parentId", folderId } }); await LoadBlob(context, userId, bucket, "ML_report.pdf", "application/pdf", new Dictionary <string, object>() { { "parentId", folderId } }); await context.Publish <ReportGenerationFailed>(new { TimeStamp = DateTimeOffset.UtcNow, CorrelationId = correlationId, Message = "Something wrong happened during report generation...", NumberOfGenericFiles = 2 }); } else { await LoadBlob(context, userId, bucket, "FocusSynthesis_InStock.csv", "application/octet-stream", new Dictionary <string, object>() { { "parentId", folderId } }); await LoadBlob(context, userId, bucket, "ML_report.pdf", "application/pdf", new Dictionary <string, object>() { { "parentId", folderId } }); await LoadBlob(context, userId, bucket, "ml-training-image.png", "application/octet-stream", new Dictionary <string, object>() { { "parentId", folderId } }); await context.Publish <ReportGenerated>(new { CorrelationId = correlationId, TimeStamp = DateTimeOffset.UtcNow, NumberOfGenericFiles = 3 }); } }
public async Task Consume(ConsumeContext <OptimizeTraining> context) { var message = context.Message; var correlationId = message.CorrelationId; var bucket = message.SourceBucket; var userId = message.UserId; var blobInfo = await BlobStorage.GetFileInfo(message.SourceBlobId, message.SourceBucket); if (blobInfo.Metadata["case"].Equals("valid one model with success optimization")) { await LoadBlob(context, userId, bucket, "FocusSynthesis_InStock.csv", "application/octet-stream", new Dictionary <string, object>() { { "parentId", context.Message.TargetFolderId }, { "userId", userId } }); await context.Publish <TrainingOptimized>(new { Id = message.Id, CorrelationId = correlationId, UserId = message.UserId, Scaler = "Somebody knows what is Scaler???", SubSampleSize = (decimal)1, TestDataSize = (decimal)0.2, KFold = 4, Fingerprints = new List <IDictionary <string, object> >() { new Dictionary <string, object>() { { "radius", 2 }, { "size", 512 }, { "type", "ecfp" } } } }); } if (blobInfo.Metadata["case"].Equals("train model with failed optimization")) { await context.Publish <TrainingOptimizationFailed>(new { Id = message.Id, CorrelationId = correlationId, UserId = message.UserId, Message = "It`s just test. Nothing personal." }); } }
public async void SpaceReuse() { File.Delete("test.blob"); using (var s = new BlobStorage("test.blob")) { Assert.True(await s.Initialize <AppDomainConcurrencyHandler>(CancellationToken.None)); var data = Enumerable.Range(0, 256).Select(r => (byte)1).ToArray(); var c1 = await s.AddChunk(ChunkTypes.Test, 11, data, CancellationToken.None); Assert.Equal(11u, c1.UserData); Assert.Equal((uint)data.Length, c1.Size); var res = await s.ReadChunks(c => c.Id == c1.Id, CancellationToken.None); Assert.Equal(data, res.First().Data); data = Enumerable.Range(0, 256).Select(r => (byte)2).ToArray(); var c2 = await s.AddChunk(ChunkTypes.Test, 12, data, CancellationToken.None); Assert.Equal(12u, c2.UserData); Assert.Equal((uint)data.Length, c2.Size); res = await s.ReadChunks(c => c.Id == c2.Id, CancellationToken.None); Assert.Equal(data, res.First().Data); s.Info.Refresh(); var size = s.Info.Length; await s.RemoveChunk(sc => sc.Chunks.FirstOrDefault(c => c.Id == c1.Id), CancellationToken.None); data = Enumerable.Range(0, 128).Select(r => (byte)3).ToArray(); var c3 = await s.AddChunk(ChunkTypes.Test, 13, data, CancellationToken.None); Assert.Equal(13u, c3.UserData); Assert.Equal((uint)data.Length, c3.Size); res = await s.ReadChunks(c => c.Id == c3.Id, CancellationToken.None); Assert.Equal(data, res.First().Data); Assert.Equal(size, s.Info.Length); } }
/// <summary> /// Main run method /// </summary> /// <param name="req">HttpRequestMessage</param> /// <param name="log">TraceWriter</param> /// <returns>Result</returns> public static async Task <IActionResult> Run(HttpRequestMessage req, TraceWriter log) { try { log.Info("C# HTTP trigger function processed a request."); var channelSecret = Environment.GetEnvironmentVariable("ChannelSecret"); var events = await req.GetWebhookEventsAsync(channelSecret); var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage"); var eventSourceState = await TableStorage <EventSourceState> .CreateAsync(connectionString, "eventsourcestate"); var blobStorage = await BlobStorage.CreateAsync(connectionString, "linebotcontainer"); // Create the LineBotApp and run it. var app = new LineBotApp(lineMessagingClient, eventSourceState, blobStorage, log); await app.RunAsync(events); } catch (InvalidSignatureException e) { return(new ObjectResult(e.Message) { StatusCode = (int)HttpStatusCode.Forbidden }); } catch (LineResponseException e) { log.Error(e.ToString()); var debugUserId = Environment.GetEnvironmentVariable("DebugUser"); if (debugUserId != null) { await lineMessagingClient.PushMessageAsync(debugUserId, $"{e.StatusCode}({(int)e.StatusCode}), {e.ResponseMessage.ToString()}"); } } catch (Exception e) { log.Error(e.ToString()); var debugUserId = Environment.GetEnvironmentVariable("DebugUser"); if (debugUserId != null) { await lineMessagingClient.PushMessageAsync(debugUserId, e.Message); } } return(new OkObjectResult("OK")); }
public bool DeleteExecute() { MessageBoxResult messageresult = MessageBox.Show("Esta seguro de eliminar a " + ArbitroEliminar.Nombre_Completo + " con DNI: " + ArbitroEliminar.Dni + "?. Los partidos en los que ha participados se verán afectados", "Advertencia", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (messageresult == MessageBoxResult.Yes) { CambiaArbitroDelete(); if (!ArbitroEliminar.Foto.Equals("/Assets/equipodefecto.jpg")) { string[] blobreference = ArbitroEliminar.Foto.Split('/'); BlobStorage.EliminarImagen(blobreference[blobreference.Length - 1], ArbitroEliminar); } ApiRest.DeleteteArbitro(ArbitroEliminar.Id); return(true); } return(false); }
private static ZonelessEventStore ProcessIcalExample(string example, string source, Calinfo calinfo, FeedRegistry fr, Collector collector, bool purge) { DeleteZonedObjects(calinfo.id); if (purge) { Utils.PurgeFeedCacheForHub(calinfo.id); } var feedurl = BlobStorage.MakeAzureBlobUri("admin", example + ".ics", false).ToString(); fr.AddFeed(feedurl, source); var es = new ZonedEventStore(calinfo, SourceType.ical); collector.CollectIcal(fr, es, false); EventStore.CombineZonedEventStoresToZonelessEventStore(calinfo.id, settings); var zes = new ZonelessEventStore(calinfo).Deserialize(); return(zes); }
public void añadirCategoria() { if (!BbddService.ExisteCategoria(nuevaCategoria)) { if (nuevaCategoria.ImagenCategoriaURL != null && nuevaCategoria.ImagenCategoriaURL != "") { string[] rutaFichero = nuevaCategoria.ImagenCategoriaURL.Split('\\'); string urlImagen = BlobStorage.guardarImagen(nuevaCategoria.ImagenCategoriaURL, rutaFichero[rutaFichero.Length - 1]); nuevaCategoria.ImagenCategoriaURL = urlImagen; } BbddService.AddCategoria(nuevaCategoria); vaciarCampos(); } }
public async Task ChemicalProcessing_ValidMol_GenerateExpectedFileEntity() { var startTime = DateTime.UtcNow; var blobInfo = await BlobStorage.GetFileInfo(BlobId, JohnId.ToString()); blobInfo.Should().NotBeNull(); var fileEntityResponse = await JohnApi.GetFileEntityById(FileId); var fileEntity = JsonConvert.DeserializeObject <JObject>(await fileEntityResponse.Content.ReadAsStringAsync()); fileEntity.Should().NotBeNull(); fileEntity.Should().ContainsJson($@" {{ 'id': '{FileId}', 'blob': {{ 'id': '{blobInfo.Id}', 'bucket': '{JohnId}', 'length': {blobInfo.Length}, 'md5': '{blobInfo.MD5}' }}, 'subType': '{FileType.Records}', 'ownedBy': '{JohnId}', 'createdBy': '{JohnId}', 'createdDateTime': '{startTime}', 'updatedBy': '{JohnId}', 'updatedDateTime': '{startTime}', 'parentId': '{JohnId}', 'name': '{blobInfo.FileName}', 'status': '{FileStatus.Processed}', 'version': *EXIST*, 'totalRecords': 1, 'properties': {{ 'fields': [ 'StdInChI', 'StdInChIKey', 'SMILES' ], 'chemicalProperties': *EXIST* }} }}" ); }
public static void CombineZonedEventStoresToZonelessEventStore(string id, Dictionary <string, string> settings) { var bs = BlobStorage.MakeDefaultBlobStorage(); var calinfo = new Calinfo(id); var lists_of_zoned_events = new List <List <ZonedEvent> >(); var ical_uri = BlobStorage.MakeAzureBlobUri(container: id, name: id + "." + SourceType.ical + ".zoned.obj", use_cdn: false); DeserializeZoned(ical_uri, lists_of_zoned_events); //if (calinfo.hub_type == HubType.where.ToString()) if (calinfo.hub_enum == HubType.where) { Uri non_ical_uri; //foreach (var type in non_ical_types) foreach (NonIcalType type in Enum.GetValues(typeof(CalendarAggregator.NonIcalType))) { if (Utils.UseNonIcalService(type, settings, calinfo) == false) { continue; } non_ical_uri = BlobStorage.MakeAzureBlobUri(container: id, name: id + "." + type + ".zoned.obj", use_cdn: false); if (BlobStorage.ExistsBlob(non_ical_uri)) // // might not exist, e.g. if facebook=no in hub metadata { DeserializeZoned(non_ical_uri, lists_of_zoned_events); } } } var es_zoneless = new ZonelessEventStore(calinfo); // combine the various List<ZonedEvent> objects into our new ZonelessEventStore // always add the local time foreach (var list in lists_of_zoned_events) { foreach (var evt in list) { es_zoneless.AddEvent(evt.title, evt.url, evt.source, evt.lat, evt.lon, evt.dtstart.LocalTime, evt.dtend.LocalTime, evt.allday, evt.categories, evt.description, evt.location); } } ZonelessEventStore.Finalize(calinfo, es_zoneless); }
private async static Task <HttpResponseMessage> UpdateWall(HttpRequestMessage req, string wallId) { var name = ""; var nameId = ""; if (IsAuthenticated && auth != null) { name = auth.GetClaim(ClaimTypes.GivenName).Value; nameId = auth.GetClaim(ClaimTypes.NameIdentifier).Value; } var wall = BlobStorage.GetWall(wallId); if (wall == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } var message = await req.Content.ReadAsStringAsync(); var wallMessage = new Message { Text = message, Username = name, NameId = nameId }; wall.Messages.Add(wallMessage); var wallPath = string.Format($"{wallId}/wall"); var block = BlobStorage.GetBlob(Constants.BlobContainerNames.Wall, wallPath); var json = JsonConvert.SerializeObject(wall); block.UploadText(json); wallMessage.SendToSlack(wallId); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(json) }; return(response); }
static async void TestUploadBinaryAsync() { BlobStorageConfig config = BlobStorageConfig.GetConfig("C:/Users/t-chwang/source/repos/ImageServingPlatform/Core/config.json"); BlobStorage blobStorage = new BlobStorage(config); ImageProcessor imageProcessor = new ImageProcessor(); ImageDBManager imageDBManager = new ImageDBManager(new MediaRecordDatabaseContext()); ImageService imageService = new ImageService(config, imageProcessor, blobStorage, imageDBManager); FileStream fs = new FileStream("C:/Users/t-chwang/source/repos/ImageServingPlatform/Core/Resource/testpic/github-octocat.png", FileMode.Open); byte[] fileContent = new BinaryReader(fs).ReadBytes((int)fs.Length); Console.WriteLine(fileContent.Length); fs.Close(); await imageService.UploadBinaryAsync(fileContent, "abc.png"); Console.WriteLine("End of TestUploadBinaryAsync. "); }
/// <summary> /// Reads the stream. /// </summary> /// <param name="blobInfo">The BLOB info.</param> /// <returns></returns> public override System.IO.Stream ReadStream(BlobInfo blobInfo) { Stream stream = null; try { BlobStorage.RaiseReadingEvent(blobInfo); GetObjectRequest request = new GetObjectRequest(_Service, this.BucketName, blobInfo.Uid.ToString(), false); GetObjectResponse response = request.GetResponse(); stream = response.GetResponseStream(); BlobStorage.RaiseReadedEvent(blobInfo); } catch (Exception exception) { Trace.WriteLine(exception); throw; } return(stream); }
private async Task FaultTask(string id, string container, string filename, byte[] payload, string contentType, bool canAudit) { AuditRecord record = null; try { BlobStorage storage = BlobStorage.New(connectionString, 2048, 102400); if (blobType == "block") { string[] parts = filename.Split(new char[] { '.' }); string path2 = parts.Length == 2 ? String.Format("{0}-R.{1}", parts[0], parts[1]) : String.Format("{0}-R", filename); await storage.WriteBlockBlobAsync(container, path2, payload, contentType); } else if (blobType == "page") { int pad = payload.Length % 512 != 0 ? 512 - payload.Length % 512 : 0; byte[] buffer = new byte[payload.Length + pad]; Buffer.BlockCopy(payload, 0, buffer, 0, payload.Length); await storage.WritePageBlobAsync(container, filename, buffer, contentType); } else { await storage.WriteAppendBlobAsync(container, filename, payload, contentType); } record = new MessageAuditRecord(id, uri.Query.Length > 0 ? uri.ToString().Replace(uri.Query, "") : uri.ToString(), "AzureBlob", "AzureBlob", payload.Length, MessageDirectionType.Out, true, DateTime.UtcNow); } catch (Exception ex) { Trace.TraceWarning("Retry Blob failed."); Trace.TraceError(ex.Message); record = new MessageAuditRecord(id, uri.Query.Length > 0 ? uri.ToString().Replace(uri.Query, "") : uri.ToString(), "AzureBlob", "AzureBlob", payload.Length, MessageDirectionType.Out, false, DateTime.UtcNow, ex.Message); } finally { if (canAudit) { await auditor?.WriteAuditRecordAsync(record); } } }
public async void AddChunk() { File.Delete("test.blob"); using (var s = new BlobStorage("test.blob")) { Assert.True(await s.Initialize <AppDomainConcurrencyHandler>(CancellationToken.None)); var data = Enumerable.Range(0, 256).Select(r => (byte)1).ToArray(); var c1 = await s.AddChunk(ChunkTypes.Test, 11, data, CancellationToken.None); Assert.Equal(1u, c1.Id); Assert.Equal(11u, c1.UserData); Assert.Equal((uint)data.Length, c1.Size); var res = await s.ReadChunks(c => c.Id == 1, CancellationToken.None); Assert.Equal(data, res.First().Data); } }
public async void Initialization() { File.Delete("test.blob"); using (var s = new BlobStorage("test.blob")) { Assert.True(await s.Initialize <AppDomainConcurrencyHandler>(CancellationToken.None)); Assert.True(await s.Initialize <SessionConcurrencyHandler>(CancellationToken.None)); } File.Delete("test.blob"); using (var s = new BlobStorage("test.blob")) { Assert.True(await s.Initialize <AppDomainConcurrencyHandler>(CancellationToken.None)); using (var s1 = new BlobStorage("test.blob")) { Assert.True(await s1.Initialize <AppDomainConcurrencyHandler>(CancellationToken.None)); } } File.Delete("test2.blob"); File.WriteAllText("test2.blob", "ab"); using (var s = new BlobStorage("test2.blob")) { Assert.False(await s.Initialize <AppDomainConcurrencyHandler>(CancellationToken.None)); } File.Delete("test2.blob"); File.WriteAllText("test2.blob", "ABCD234 "); using (var s = new BlobStorage("test2.blob")) { Assert.False(await s.Initialize <AppDomainConcurrencyHandler>(CancellationToken.None)); } File.Delete("test2.blob"); File.WriteAllText("test2.blob", "BLOB234 "); using (var s = new BlobStorage("test2.blob")) { Assert.False(await s.Initialize <AppDomainConcurrencyHandler>(CancellationToken.None)); } }
protected async Task <Guid> UploadModel(string bucket, string fileName, IDictionary <string, object> metadata = null) { var blobId = await AddBlob(bucket, fileName, metadata); var blobInfo = await BlobStorage.GetFileInfo(blobId, bucket); await Bus.Publish <BlobLoaded>(new { BlobInfo = new LoadedBlobInfo(blobId, fileName, blobInfo.Length, JohnId, blobInfo.UploadDateTime, blobInfo.MD5, bucket, blobInfo.Metadata), TimeStamp = DateTimeOffset.UtcNow }); if (!Harness.Published.Select <ModelPersisted>(e => e.Context.Message.BlobId == blobId).Any()) { throw new TimeoutException(); } return(blobId); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) { string serverCallId = req.Query["serverCallId"]; if (string.IsNullOrEmpty(serverCallId)) { return(new BadRequestObjectResult("`serverCallId` not set")); } var storageClient = new BlobStorage(log, Settings.GetRecordingStoreConnectionString(), Settings.GetRecordingStoreContainerName()); var response = new ListRecordingsResponse { Blobs = storageClient.GetBlobNames($"call_{serverCallId}") }; return(new OkObjectResult(JsonConvert.SerializeObject(response))); }
/// <summary> /// Adds an instance of Azure Blob storage as a singleton, using managed user config to setup. Requires the instance /// name, TenantId and SubscriptionId to be supplied. /// NOTE - will create the container if it doesn't already exist. /// </summary> /// <param name="services">The services to extend.</param> /// <param name="key">The key to use when looking up the instance from the factory.</param> /// <param name="instanceName">Name of the blob storage instance to connect to.</param> /// <param name="tenantId">Tenant Id the instance lives in.</param> /// <param name="subscriptionId">Subscription Id for the tenant.</param> /// <returns>IServiceCollection.</returns> public static IServiceCollection AddBlobStorageSingletonNamed(this IServiceCollection services, string key, string instanceName, string tenantId, string subscriptionId) { var instance = new BlobStorage(new MsiConfig { InstanceName = instanceName, TenantId = tenantId, SubscriptionId = subscriptionId, CreateFolderIfNotExists = true }); if (!key.IsNullOrEmpty()) { instance.Name = key; } services.AddSingleton <IBlobStorage>(instance); services.AddFactoryIfNotAdded <IBlobStorage>(); return(services); }
public AppManifestBase MigrateFromFileSystemToAzure(AppManifestBase manifest, string storageAccount, string accountKey) { var js = new JavaScriptSerializer(); //clone the manifest var migratedManifest = js.Deserialize <AppManifestBase>(js.Serialize(manifest)); var containerName = migratedManifest.ManifestName.ToLower().Replace(' ', '-'); if (!containerName.Replace("-", "").All(char.IsLetterOrDigit)) { throw new InvalidOperationException(containerName + " is not valid."); } var blobStorage = new BlobStorage(storageAccount, accountKey, migratedManifest.ManifestName.ToLower().Replace(' ', '-')); OnVerboseNotify("Connected to Azure storage"); migratedManifest.StorageType = StorageTypes.AzureStorage; if (migratedManifest.FileCreators != null && migratedManifest.FileCreators.Count > 0) { foreach (var fileCreator in migratedManifest.FileCreators) { //Wiki pages don't have actual files to upload if (fileCreator.Value.ContentType != "Wiki Page") { var blobName = fileCreator.Value.Url; blobStorage.UploadFromFile(manifest.BaseFilePath + fileCreator.Value.RelativeFilePath, blobName); OnVerboseNotify("Migrated " + blobName); } } } migratedManifest.BaseFilePath = containerName; blobStorage.UploadText(js.Serialize(migratedManifest), "manifest.json"); return(migratedManifest); }
public async Task FileSharing_ListOfSharedFiles_ContainsExpectedFileNode() { var blobInfo = await BlobStorage.GetFileInfo(BlobId, JohnId.ToString()); blobInfo.Should().NotBeNull(); var fileEntityResponse = await JohnApi.GetSharedFiles(); var sharedInfo = JsonConvert.DeserializeObject <JArray>(await fileEntityResponse.Content.ReadAsStringAsync()); var fileNode = sharedInfo.Last(); fileNode.Should().NotBeNull(); fileNode.Should().ContainsJson($@" {{ 'id': '{FileId}', 'type': 'File', 'blob': {{ 'id': '{blobInfo.Id}', 'bucket': '{JohnId}', 'length': {blobInfo.Length}, 'md5': '{blobInfo.MD5}' }}, 'subType': '{FileType.Records}', 'ownedBy': '{JohnId}', 'createdBy': '{JohnId}', 'createdDateTime': '{DateTime.UtcNow}', 'updatedBy': '{JohnId}', 'updatedDateTime': '{DateTime.UtcNow}', 'parentId': '{JohnId}', 'name': '{blobInfo.FileName}', 'status': '{FileStatus.Processed}', 'version': *EXIST*, 'totalRecords': 1, 'accessPermissions': {{ 'id': '{FileId}', 'isPublic': 'True', 'users': *EXIST*, 'groups': *EXIST* }} }}" ); }
public async static void Run([QueueTrigger("watermarkqueue", Connection = "")] PictureWaterMarkQueque myQueueItem, ILogger log) { try { // AzureStorageConstant.AzureStorageConnectionString = "AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"; IBlobStorage blobStorage = new BlobStorage(); INoSqlStorage <UserPicture> noSqlStorage = new TableStorage <UserPicture>(); foreach (var item in myQueueItem.Pictures) { using var stream = await blobStorage.DownloadAsync(item, EContainerName.pictures); using var memoryStream = AddWaterMark(myQueueItem.WatermarkText, stream); await blobStorage.UploadAsync(memoryStream, item, EContainerName.watermarkpictures); log.LogInformation($"{item} Pictures added for watermark."); } var userpicture = await noSqlStorage.Get(myQueueItem.UserId, myQueueItem.UserPartitionKey); if (userpicture.WatermarkRawPaths != null) { myQueueItem.Pictures.AddRange(userpicture.WatermarkPaths); } userpicture.WatermarkPaths = myQueueItem.Pictures; await noSqlStorage.Add(userpicture); HttpClient httpClient = new HttpClient(); var response = await httpClient.GetAsync("https://localhost:44392/api/Notifications/CompleteWatermarkProcess/" + myQueueItem.ConnectionId); log.LogInformation($"Client({myQueueItem.ConnectionId}) my process complate."); } catch (Exception e) { Console.WriteLine(e.Message); } }
public async Task <IHttpActionResult> PostPin(Incident incident) { if (incident == null) { return(BadRequest()); } var load = new BlobStorage(); try { var photo = await load.UploadImageToStorage(incident.Photo); var query = db.CREATE_INCIDENT_SP(incident.UserId, incident.Name, incident.Latitude, incident.Longitude, incident.Secure, photo, incident.Description, incident.Help); return(Ok()); }catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void ConfigureServices(IServiceCollection services) { // Set up IOptions and populate AzureStorageConfig from configuration services.AddOptions(); services.Configure <AzureStorageConfig>(Configuration.GetSection("AzureStorageConfig")); // Wire up a single instance of BlobStorage, calling Initialize() when we first use it. services.AddSingleton <IStorage>(serviceProvider => { var blobStorage = new BlobStorage(serviceProvider.GetService <IOptions <AzureStorageConfig> >()); blobStorage.Initialize().GetAwaiter().GetResult(); return(blobStorage); }); services.AddMvc(); services.AddAzureClients(builder => { builder.AddBlobServiceClient(Configuration["ConnectionStrings:CONNECTIONSTRING:blob"], preferMsi: true); builder.AddQueueServiceClient(Configuration["ConnectionStrings:CONNECTIONSTRING:queue"], preferMsi: true); }); }
public void Test_CanUploadRetrieveDeleteXMLBlob() { var storage = new BlobStorage(account, _containerName); Assert.IsTrue(storage.Create()); XDocument xml = new XDocument( new XComment("This is a comment"), new XElement("Root", new XElement("Child1", "data1"), new XElement("Child2", "data2"), new XElement("Child3", "data3"), new XElement("Child2", "data4"), new XElement("Info5", "info5"), new XElement("Info6", "info6"), new XElement("Info7", "info7"), new XElement("Info8", "info8") ) ); Assert.IsTrue(storage.UploadXml("test.xml", xml)); XDocument content = storage.DownloadXml("test.xml"); Assert.AreEqual(xml.ToString(), content.ToString()); Assert.IsTrue(storage.Delete("test.xml")); Assert.IsTrue(storage.Delete()); }
public void Test_CanCreateAndDeleteContainer() { var storage = new BlobStorage(account, _containerName); Assert.IsTrue(storage.Create()); Assert.IsTrue(storage.Delete()); }
public void Test_CanInstantiateFromConnectionString() { var storage = new BlobStorage("UseDevelopmentStorage=true", "test"); Assert.IsNotNull(storage.Account.Instance); }
public void DeleteContainerShouldSucceed() { var blobContainerToDelete = new BlobStorage(EndpointUrl, ContainerToDelete, Account, Key); var result = blobContainerToDelete.DeleteBlobContainer(); Assert.True(result.StatusCode == HttpStatusCode.Accepted); }
public void Test_CanInstantiateFromAccount() { var account = new Account("UseDevelopmentStorage=true"); var storage = new BlobStorage(account, "test"); Assert.IsNotNull(storage.Account.Instance); }
public void Test_CanUploadRetrieveDeleteBinaryBlob() { var storage = new BlobStorage(account, _containerName); Assert.IsTrue(storage.Create()); byte[] dataContent = new byte[] { 1, 2, 3 }; const string fileName = "test.bin"; Assert.IsTrue(storage.UploadBinary(fileName, dataContent, "binary/binary")); byte[] content = storage.DownloadBinary(fileName); for (int i = 0; i < 3; i++) { Assert.AreEqual(dataContent[i], content[i]); } Assert.IsTrue(storage.Delete(fileName)); Assert.IsTrue(storage.Delete()); }
public BlobStorageTests() { blobStorage = new BlobStorage(EndpointUrl, ContainerName, Account, Key); }