7 Commits

Author SHA1 Message Date
9fd3bb7fa5 bump 0.2.7 2026-01-15 20:07:10 +01:00
67cdfb0c21 fix(debug): hide debug console 2026-01-15 20:06:48 +01:00
ddc7206a73 optim(redmine): hour stats are also improved 2026-01-15 20:03:45 +01:00
d152b62cc4 optim(redmine): made most requests async 2026-01-15 16:31:53 +01:00
0b6df0c508 bump 0.2.2 2025-12-17 12:34:27 +01:00
ec077240a4 fix update button, bump 0.2.1 2025-12-17 12:32:24 +01:00
56fd7a6da7 bump 0.2.0 2025-12-17 12:23:56 +01:00
6 changed files with 211 additions and 76 deletions

View File

@@ -1,5 +1,8 @@
using Blueberry.Redmine.Dto; using Blueberry.Redmine.Dto;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@@ -76,7 +79,7 @@ namespace Blueberry.Redmine
throw new RedmineApiException("Redmine API Unreachable"); throw new RedmineApiException("Redmine API Unreachable");
} }
/*
private async Task<List<TReturn>> SendRequestWithPagingAsync<TResponse, TReturn>(HttpMethod method, string endpoint, int limit, Func<TResponse, List<TReturn>> itemParser, private async Task<List<TReturn>> SendRequestWithPagingAsync<TResponse, TReturn>(HttpMethod method, string endpoint, int limit, Func<TResponse, List<TReturn>> itemParser,
IProgress<(int current, int total)>? progress = null, object? payload = null, CancellationToken? token = null) where TResponse : IResponseList IProgress<(int current, int total)>? progress = null, object? payload = null, CancellationToken? token = null) where TResponse : IResponseList
{ {
@@ -84,6 +87,8 @@ namespace Blueberry.Redmine
List<TReturn> returnList = []; List<TReturn> returnList = [];
_logger.LogDebug("Starting paged request to {Endpoint} with limit {Limit}", endpoint, limit);
while (true) while (true)
{ {
var path = ""; var path = "";
@@ -110,6 +115,106 @@ namespace Blueberry.Redmine
return returnList; return returnList;
} }
*/
private async Task<List<TReturn>> SendRequestWithPagingAsync<TResponse, TReturn>(HttpMethod method, string endpoint, int limit, Func<TResponse, List<TReturn>> itemParser,
IProgress<(int current, int total)>? progress = null, object? payload = null, CancellationToken? token = null) where TResponse : IResponseList
{
var sw = new Stopwatch();
sw.Start();
var offset = 0;
List<TReturn> returnList = [];
_logger.LogDebug("Starting paged request to {Endpoint} with limit {Limit}", endpoint.Split('?')[0], limit);
var path = "";
if (endpoint.Contains('?'))
path = $"{endpoint}&limit={limit}&offset={offset}";
else
path = $"{endpoint}?limit={limit}&offset={offset}";
var responseList = await SendRequestAsync<TResponse>(HttpMethod.Get, path, token: token)
?? throw new NullReferenceException();
var total = responseList.TotalCount;
returnList.AddRange(itemParser(responseList));
offset += limit;
if (offset >= responseList.TotalCount)
{
_logger.LogDebug(" + Single request retrieved all {TotalItems} items", returnList.Count);
return returnList;
}
var remain = total - offset;
var tasks = new Task[(int)Math.Ceiling((double)remain / limit)];
List<(int id, IEnumerable<TReturn> items)> responses = [];
var preparationTime = sw.ElapsedMilliseconds;
sw.Restart();
for (int i = 0; i < tasks.Length; i++)
{
var id = i;
var o = offset;
tasks[i] = Task.Run(async () =>
{
if (endpoint.Contains('?'))
path = $"{endpoint}&limit={limit}&offset={o}";
else
path = $"{endpoint}?limit={limit}&offset={o}";
var responseList = await SendRequestAsync<TResponse>(HttpMethod.Get, path, token: token)
?? throw new NullReferenceException();
responses.Add((id, itemParser(responseList)));
});
offset += limit;
}
while (tasks.Any(t => !t.IsCompleted))
{
if (progress != null)
{
var current = Math.Min(tasks.Count(x=>x.IsCompletedSuccessfully), tasks.Length);
progress.Report((current, tasks.Length));
}
await Task.Delay(250);
}
await Task.WhenAll(tasks);
await Task.Delay(50);
var executionTime = sw.ElapsedMilliseconds;
sw.Restart();
foreach (var resp in responses.OrderBy(x => x.id))
{
returnList.AddRange(resp.items);
}
_logger.LogDebug(" + Aggregated total of {TotalItems} items from {Count} responses", returnList.Count, responses.Count);
var aggregationTime = sw.ElapsedMilliseconds;
sw.Stop();
// log times
_logger.LogDebug(" + Paging completed in:\n Preparation: {Preparation}ms\n Execution: {Execution}ms\n Aggregation: {Aggregation}ms\n Total: {Total}ms"
, preparationTime, executionTime, aggregationTime, preparationTime + executionTime + aggregationTime);
// log avarege time per task and per item, round them to whole ms
_logger.LogDebug(" + Average time per task: {AvgTask}ms, Average time per item: {AvgItem}ms",
Math.Round((double)(preparationTime + executionTime) / tasks.Length + 1),
Math.Round((double)(executionTime) / returnList.Count));
return returnList;
}
public async Task<List<StatusList.IssueStatus>> GetStatusesAsync(CancellationToken? token = null) public async Task<List<StatusList.IssueStatus>> GetStatusesAsync(CancellationToken? token = null)
{ {
@@ -364,7 +469,7 @@ namespace Blueberry.Redmine
{ {
var path = "users.json"; var path = "users.json";
return await SendRequestWithPagingAsync<UserList.Root, UserInfo.User>(HttpMethod.Get, path, limit, (x) => x.Users, progress, token); return [.. (await SendRequestWithPagingAsync<UserList.Root, UserInfo.User>(HttpMethod.Get, path, limit, (x) => x.Users, progress, token)).OrderBy(x => x.FullName)];
} }
public async Task SetIssueStatusAsync(int issueId, int statusId, CancellationToken? token = null) public async Task SetIssueStatusAsync(int issueId, int statusId, CancellationToken? token = null)

View File

@@ -2,6 +2,7 @@
using Blueberry.Redmine; using Blueberry.Redmine;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.IO; using System.IO;
@@ -33,10 +34,16 @@ namespace BlueMine
}); });
//services.AddTransient<RedmineAuthHandler>(); //services.AddTransient<RedmineAuthHandler>();
services.AddHttpClient<RedmineManager>(client => client.BaseAddress = new Uri("http://localhost/")); //services.AddHttpClient("client", client => client.BaseAddress = new Uri("http://localhost/")).RemoveAllLoggers();
services.AddHttpClient("client").RemoveAllLoggers();
services.Configure<LoggerFilterOptions>(opts =>
{
opts.AddFilter("System.Net.Http.HttpClient", LogLevel.Warning);
});
// .AddHttpMessageHandler<RedmineAuthHandler>(); // .AddHttpMessageHandler<RedmineAuthHandler>();
services.AddSingleton<RedmineManager>(); services.AddSingleton<RedmineManager>();
services.AddSingleton<HoursWindow>();
services.AddSingleton<MainWindow>(); services.AddSingleton<MainWindow>();
}).Build(); }).Build();

