private void Render() { var comments = _comments .Where(x => string.Equals(x.Path, _path)) .Select(comment => new DiffCommentModel { Id = comment.Id, GroupId = comment.Id, Username = comment.User.Login, AvatarUrl = comment.User.AvatarUrl, LineTo = comment.Position, LineFrom = comment.Position, Body = _markdownService.Convert(comment.Body), Date = comment.CreatedAt.Humanize() }); var diffModel = new DiffModel( _patch.Split('\n'), comments, (int)UIFont.PreferredSubheadline.PointSize); var diffView = new DiffWebView { Model = diffModel }; LoadContent(diffView.GenerateString()); }
public async Task OnNextAsync(DiffModel item, StreamSequenceToken token = null) { _logger.Verbose($"OnNextAsync called with {item.NewGrains.Count} items"); var newGrains = await ApplyFilter(item.NewGrains); CurrentStats?.AddRange(newGrains); if (InSummaryMode) { await _dashboardInstanceStream.OnNextAsync(new DiffModel { SummaryView = InSummaryMode, TypeCounts = item.TypeCounts, NewGrains = GetGrainSummaries(), SummaryViewLinks = GetGrainSummaryLinks(), SessionId = SessionId }); } else { item.NewGrains = newGrains; _logger.Verbose($"OnNextAsync called with {item.NewGrains.Count} items"); if (item.NewGrains != null && (item.NewGrains.Any() || item.RemovedGrains.Any())) { item.SummaryView = InSummaryMode; item.SessionId = SessionId; await _dashboardInstanceStream.OnNextAsync(item); } } }
private static IEnumerable <object[]> CasesEquals() { var service = new Mock <DiffService>(MockBehavior.Strict, null).Object; const string id = "dsgfdsfsdfasdf"; var left = new byte[] { 1, 2 }; var right = new byte[] { 5, 6 }; var model = new DiffModel(service, id).SetLeft(left).SetRight(right); var servico2 = new Mock <DiffService>(MockBehavior.Strict, null).Object; yield return(new object[] { true, model, model }); yield return(new object[] { true, model, new DiffModel(service, id).SetLeft(left).SetRight(right) }); yield return(new object[] { false, model, null }); yield return(new object[] { false, model, new DiffModel(servico2, id).SetLeft(left).SetRight(right) }); yield return(new object[] { false, model, new DiffModel(service, "fasdfds").SetLeft(left).SetRight(right) }); yield return(new object[] { false, model, new DiffModel(service, id).SetLeft(new byte[] { 5 }).SetRight(right) }); yield return(new object[] { false, model, new DiffModel(service, id).SetLeft(left).SetRight(new byte[] { 5 }) }); }
private async Task <DiffModel> GetChanges() { var newStats = await _GetAllFromCluster() ?? new List <UpdateModel>(); var diffModel = new DiffModel { RemovedGrains = CurrentStats?.Where(p => newStats.All(n => n.GrainId != p.GrainId)).Select(p => p.GrainId).ToList(), NewGrains = newStats.Where(n => CurrentStats?.Any(c => c.Id == n.Id) == false).ToList(), TypeCounts = newStats.GroupBy(p => p.TypeShortName).Select(p => new TypeCounter { TypeName = p.Key, Total = p.Count() }).ToList() }; //Update the CurrentStats with the latest. CurrentStats = newStats; _logger.Verbose($"Sending {diffModel.RemovedGrains?.Count} RemovedGrains from DashboardCollectorGrain"); _logger.Verbose($"Sending {diffModel.NewGrains?.Count} NewGrains from DashboardCollectorGrain"); _logger.Verbose($"Sending {diffModel.TypeCounts?.Count} TypeCounts from DashboardCollectorGrain"); var streamProvider = GetStreamProvider(StreamKeys.StreamProvider); _logger.Info($"About to send the changes to the dashboardInstanceGrains"); var stream = streamProvider.GetStream <DiffModel>(Guid.Empty, StreamKeys.OrniscientChanges); await stream.OnNextAsync(diffModel); return(diffModel); }
public IActionResult Set([FromRoute] string id, [FromRoute] Side side, [FromBody] DiffModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _stateService.Set(id, side, model.Data); return(StatusCode((int)HttpStatusCode.Accepted)); }
public void Should_create_new_instance() { var id = RandomString(); var expected = new DiffModel(_service, id); var actual = _service.Create(id); Assert.AreEqual(expected, actual); }
public void Should_return_null_when_no_left_or_side(byte[] left, byte[] right) { const string id = "dsgfdsfsdfasdf"; var model = new DiffModel(_serviceMock.Object, id).SetLeft(left).SetRight(right); var actual = model.Similarity; Assert.IsNull(actual); }
public void Should_build_instance() { const string id = "dasjdkasl"; var model = new DiffModel(_serviceMock.Object, id); Assert.AreEqual(id, model.Id, nameof(model.Id)); Assert.AreSame(_serviceMock.Object, model.Owner, nameof(model.Owner)); Assert.IsNull(model.Left, nameof(model.Left)); Assert.IsNull(model.Right, nameof(model.Right)); }
public ActionResult <string> Right(DiffModel rightInput) { if (!ModelState.IsValid) { return(BadRequest("Formato inválido. Leia nosso arquivo Readme.")); } FileHelper.SaveData(rightInput.Data, "right"); return(Ok("Input \"right\" enviados com sucesso!")); }
public void Should_set_right_array() { const string id = "dsgfasdf"; var model = new DiffModel(_serviceMock.Object, id); var expected = new byte[] { 1, 2, 3 }; var actual = model.SetRight(expected); Assert.AreSame(actual, model); Assert.AreSame(expected, model.Right, nameof(model.Right)); Assert.IsNull(model.Left, nameof(model.Left)); }
public void Should_return_null_when_no_left_or_side() { const string id = "dsgfdsfsdfasdf"; var left = new byte[] { 4, 5, 6 }; var right = new byte[] { 3, 8, 7, 9 }; var model = new DiffModel(_serviceMock.Object, id).SetLeft(left).SetRight(right); var actual = model.Similarity as BytesSimilarity; Assert.IsNotNull(actual); Assert.AreEqual(left, actual.Left, nameof(actual.Left)); Assert.AreEqual(right, actual.Right, nameof(actual.Right)); }
public void Should_return_new_when_not_exists() { var id = RandomString(); _repositoryMock.Setup(mock => mock.Read(id)).Returns(default(DiffContent)); var expected = new DiffModel(_service, id); var actual = _service.LoadOrCreate(id); Assert.AreEqual(expected, actual); _repositoryMock.Verify(mock => mock.Read(It.IsAny <string>()), Times.Once); }
public void Should_save_data() { _serviceMock.Setup(mock => mock.Save(It.IsAny <string>(), It.IsAny <DiffContent>())); const string id = "dsgfdsfsdfasdf"; var left = new byte[] { 4, 5, 6 }; var right = new byte[] { 3, 8, 7, 9 }; var model = new DiffModel(_serviceMock.Object, id).SetLeft(left).SetRight(right); model.Save(); _serviceMock.Verify(mock => mock.Save(It.IsAny <string>(), It.IsAny <DiffContent>()), Times.Once()); _serviceMock.Verify(mock => mock.Save(id, It.Is <DiffContent>(actual => actual.Left == left && actual.Right == right))); }
public void Should_update_read_data() { const string id = "dsgfdsfsdfasdf"; var model = new DiffModel(_serviceMock.Object, id); var left = new byte[] { 4, 5, 6 }; var right = new byte[] { 3, 8, 7, 9 }; var actual = model.SetData(new DiffContent(id) { Left = left, Right = right }); Assert.AreSame(actual, model); Assert.AreSame(left, model.Left, nameof(model.Left)); Assert.AreSame(right, model.Right, nameof(model.Right)); }
public void Should_return_loaded_when_exists_too() { var id = RandomString(); var left = new byte[] { 1, 4, 5 }; var right = new byte[] { 1, 5, 7 }; _repositoryMock.Setup(mock => mock.Read(id)).Returns(new DiffContent(id) { Left = left, Right = right }); var expected = new DiffModel(_service, id).SetLeft(left).SetRight(right); var actual = _service.LoadOrCreate(id); Assert.AreEqual(expected, actual); _repositoryMock.Verify(mock => mock.Read(It.IsAny <string>()), Times.Once); }
public void Should_compare_with_object(bool expected, DiffModel model1, DiffModel model2) { var actual = model1.Equals((object)model2); Assert.AreEqual(expected, actual); }
public void Should_compare_with_unequal_operator(bool expected, DiffModel model1, DiffModel model2) { var actual = model1 != model2; Assert.AreNotEqual(expected, actual); }
public static void diffStrings(string orig, string mod, int origLength, int modLength, int[,] lookupTable, DiffModel diffTextModel) { if (origLength > 0 && modLength > 0 && orig[origLength - 1] == mod[modLength - 1]) { diffStrings(orig, mod, origLength - 1, modLength - 1, lookupTable, diffTextModel); diffTextModel.right.Add("" + mod[modLength - 1]); diffTextModel.left.Add("" + orig[origLength - 1]); } else if (modLength > 0 && (origLength == 0 || lookupTable[origLength, modLength - 1] >= lookupTable[origLength - 1, modLength])) { diffStrings(orig, mod, origLength, modLength - 1, lookupTable, diffTextModel); diffTextModel.right.Add("PIKA" + mod[modLength - 1] + "CHU"); } else if (origLength > 0 && (modLength == 0 || lookupTable[origLength, modLength - 1] < lookupTable[origLength - 1, modLength])) { diffStrings(orig, mod, origLength - 1, modLength, lookupTable, diffTextModel); diffTextModel.left.Add("PIKA" + orig[origLength - 1] + "CHU"); } }
public DiffModel Post() { DiffModel diffTextModel = new DiffModel(); diffTextModel.left = new List <string>(); diffTextModel.right = new List <string>(); var file1 = Request.Form.Files[0]; var file2 = Request.Form.Files[1]; var notHtml = true; if (file1.FileName.Contains("html") && file2.FileName.Contains("html")) { notHtml = false; } var stream1 = new StreamReader(file1.OpenReadStream()); var stream2 = new StreamReader(file2.OpenReadStream()); List <string> lines = new List <string>(); String line; int MaxLineLength = 1024; while ((line = stream1.ReadLine()) != null) { if (line.Length > MaxLineLength) { throw new InvalidOperationException( string.Format("File contains a line greater than {0} characters.", MaxLineLength.ToString())); } lines.Add(line + "\r\n"); } string originalDoc = string.Join(" ", lines); lines = new List <string>(); while ((line = stream2.ReadLine()) != null) { if (line.Length > MaxLineLength) { throw new InvalidOperationException( string.Format("File contains a line greater than {0} characters.", MaxLineLength.ToString())); } lines.Add(line + "\r\n"); } string modifiedDoc = string.Join(" ", lines); int[,] lookupTable = new int[originalDoc.Length + 1, modifiedDoc.Length + 1]; lcsLength(originalDoc, modifiedDoc, originalDoc.Length, modifiedDoc.Length, lookupTable); diffStrings(originalDoc, modifiedDoc, originalDoc.Length, modifiedDoc.Length, lookupTable, diffTextModel); diffTextModel.left = string.Join("", diffTextModel.left).Replace("PIKA\rCHUPIKA\nCHU", " \r\n ") .Replace("PIKA", "<span class=\"deleted\">").Replace("CHU", "</span>").Split("\r\n").ToList(); diffTextModel.right = string.Join("", diffTextModel.right).Replace("PIKA\rCHUPIKA\nCHU", " \r\n ") .Replace("PIKA", "<span class=\"added\">").Replace("CHU", "</span>").Split("\r\n").ToList(); if (notHtml) { for (int i = 0; i < diffTextModel.left.Count; i++) { diffTextModel.left[i] = diffTextModel.left[i] + "<br>"; } for (int i = 0; i < diffTextModel.right.Count; i++) { diffTextModel.right[i] = diffTextModel.right[i] + "<br>"; } } return(diffTextModel); }
public async Task OnNextAsync(DiffModel item, StreamSequenceToken token = null) { _logger.Verbose($"OnNextAsync called with {item.NewGrains.Count} new grains, {item.RemovedGrains.Count} removed grains"); List <UpdateModel> previousSummary = null; if (InSummaryMode) { previousSummary = GetGrainSummaries(); } item.NewGrains = await ApplyFilter(item.NewGrains); CurrentStats?.AddRange(item.NewGrains); if (item.RemovedGrains?.Any() == true) { CurrentStats = CurrentStats?.Where(p => item.RemovedGrains.All(q => q != p.Id)).ToList(); } if (InSummaryMode) { var updatedSummary = GetGrainSummaries(); var diffModel = new DiffModel { SummaryView = InSummaryMode, TypeCounts = item.TypeCounts, NewGrains = updatedSummary, SummaryViewLinks = GetGrainSummaryLinks(), SessionId = SessionId }; if (previousSummary != null && previousSummary.Count > 0) { var removed = previousSummary.Where(grain => !updatedSummary.Any(currentGrain => currentGrain.Id == grain.Id)).Select(grain => grain.Id).ToList(); diffModel.RemovedGrains = removed; } _logger.Verbose($"DashboardInstanceGrain sending out {diffModel.NewGrains.Count} new grains, {diffModel.RemovedGrains.Count} removed grains"); await _dashboardInstanceStream.OnNextAsync(diffModel); } else { if (previousSummary != null) { if (item.RemovedGrains == null) { item.RemovedGrains = new List <string>(); } item.RemovedGrains.AddRange(previousSummary.Select(grain => grain.Id)); item.NewGrains = new List <UpdateModel>(CurrentStats); } if (item.NewGrains?.Any() == true || item.RemovedGrains?.Any() == true) { item.SummaryView = InSummaryMode; item.SessionId = SessionId; _logger.Verbose($"DashboardInstanceGrain sending out {item.NewGrains?.Count} new grains, {item.RemovedGrains?.Count} removed grains"); await _dashboardInstanceStream.OnNextAsync(item); } } }