more pdf
This commit is contained in:
parent
0041872afd
commit
3e9d887a12
@ -2,7 +2,7 @@
|
|||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="clr-namespace:PrototypWPFHAG"
|
xmlns:local="clr-namespace:PrototypWPFHAG"
|
||||||
StartupUri="MainWindow.xaml">
|
StartupUri="SearchWindow.xaml">
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
@ -50,6 +50,8 @@
|
|||||||
<Grid Background="Transparent" AllowDrop="True"
|
<Grid Background="Transparent" AllowDrop="True"
|
||||||
DragEnter="PdfDropCanvas_DragEnter" Drop="PdfDropCanvas_Drop" Margin="0,0,9,0">
|
DragEnter="PdfDropCanvas_DragEnter" Drop="PdfDropCanvas_Drop" Margin="0,0,9,0">
|
||||||
<!-- Hinweistext und ggf. Vorschau (zunächst unsichtbar) -->
|
<!-- Hinweistext und ggf. Vorschau (zunächst unsichtbar) -->
|
||||||
|
<Button Grid.Column="0" Content="Wähle PDF aus" Background="LightBlue" Click="ChoosePdfButton_Click"
|
||||||
|
Margin="296,-2,-15,0"/>
|
||||||
<TextBlock x:Name="DropHintText" Text="PDF hier rein ziehen"
|
<TextBlock x:Name="DropHintText" Text="PDF hier rein ziehen"
|
||||||
Foreground="Gray" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5"/>
|
Foreground="Gray" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5"/>
|
||||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,30,0,0">
|
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,30,0,0">
|
||||||
|
@ -32,6 +32,7 @@ namespace PrototypWPFHAG
|
|||||||
private readonly PdfServiceClient _pdfServiceClient = new();
|
private readonly PdfServiceClient _pdfServiceClient = new();
|
||||||
private const string BaseUrl = "http://localhost:8000"; // Microservice-URL
|
private const string BaseUrl = "http://localhost:8000"; // Microservice-URL
|
||||||
private string _selectedPdfPath;
|
private string _selectedPdfPath;
|
||||||
|
private List<string> _selectedPdfPaths = new List<string>();
|
||||||
public SearchWindow()
|
public SearchWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -150,6 +151,7 @@ namespace PrototypWPFHAG
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task SearchBySimilarityAsync()
|
private async Task SearchBySimilarityAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -191,18 +193,39 @@ namespace PrototypWPFHAG
|
|||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ChoosePdfButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var openFileDialog = new Microsoft.Win32.OpenFileDialog
|
||||||
|
{
|
||||||
|
Filter = "PDF Files (*.pdf)|*.pdf",
|
||||||
|
Multiselect = true
|
||||||
|
};
|
||||||
|
|
||||||
|
if (openFileDialog.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
_selectedPdfPaths.AddRange(openFileDialog.FileNames);
|
||||||
|
|
||||||
|
|
||||||
|
PdfIcon.Visibility = Visibility.Visible;
|
||||||
|
PdfFileNameText.Text = string.Join(", ", _selectedPdfPaths.Select(System.IO.Path.GetFileName));
|
||||||
|
PdfFileNameText.Visibility = Visibility.Visible;
|
||||||
|
DropHintText.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
private void PdfDropCanvas_Drop(object sender, DragEventArgs e)
|
private void PdfDropCanvas_Drop(object sender, DragEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||||
{
|
{
|
||||||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||||
_selectedPdfPath = files.FirstOrDefault(f => System.IO.Path.GetExtension(f).Equals(".pdf", StringComparison.OrdinalIgnoreCase));
|
var pdfFiles = files.Where(f => System.IO.Path.GetExtension(f).Equals(".pdf", StringComparison.OrdinalIgnoreCase)).ToList();
|
||||||
|
|
||||||
if (_selectedPdfPath != null)
|
if (pdfFiles.Any())
|
||||||
{
|
{
|
||||||
// Vorschau anzeigen
|
_selectedPdfPaths.AddRange(pdfFiles);
|
||||||
|
|
||||||
|
// 更新UI以显示所有文件
|
||||||
PdfIcon.Visibility = Visibility.Visible;
|
PdfIcon.Visibility = Visibility.Visible;
|
||||||
PdfFileNameText.Text = System.IO.Path.GetFileName(_selectedPdfPath);
|
PdfFileNameText.Text = string.Join(", ", _selectedPdfPaths.Select(System.IO.Path.GetFileName));
|
||||||
PdfFileNameText.Visibility = Visibility.Visible;
|
PdfFileNameText.Visibility = Visibility.Visible;
|
||||||
DropHintText.Visibility = Visibility.Collapsed;
|
DropHintText.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
@ -262,7 +285,7 @@ namespace PrototypWPFHAG
|
|||||||
|
|
||||||
private async void UploadButton_Click(object sender, RoutedEventArgs e)
|
private async void UploadButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(_selectedPdfPath))
|
if (!_selectedPdfPaths.Any())
|
||||||
{
|
{
|
||||||
MessageBox.Show("Keine PDF ausgewählt!");
|
MessageBox.Show("Keine PDF ausgewählt!");
|
||||||
return;
|
return;
|
||||||
@ -275,54 +298,46 @@ namespace PrototypWPFHAG
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var httpClient = new HttpClient())
|
int totalFiles = _selectedPdfPaths.Count;
|
||||||
using (var fileStream = File.OpenRead(_selectedPdfPath))
|
int currentFile = 0;
|
||||||
|
|
||||||
|
foreach (var pdfPath in _selectedPdfPaths)
|
||||||
{
|
{
|
||||||
var progress = new Progress<float>(percent =>
|
currentFile++;
|
||||||
|
UploadStatusText.Text = $"Upload {currentFile}/{totalFiles}: {System.IO.Path.GetFileName(pdfPath)}";
|
||||||
|
|
||||||
|
using (var httpClient = new HttpClient())
|
||||||
|
using (var fileStream = File.OpenRead(pdfPath))
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(() =>
|
var content = new StreamContent(fileStream);
|
||||||
|
var formData = new MultipartFormDataContent();
|
||||||
|
formData.Add(content, "file", System.IO.Path.GetFileName(pdfPath));
|
||||||
|
|
||||||
|
var response = await httpClient.PostAsync($"{BaseUrl}/upload-pdf", formData);
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
UploadProgressBar.Value = percent * 100;
|
UploadStatusText.Text = $"Erfolgreich hochgeladen: {System.IO.Path.GetFileName(pdfPath)}";
|
||||||
UploadStatusText.Text = $"Upload: {(int)(percent * 100)}%";
|
}
|
||||||
});
|
else
|
||||||
});
|
|
||||||
|
|
||||||
var content = new StreamContent(fileStream);
|
|
||||||
var formData = new MultipartFormDataContent();
|
|
||||||
formData.Add(content, "file", Path.GetFileName(_selectedPdfPath));
|
|
||||||
|
|
||||||
// Simulierter Fortschritt
|
|
||||||
for (int i = 0; i <= 100; i += 10)
|
|
||||||
{
|
|
||||||
await Task.Delay(100);
|
|
||||||
((IProgress<float>)progress).Report(i / 100f);
|
|
||||||
}
|
|
||||||
|
|
||||||
var response = await httpClient.PostAsync($"{BaseUrl}/upload-pdf", formData);
|
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
// Erfolgsmeldung anzeigen
|
|
||||||
UploadStatusText.Text = "Erfolgreich hochgeladen!";
|
|
||||||
|
|
||||||
// Canvas zurücksetzen
|
|
||||||
Dispatcher.Invoke(() =>
|
|
||||||
{
|
{
|
||||||
PdfIcon.Visibility = Visibility.Collapsed;
|
UploadStatusText.Text = $"Fehler beim Upload von {System.IO.Path.GetFileName(pdfPath)}";
|
||||||
PdfFileNameText.Visibility = Visibility.Collapsed;
|
}
|
||||||
DropHintText.Visibility = Visibility.Visible;
|
|
||||||
_selectedPdfPath = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Erfolgsmeldung nach 3 Sekunden ausblenden
|
|
||||||
await Task.Delay(3000);
|
|
||||||
UploadStatusText.Text = string.Empty;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UploadStatusText.Text = "Fehler beim Upload";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Canvas zurücksetzen
|
||||||
|
Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
PdfIcon.Visibility = Visibility.Collapsed;
|
||||||
|
PdfFileNameText.Visibility = Visibility.Collapsed;
|
||||||
|
DropHintText.Visibility = Visibility.Visible;
|
||||||
|
_selectedPdfPaths.Clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Erfolgsmeldung nach 3 Sekunden ausblenden
|
||||||
|
await Task.Delay(3000);
|
||||||
|
UploadStatusText.Text = string.Empty;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user