View File

@@ -1,9 +1,12 @@
using Blueberry.Redmine; using Blueberry.Redmine;
using Blueberry.Redmine.Dto; using Blueberry.Redmine.Dto;
using Microsoft.Extensions.Logging;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows; using System.Windows;
using Wpf.Ui.Controls; using Wpf.Ui.Controls;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Blueberry namespace Blueberry
{ {
@@ -16,15 +19,17 @@ namespace Blueberry
private readonly RedmineManager _manager; private readonly RedmineManager _manager;
private readonly RedmineConfig _config; private readonly RedmineConfig _config;
private readonly ConcurrentDictionary<int, string> _issueNames = []; private readonly ConcurrentDictionary<int, string> _issueNames = [];
private readonly ILogger _logger;
public ObservableCollection<DisplayHours> Hours { get; set; } = []; public ObservableCollection<DisplayHours> Hours { get; set; } = [];
public HoursWindow(RedmineManager manager, RedmineConfig config) public HoursWindow(RedmineManager manager, RedmineConfig config, ILogger<HoursWindow> logger)
{ {
InitializeComponent(); InitializeComponent();
DataContext = this; DataContext = this;
_manager = manager; _manager = manager;
_config = config; _config = config;
_logger = logger;
} }
private async void FluentWindow_Loaded(object sender, RoutedEventArgs e) private async void FluentWindow_Loaded(object sender, RoutedEventArgs e)
@@ -42,7 +47,7 @@ namespace Blueberry
foreach (var user in u) foreach (var user in u)
userComboBox.Items.Add(user); userComboBox.Items.Add(user);
userComboBox.SelectedItem = current; userComboBox.SelectedItem = _users.First(x=>x.Id == current.Id);
userComboBox.IsEnabled = userComboBox.IsEnabled =
searchButton.IsEnabled = searchButton.IsEnabled =
dateButton.IsEnabled = true; dateButton.IsEnabled = true;
@@ -113,15 +118,33 @@ namespace Blueberry
Task[] tasks = new Task[selectedDates.Count]; Task[] tasks = new Task[selectedDates.Count];
Hours.Clear(); Hours.Clear();
hoursProgress.Visibility= Visibility.Visible; hoursProgress.Visibility= Visibility.Visible;
var firstDate = userCalendar.SelectedDates.First();
var lastDate = userCalendar.SelectedDates.Last();
for (int i = 0; i < selectedDates.Count; i++) var newTicketTask = _manager.GetIssuesAsync(user.Id, createdFrom: selectedDates.First(), createdTo: selectedDates.Last());
var closedTicketTask = _manager.GetIssuesAsync(user.Id, isOpen: false, updatedFrom: selectedDates.First(), updatedTo: selectedDates.Last());
var currentTicketTask = _manager.GetUserOpenIssuesAsync(user.Id);
var h = await _manager.GetTimeForUserAsync(user.Id, firstDate, lastDate);
var list = new List<string>();
foreach (var item in h)
if (await GetIssueNameAsync(item.Issue.Id, download: false) == "")
list.Add(item.Issue.Id.ToString());
if (list.Count > 0)
{ {
hoursProgress.IsIndeterminate = false; list = [.. list.Distinct()];
totalI = selectedDates.Count; _logger.LogDebug("Downloading issue names for {count} issues", list.Count);
var date = selectedDates[i]; var ts = new Task[list.Count];
tasks[i] = Task.Run(async () => for (int y = 0; y < list.Count; y++)
{ {
var h = await _manager.GetTimeForUserAsync(user.Id, date, date); string? id = list[y];
ts[y] = GetIssueNameAsync(int.Parse(id));
}
await Task.WhenAll(ts);
}
foreach (var item in h) foreach (var item in h)
{ {
var dh = new DisplayHours() var dh = new DisplayHours()
@@ -129,7 +152,7 @@ namespace Blueberry
ProjectName = item.Project.Name, ProjectName = item.Project.Name,
IssueName = await GetIssueNameAsync(item.Issue.Id), IssueName = await GetIssueNameAsync(item.Issue.Id),
IssueId = item.Issue.Id.ToString(), IssueId = item.Issue.Id.ToString(),
Date = date, Date = DateTime.Parse(item.SpentOn),
CreatedOn = item.CreatedOn, CreatedOn = item.CreatedOn,
Hours = item.Hours.ToString(), Hours = item.Hours.ToString(),
Comments = item.Comments, Comments = item.Comments,
@@ -137,19 +160,34 @@ namespace Blueberry
}; };
hours.Add(dh); hours.Add(dh);
} }
loadI++;
UpdateProgressI(); var orderedHours = hours.OrderByDescending(h => h.CreatedOn).OrderBy(h => h.Date).ToList();
}); var previousDate = DateTime.MinValue;
await Task.Delay(10); for (int i = 0; i < orderedHours.Count; i++)
{
if (orderedHours[i].Date.Date > previousDate)
{
var ttl = orderedHours.Where(x => x.Date.Date == orderedHours[i].Date.Date).Sum(x => double.Parse(x.Hours));
var dh = new DisplayHours()
{
IsSeparator = true,
SeparatorText = orderedHours[i].Date.ToString("yyyy-MM-dd") + " | Összesen: " + ttl + " óra"
};
orderedHours.Insert(i, dh);
previousDate = orderedHours[i + 1].Date.Date;
}
} }
await Task.WhenAll(tasks); hoursProgress.Visibility = Visibility.Hidden;
hoursProgress.IsIndeterminate = true; foreach (var item in orderedHours)
Hours.Add(item);
var newTickets = await _manager.GetIssuesAsync(user.Id, createdFrom: selectedDates.First(), createdTo: selectedDates.Last()); await Task.WhenAll(newTicketTask, closedTicketTask, currentTicketTask);
var closedTickets = await _manager.GetIssuesAsync(user.Id, isOpen: false, updatedFrom: selectedDates.First(), updatedTo: selectedDates.Last());
var currentTickets = await _manager.GetUserOpenIssuesAsync(user.Id); var newTickets = newTicketTask.Result;
var closedTickets = closedTicketTask.Result;
var currentTickets = currentTicketTask.Result;
var total = hours.Sum(x => double.Parse(x.Hours)); var total = hours.Sum(x => double.Parse(x.Hours));
totalHoursTextBlock.Text = total.ToString(); totalHoursTextBlock.Text = total.ToString();
@@ -172,40 +210,23 @@ namespace Blueberry
avgTicketAgeTextBlock.Text = Math.Round(currentTickets.Average(x => (DateTime.Now - x.CreatedOn).TotalDays), 2) + " nap"; avgTicketAgeTextBlock.Text = Math.Round(currentTickets.Average(x => (DateTime.Now - x.CreatedOn).TotalDays), 2) + " nap";
var ages = currentTickets.Select(x => (DateTime.Now - x.CreatedOn).TotalDays).Order().ToList(); var ages = currentTickets.Select(x => (DateTime.Now - x.CreatedOn).TotalDays).Order().ToList();
medianTicketAgeTextBlock.Text = Math.Round(ages[ages.Count / 2], 2) + " nap"; medianTicketAgeTextBlock.Text = Math.Round(ages[ages.Count / 2], 2) + " nap";
var orderedHours = hours.OrderByDescending(h => h.CreatedOn).OrderBy(h => h.Date).ToList();
var previousDate = DateTime.MinValue;
for (int i = 0; i < orderedHours.Count; i++)
{
if(orderedHours[i].Date.Date > previousDate)
{
total = orderedHours.Where(x => x.Date.Date == orderedHours[i].Date.Date).Sum(x => double.Parse(x.Hours));
var dh = new DisplayHours()
{
IsSeparator = true,
SeparatorText = orderedHours[i].Date.ToString("yyyy-MM-dd") + " | Összesen: " + total + " óra"
};
orderedHours.Insert(i, dh);
previousDate = orderedHours[i+1].Date.Date;
}
} }
hoursProgress.Visibility = Visibility.Hidden; private async Task<string> GetIssueNameAsync(int issueId, bool download = true)
foreach (var item in orderedHours)
Hours.Add(item);
}
private async Task<string> GetIssueNameAsync(int issueId)
{ {
try try
{ {
if (_issueNames.ContainsKey(issueId)) if (_issueNames.ContainsKey(issueId))
return _issueNames[issueId]; return _issueNames[issueId];
if(download)
{
var name = (await _manager.GetSimpleIssueAsync(issueId)).Subject; var name = (await _manager.GetSimpleIssueAsync(issueId)).Subject;
_issueNames.TryAdd(issueId, name); _issueNames.TryAdd(issueId, name);
return name; return name;
} else
{
return "";
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -247,5 +268,6 @@ namespace Blueberry
} }
} }
} }
} }
} }

