/// <summary> /// Gets the current gameweek from persistent storage /// </summary> /// <returns>The currently active gameweek retriveed from persistent storage</returns> internal int GetGameweek() { this.logger.Log("Loading current gameweek Id from persistent storage"); this.gameweek = this.useAzure ? int.Parse(gameweekBlob.DownloadText()) : int.Parse(File.ReadAllText(this.gameweekPath)); return(this.gameweek); }
public static string downloadMcellOutput_Click(string userId, string jobId) { //Conexion para acceder a la cuenta de almacenamiento CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(VariablesConfiguracion.containerName); CloudBlobContainer publicContainer = blobClient.GetContainerReference(VariablesConfiguracion.publicContainerName); //Se obtiene la salida de MCell con los ids correspondientes string blobName = VariablesConfiguracion.mcellOutput.Replace("ID", userId + "." + jobId); CloudBlockBlob blob = container.GetBlockBlobReference(blobName); string result = ""; if (blob.Exists()) { string mcellOutput = blob.DownloadText(); //Se copia el blob al contenedor publico para que pueda ser descargado por el usuario CloudBlockBlob publicBlob = publicContainer.GetBlockBlobReference("SalidaMcell_" + userId + "." + jobId + ".txt"); publicBlob.UploadText(mcellOutput); result = publicBlob.Uri.AbsoluteUri; } return(result); }
public static string downloadJobMDL_Click(string userId, string jobId) { //Conexion para acceder a la cuenta de almacenamiento CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(VariablesConfiguracion.containerName); CloudBlobContainer publicContainer = blobClient.GetContainerReference(VariablesConfiguracion.publicContainerName); string result = ""; string blobName = VariablesConfiguracion.simulationMDL.Replace("ID", userId + "." + jobId); foreach (string value in VariablesConfiguracion.fernetModes.Values) { //Se obtienen los MDLs con los ids correspondientes string aux = blobName; CloudBlockBlob blob = container.GetBlockBlobReference(aux.Replace("MODE", value)); if (blob.Exists()) { string mdl = blob.DownloadText(); //Se copia el blob al contenedor publico para que pueda ser descargado por el usuario CloudBlockBlob publicBlob = publicContainer.GetBlockBlobReference("ArchivoMDL_" + userId + "." + jobId + ".mdl"); publicBlob.UploadText(mdl); result = publicBlob.Uri.AbsoluteUri; break; } } return(result); }
public static void ProcessPdf(string htmlBlobName) { var connectionString = "DefaultEndpointsProtocol=https;AccountName=iconingestmsgstoredev;AccountKey=+3gc0hIrMBDE9l8uJARYjlCZewppkXgoqcGSFVTRcjmSVRwbV6eXtkMFPDzTQK8A/Ksky9t6DzIh/RVPG9RKgw=="; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("pdfgeneration"); container.CreateIfNotExists(); var pdfBlobName = Path.GetFileName(htmlBlobName) + ".pdf"; CloudBlockBlob inputblockBlob = container.GetBlockBlobReference(htmlBlobName); CloudBlockBlob pdfBlockBlob = container.GetBlockBlobReference(pdfBlobName); pdfBlockBlob.Properties.ContentType = "application/pdf"; //var reportHtml = File.ReadAllText(@"Resource\Test.html"); var reportHtml = inputblockBlob.DownloadText(); using (var memStream = new MemoryStream()) { var pdfUtil = new PdfUtil(); pdfUtil.WebURl = @"Resource"; pdfUtil.GeneratePdf(reportHtml, memStream).Wait(); var bytes = memStream.ToArray(); pdfBlockBlob.UploadFromByteArray(bytes, 0, bytes.Length); //pdfBlockBlob.UploadFromStream(memStream); //File.WriteAllBytes(@"C:\temp\test.pdf", memStream.ToArray()); memStream.Flush(); } }
protected void Page_Load(object sender, EventArgs e) { ticketID = Request.QueryString.Get("TicketID"); if (ticketID == null || ticketID.Length == 0) { return; } CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("blobStorageConn")); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container. CloudBlobContainer container = blobClient.GetContainerReference("rpaticketsblob"); // Retrieve reference to a blob named "photo1.jpg". CloudBlockBlob blockBlob = container.GetBlockBlobReference(ticketID); string strTicket = blockBlob.DownloadText(); XmlSerializer serializer = new XmlSerializer(new RPATicket().GetType()); StringReader rdr = new StringReader(strTicket); ticket = (RPATicket)serializer.Deserialize(rdr); }
private static IEnumerable <Article> ReadArticles(CloudBlockBlob blob) { var text = blob.DownloadText(); using (var sr = new StringReader(text)) { string line; var row = 0; while ((line = sr.ReadLine()) != null) { row++; if (row == 1) { continue; } var fields = line.Split(','); yield return(new Article { Name = fields[0], Intro = fields[1], Content = fields[2], ImageUrl = fields[3] }); } } }
// gets ONLY the snippet content public string GetSnippet(string sFileName) { CloudBlockBlob pBlob = this.Container.GetBlockBlobReference(sFileName); string pContents = pBlob.DownloadText(); return(pContents); }
private bool TryGetFromStorage(string url, out string result) { result = null; try { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer blobContainer = blobClient.GetContainerReference("demo-exchanges"); if (blobContainer.CreateIfNotExists()) { Log.Event("Created new blob storage container demo-exchanges"); } CloudBlockBlob blob = blobContainer.GetBlockBlobReference(url); if (blob.Exists()) { result = blob.DownloadText(); return(true); } } catch (Exception ex) { Log.Error(ex); } return(false); }
protected override JObject LoadJson() { string json = _blob.DownloadText(); JObject obj = JObject.Parse(json); return(obj); }
private object LoadBlob(string connectionString, string containerName, string fileName, bool binary) { if ((connectionString != null) && (containerName != null) || (fileName != null)) { var storageAccount = CloudStorageAccount.Parse(connectionString); var blobClient = storageAccount.CreateCloudBlobClient(); var container = blobClient.GetContainerReference(containerName); CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName); if (blockBlob.Exists()) { if (binary) { MemoryStream ms = new MemoryStream(); blockBlob.DownloadToStream(ms); return(ms.GetBuffer()); } else { return(blockBlob.DownloadText()); } } } return(null); }
public string ReadHash(string Hash, string Collection) { string sResult = ""; try { Collection = Collection.ToLower(); string sColl = Collection; switch (Collection) { case "_assets": sColl = "assets"; break; case "_chain": sColl = "chain"; break; default: return(""); } CloudBlobContainer container = blobClient.GetContainerReference(sColl); CloudBlockBlob blockBlob = container.GetBlockBlobReference(Hash); sResult = blockBlob.DownloadText(); } catch { } return(sResult); }
public static HttpResponseMessage Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "v1/azuresearch/performance/blobstorage/serially/repetitions/{repetitions}")] HttpRequestMessage req, int repetitions, ExecutionContext executionContext, TraceWriter log) { List <string> ids = Common.IdsList; DateTime startTime = DateTime.Now; StorageCredentials storageCredentials = new StorageCredentials(CloudConfigurationManager.GetSetting("storageAccountName"), CloudConfigurationManager.GetSetting("storageAccountKey")); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(storageCredentials, useHttps: true); CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient(); CloudBlobContainer cloudBlobContainer = blobClient.GetContainerReference("providers"); List <KyruusDataStructure> providers = new List <KyruusDataStructure>(ids.Count); for (int r = 0; r < repetitions; r++) { foreach (string id in ids) { CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference($"p-2018-11-12-15-00-01-000726-Utc-4d41468f-51d7-4c4f-9698-24b6637b7eb5/{id}.json"); string doc = cloudBlockBlob.DownloadText(); KyruusDataStructure p = JsonConvert.DeserializeObject <KyruusDataStructure>(doc); providers.Add(p); } } return(req.CreateResponse( HttpStatusCode.OK, $"{repetitions} repetitions in {nameof(BlobStorageSerial)}->{executionContext.FunctionName}(): {(DateTime.Now - startTime).TotalMilliseconds}, per repetition {(DateTime.Now - startTime).TotalMilliseconds/repetitions}")); }
/// <summary> /// Gets a balance sheet from Azure storage. /// </summary> /// <param name="date"> Date for which to get the balance sheet. </param> /// <returns> A snapshot. </returns> public Snapshot GetBalanceSheet(DateTime date) { Trace.TraceInformation("Entering AzureRepository.GetCurrentBalanceSheet."); CloudBlobContainer container = GetCloudBlobContainer(); DateTime result; CloudBlockBlob blob = (CloudBlockBlob)container .ListBlobs() .Where(x => DateTime.TryParse(((CloudBlockBlob)x).Name.Split('.')[0], out result)) .Where(x => DateTime.Parse(((CloudBlockBlob)x).Name.Split('.')[0]) <= date) .OrderByDescending(x => ((CloudBlockBlob)x).Properties.LastModified) .First(); string text = blob.DownloadText(); Snapshot snapshot = JsonConvert.DeserializeObject <Snapshot>(text); snapshot.Date = DateTime.Parse(blob.Name.Split('.')[0]); CloudBlockBlob targets = container.GetBlockBlobReference(System.Configuration.ConfigurationManager.AppSettings["targets"]); text = targets.DownloadText(); snapshot.Targets = JsonConvert.DeserializeObject <Targ[]>(text); Trace.TraceInformation("Exiting AzureRepository.GetCurrentBalanceSheet."); return(snapshot); }
/// <summary> /// Gets the balance sheets between 2 given dates. /// </summary> /// <param name="start"> Start date. </param> /// <param name="end"> End date. </param> /// <returns> Array of snapshots. </returns> public Snapshot[] GetHistoryBalanceSheets(DateTime start, DateTime end) { Trace.TraceInformation(string.Format("Entering AzureRepository.GetHistoryBalanceSheets with start = {0} and end = {1}.", start.ToString(), end.ToString())); CloudBlobContainer container = GetCloudBlobContainer(); DateTime result; var blobs = container .ListBlobs() .Where(x => DateTime.TryParse(((CloudBlockBlob)x).Name.Split('.')[0], out result)) .Where(x => DateTime.Parse(((CloudBlockBlob)x).Name.Split('.')[0]) >= start && DateTime.Parse(((CloudBlockBlob)x).Name.Split('.')[0]) <= end); int count = blobs.Count(); Snapshot[] snapshots = new Snapshot[count]; for (int i = 0; i < count; i++) { CloudBlockBlob blob = (CloudBlockBlob)blobs.ElementAt(i); string text = blob.DownloadText(); snapshots[i] = JsonConvert.DeserializeObject <Snapshot>(text); snapshots[i].Date = DateTime.Parse(blob.Name.Split('.')[0]); } Trace.TraceInformation("Exiting AzureRepository.GetHistoryBalanceSheets."); return(snapshots); }
public IEnumerable <JObject> GetRawAssets(string paths) { //paths = "*"; //Azure Blob store full assets only CloudBlobContainer container = blobClient.GetContainerReference("assets"); foreach (var bAsset in container.ListBlobs()) { if (bAsset.GetType() == typeof(CloudBlockBlob)) { CloudBlockBlob blob = (CloudBlockBlob)bAsset; JObject jObj = new JObject(); jObj = JObject.Parse(blob.DownloadText()); if (jObj["_hash"] == null) { jObj.Add(new JProperty("_hash", blob.Name)); } yield return(jObj); } else { continue; } } }
public static bool TryReadBlob <T>(CloudBlockBlob blob, out T configurationStore) where T : class { configurationStore = default(T); try { string content = blob.DownloadText(); if (content == Constants.ConfigurationStoreUpdatingText) { return(false); } string blobContent = content; configurationStore = JsonStore <T> .Deserialize(blobContent); return(true); } catch (Exception e) { ReplicatedTableLogger.LogError("Error reading blob: {0}. Exception: {1}", blob.Uri, e.Message); } return(false); }
static private void GetLatestPreProcessedData() { CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=pcldevbgwilkinson01;AccountKey=NPkk2BjPvlG1Am78JrSi4ylEQNB3F6tacE/G8P3x8zLOe/BqZwvYMCXP+ni9KMwmx+px/f+J+n9QJq+v9eVSGg==;BlobEndpoint=https://pcldevbgwilkinson01.blob.core.windows.net/;QueueEndpoint=https://pcldevbgwilkinson01.queue.core.windows.net/;TableEndpoint=https://pcldevbgwilkinson01.table.core.windows.net/;FileEndpoint=https://pcldevbgwilkinson01.file.core.windows.net/"); CloudBlobClient client = storageAccount.CreateCloudBlobClient(); try { List <CloudBlockBlob> rgBlobs = GetAllList(client); if (rgBlobs.Count == 0) { Console.WriteLine(false); return; } CloudBlockBlob blockBlob = rgBlobs[0]; string blobText = blockBlob.DownloadText(); if (File.Exists(@"..\test_files\preprocessed_data.json")) { File.Delete(@"..\test_files\preprocessed_data.json"); } File.WriteAllText(@"..\test_files\preprocessed_data.json", blobText); blockBlob.Delete(); Console.WriteLine(true); } catch (Exception e) { Console.WriteLine("False " + e.Message); } }
public Dictionary <string, string> GetBlobAsync(string blobPrefix = "") { try { Dictionary <string, string> surveys = new Dictionary <string, string>(); // List the blobs in the container. BlobContinuationToken blobContinuationToken = null; do { //var a = BlobList(blobName); //var fileList = cloudFileShare.GetRootDirectoryReference().ListFilesAndDirectories(); //var resultss = await blobContainer.ListBlobsSegmentedAsync(blobName, blobContinuationToken); //var results = await result.ListBlobsSegmentedAsync(blobContinuationToken); // Get the value of the continuation token returned by the listing call. //blobContinuationToken = result.ContinuationToken; var result = blobContainer.GetDirectoryReference(blobPrefix); List <string> blobNames = result.ListBlobs().OfType <CloudBlockBlob>().Select(b => b.Name).ToList(); foreach (string blobName in blobNames) { CloudBlockBlob cloudBlockBlob = blobContainer.GetBlockBlobReference(blobName); var stringResult = cloudBlockBlob.DownloadText(); var key = blobName.Split("/").LastOrDefault(); surveys[key] = stringResult; } } while (blobContinuationToken != null); // Loop while the continuation token is not null. return(surveys); } catch (Exception e) { throw new Exception(e.Message); } }
public Tuple <List <ChunkInfo>, byte[]> GetBlobMetadata(string blobName) { CloudBlockBlob chunkMDblockBlob = GetBlockBlobReference(ChunkMetadataBlobPrefix + blobName); bool blobExists = BlockBlobExists(chunkMDblockBlob); List <ChunkInfo> retVal; byte[] hash; if (blobExists) { string chunkMD_JSON = chunkMDblockBlob.DownloadText(); FileMD fileMD = JsonConvert.DeserializeObject <FileMD>(chunkMD_JSON); SHA1 sha1 = new SHA1CryptoServiceProvider(); hash = sha1.ComputeHash(Encoding.ASCII.GetBytes(chunkMD_JSON)); retVal = fileMD.ChunkList; } else { retVal = null; hash = null; if (!blobName.Equals("stream_md.dat")) { Console.WriteLine("Now: blob exists false for " + chunkMDblockBlob); } } return(new Tuple <List <ChunkInfo>, byte[]>(retVal, hash)); }
static string GetBlobData(CloudBlockBlob cloudBlockBlob) { return(cloudBlockBlob.DownloadText(TextEncoding, new AccessCondition(), new BlobRequestOptions { RetryPolicy = new ExponentialRetry() }, new OperationContext())); }
public static List <Dictionary <string, dynamic> > Download(Blob payload) { var result = new List <dynamic>(); var dictToReturn = new List <Dictionary <string, dynamic> >(); try { CloudBlobContainer container = new CloudBlobContainer(new Uri(payload.SASToken)); int i = 0; int count = payload.FileNames.Count; foreach (var fileName in payload.FileNames) { var dictToCollection = new Dictionary <string, dynamic>(); CloudBlockBlob blob = container.GetBlockBlobReference(fileName); var obj = JsonConvert.DeserializeObject <object>(blob.DownloadText()); dictToCollection.Add(fileName, obj); dictToReturn.Add(dictToCollection); WriteProgress(i++, count); } } catch (StorageException ex) { ConsoleHelper.WriteException(ex); } return(dictToReturn); }
public IEnumerable <InvocationDetails> MethodInfoToInvocations(MethodInfo methodInfo) { string functionDefinitionId = MethodInfoToFunctionDefinitionId(methodInfo); if (functionDefinitionId == null) { yield break; } IEnumerable <IListBlobItem> invocationIndices = _dashboardContainer.ListBlobs( FunctionsByFunctionIndexPrefix + functionDefinitionId, useFlatBlobListing: true); foreach (CloudBlockBlob invocationIndexBlob in invocationIndices.OfType <CloudBlockBlob>()) { string invocationId = invocationIndexBlob.Name.Split('_').Last(); CloudBlockBlob invocationBlob = _dashboardContainer.GetBlockBlobReference(FunctionsInstancesIndexPrefix + invocationId); if (!invocationBlob.Exists()) { continue; } string blobContent = invocationBlob.DownloadText(); yield return(JsonConvert.DeserializeObject <InvocationDetails>(blobContent)); } }
public string AssemblyToHostId(Assembly assembly) { if (assembly == null) { throw new ArgumentNullException("assembly"); } if (!_hostsContainer.Exists()) { return(null); } CloudBlockBlob hostBlob = _hostsContainer.GetBlockBlobReference(string.Format(HostIdsIndexPrefix + "/{0}/{1}", _storageAccount.Credentials.AccountName, assembly.FullName)); if (!hostBlob.Exists()) { return(null); } string hostId = hostBlob.DownloadText(); return(string.IsNullOrWhiteSpace(hostId) ? null : hostId); }
protected override T ReadObject(CloudBlockBlob blob) { return(new JavaScriptSerializer() { MaxJsonLength = int.MaxValue }.Deserialize <T>(blob.DownloadText())); }
public static GithubStatus Retrieve(CloudBlockBlob githubStatusBlob) { var output = new GithubStatus(); // get the "Last Modified" date value from the config file stored in blob storage string json = ""; if (githubStatusBlob.Exists() == true) { json = githubStatusBlob.DownloadText(); } else { json = "{ events_last_modified: \"" + DateTime.UtcNow.AddDays(-3).ToString("ddd, dd MMM yyyy hh:mm:ss 'GMT'") + "\", followees_etag: null }"; } output.Raw = JsonConvert.DeserializeObject <dynamic>(json); output.EventsLastModified = DateTime.Parse(output.Raw.events_last_modified.Value); output.FolloweesEtag = output.Raw.followees_etag.Value; if (output.Raw.followees == null) { output.Followees = new List <GithubFollowee>(); } else { output.Followees = output.Raw.followees.ToObject <List <GithubFollowee> >(); } return(output); }
public string GetStringFromBlobStorage(string ContainerName, string BlobName) { GetContainer(ContainerName); CloudBlockBlob blockBlob = BlobContainer.GetBlockBlobReference(BlobName); blockBlob.FetchAttributes(); return(blockBlob.DownloadText()); }
private Product GetProductFromCloudBlockBlob(CloudBlockBlob blob) { string json = blob.DownloadText(Encoding.UTF8); var product = JsonConvert.DeserializeObject <Product>(json); return(product); }
public string Read(string caminho) { CloudBlockBlob blockBlob = container.GetBlockBlobReference(caminho); var conteudo = blockBlob.DownloadText(); return(conteudo); }
public string Get(string path) { var blobIdent = BlobResource.Parse(_rootUri, path); CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(blobIdent.Id); string content = blob.DownloadText(); return(content); }
public void GetSasToken() { var sasuri = TokenGenerator.GetBlobSasUri(Container, "messageType/queue/2015-06-20/filename_21-58-40_fc5ebd3b-ca42-41fb-abec-842db13ccd4b.xml"); CloudBlockBlob cloudBlockBlob = new CloudBlockBlob(new Uri(sasuri)); string text = cloudBlockBlob.DownloadText(); }