Пример #1
0
        /// <summary>
        /// Sends the MD5 hash of the final matrix cross product and receives an answer as to whether the calculation was correct.
        /// </summary>
        /// <param name="MD5String"></param>
        /// <returns>Returns: ResultOfString containing a phrase indicating whether the calculation was correct</returns>
        public async Task <ResultOfString> CheckAnswer(string MD5String)
        {
            // Post to service to check whether the matrix was correct.
            string address = "api/numbers/validate";

            HttpResponseMessage response = await client.PostAsync(address, new StringContent(MD5String, Encoding.UTF8, "text/json"));

            string content = await response.Content.ReadAsStringAsync();

            object         resultObj = JsonConvert.DeserializeObject(content, typeof(ResultOfString));
            ResultOfString result    = (ResultOfString)resultObj;

            return(result);
        }
Пример #2
0
        /// <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;
            }
        }