View File

@@ -113,8 +113,11 @@
<RowDefinition Height="3*"/> <RowDefinition Height="3*"/>
<RowDefinition Height="2*"/> <RowDefinition Height="2*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Center" FontSize="20" FontFamily="/Resources/Inter.ttf#Inter" <ui:Button Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Center" x:Name="openIssueButton"
Margin="5, 0, 10, 0" Text="{Binding Id}" /> Click="openTicketButton_Click" Margin="5, 0, 10, 0" HorizontalAlignment="Stretch">
<TextBlock Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Center" FontSize="18" FontFamily="/Resources/Inter.ttf#Inter" Text="{Binding Id}" />
</ui:Button>
<TextBlock Grid.Column="1" Grid.Row="0" Grid.RowSpan="1" VerticalAlignment="Center" FontSize="14" <TextBlock Grid.Column="1" Grid.Row="0" Grid.RowSpan="1" VerticalAlignment="Center" FontSize="14"
Text="{Binding Subject}" TextTrimming="CharacterEllipsis" ToolTip="{Binding Subject}" ToolTipService.InitialShowDelay="500" /> Text="{Binding Subject}" TextTrimming="CharacterEllipsis" ToolTip="{Binding Subject}" ToolTipService.InitialShowDelay="500" />
<TextBlock Grid.Column="1" Grid.Row="1" Grid.RowSpan="1" VerticalAlignment="Center" FontSize="10" Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}" <TextBlock Grid.Column="1" Grid.Row="1" Grid.RowSpan="1" VerticalAlignment="Center" FontSize="10" Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
@@ -122,13 +125,8 @@
<TextBlock Grid.Column="2" Grid.Row="0" Grid.RowSpan="1" VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="12" <TextBlock Grid.Column="2" Grid.Row="0" Grid.RowSpan="1" VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="12"
Margin="20, 0, 10, 0" Text="{Binding StatusName}" /> Margin="20, 0, 10, 0" Text="{Binding StatusName}" />
<TextBlock Grid.Column="2" Grid.Row="1" Grid.RowSpan="1" VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="10" <TextBlock Grid.Column="2" Grid.Row="1" Grid.RowSpan="1" VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="10"
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}" Margin="20, 0, 0, 0" Text="{Binding LastUpdate}" Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}" Margin="20, 0, 10, 0" Text="{Binding LastUpdate}"
ToolTip="{Binding UpdatedOn}" ToolTipService.InitialShowDelay="200" /> ToolTip="{Binding UpdatedOn}" ToolTipService.InitialShowDelay="200" />
<ui:Button x:Name="openTicketButton" Grid.RowSpan="2" Grid.Column="3" Margin="10, 0, 10, 0" Click="openTicketButton_Click">
<ui:Button.Icon>
<ui:SymbolIcon Symbol="Open24" />
</ui:Button.Icon>
</ui:Button>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ui:ListView.ItemTemplate> </ui:ListView.ItemTemplate>
@@ -262,7 +260,7 @@
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ui:Button x:Name="updateButton" Content="Frissítés" Grid.Column="1" Margin="2" Visibility="Hidden" Click="updateButton_Click" /> <ui:Button x:Name="updateButton" Content="Frissítés" FontSize="8" Grid.Column="1" Margin="2" Visibility="Hidden" Click="updateButton_Click" />
<ui:TextBlock x:Name="versionTextBlock" Grid.Column="2" HorizontalAlignment="Right" FontSize="8" Text="0.0.0" Margin="10" /> <ui:TextBlock x:Name="versionTextBlock" Grid.Column="2" HorizontalAlignment="Right" FontSize="8" Text="0.0.0" Margin="10" />
</Grid> </Grid>
</Grid> </Grid>

