private DiffItem(DiffItemType type, string path, int?time, int?size) { Type = type; Path = path; Time = time; Size = size; }
/// <summary> /// Save the data to storage, adding the data if not present /// or updating the same if it already exists. /// </summary> /// <param name="id">Identifier of left/right blocks to be persisted</param> /// <param name="data">Data to be saved.</param> /// <param name="itemType">Define if the data being saved is related to left or right.</param> public Task Save(int id, string data, DiffItemType itemType) { byte[] binaryData = Convert.FromBase64String(data); // There isn't any invalid possible id, so any received id not present in // database will generate a new entry. InMemoryDiffData diffData = _repository.GetById(id); if (diffData == null) { diffData = new InMemoryDiffData { Id = id }; } switch (itemType) { case DiffItemType.Left: diffData.Left = binaryData; break; case DiffItemType.Right: diffData.Right = binaryData; break; default: throw new ArgumentOutOfRangeException(nameof(itemType)); } _repository.Save(diffData); // Here a Task is being returned just in order to alow // other methods to simulate a async call to some IO resource. return(Task.CompletedTask); }
/// <summary> /// Persists received data accordingly to <paramref name="diffItemType"/>. /// </summary> /// <param name="id">Data identity.</param> /// <param name="data">Base 64 string data to be persisted.</param> /// <param name="diffItemType">Define if data belongs to left or to the right.</param> /// <returns>The HTTP status of the operation.</returns> private async Task <IHttpActionResult> SavePostDiffData(int id, string data, DiffItemType diffItemType) { try { await _repository.Save(id, data, diffItemType); } catch { // Some additional log routines could be added. // No further information is being send to the cliente due to a possible security reasons. return(InternalServerError()); } return(Ok()); }