public async Task <IActionResult> Diff(string id) { if (string.IsNullOrEmpty(id)) { return(StatusCode(400)); } try { JsonDiffDto diffResult = await _service.GetComparison(id); return(StatusCode(200, diffResult)); } catch (Exception) { return(StatusCode(400, "Error when input data")); } }
public async Task <JsonDiffDto> GetComparison(string id) { JsonBase64ItemDto itemLeft = await Select(id, EJsonBase64Position.Left); JsonBase64ItemDto itemRight = await Select(id, EJsonBase64Position.Right); JsonDiffDto result = new JsonDiffDto(); result.Id = id; if (itemLeft == null || itemRight == null) { result.Message = "Data not found. Send both sides again."; return(result); } if (itemLeft.Data.Length != itemRight.Data.Length) { result.Message = "The data is not the same size"; return(result); } result.Message = "The data is the same"; byte[] leftArray = Convert.FromBase64String(itemLeft.Data); byte[] right = Convert.FromBase64String(itemRight.Data); List <int> offsetList = new List <int>(); for (int i = 0; i < leftArray.Length; i++) { if (leftArray[i] != right[i]) { offsetList.Add(i); } } result.Length = offsetList.Count; return(result); }