Example #1
0
        private async void UploadFileAndQueryButton_OnClick(object sender, RoutedEventArgs e)
        {
            using var fileDialog = new CommonOpenFileDialog("选择文件")
                  {
                      Multiselect = false
                  };
            try
            {
                if (fileDialog.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    Searching.Visibility         = Visibility.Visible;
                    UploadFileTextBox.Text       = fileDialog.FileName;
                    await using var memoryStream = new MemoryStream(await File.ReadAllBytesAsync(UploadFileTextBox.Text), false);
                    var sauceResponse = await RestService.For <ISauceNAOProtocol>(ProtocolBase.SauceNAOUrl)
                                        .GetSauce(new StreamPart(memoryStream, Path.GetFileName(fileDialog.FileName), Texts.AssumeImageContentType(fileDialog.FileName)));

                    var content = await sauceResponse.Content.ReadAsStringAsync();

                    if ((await ParseSauce(content)).ToList() is { } sauceResults&& sauceResults.Any())
                    {
                        MainWindow.Instance.OpenIllustBrowser(await PixivHelper.IllustrationInfo(sauceResults[0]));
                    }
                    else
                    {
                        MainWindow.MessageQueue.Enqueue("找不到结果TAT");
                    }
                }
            }