public IHttpActionResult Get(int id) { //MethodSummary: get object, compare and return diff DiffObject diffObject; //if Left or Right properties were not set return not found if (!_diffObjectRepository.TryGet(id, out diffObject) || diffObject.Left == null || diffObject.Right == null) { return(NotFound()); } ObjectDiff objectDiff = _differ.GetDiff(diffObject.Left, diffObject.Right); return(Ok(objectDiff)); }
public void LeftNullAndRightNullTest() { byte[] left = null; byte[] right = null; ObjectDiff objectDiff = _differ.GetDiff(left, right); Assert.IsNotNull(objectDiff); Assert.AreEqual(DiffResultType.Equals, objectDiff.diffResultType); Assert.IsNull(objectDiff.diffs); }
public async Task <PriceUpdateResultStatus> ProcessPrice(CancellationTokenSource cancellationToken) { foreach (var supplierSettings in _configuration.Suppliers) { if (cancellationToken.IsCancellationRequested) { return(PriceUpdateResultStatus.ProcessAborted); } if (!_startArgs.UpdateTypes.Contains(supplierSettings.Type)) { continue; } var priceManager = _priceManagerBuilder.Build(supplierSettings); Log.Information("Processing price: '{Name}' Type: {PriceType}", supplierSettings.Name, supplierSettings.Type); var loadUpdatesResult = priceManager.LoadUpdates(supplierSettings.Type, _startArgs.IsForce); if (loadUpdatesResult.IsSuccess) { Log.Debug("Building the diff"); var diff = _differ.GetDiff(loadUpdatesResult.NewPriceLoadResult.PriceItems, loadUpdatesResult.OldPriceLoadResult?.PriceItems, _configuration.IgnoredProducts); if (_startArgs.DebugReferences != null && _startArgs.DebugReferences.Any()) { diff.NewItems = diff.NewItems.Where(s => _startArgs.DebugReferences.Contains(s.Key)).ToDictionary(k => k.Key, pair => pair.Value); diff.UpdatedItems = diff.UpdatedItems.Where(s => _startArgs.DebugReferences.Contains(s.Key)).ToDictionary(k => k.Key, pair => pair.Value); diff.DeletedItems = diff.DeletedItems.Where(s => _startArgs.DebugReferences.Contains(s.Key)).ToDictionary(k => k.Key, pair => pair.Value); } var result = await priceManager.Process(diff, supplierSettings.Type); Log.Information("{total} lines processed. {updated} updated, {new} added, {deleted} deleted", loadUpdatesResult.NewPriceLoadResult.PriceItems.Count, diff.UpdatedItems.Count, diff.NewItems.Count, diff.DeletedItems.Count); if (result.Status != PriceUpdateResultStatus.Ok) { Log.Information("Price update finished. ErrorCode: " + result.Status); File.Delete(loadUpdatesResult.NewPriceLoadResult.FilePath); return(result.Status); } if (diff.DeletedItems.Any() || diff.NewItems.Any() || diff.UpdatedItems.Any()) { var file = Path.GetFileName(loadUpdatesResult.NewPriceLoadResult.FilePath); var archivePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), supplierSettings.ArchiveDirectory); File.Move(loadUpdatesResult.NewPriceLoadResult.FilePath, Path.Combine(archivePath, file)); } else { File.Delete(loadUpdatesResult.NewPriceLoadResult.FilePath); } } else { Log.Fatal("Unable to load new price"); return(PriceUpdateResultStatus.PriceLoadFail); } } Log.Information("Price update finished successfully"); return(PriceUpdateResultStatus.Ok); }