Created
March 16, 2022 14:59
-
-
Save geralexgr/f1a4f6ab8fd8a3a2c03f3f0e93d3139b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using System.Configuration; | |
using System.Collections.Generic; | |
using System.Net; | |
using System.Timers; | |
using Azure.Storage.Blobs; | |
using Azure.Storage.Blobs.Models; | |
using System; | |
using System.IO; | |
using System.Threading.Tasks; | |
using System.Text; | |
using storageaccount; | |
using Newtonsoft.Json; | |
public class Program | |
{ | |
public static readonly string BlobConnectionString = "" | |
public static readonly string containerName = "application"; | |
public static readonly string fileName = "locations.json"; | |
static async Task Main(string[] args) | |
{ | |
//await RetrieveBlobContents(); | |
while (true) | |
{ | |
Thread.Sleep(5000); | |
await WriteContentOnBlob(); | |
} | |
} | |
private static async Task RetrieveBlobContents() | |
{ | |
BlobServiceClient blobServiceClient = new BlobServiceClient(BlobConnectionString); | |
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName); | |
BlobClient blobClient = containerClient.GetBlobClient(fileName); | |
var response = await blobClient.DownloadAsync(); | |
using (var streamReader = new StreamReader(response.Value.Content)) | |
{ | |
while (!streamReader.EndOfStream) | |
{ | |
var line = await streamReader.ReadLineAsync(); | |
Console.WriteLine(line); | |
} | |
} | |
} | |
private static async Task WriteContentOnBlob() | |
{ | |
BlobServiceClient blobServiceClient = new BlobServiceClient(BlobConnectionString); | |
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName); | |
BlobClient blobClient = containerClient.GetBlobClient(fileName); | |
Directory.CreateDirectory("./data"); | |
string localPath = "./data/"; | |
Random rnd = new Random(); | |
Double _longtitude = rnd.NextDouble(); | |
Double _latitude = rnd.NextDouble(); | |
Location blobLocation = new Location(); | |
blobLocation.Latitude = _latitude; | |
blobLocation.Longitude = _longtitude; | |
string json = JsonConvert.SerializeObject(blobLocation); | |
//blobClient.write(json); | |
string localFilePath = Path.Combine(localPath, fileName); | |
await File.WriteAllTextAsync(localFilePath, json); | |
await blobClient.UploadAsync(localFilePath, true); | |
Console.WriteLine("Latitude: {0} Longtitude: {1} ",_latitude,_longtitude); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment