protected override void GivenThat()
        {
            base.GivenThat();

            _webClientFactory      = GenerateMock <IWebClientFactory>();
            _webClient             = GenerateMock <IWebClient>();
            _directoryInfoProvider = GenerateMock <IDirectoryInfoProvider>();
            _directoryInfo         = GenerateMock <IDirectoryInfo>();
            _fileUtilities         = GenerateMock <IFileUtilities>();
            _stateProvider         = GenerateMock <IStateProvider>();
            _counterFactory        = GenerateMock <ICounterFactory>();
            _averageCounterTime    = GenerateMock <IAverageCounter>();
            _averageCounterSize    = GenerateMock <IAverageCounter>();
            _state           = GenerateMock <IState>();
            _commandExecuter = GenerateMock <ICommandExecuter>();

            _syncItem  = new SyncItem();
            _exception = null;

            SetupData();
            SetupStubs();

            _downloader = new EpisodeDownloader(_webClientFactory, _directoryInfoProvider, _fileUtilities, _stateProvider, _counterFactory, _commandExecuter);
            _downloader.StatusUpdate   += new EventHandler <StatusUpdateEventArgs>(DownloaderStatusUpdate);
            _downloader.ProgressUpdate += new EventHandler <ProgressEventArgs>(DownloaderProgressUpdate);
        }
示例#2
0
 /// <summary>
 /// Register new
 /// <see cref="ICounterFactory"/>.
 /// </summary>
 /// <remarks>
 /// Register new
 /// <see cref="ICounterFactory"/>
 /// . Does nothing if same factory was already registered.
 /// </remarks>
 /// <param name="factory">
 ///
 /// <see cref="ICounterFactory"/>
 /// to be registered
 /// </param>
 public virtual void Register(ICounterFactory factory)
 {
     if (factory != null)
     {
         factories.Add(factory);
     }
 }
示例#3
0
 public static IMessagePerformanceCounter Counter(ICounterFactory factory)
 {
     if (_cache == null)
     {
         _cache = new Lazy <MessagePerformanceCounter <T> >(() => new MessagePerformanceCounter <T>(factory));
     }
     return(_cache.Value);
 }
示例#4
0
 /// <summary>
 /// Unregister specified
 /// <see cref="ICounterFactory"/>.
 /// </summary>
 /// <remarks>
 /// Unregister specified
 /// <see cref="ICounterFactory"/>
 /// . Does nothing if this factory wasn't registered first.
 /// </remarks>
 /// <param name="factory">
 ///
 /// <see cref="ICounterFactory"/>
 /// to be unregistered
 /// </param>
 /// <returns>
 ///
 /// <see langword="true"/>
 /// if specified factory was registered first
 /// </returns>
 public virtual bool Unregister(ICounterFactory factory)
 {
     if (factory != null)
     {
         return(factories.Remove(factory));
     }
     return(false);
 }
 /// <summary>
 /// construct the factory
 /// </summary>
 public EpisodeDownloaderFactory(IWebClientFactory webClientFactory, IDirectoryInfoProvider directoryInfoProvider, IFileUtilities fileUtilities, IStateProvider stateProvider, ICounterFactory counterFactory, ICommandExecuter commandExecuter)
 {
     _webClientFactory      = webClientFactory;
     _commandExecuter       = commandExecuter;
     _counterFactory        = counterFactory;
     _stateProvider         = stateProvider;
     _fileUtilities         = fileUtilities;
     _directoryInfoProvider = directoryInfoProvider;
 }
 /// <summary>
 /// create a task
 /// </summary>
 public EpisodeDownloader(IWebClientFactory webClientFactory, IDirectoryInfoProvider directoryInfoProvider, IFileUtilities fileUtilities, IStateProvider stateProvider, ICounterFactory counterFactory, ICommandExecuter commandExecuter)
 {
     _webClientFactory      = webClientFactory;
     _commandExecuter       = commandExecuter;
     _counterFactory        = counterFactory;
     _stateProvider         = stateProvider;
     _fileUtilities         = fileUtilities;
     _directoryInfoProvider = directoryInfoProvider;
     TaskComplete           = new ManualResetEvent(false);
 }
示例#7
0
 protected override void GivenThat()
 {
     base.GivenThat();
     _counterFactory        = GenerateMock <ICounterFactory>();
     _stateProvider         = GenerateMock <IStateProvider>();
     _webClientFactory      = new WebClientFactory();
     _directoryInfoProvider = GenerateMock <IDirectoryInfoProvider>();
     _fileUtilities         = GenerateMock <IFileUtilities>();
     _commandExecuter       = GenerateMock <ICommandExecuter>();
     _factory = new EpisodeDownloaderFactory(_webClientFactory, _directoryInfoProvider, _fileUtilities, _stateProvider, _counterFactory, _commandExecuter);
 }
        public ConsumerPerformanceCounter(ICounterFactory factory, string consumerType)
        {
            if (consumerType.Length > 127)
                consumerType = consumerType.Substring(consumerType.Length - 127);

            _totalMessages = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.TotalMessages.CounterName, consumerType);
            _consumeRate = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.ConsumeRate.CounterName, consumerType);
            _duration = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.Duration.CounterName, consumerType);
            _durationBase = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.DurationBase.CounterName, consumerType);
            _totalFaults = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.TotalFaults.CounterName, consumerType);
            _faultPercentage = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.FaultPercentage.CounterName, consumerType);
            _faultPercentageBase = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.FaultPercentageBase.CounterName, consumerType);
        }
