Exemplo n.º 1
0
        private JsonBase64ItemDto ConvertToDto(JsonBase64Item item)
        {
            if (item == null)
            {
                return(null);
            }
            else
            {
                JsonBase64ItemDto itemDto = new JsonBase64ItemDto()
                {
                    Id       = item.Id,
                    Data     = item.Data,
                    Position = (item.Position == "L" ? EJsonBase64Position.Left : EJsonBase64Position.Right)
                };

                return(itemDto);
            }
        }
Exemplo n.º 2
0
        private JsonBase64Item ConvertFromDto(JsonBase64ItemDto itemDto)
        {
            if (itemDto == null)
            {
                return(null);
            }
            else
            {
                JsonBase64Item item = new JsonBase64Item()
                {
                    Id       = itemDto.Id,
                    Data     = itemDto.Data,
                    Position = (itemDto.Position == EJsonBase64Position.Left ? "L" : "R")
                };

                return(item);
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Left(string id, [FromBody] DiffDataRequest jsonData)
        {
            if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(jsonData.Data))
            {
                return(StatusCode(400, new DiffDataResponse()
                {
                    Message = "Required data not found"
                }));
            }

            JsonBase64ItemDto entity = new JsonBase64ItemDto()
            {
                Id = id, Position = Domain.Enums.EJsonBase64Position.Left, Data = jsonData.Data
            };

            try
            {
                bool success = await _service.Save(entity);

                if (success)
                {
                    return(StatusCode(201, new DiffDataResponse()
                    {
                        Message = "OK"
                    }));
                }
                else
                {
                    return(StatusCode(400, new DiffDataResponse()
                    {
                        Message = "Error when input data"
                    }));
                }
            }
            catch (Exception)
            {
                //write log error
                return(StatusCode(400, new DiffDataResponse()
                {
                    Message = "Error when input data"
                }));
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public async Task <bool> Save(JsonBase64ItemDto entity)
        {
            string         position = entity.Position == EJsonBase64Position.Left ? "L" : "R";
            JsonBase64Item item     = new JsonBase64Item()
            {
                Id = entity.Id, Data = entity.Data, Position = position
            };

            try
            {
                if (await _repository.AddOrUpdate(item))
                {
                    _repository.Save();
                }

                return(await Task.FromResult(true));
            }
            catch (Exception ex)
            {
                return(await Task.FromResult(false));
            }
        }