public DataLakeStorageClient(string accountName, string fileSystem, AzureADSettings azureADSettings) { this.AccountName = accountName; this.AzureADSettings = azureADSettings; AzureADServiceSettings = new ActiveDirectoryServiceSettings { AuthenticationEndpoint = new Uri(string.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/token", azureADSettings.TenantId)), //TokenAudience = new Uri(string.Format("https://{0}{1}/", accountName, SUFFIX)), TokenAudience = new Uri("https://storage.azure.com"), ValidateAuthority = true }; this.FileSystem = fileSystem; }
static void Main(string[] args) { Console.WriteLine("Hello World!"); string path = "test3.txt"; byte[] content = File.ReadAllBytes(ToApplicationPath("test1.txt")); //var client = new DataLakeStorageClient(ACCOUNT_NAME, ACCOUNT_KEY, FILESYSTEM); var azureADSettings = new AzureADSettings { TenantId = TENANT_ID, ServicePrincipalId = CLIENT_ID, ServicePrincipalSecret = CLIENT_SECRET }; var client = new DataLakeStorageClient(ACCOUNT_NAME, FILESYSTEM, azureADSettings); Console.WriteLine("Creating File"); var res = client.CreateFile(path).Result; Console.WriteLine("StatusCode=" + res.StatusCode); Console.WriteLine("StatusCode=" + res.ToString()); Console.WriteLine("================================"); res.EnsureSuccessStatusCode(); Console.WriteLine("Uploading"); res = client.Append(path, content, "text/csv").Result; Console.WriteLine("StatusCode=" + res.StatusCode); Console.WriteLine("StatusCode=" + res.ToString()); Console.WriteLine("================================"); res.EnsureSuccessStatusCode(); Console.WriteLine("Flushing"); res = client.Flush(path, content.Length).Result; Console.WriteLine("StatusCode=" + res.StatusCode); Console.WriteLine("StatusCode=" + res.ToString()); res.EnsureSuccessStatusCode(); Console.WriteLine("Reading"); res = client.Read(path, 30).Result; Console.WriteLine("StatusCode=" + res.StatusCode); Console.WriteLine("StatusCode=" + res.ToString()); res.EnsureSuccessStatusCode(); var target = ToApplicationPath("test1-" + Guid.NewGuid().ToString() + ".txt"); Console.WriteLine("Writing to =" + target); File.WriteAllBytes(target, res.Content.ReadAsByteArrayAsync().Result); }