示例#9
0
        public ConsumerPerformanceCounter(ICounterFactory factory, string consumerType)
        {
            if (consumerType.Length > 127)
            {
                consumerType = consumerType.Substring(consumerType.Length - 127);
            }

            _totalMessages       = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.TotalMessages.CounterName, consumerType);
            _consumeRate         = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.ConsumeRate.CounterName, consumerType);
            _duration            = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.Duration.CounterName, consumerType);
            _durationBase        = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.DurationBase.CounterName, consumerType);
            _totalFaults         = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.TotalFaults.CounterName, consumerType);
            _faultPercentage     = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.FaultPercentage.CounterName, consumerType);
            _faultPercentageBase = factory.Create(BuiltInCounters.Consumers.Category, ConsumerPerformanceCounters.FaultPercentageBase.CounterName, consumerType);
        }
        protected override void GivenThat()
        {
            base.GivenThat();

            _counterFactory    = GenerateMock <ICounterFactory>();
            _stateProvider     = GenerateMock <IStateProvider>();
            _webClientFactory  = GenerateMock <IWebClientFactory>();
            _commandExecuter   = GenerateMock <ICommandExecuter>();
            _downloaderFactory = new EpisodeDownloaderFactory(_webClientFactory, _directoryInfoProvider, _fileUtilities, _stateProvider, _counterFactory, _commandExecuter);
            _downloadItems     = new List <ISyncItem>(10);

            SetupData();
            SetupStubs();

            _converter = new SyncItemToEpisodeDownloaderTaskConverter(_downloaderFactory);
        }
        public MessagePerformanceCounter(ICounterFactory factory)
        {
            string messageType = TypeMetadataCache <TMessage> .ShortName;

            if (messageType.Length > 127)
            {
                messageType = messageType.Substring(messageType.Length - 127);
            }

            _totalConsumed = factory.Create(BuiltInCounters.Messages.Category,
                                            MessagePerformanceCounters.TotalReceived.CounterName, messageType);
            _consumedPerSecond = factory.Create(BuiltInCounters.Messages.Category,
                                                MessagePerformanceCounters.ConsumedPerSecond.CounterName, messageType);
            _consumeDuration = factory.Create(BuiltInCounters.Messages.Category,
                                              MessagePerformanceCounters.ConsumeDuration.CounterName, messageType);
            _consumeDurationBase = factory.Create(BuiltInCounters.Messages.Category,
                                                  MessagePerformanceCounters.ConsumeDurationBase.CounterName, messageType);
            _faulted = factory.Create(BuiltInCounters.Messages.Category,
                                      MessagePerformanceCounters.ConsumeFaulted.CounterName, messageType);
            _faultPercentage = factory.Create(BuiltInCounters.Messages.Category,
                                              MessagePerformanceCounters.ConsumeFaultPercentage.CounterName, messageType);
            _faultPercentageBase = factory.Create(BuiltInCounters.Messages.Category,
                                                  MessagePerformanceCounters.ConsumeFaultPercentageBase.CounterName, messageType);
            _totalSent = factory.Create(BuiltInCounters.Messages.Category,
                                        MessagePerformanceCounters.TotalSent.CounterName, messageType);
            _sentPerSecond = factory.Create(BuiltInCounters.Messages.Category,
                                            MessagePerformanceCounters.SentPerSecond.CounterName, messageType);
            _sendFaulted = factory.Create(BuiltInCounters.Messages.Category,
                                          MessagePerformanceCounters.SendFaulted.CounterName, messageType);
            _sendFaultPercentage = factory.Create(BuiltInCounters.Messages.Category,
                                                  MessagePerformanceCounters.SendFaultPercentage.CounterName, messageType);
            _sendFaultPercentageBase = factory.Create(BuiltInCounters.Messages.Category,
                                                      MessagePerformanceCounters.SendFaultPercentageBase.CounterName, messageType);
            _totalPublished = factory.Create(BuiltInCounters.Messages.Category,
                                             MessagePerformanceCounters.TotalPublished.CounterName, messageType);
            _publishedPerSecond = factory.Create(BuiltInCounters.Messages.Category,
                                                 MessagePerformanceCounters.PublishedPerSecond.CounterName, messageType);
            _publishFaulted = factory.Create(BuiltInCounters.Messages.Category,
                                             MessagePerformanceCounters.PublishFaulted.CounterName, messageType);
            _publishFaultPercentage = factory.Create(BuiltInCounters.Messages.Category,
                                                     MessagePerformanceCounters.PublishFaultPercentage.CounterName, messageType);
            _publishFaultPercentageBase = factory.Create(BuiltInCounters.Messages.Category,
                                                         MessagePerformanceCounters.PublishFaultPercentageBase.CounterName, messageType);
        }
 public static IConsumerPerformanceCounter GetCounter(ICounterFactory factory, string consumerType)
 {
     return Cached.Counter.Value._types
         .GetOrAdd(consumerType, x => new Lazy<ConsumerPerformanceCounter>(() => new ConsumerPerformanceCounter(factory, x)))
         .Value;
 }
 public static IConsumerPerformanceCounter GetCounter(ICounterFactory factory, string consumerType)
 {
     return(Cached.Counter.Value._types
            .GetOrAdd(consumerType, x => new Lazy <ConsumerPerformanceCounter>(() => new ConsumerPerformanceCounter(factory, x)))
            .Value);
 }
