public void UpdateBuffer(LikeUpdateDto dto)
        {
            if (!_postFrom.ContainsKey(dto.Liker))
            {
                _postFrom[dto.Liker] = new List <int> {
                    dto.Likee
                };
            }
            else
            {
                _postFrom[dto.Liker].Add(dto.Likee);
            }

            if (!_postTo.ContainsKey(dto.Likee))
            {
                _postTo[dto.Likee] = new List <LikeDto> {
                    new LikeDto {
                        Id = dto.Liker, TimeStamp = dto.TimeStamp
                    }
                };
            }
            else
            {
                _postTo[dto.Likee].Add(new LikeDto {
                    Id = dto.Liker, TimeStamp = dto.TimeStamp
                });
            }
        }
Exemple #2
0
        public void UpdateBuffer(LikeUpdateDto dto)
        {
            if (_likesFrom[dto.Liker] == null)
            {
                _likesFrom[dto.Liker] = Compress(ConvertIntToString(new int[] { dto.Likee }));
            }
            else
            {
                var existed = ConvertStringToIds(Decompress(_likesFrom[dto.Liker]));
                existed.Add(dto.Likee);
                _likesFrom[dto.Liker] = Compress(ConvertIntToString(existed));
            }

            var likeDto = new LikeDto {
                Id = dto.Liker, TimeStamp = dto.TimeStamp
            };

            if (_likesTo[dto.Likee] == null)
            {
                _likesTo[dto.Liker] = Compress(ConvertLikeDtoToString(new List <LikeDto> {
                    likeDto
                }));
            }
            else
            {
                var existed = ConvertStringToLikeDto(Decompress(_likesTo[dto.Likee]));
                existed.Add(likeDto);
                _likesTo[dto.Likee] = Compress(ConvertLikeDtoToString(existed));
            }
        }
Exemple #3
0
        public ActionResult <LikeReadDto> Update(LikeUpdateDto likeUpdateDto)
        {
            Like like = _likeRepository.Get(likeUpdateDto.Id);

            if (like == null)
            {
                return(BadRequest("Like with that id doesn't exist."));
            }
            like = _mapper.Map(likeUpdateDto, like);
            _likeRepository.Update(like);
            _logger.Log("Update like");
            return(Ok(like));
        }
        public void UpdateBuffer(LikeUpdateDto dto)
        {
            if (_fromData[dto.Liker] == null)
            {
                _fromData[dto.Liker] = new List <int> {
                    dto.Likee
                };
            }
            else
            {
                _fromData[dto.Liker].Add(dto.Likee);
            }

            if (_toData[dto.Likee] == null)
            {
                _toData[dto.Likee] = new List <long> {
                    Transform(dto.Liker, dto.TimeStamp)
                };
            }
            else
            {
                _toData[dto.Likee].Add(Transform(dto.Liker, dto.TimeStamp));
            }
        }
Exemple #5
0
        private LikeUpdateDto SetValue(string type, int value, LikeUpdateDto dto)
        {
            switch (type)
            {
            case "ts":
            {
                dto.TimeStamp = value;
                return(dto);
            }

            case "liker":
            {
                if (!_repo.IsExistedAccountId(value))
                {
                    return(null);
                }

                dto.Liker = value;
                return(dto);
            }

            case "likee":
            {
                if (!_repo.IsExistedAccountId(value))
                {
                    return(null);
                }

                dto.Likee = value;
                return(dto);
            }

            default:
                return(null);
            }
        }
Exemple #6
0
        public List <LikeUpdateDto> Deserialize(Stream stream)
        {
            var result = new List <LikeUpdateDto>();

            using (var reader = new StreamReader(stream))
            {
                var c = reader.Read();
                while (c != -1)
                {
                    if (c == '[')
                    {
                        break;
                    }

                    c = reader.Read();
                }

                var buffer = new List <char>();

                while (c >= 0)
                {
                    c = reader.Read();
                    if (c == '{')
                    {
                        var dto = new LikeUpdateDto();
                        c = reader.Read();

                        while (c != '"')
                        {
                            c = reader.Read();
                        }

                        buffer.Clear();
                        c = reader.Read();
                        while (c != '"')
                        {
                            buffer.Add((char)c);
                            c = reader.Read();
                        }

                        var type = new string(buffer.ToArray());

                        while (c != ':')
                        {
                            c = reader.Read();
                        }

                        c = reader.Read();
                        buffer.Clear();
                        while (c != ',')
                        {
                            buffer.Add((char)c);
                            c = reader.Read();
                        }

                        if (!int.TryParse(buffer.ToArray(), out int value))
                        {
                            return(null);
                        }

                        dto = SetValue(type, value, dto);
                        if (dto == null)
                        {
                            return(null);
                        }

                        // Second line

                        while (c != '"')
                        {
                            c = reader.Read();
                        }

                        buffer.Clear();
                        c = reader.Read();
                        while (c != '"')
                        {
                            buffer.Add((char)c);
                            c = reader.Read();
                        }

                        type = new string(buffer.ToArray());

                        while (c != ':')
                        {
                            c = reader.Read();
                        }

                        buffer.Clear();
                        c = reader.Read();
                        while (c != ',')
                        {
                            buffer.Add((char)c);
                            c = reader.Read();
                        }

                        if (!int.TryParse(buffer.ToArray(), out int value2))
                        {
                            return(null);
                        }

                        dto = SetValue(type, value2, dto);
                        if (dto == null)
                        {
                            return(null);
                        }

                        // Third line

                        while (c != '"')
                        {
                            c = reader.Read();
                        }

                        buffer.Clear();
                        c = reader.Read();
                        while (c != '"')
                        {
                            buffer.Add((char)c);
                            c = reader.Read();
                        }

                        type = new string(buffer.ToArray());

                        while (c != ':')
                        {
                            c = reader.Read();
                        }

                        buffer.Clear();
                        c = reader.Read();
                        while (c != '}')
                        {
                            buffer.Add((char)c);
                            c = reader.Read();
                        }


                        if (!int.TryParse(buffer.ToArray(), out int value3))
                        {
                            return(null);
                        }

                        dto = SetValue(type, value3, dto);
                        if (dto == null)
                        {
                            return(null);
                        }

                        result.Add(dto);
                    }
                }
            }

            return(result);
        }