Добавьте файлы проекта.
This commit is contained in:
46
Services/PdfShellService.cs
Normal file
46
Services/PdfShellService.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using CRAWLER.Models;
|
||||
|
||||
namespace CRAWLER.Services;
|
||||
|
||||
internal interface IPdfOpener
|
||||
{
|
||||
void OpenAttachment(PdfAttachment attachment);
|
||||
void OpenUri(string uri);
|
||||
}
|
||||
|
||||
internal sealed class PdfShellService : IPdfOpener
|
||||
{
|
||||
public void OpenAttachment(PdfAttachment attachment)
|
||||
{
|
||||
if (attachment == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(attachment.LocalPath) && File.Exists(attachment.LocalPath))
|
||||
{
|
||||
OpenUri(attachment.LocalPath);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(attachment.SourceUrl))
|
||||
{
|
||||
OpenUri(attachment.SourceUrl);
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenUri(string uri)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(uri))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Process.Start(new ProcessStartInfo(uri)
|
||||
{
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user