Ejemplo n.º 1
0
        public async Task PushesReadyToReadyContentsObservable()
        {
            var content = new[]
            {
                new SourceContent
                {
                    SourceSide = SourceSide.Left,
                    Data       = new byte[] { 1, 2, 3 }
                },
                new SourceContent
                {
                    SourceSide = SourceSide.Right,
                    Data       = new byte[] { 3, 4, 5 }
                }
            }.AsEnumerable();

            DiffBag <IEnumerable <SourceContent> > received = null;

            var queue = new DifferenceQueue();

            queue.ReadyContents.Subscribe(r => received = r);
            await queue.PushReadyAsync(content.InDiffBag(10));

            received.ShouldBeEquivalentTo(content.InDiffBag(10));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves the content of the diff in the storage.
        /// </summary>
        /// <param name="content">The content to save.</param>
        /// <returns>The task that saves the content.</returns>
        public async Task SaveDiffAsync(DiffBag <DifferenceContent> content)
        {
            var fileName = GetDiffFileName(content.DiffId);
            var json     = JsonConvert.SerializeObject(content.Data);

            await File.WriteAllTextAsync(fileName, json);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves the content of the source in the storage.
        /// </summary>
        /// <param name="content">The content to save.</param>
        /// <returns>The task that saves the content.</returns>
        public async Task SaveSourceAsync(DiffBag <SourceContent> content)
        {
            var fileName = GetSourceFileName(content.DiffId, content.Data.SourceSide);
            var bytes    = content.Data.Data;

            await File.WriteAllBytesAsync(fileName, bytes);
        }
Ejemplo n.º 4
0
        public async Task PushesSourceContentToSourceContentsObservable()
        {
            var content = new SourceContent
            {
                SourceSide = SourceSide.Right,
                Data       = new byte[] { 1, 2, 3 }
            };

            DiffBag <SourceContent> received = null;

            var queue = new DifferenceQueue();

            queue.SourceContents.Subscribe(c => received = c);
            await queue.PushSourceAsync(content.InDiffBag(10));

            received.ShouldBeEquivalentTo(content.InDiffBag(10));
        }
Ejemplo n.º 5
0
        private async Task OnSourceContentAsync(DiffBag <SourceContent> content)
        {
            var otherSide = content.Data.SourceSide == SourceSide.Left
                                   ? SourceSide.Right : SourceSide.Left;

            var(otherSideContent, otherSideExists) = await _storage.LoadSourceAsync(content.DiffId, otherSide);

            if (otherSideExists)
            {
                // Do not save received content if both sides are available.
                // It is a subject to change. We must save content when we have
                // an ability to retry to build diff after system failure.
                var readyContent = new[] { content.Data, otherSideContent };
                await _queue.PushReadyAsync(readyContent.AsEnumerable().InDiffBag(content.DiffId));

                return;
            }

            await _storage.SaveSourceAsync(content);
        }
Ejemplo n.º 6
0
        private async Task OnReadyContentAsync(DiffBag <IEnumerable <SourceContent> > content)
        {
            var diff = await _algorithm.GetDiffAsync(content.Data);

            await _storage.SaveDiffAsync(diff.InDiffBag(content.DiffId));
        }