47 lines
955 B
C#
47 lines
955 B
C#
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
|
|
});
|
|
}
|
|
}
|