示例#14
0
        private void LogFile(string fileName, string itemsName, ICounterFactory counterFactory)
        {
            var fullFileName = _directory + fileName + ".csv";

            using (TextWriter tw = File.CreateText(fullFileName)) {
                bool isSimp = false;
                if (_allLoggedData.Count == 0)
                {
                    return;
                }

                if (counterFactory.GetNewCounter(_allLoggedData[0]) is SimpCounter)
                {
                    isSimp = true;
                }

                WriteHeadings(tw, itemsName, isSimp);

                var totalBefore  = 0;
                var totalAfter   = 0;
                var totalRemoved = 0;

                var totalSubexprsBefore     = 0;
                var totalSubexprsAfter      = 0;
                var totalNumItemsSimplified = 0;

                //var data = new List<Tuple<string, int, int, float, float, float>>();
                foreach (var logData in _allLoggedData)
                {
                    var counter     = counterFactory.GetNewCounter(logData);
                    var countBefore = counter.GetCountBefore();
                    if (countBefore == 0)
                    {
                        continue;
                    }
                    var   countAfter        = counter.GetCountAfter();
                    var   countRemoved      = counter.GetRemovedCount();
                    float removalPercentage = ((float)countRemoved / (float)countBefore) * 100;
                    totalBefore  += countBefore;
                    totalAfter   += countAfter;
                    totalRemoved += countRemoved;

                    tw.Write("{0},{1},{2},{3},{4}%", logData.OriginalProgram.Name, countBefore, countAfter, countRemoved, removalPercentage);
                    if (!isSimp || countAfter == 0)
                    {
                        tw.WriteLine();
                    }
                    else
                    {
                        var simpCounter                  = counter as SimpCounter;
                        var numberOfItemsSimplified      = simpCounter.GetNumberOfRemainingThatCanBeSimplified();
                        var subexprsBeforeSimplification = simpCounter.GetNumberOfSubexpressionsBeforeSimplification();
                        var subexprsAfterSimplification  = simpCounter.GetNumberOfSubexpressionsAfterSimplification();
                        var subexprsRemoved              = subexprsBeforeSimplification - subexprsAfterSimplification;
                        totalNumItemsSimplified += numberOfItemsSimplified;
                        totalSubexprsBefore     += subexprsBeforeSimplification;
                        totalSubexprsAfter      += subexprsAfterSimplification;
                        float subexprRemovedPercentage       = ((float)subexprsRemoved / (float)subexprsBeforeSimplification) * 100f;
                        float numberRemainingItemsSimplified = ((float)numberOfItemsSimplified / (float)countAfter) * 100f;
                        tw.WriteLine(",{0},{1}%,{2},{3},{4},{5}%", numberOfItemsSimplified, numberRemainingItemsSimplified, subexprsBeforeSimplification, subexprsAfterSimplification,
                                     subexprsRemoved, subexprRemovedPercentage);
                    }
                }
                tw.WriteLine();
                float avgRemovalPct = ((float)totalRemoved / (float)totalBefore) * 100f;
                tw.Write("Total,{0},{1},{2},{3}%", totalBefore, totalAfter, totalRemoved, avgRemovalPct);
                if (!isSimp || totalAfter == 0)
                {
                    tw.WriteLine();
                }
                else
                {
                    var   subExprsRemoved          = totalSubexprsBefore - totalSubexprsAfter;
                    float subExprRemovalPct        = ((float)subExprsRemoved / (float)totalSubexprsBefore) * 100f;
                    float pctOfRemainingSimplified = ((float)totalNumItemsSimplified / (float)totalAfter) * 100f;
                    tw.WriteLine(",{0},{1}%,{2},{3},{4},{5}%", totalNumItemsSimplified, pctOfRemainingSimplified,
                                 totalSubexprsBefore, totalSubexprsAfter, subExprsRemoved, subExprRemovalPct);
                }
            }
        }
示例#15
0
 public PerformanceCounterReceiveObserver(ICounterFactory factory)
 {
     _factory = factory;
 }
 public PerformanceCounterBusObserver(ICounterFactory factory)
 {
     _factory = factory;
 }
示例#17
0
 public PerformanceCounterPublishObserver(ICounterFactory factory)
 {
     _factory = factory;
 }
 public PerformanceCounterBusFactorySpecification(ICounterFactory factory)
 {
     _factory = factory;
 }
 public PerformanceCounterBusFactorySpecification(ICounterFactory factory)
 {
     _factory = factory;
 }