예제 #1
0
        private void ChangeSelection(Changes changes)
        {
            if (changes == null)
            {
                return;
            }
            ChangePatch = string.Empty;

            _colorService = new DifferencesColoringService(changes.ChangeContent, string.Empty);
            _colorService.FillColorDifferences();

            ChangePatchCollection = new ObservableCollection <ChangesColorModel>();
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                int startedIndex = 0;
                if (_colorService != null && _colorService.TextAList.Count > 3 && Regex.IsMatch(_colorService.TextAList.First().Line, "diff --git") && Regex.IsMatch(_colorService.TextAList[3].Line, "Binary files"))
                {
                    startedIndex = 3;
                }
                else if (_colorService != null && _colorService.TextAList.Count > 3 && Regex.IsMatch(_colorService.TextAList.First().Line, "diff --git") && !Regex.IsMatch(_colorService.TextAList[3].Line, "Binary files"))
                {
                    startedIndex = 5;
                }

                foreach (var item in _colorService.TextAList.Skip(startedIndex))
                {
                    ChangePatchCollection.Add(item);
                }
            }));


            Messenger.Default.Send <DataMessageToChartOfChanges>(new DataMessageToChartOfChanges(_colorService.TextAList));
        }
        public override async void FillData()
        {
            this.ClearCollections();
            int sumAdded = 0, sumDeleted = 0;

            await Task.Run(new Action(() =>
            {
                this.IsLoading = true;
                FilteringHelper.Instance.SelectedRepositories.ForEach(selectedRepository =>
                {
                    var addedItemsSource = new List <ChartData>();
                    var deletedItemsSource = new List <ChartData>();

                    List <string> authors = GetAuthors(selectedRepository);

                    Parallel.ForEach(authors, author =>
                    {
                        using (var session = DbService.Instance.SessionFactory.OpenSession())
                        {
                            int added = 0, deleted = 0;
                            if (author == string.Empty)
                            {
                                return;
                            }

                            Changes changezzz = null;
                            var query = FilteringHelper.Instance.GenerateQuery(session, selectedRepository);
                            var changeIds =
                                query.JoinAlias(c => c.Changes, () => changezzz, JoinType.InnerJoin)
                                .Where(c => c.Author == author)
                                .SelectList(list => list.SelectGroup(() => changezzz.Id))
                                .List <int>();

                            changeIds.ForEach(changeId =>
                            {
                                using (var session2 = DbService.Instance.SessionFactory.OpenSession())
                                {
                                    var getChangeContent =
                                        session2.QueryOver <Changes>()
                                        .Where(c => c.Id == changeId)
                                        .Select(c => c.ChangeContent)
                                        .SingleOrDefault <string>();

                                    var colorServiceT = new DifferencesColoringService(getChangeContent, string.Empty);
                                    colorServiceT.FillColorDifferences();

                                    added += colorServiceT.TextAList.Count(x => x.Color == ChangeType.Added);
                                    deleted += colorServiceT.TextAList.Count(x => x.Color == ChangeType.Deleted);
                                }
                            });
                            sumAdded += added;
                            sumDeleted += deleted;

                            addedItemsSource.Add(new ChartData()
                            {
                                RepositoryValue = selectedRepository,
                                ChartKey = author,
                                ChartValue = added
                            });

                            deletedItemsSource.Add(new ChartData()
                            {
                                RepositoryValue = selectedRepository,
                                ChartKey = author,
                                ChartValue = deleted
                            });

                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                this.CodeFrequencyDataRows.Add(new CodeFrequencyDataRow()
                                {
                                    Repository = selectedRepository,
                                    ChartKey = author,
                                    AddedLines = added,
                                    DeletedLines = deleted
                                });
                            });
                        }
                    });
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        this.AddSeriesToChartCollection(AddedLinesChartList, selectedRepository, addedItemsSource);
                        this.AddSeriesToChartCollection(DeletedLinesChartList, selectedRepository, deletedItemsSource);
                    });
                });
            }));

            SummaryString = this.GetLocalizedString("Added") + ": " + sumAdded + " " +
                            this.GetLocalizedString("Lines") + "\n" +
                            this.GetLocalizedString("Deleted") + ": " + sumDeleted + " " +
                            this.GetLocalizedString("Lines");
            this.RaisePropertyChanged("SummaryString");

            this.AddedChartViewModel.RedrawChart(this.AddedLinesChartList);
            this.DeletedChartViewModel.RedrawChart(this.DeletedLinesChartList);
            this.IsLoading = false;
        }
        public override async void FillData()
        {
            this.ClearCollections();
            int sumAdded = 0, sumDeleted = 0;

            await Task.Run(new Action(() =>
            {
                this.IsLoading = true;
                FilteringHelper.Instance.SelectedRepositories.ForEach(selectedRepository =>
                {
                    var addedItemsSource = new List <ChartData>();
                    var deletedItemsSource = new List <ChartData>();

                    var days = Enumerable.Range(1, 31).ToList();

                    Parallel.ForEach(days, day =>
                    {
                        using (var session = DbService.Instance.SessionFactory.OpenSession())
                        {
                            int added = 0, deleted = 0;
                            var commits =
                                FilteringHelper.Instance.GenerateQuery(session, selectedRepository)
                                .List <Commit>()
                                .Where(c => c.Date.Day == day).Select(c => c.Id).Distinct().ToList();

                            using (var session2 = DbService.Instance.SessionFactory.OpenSession())
                            {
                                Commit commitAlias = null;
                                var changes =
                                    session2.QueryOver <Changes>()
                                    .JoinAlias(change => change.Commit, () => commitAlias, JoinType.InnerJoin)
                                    .WhereRestrictionOn(() => commitAlias.Id).IsIn(commits).List <Changes>();

                                changes.ForEach(change =>
                                {
                                    var colorServiceT = new DifferencesColoringService(change.ChangeContent, string.Empty);
                                    colorServiceT.FillColorDifferences();

                                    added += colorServiceT.TextAList.Count(x => x.Color == ChangeType.Added);
                                    deleted += colorServiceT.TextAList.Count(x => x.Color == ChangeType.Deleted);
                                });
                            }

                            sumAdded += added;
                            sumDeleted += deleted;

                            addedItemsSource.Add(new ChartData()
                            {
                                RepositoryValue = selectedRepository,
                                ChartKey = day.ToString(),
                                ChartValue = added,
                                NumericChartValue = day
                            });

                            deletedItemsSource.Add(new ChartData()
                            {
                                RepositoryValue = selectedRepository,
                                ChartKey = day.ToString(),
                                ChartValue = deleted,
                                NumericChartValue = day
                            });

                            if (added != 0 || deleted != 0)
                            {
                                Application.Current.Dispatcher.Invoke(() =>
                                {
                                    this.CodeFrequencyDataRows.Add(new CodeFrequencyDataRow()
                                    {
                                        Repository = selectedRepository,
                                        NumericChartKey = day,
                                        AddedLines = added,
                                        DeletedLines = deleted
                                    });
                                });
                            }
                        }
                    });
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        this.AddSeriesToChartCollection(AddedLinesChartList, selectedRepository, addedItemsSource);
                        this.AddSeriesToChartCollection(DeletedLinesChartList, selectedRepository, deletedItemsSource);
                    });
                });
            }));

            SummaryString = this.GetLocalizedString("Added") + ": " + sumAdded + " " +
                            this.GetLocalizedString("Lines") + "\n" +
                            this.GetLocalizedString("Deleted") + ": " + sumDeleted + " " +
                            this.GetLocalizedString("Lines");
            this.RaisePropertyChanged("SummaryString");

            this.AddedChartViewModel.RedrawChart(this.AddedLinesChartList);
            this.DeletedChartViewModel.RedrawChart(this.DeletedLinesChartList);

            this.IsLoading = false;
        }