private async Task <IActionResult> ReceiveSourceContent( int id, SourceSide side, SourceContentRequest model) { if (!ModelState.IsValid) { return(BadRequest()); } var content = new SourceContent { SourceSide = side }; try { content.Data = Convert.FromBase64String(model.Data); } catch (FormatException) { return(BadRequest()); } await _differenceService.AddSourceAsync(id, content); return(Ok()); }
public override string ToString() { string ret = ""; ret += isSeries > 0 ? "Series of " : ""; ret += SourceSide.Trim().Length > 0 ? SourceSide.ToLower() + " " : ""; ret += ActionType.Trim().Length > 0 ? ActionType.ToLower() + " " : ""; ret += SourcePart.Trim().Length > 0 ? SourcePart.ToLower() + " " : ""; ret += TransitionText.Trim().Length > 0 ? TransitionText.ToLower() + " " : ""; ret += DestSide.Trim().Length > 0 ? DestSide.ToLower() + " " : ""; ret += DestPart.Trim().Length > 0 ? DestPart.ToLower() + " " : ""; ret += SpecialText.Trim().Length > 0 ? SpecialText.ToLower() + " " : ""; return(ret); }
public async Task SavesSourceToDataDir(int diffId, SourceSide side) { var content = new SourceContent { Data = new byte[] { 1, 2, 3 }, SourceSide = side }; var expectedFileName = Path.Combine(_DataDir, string.Concat( diffId.ToString(), ".", side.ToString().ToLowerInvariant())); File.Delete(expectedFileName); var storage = new DiskStorage(_Options); await storage.SaveSourceAsync(content.InDiffBag(diffId)); File.ReadAllBytes(expectedFileName) .Should().Equal(new byte[] { 1, 2, 3 }); }
public async Task LoadsSourceFromDataDir(int diffId, SourceSide side) { var data = new byte[] { 3, 4, 5 }; var expectedFileName = Path.Combine(_DataDir, string.Concat( diffId.ToString(), ".", side.ToString().ToLowerInvariant())); File.WriteAllBytes(expectedFileName, data); try { var storage = new DiskStorage(_Options); var(source, exists) = await storage.LoadSourceAsync(diffId, side); source.SourceSide.Should().Be(side); source.Data.Should().Equal(data); exists.Should().BeTrue(); } finally { File.Delete(expectedFileName); } }
/// <summary> /// Loads content of source by diff identifier and side. /// </summary> /// <param name="diffId">Identifier of diff which the source belongs to.</param> /// <param name="side">The side a content had come from.</param> /// <returns>The task that loads content of the source.</returns> public async Task <(SourceContent, bool)> LoadSourceAsync(int diffId, SourceSide side) { byte[] bytes; var fileName = GetSourceFileName(diffId, side); try { bytes = await File.ReadAllBytesAsync(fileName); } catch (FileNotFoundException) { return(null, false); } var content = new SourceContent { SourceSide = side, Data = bytes }; return(content, true); }
public async Task ReturnsNotReadyForDiffThatDoesntExistsInDataDirButHasSource(SourceSide side) { var data = new byte[] { 3, 4, 5 }; var sourceFileName = Path.Combine(_DataDir, string.Concat( "11.", side.ToString().ToLowerInvariant())); File.WriteAllBytes(sourceFileName, data); try { var storage = new DiskStorage(_Options); var(_, readiness) = await storage.LoadDiffAsync(11); readiness.Should().Be(DifferenceReadiness.NotReady); } finally { File.Delete(sourceFileName); } }
private string GetSourceFileName(int diffId, SourceSide side) { var fileName = string.Concat(diffId.ToString(), ".", side.ToString().ToLowerInvariant()); return(Path.Combine(_dataDir, fileName)); }