/// <summary> /// This method calls the API to initialize the dataset. This method receives an object of type ResultOfInt32 /// </summary> /// <param name="size">Size of data set</param> /// <returns>ResultOfInt32 with data from the server</returns> public async Task <ResultOfInt32> InitializeDataset(string size) { HttpResponseMessage response = await client.GetAsync($"/api/numbers/init/{size}"); response.EnsureSuccessStatusCode(); string content = await response.Content.ReadAsStringAsync(); var resultObj = JsonConvert.DeserializeObject(content, typeof(ResultOfInt32)); ResultOfInt32 result = (ResultOfInt32)resultObj; return(result); }
/// <summary> /// Main method run using async /// </summary> /// <returns></returns> static async Task MainAsync() { // does all calculations CalculationsAsync calculations = new CalculationsAsync(); stringBuilder = new StringBuilder(); // initialize datasets int[][] cols = new int[numElements][]; GetData getData = new GetData(); ResultOfInt32 resultOfInt32 = await getData.InitializeDataset(numElements.ToString()); firstDate = DateTime.Now; datasetA = await getData.Fillmatrix("A", numElements); datasetB = await getData.Fillmatrix("B", numElements); afterload = DateTime.Now; // Better to use parallel processing //int[][] datasetProd = await calculations.CalculateproductAsync(datasetA, datasetB, numElements); int[][] datasetProd = calculations.CalculateMatrixParallel(datasetA, datasetB, numElements); // Build the string to hash secondDate = DateTime.Now; for (int i = 0; i < numElements; i++) { for (int j = 0; j < numElements; j++) { stringBuilder.Append(datasetProd[i][j]); } } // build the MD5 hash. Fatser to build string using a stringbuilder string finalString = stringBuilder.ToString(); string md5hash = calculations.BuildMD5String(finalString); thirdDate = DateTime.Now; ResultOfString result = await getData.CheckAnswer(md5hash); passed = result.Success; if (result.Value == null) { message = "No Message"; } else { message = result.Value; } }