예제 #1
0
        private void SetTransactionLines(TransactionViewModel viewModel, AggregationData aggregatedTransactionData)
        {
            var aggregatedLevyTransactions = aggregatedTransactionData.TransactionLines
                                             .Where(t => t.TransactionType == TransactionItemType.Declaration)
                                             .GroupBy(t => t.DateCreated.Date)
                                             .Select(grp =>
            {
                var firstLevyTransactionInDay = grp.First();
                return(new TransactionLine
                {
                    AccountId = firstLevyTransactionInDay.AccountId,
                    DateCreated = firstLevyTransactionInDay.DateCreated,
                    Amount = grp.Sum(ltl => ltl.Amount),
                    TransactionType = TransactionItemType.Declaration,
                    Description = firstLevyTransactionInDay.Description,
                    PayrollDate = firstLevyTransactionInDay.PayrollDate,
                    PayrollMonth = firstLevyTransactionInDay.PayrollMonth,
                    PayrollYear = firstLevyTransactionInDay.PayrollYear
                });
            });

            var newTransactionLines = aggregatedTransactionData.TransactionLines
                                      .Where(t => t.TransactionType != TransactionItemType.Declaration)
                                      .Union(aggregatedLevyTransactions)
                                      .ToArray();

            viewModel.Data.TransactionLines = newTransactionLines;
        }
예제 #2
0
        private void AddRecordToDict(object key)
        {
            TOutput firstEntry = default(TOutput);

            firstEntry = (TOutput)Activator.CreateInstance(typeof(TOutput));
            AggregationData.Add(key, firstEntry);
        }
예제 #3
0
 static AggregationFacade()
 {
     baseAggregationData  = new AggregationData();
     forumAggregationData = new ForumAggregationData();
     AggregationDataSubject.Attach(baseAggregationData);
     AggregationDataSubject.Attach(forumAggregationData);
 }
예제 #4
0
        private void WrapAggregationAction(TInput row)
        {
            object key = GroupingFunc?.Invoke(row) ?? string.Empty;

            if (!AggregationData.ContainsKey(key))
            {
                AddRecordToDict(key);
            }

            TOutput currentAgg = AggregationData[key];

            AggregationAction.Invoke(row, currentAgg);
        }
예제 #5
0
        private TransactionViewModel BuildTransactionViewModel(AggregationData aggregationData, int year, int month)
        {
            var viewModel = new TransactionViewModel
            {
                Data = new AggregationData
                {
                    AccountId       = aggregationData.AccountId,
                    HashedAccountId = aggregationData.HashedAccountId,
                },
                CurrentBalance = aggregationData.Balance
            };

            SetTransactionLines(viewModel, aggregationData);
            return(viewModel);
        }
예제 #6
0
        static AggregationFacade()
        {
            baseAggregationData  = new AggregationData();
            forumAggregationData = new ForumAggregationData();
            spaceAggregationData = new SpaceAggregationData();
            albumAggregationData = new AlbumAggregationData();
            photoAggregationData = new PhotoAggregationData();
            goodsAggregationData = new GoodsAggregationData();

            //加载要通知的聚合数据对象
            AggregationDataSubject.Attach(baseAggregationData);
            AggregationDataSubject.Attach(forumAggregationData);
            AggregationDataSubject.Attach(spaceAggregationData);
            AggregationDataSubject.Attach(albumAggregationData);
            AggregationDataSubject.Attach(photoAggregationData);
        }
예제 #7
0
        /// <summary>
        /// Logs the timing data via slf4net logger.
        /// </summary>
        /// <param name="timingData">The timing to be serialized to JSON and be logged.</param>
        /// <param name="aggregations">The aggregations to be merged to timing data.</param>
        protected void LogTimingData(TimingDataBase timingData
            , params KeyValuePair<string, TimingAggregation>[] aggregations)
        {
            if (!_logger.Value.IsInfoEnabled)
            {
                return;
            }

            var json = Serialize(timingData);

            // merge aggregations to JSON of timing data
            if (aggregations != null && aggregations.Length > 0)
            {
                var sb = new StringBuilder(json.Substring(0, json.Length - 1));

                foreach (var aggr in aggregations)
                {
                    var aggrData = new AggregationData();
                    aggrData.Count = aggr.Value.Count;
                    aggrData.Duration = aggr.Value.TotalDurationMilliseconds;

                    var jsonAggr = Serialize(aggrData);
                    var aggrType = aggr.Key.ToLowerInvariant();
                    sb.Append(",");
                    sb.Append(
                        jsonAggr.Substring(1, jsonAggr.Length - 2)
                        .Replace("count", aggrType + "Count")
                        .Replace("duration", aggrType + "Duration"));
                }

                sb.Append("}");
                json = sb.ToString();
            }

            _logger.Value.Info(json);
        }