Exemplo n.º 1
0
        public List <NHEntityStatistics> Get()
        {
            if (!(_previousStatistics?.Any() == true || _currentStatistics?.Any() == true))
            {
                return(null);
            }

            if (_currentStatistics?.Any() == true && _previousStatistics?.Any() != true)
            {
                return(_currentStatistics);
            }

            if (_previousStatistics?.Any() == true && _currentStatistics?.Any() != true)
            {
                return(_previousStatistics);
            }

            var result = new List <NHEntityStatistics>();

            try
            {
                var allEntities = _previousStatistics.Select(x => x.EntityName).Union(_currentStatistics.Select(x => x.EntityName)).Distinct();

                foreach (var ent in allEntities)
                {
                    var record = new NHEntityStatistics();

                    var previous = _previousStatistics?.FirstOrDefault(x => x.EntityName == ent);
                    var current  = _currentStatistics?.FirstOrDefault(x => x.EntityName == ent);

                    record.EntityName             = ent;
                    record.EntityType             = current != null ? current.EntityType : previous.EntityType;
                    record.DeleteCount            = current?.DeleteCount - previous?.DeleteCount;
                    record.FetchCount             = current?.FetchCount - previous?.FetchCount;
                    record.InsertCount            = current?.InsertCount - previous?.InsertCount;
                    record.LoadCount              = current?.LoadCount - previous?.LoadCount;
                    record.OptimisticFailureCount = current?.OptimisticFailureCount - previous?.OptimisticFailureCount;
                    record.UpdateCount            = current?.UpdateCount - previous?.UpdateCount;
                    record.RecreateCount          = current?.RecreateCount - previous?.RecreateCount;

                    result.Add(record);
                }
            }
            catch (Exception e)
            {
                _log.Error($"{_nameOfThis} - Failed to Calculate Statistics for {_nameOfThis}: {e.Message}");
                _log.Debug($"{_nameOfThis} - Failed to Calculate Statistics for {_nameOfThis}: {e.StackTrace}");
                if (!ContinueOnError)
                {
                    throw;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        private NHEntityStatistics Get(IStatistics statistics, string entityName)
        {
            var result = new NHEntityStatistics();

            try
            {
                var entityType = GetEntityType(statistics, entityName);
                result.EntityType = entityType;
                result.EntityName = entityName;
                switch (entityType)
                {
                case "Entity":
                    var entityStatistics = statistics.GetEntityStatistics(entityName);
                    result.DeleteCount            = entityStatistics.DeleteCount;
                    result.FetchCount             = entityStatistics.FetchCount;
                    result.InsertCount            = entityStatistics.InsertCount;
                    result.LoadCount              = entityStatistics.LoadCount;
                    result.OptimisticFailureCount = entityStatistics.OptimisticFailureCount;
                    result.UpdateCount            = entityStatistics.UpdateCount;
                    result.EntityName             = entityStatistics.CategoryName;
                    break;

                case "Collection":
                    var collectionStatistics = statistics.GetCollectionStatistics(entityName);
                    result.DeleteCount   = collectionStatistics.RemoveCount;
                    result.FetchCount    = collectionStatistics.FetchCount;
                    result.LoadCount     = collectionStatistics.LoadCount;
                    result.RecreateCount = collectionStatistics.RecreateCount;
                    result.UpdateCount   = collectionStatistics.UpdateCount;
                    result.EntityName    = collectionStatistics.CategoryName;
                    break;

                default:
                    result.EntityType = "Unknown";
                    break;
                }
            }
            catch (Exception e)
            {
                _log.Error($"{_nameOfThis} - Failed to Get Statistics for {entityName}, by {_nameOfThis}: {e.Message}");
                _log.Debug($"{_nameOfThis} - Failed to Get Statistics for {entityName}, by {_nameOfThis}: {e.StackTrace}");
                if (!ContinueOnError)
                {
                    throw;
                }
            }

            return(result);
        }