Skip to content
This repository was archived by the owner on Oct 26, 2023. It is now read-only.

Commit a38bbd6

Browse files
committed
various codefixes
1 parent 6d0d3d1 commit a38bbd6

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

ServerlessMapReduce.v2/Sample.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static async Task<HttpResponseMessage> StartAsync([HttpTrigger(Authorizat
2626
{
2727
// retrieve storage blobs URI of the taxi dataset
2828
var pathString = req.RequestUri.ParseQueryString()[@"path"] ?? throw new ArgumentNullException(@"required query string parameter 'path' not found");
29-
Uri path = new Uri(pathString);
29+
var path = new Uri(pathString);
3030

3131
var containerUrl = path.GetLeftPart(UriPartial.Authority) + "/" + path.Segments[1];
3232
var prefix = string.Join(string.Empty, path.Segments.Skip(2));
@@ -66,7 +66,7 @@ public static async Task<string> BeginMapReduce([OrchestrationTrigger]IDurableOr
6666
context.SetCustomStatus(new { status = @"Creating mappers", files });
6767
}
6868
//create mapper tasks which download and calculate avg speed from each csv file
69-
Task<double[]>[] tasks = new Task<double[]>[files.Length];
69+
var tasks = new Task<double[]>[files.Length];
7070
for (var i = 0; i < files.Length; i++)
7171
{
7272
tasks[i] = context.CallActivityAsync<double[]>(
@@ -108,13 +108,12 @@ public static async Task<string> BeginMapReduce([OrchestrationTrigger]IDurableOr
108108
/// </summary>
109109
[FunctionName(nameof(GetFileListAsync))]
110110
public static async Task<string[]> GetFileListAsync(
111-
[ActivityTrigger] string[] paras,
112-
ILogger log)
111+
[ActivityTrigger] string[] paras)
113112
{
114-
CloudBlobContainer cloudBlobContainer = new CloudBlobContainer(new Uri(paras[0]));
113+
var cloudBlobContainer = new CloudBlobContainer(new Uri(paras[0]));
115114

116115
var blobs = Enumerable.Empty<IListBlobItem>();
117-
BlobContinuationToken continuationToken = default(BlobContinuationToken);
116+
var continuationToken = default(BlobContinuationToken);
118117
do
119118
{
120119
var segmentBlobs = await cloudBlobContainer.ListBlobsSegmentedAsync(paras[1], continuationToken);
@@ -139,8 +138,10 @@ public static async Task<IEnumerable<double>> MapperAsync(
139138
var numberOfLogsPerDayOfWeek = new int[7];
140139

141140
// download blob file
141+
#pragma warning disable IDE0067 // Dispose objects before losing scope
142142
// Don't wrap in a Using because this was causing occasional ObjectDisposedException errors in v2 executions
143-
StreamReader reader = new StreamReader(await _httpClient.GetStreamAsync(fileUri));
143+
var reader = new StreamReader(await _httpClient.GetStreamAsync(fileUri));
144+
#pragma warning restore IDE0067 // Dispose objects before losing scope
144145

145146
var lineText = string.Empty;
146147
// read a line from NetworkStream
@@ -156,10 +157,10 @@ public static async Task<IEnumerable<double>> MapperAsync(
156157
}
157158

158159
// retrieve the value of pickup_datetime column
159-
DateTime pickup_datetime = DateTime.Parse(segdata[1]);
160+
var pickup_datetime = DateTime.Parse(segdata[1]);
160161

161162
// retrieve the value of dropoff_datetime column
162-
DateTime dropoff_datetime = DateTime.Parse(segdata[2]);
163+
var dropoff_datetime = DateTime.Parse(segdata[2]);
163164

164165
// retrieve the value of trip_distance column
165166
var trip_distance = Convert.ToDouble(segdata[4]);
@@ -177,10 +178,12 @@ public static async Task<IEnumerable<double>> MapperAsync(
177178
continue;
178179
}
179180
}
181+
#pragma warning disable CA1031 // Do not catch general exception types
180182
catch (DivideByZeroException)
181183
{ // skip it
182184
continue;
183185
}
186+
#pragma warning restore CA1031 // Do not catch general exception types
184187

185188
// sum of avg speed by each day of week
186189
speedsByDayOfWeek[(int)pickup_datetime.DayOfWeek] += avgSpeed;
@@ -190,7 +193,7 @@ public static async Task<IEnumerable<double>> MapperAsync(
190193
}
191194
}
192195

193-
List<double> results = numberOfLogsPerDayOfWeek
196+
var results = numberOfLogsPerDayOfWeek
194197
.Select((val, idx) => val != 0 ? speedsByDayOfWeek[idx] / val : 0)
195198
.AsParallel()
196199
.ToList();
@@ -241,11 +244,10 @@ public static string Reducer(
241244
/// </summary>
242245
[FunctionName(nameof(WriteToBlob))]
243246
public static async Task WriteToBlob(
244-
[ActivityTrigger] string content,
245-
ILogger log)
247+
[ActivityTrigger] string content)
246248
{
247249
var storageConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
248-
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
250+
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
249251

250252
// Create the CloudBlobClient that represents the Blob storage endpoint for the storage account.
251253
var cloudBlobClient = storageAccount.CreateCloudBlobClient();

0 commit comments

Comments
 (0)