View File

@@ -1,6 +1,7 @@
using Blueberry; using Blueberry;
using Blueberry.Redmine; using Blueberry.Redmine;
using Blueberry.Redmine.Dto; using Blueberry.Redmine.Dto;
using Microsoft.Extensions.Logging;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@@ -19,16 +20,18 @@ namespace BlueMine
private readonly RedmineSettingsManager _settings; private readonly RedmineSettingsManager _settings;
private readonly RedmineConfig _config; private readonly RedmineConfig _config;
private List<IssueList.Issue> _issues = []; private List<IssueList.Issue> _issues = [];
private readonly ILoggerFactory _loggerFactory;
public ObservableCollection<IssueList.Issue> IssuesList { get; set; } = []; public ObservableCollection<IssueList.Issue> IssuesList { get; set; } = [];
public ObservableCollection<StatusList.IssueStatus> StatusList { get; set; } = []; public ObservableCollection<StatusList.IssueStatus> StatusList { get; set; } = [];
public MainWindow(RedmineManager manager, RedmineSettingsManager settings, RedmineConfig config) public MainWindow(RedmineManager manager, RedmineSettingsManager settings, RedmineConfig config, ILoggerFactory loggerFactory)
{ {
_settings = settings; _settings = settings;
_config = config; _config = config;
_manager = manager; _manager = manager;
InitializeComponent(); InitializeComponent();
DataContext = this; DataContext = this;
_loggerFactory = loggerFactory;
} }
private async void WindowLoaded(object sender, RoutedEventArgs e) private async void WindowLoaded(object sender, RoutedEventArgs e)
@@ -368,7 +371,7 @@ namespace BlueMine
private async void hoursButton_Click(object sender, RoutedEventArgs e) private async void hoursButton_Click(object sender, RoutedEventArgs e)
{ {
var hoursWindow = new HoursWindow(_manager, _config); var hoursWindow = new HoursWindow(_manager, _config, _loggerFactory.CreateLogger<HoursWindow>());
hoursWindow.Show(); hoursWindow.Show();
} }

View File

@@ -8,7 +8,7 @@ namespace Blueberry
public static class UpdateManager public static class UpdateManager
{ {
private const string releaseUrl = "https://git.technopunk.space/api/v1/repos/tomi/Blueberry/releases/latest"; private const string releaseUrl = "https://git.technopunk.space/api/v1/repos/tomi/Blueberry/releases/latest";
public const string CurrentVersion = "0.1.9"; public const string CurrentVersion = "0.2.7";
private static readonly string appDir = AppDomain.CurrentDomain.BaseDirectory; private static readonly string appDir = AppDomain.CurrentDomain.BaseDirectory;
private static readonly string zipPath = Path.Combine(appDir, "blueberry_update.zip"); private static readonly string zipPath = Path.Combine(appDir, "blueberry_update.zip");
private static readonly HttpClient client = new(); private static readonly HttpClient client = new();