Example #1
0
        public void TestPercentageProcessed()
        {
            var source           = new Mock <ILogSource>();
            var sourceProperties = new PropertiesBufferList();

            sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.Zero);
            source.Setup(x => x.Columns).Returns(Core.Columns.Minimum);
            source.Setup(x => x.GetAllProperties(It.IsAny <IPropertiesBuffer>()))
            .Callback((IPropertiesBuffer destination) => sourceProperties.CopyAllValuesTo(destination));
            source.Setup(x => x.GetProperty(Core.Properties.PercentageProcessed))
            .Returns(() => sourceProperties.GetValue(Core.Properties.PercentageProcessed));
            source.Setup(x => x.Properties).Returns(() => sourceProperties.Properties);

            using (var file = Create(source.Object))
            {
                var fileListener = (ILogSourceListener)file;

                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.Zero, "because the filtered log file hasn't consumed anything of its source (yet)");

                _taskScheduler.RunOnce();
                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.Zero, "because even though the filter doesn't have anything to do just yet - it's because its own source hasn't even started");

                sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.FromPercent(42));
                fileListener.OnLogFileModified(source.Object, LogSourceModification.Appended(0, 84));
                _taskScheduler.RunOnce();
                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.FromPercent(42), "because now the filtered log file has processed 100% of the data the source sent it, but the original data source is still only at 42%");

                sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.HundredPercent);
                fileListener.OnLogFileModified(source.Object, LogSourceModification.Appended(84, 200));
                _taskScheduler.RunOnce();
                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);
            }
        }
Example #2
0
        private void UpdatePercentageProcessed(long streamPosition, long fileSize, bool allow100Percent)
        {
            var processed = Percentage.Of(streamPosition, fileSize).Clamped();

            if (processed >= Percentage.FromPercent(99) && !allow100Percent)
            {
                processed = Percentage.FromPercent(99);
            }
            _localProperties.SetValue(Core.Properties.PercentageProcessed, processed);
        }