private static async Task refineLogs() { StorageConnection conn = new StorageConnection(); string connectionString = "DefaultEndpointsProtocol=https;AccountName=storageaccountgepte86f5;AccountKey=tWMNBa2qlEgVEt6cOnmDbYdsJ0igQmnmJzcJx2d5lxuf0y1iYyMEbkM9n8KlUfPvlSF9Mtc3KE5CrhAWy/fpAg==;EndpointSuffix=core.windows.net"; conn.config = new MyConfig() { StorageConnection = connectionString, Container = "techathoninput" }; conn.Connect(); CloudStorageAccount sAccount = conn.storageAccount; CloudFileClient fileClient = sAccount.CreateCloudFileClient(); CloudFileShare share = fileClient.GetShareReference("scheduledfileconverter91d0"); if (await share.ExistsAsync()) { CloudFileDirectory rootDir = share.GetRootDirectoryReference(); CloudFileDirectory dir = rootDir.GetDirectoryReference(@"LogFiles/Application/Functions/Function/Function"); CloudFile logs = rootDir.GetFileReference("Logs.txt"); if (await dir.ExistsAsync()) { List <IListFileItem> results = new List <IListFileItem>(); FileContinuationToken token = null; do { FileResultSegment resultSegment = await dir.ListFilesAndDirectoriesSegmentedAsync(token); results.AddRange(resultSegment.Results); token = resultSegment.ContinuationToken; }while (token != null); List <CloudFile> files = new List <CloudFile>(); foreach (IListFileItem item in results) { if (item.GetType() == typeof(Microsoft.WindowsAzure.Storage.File.CloudFile)) { files.Add((CloudFile)item); } } string name = ""; foreach (CloudFile file in files) { name = (string.Compare(name, Path.GetFileNameWithoutExtension(file.Name)) > 0) ? name : Path.GetFileNameWithoutExtension(file.Name); } name += ".log"; CloudFile recentFile = dir.GetFileReference(name); string data = await recentFile.DownloadTextAsync(); string[] lines = data.Split("\n"); if (lines.Length < 50) { await logs.UploadTextAsync(data); } else { await logs.UploadTextAsync(string.Join("\n", lines.Skip(lines.Length - 50).ToArray())); } } } }
public Converter() { Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); this.conn = new StorageConnection(); string connectionString = "DefaultEndpointsProtocol=https;AccountName=storageaccountgepte86f5;AccountKey=tWMNBa2qlEgVEt6cOnmDbYdsJ0igQmnmJzcJx2d5lxuf0y1iYyMEbkM9n8KlUfPvlSF9Mtc3KE5CrhAWy/fpAg==;EndpointSuffix=core.windows.net"; conn.config = new MyConfig() { StorageConnection = connectionString, Container = "techathoninput" }; conn.Connect(); }