Skip to content

Commit

Permalink
R#
Browse files Browse the repository at this point in the history
  • Loading branch information
peters committed Jan 27, 2024
1 parent 9149778 commit 096ac28
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 104 deletions.
2 changes: 1 addition & 1 deletion Digipost.Api.Client.Archive.Tests/ArchiveTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void BuildCorrectNextDocumentsUri()
{
Links = new Dictionary<string, Link>
{
["NEXT_DOCUMENTS"] = new Link("https://www.testing.no/1010/archive/1000/document?limit=100&offset=0")
["NEXT_DOCUMENTS"] = new("https://www.testing.no/1010/archive/1000/document?limit=100&offset=0")
{
Rel = "https://www.testing.no/relation/next_document"
}
Expand Down
4 changes: 2 additions & 2 deletions Digipost.Api.Client.Archive/ArchiveApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public interface IArchiveApi
*/
Task<Archive> GetArchiveDocument(GetArchiveDocumentByUuidUri getArchiveDocumentUri, CancellationToken cancellationToken);

Task<Archive> FetchDocumentFromExternalId(String externalId, CancellationToken cancellationToken);
Task<Archive> FetchDocumentFromExternalId(string externalId, CancellationToken cancellationToken);

Task<Archive> FetchDocumentFromExternalId(Guid externalIdGuid, CancellationToken cancellationToken);

Task<Stream> StreamDocumentFromExternalId(String externalId, CancellationToken cancellationToken);
Task<Stream> StreamDocumentFromExternalId(string externalId, CancellationToken cancellationToken);

Task<Stream> StreamDocumentFromExternalId(Guid externalIdGuid, CancellationToken cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ public void SearchResult()
{
PersonDetails = new List<SearchDetails>
{
new SearchDetails
new()
{
FirstName = recipient0.Firstname,
MiddleName = recipient0.Middlename,
Expand All @@ -766,7 +766,7 @@ public void SearchResult()
DigipostAddress = recipient0.Digipost_Address,
SearchDetailsAddress = new List<SearchDetailsAddress>
{
new SearchDetailsAddress
new()
{
Street = recipient0.Address[0].Street,
HouseNumber = recipient0.Address[0].House_Number,
Expand All @@ -775,7 +775,7 @@ public void SearchResult()
PostalCode = recipient0.Address[0].Zip_Code,
City = recipient0.Address[0].City
},
new SearchDetailsAddress
new()
{
Street = recipient0.Address[1].Street,
HouseNumber = recipient0.Address[1].House_Number,
Expand All @@ -786,7 +786,7 @@ public void SearchResult()
}
}
},
new SearchDetails
new()
{
FirstName = recipient1.Firstname,
MiddleName = recipient1.Middlename,
Expand All @@ -797,7 +797,7 @@ public void SearchResult()
DigipostAddress = recipient1.Digipost_Address,
SearchDetailsAddress = new List<SearchDetailsAddress>
{
new SearchDetailsAddress
new()
{
Street = recipient1.Address[0].Street,
HouseNumber = recipient1.Address[0].House_Number,
Expand Down
12 changes: 6 additions & 6 deletions Digipost.Api.Client.Common/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ public class Environment

public Uri Url { get; set; }

public static Environment Production => new Environment(new Uri("https://api.digipost.no/"));
public static Environment Production => new(new Uri("https://api.digipost.no/"));

public static Environment NorskHelsenett => new Environment(new Uri("https://api.nhn.digipost.no"));
public static Environment NorskHelsenett => new(new Uri("https://api.nhn.digipost.no"));

public static Environment DifiTest => new Environment(new Uri("https://api.difitest.digipost.no/"));
public static Environment DifiTest => new(new Uri("https://api.difitest.digipost.no/"));

public static Environment Test => new Environment(new Uri("https://api.test.digipost.no/"));
public static Environment Test => new(new Uri("https://api.test.digipost.no/"));

internal static Environment Qa => new Environment(new Uri("https://api.qa.digipost.no/"));
internal static Environment Qa => new(new Uri("https://api.qa.digipost.no/"));

internal static Environment Local => new Environment(new Uri("http://localhost:8282/"));
internal static Environment Local => new(new Uri("http://localhost:8282/"));

public override string ToString()
{
Expand Down
4 changes: 2 additions & 2 deletions Digipost.Api.Client.Common/RequestForRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class RequestForRegistration
{
public RequestForRegistration(
DateTime registrationDeadline,
String phoneNumber,
String emailAddress,
string phoneNumber,
string emailAddress,
IPrintDetails printDetails
)
{
Expand Down
4 changes: 2 additions & 2 deletions Digipost.Api.Client.Common/Share/SharedDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class SharedDocument : RestLinkable

public SharedDocument(
DateTime deliveryTime,
String subject,
String fileType,
string subject,
string fileType,
int fileSizeBytes,
IOrigin origin,
Dictionary<string, Link> links)
Expand Down
20 changes: 7 additions & 13 deletions Digipost.Api.Client.Common/Utilities/SerializeUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ public static string Serialize<T>(T value)
OmitXmlDeclaration = false
};

using (var textWriter = new Utf8StringWriter())
using var textWriter = new Utf8StringWriter();
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
{
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
{
serializer.Serialize(xmlWriter, value);
}
return textWriter.ToString();
serializer.Serialize(xmlWriter, value);
}
return textWriter.ToString();
}

public static T Deserialize<T>(string xml)
Expand All @@ -45,13 +43,9 @@ public static T Deserialize<T>(string xml)

var settings = new XmlReaderSettings();

using (var textReader = new StringReader(xml))
{
using (var xmlReader = XmlReader.Create(textReader, settings))
{
return (T)serializer.Deserialize(xmlReader);
}
}
using var textReader = new StringReader(xml);
using var xmlReader = XmlReader.Create(textReader, settings);
return (T)serializer.Deserialize(xmlReader);
}

sealed class Utf8StringWriter : StringWriter
Expand Down
2 changes: 1 addition & 1 deletion Digipost.Api.Client.Common/Utilities/UUIDInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Digipost.Api.Client.Common.Utilities;

public static class UuidInterop
{
public static string NameUuidFromBytes(String input)
public static string NameUuidFromBytes(string input)
{
MD5 md5 = MD5.Create();
byte[] hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(input));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static Inbox GetInbox()

var links = new Dictionary<string, Link>
{
["GET_INBOX"] = new Link(httpClient.BaseAddress + $"{DomainUtility.GetSender().Id}/inbox") { Rel = httpClient.BaseAddress + "relations/get_inbox" }
["GET_INBOX"] = new(httpClient.BaseAddress + $"{DomainUtility.GetSender().Id}/inbox") { Rel = httpClient.BaseAddress + "relations/get_inbox" }
};
var root = new Root("")
{
Expand Down
19 changes: 19 additions & 0 deletions Digipost.Api.Client.Inbox/Inbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,29 @@ namespace Digipost.Api.Client.Inbox;

internal interface IInbox
{
/// <summary>
/// Fetches a collection of InboxDocuments asynchronously.
/// </summary>
/// <param name="offset">The offset of documents to fetch (optional, default is 0).</param>
/// <param name="limit">The maximum number of documents to fetch (optional, default is 100).</param>
/// <param name="cancellationToken">The cancellation token to cancel operation (optional, default is CancellationToken.None).</param>
/// <returns>Returns a task representing the asynchronous operation that returns a collection of InboxDocuments.</returns>
Task<IEnumerable<InboxDocument>> FetchAsync(int offset = 0, int limit = 100, CancellationToken cancellationToken = default);

/// <summary>
/// Fetches a document from the inbox asynchronously.
/// </summary>
/// <param name="document">The document to fetch.</param>
/// <param name="cancellationToken">The cancellation token to cancel operation (optional, default is CancellationToken.None).</param>
/// <returns>Returns a task representing the asynchronous operation that returns a stream containing the document content.</returns>
Task<Stream> FetchDocumentAsync(GetInboxDocumentContentUri document, CancellationToken cancellationToken);

/// <summary>
/// Deletes a document from the inbox asynchronously.
/// </summary>
/// <param name="document">The document to delete.</param>
/// <param name="cancellationToken">The cancellation token to cancel the operation (optional, default is CancellationToken.None).</param>
/// <returns>Returns a task representing the asynchronous operation.</returns>
Task DeleteDocumentAsync(InboxDocumentDeleteUri document, CancellationToken cancellationToken);
}

Expand Down
2 changes: 1 addition & 1 deletion Digipost.Api.Client.Resources/Content/ContentResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Digipost.Api.Client.Resources.Content;

internal class ContentResource
{
static readonly ResourceUtility ResourceUtility = new ResourceUtility(typeof(XsdResource).GetTypeInfo().Assembly, "Digipost.Api.Client.Resources.Content.Data");
static readonly ResourceUtility ResourceUtility = new(typeof(XsdResource).GetTypeInfo().Assembly, "Digipost.Api.Client.Resources.Content.Data");

static byte[] GetResource(params string[] path)
{
Expand Down
2 changes: 1 addition & 1 deletion Digipost.Api.Client.Resources/Xml/XmlResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Digipost.Api.Client.Resources.Xml;

internal static class XmlResource
{
static readonly ResourceUtility ResourceUtility = new ResourceUtility(typeof(XmlResource).GetTypeInfo().Assembly, "Digipost.Api.Client.Resources.Xml.Data");
static readonly ResourceUtility ResourceUtility = new(typeof(XmlResource).GetTypeInfo().Assembly, "Digipost.Api.Client.Resources.Xml.Data");

static StringContent GetResource(params string[] path)
{
Expand Down
2 changes: 1 addition & 1 deletion Digipost.Api.Client.Resources/Xsd/XsdResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Digipost.Api.Client.Resources.Xsd;

internal static class XsdResource
{
static readonly ResourceUtility ApiResourceUtility = new ResourceUtility(typeof(XsdResource).Assembly, "Digipost.Api.Client.Resources.Xsd.Data");
static readonly ResourceUtility ApiResourceUtility = new(typeof(XsdResource).Assembly, "Digipost.Api.Client.Resources.Xsd.Data");

public static XmlReader GetApiV8Xsd()
{
Expand Down
15 changes: 6 additions & 9 deletions Digipost.Api.Client.Send.Tests/DocumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,12 @@ public void DocumentFromStream()
static string CreateTempFile()
{
var tempFile = Path.GetTempFileName();
using (var fileStream = new FileStream(tempFile, FileMode.Append))
{
using (var writer = new StreamWriter(fileStream))
{
writer.WriteLine("testulf testesen");
writer.Flush();
writer.Close();
}
}
using var fileStream = new FileStream(tempFile, FileMode.Append);
using var writer = new StreamWriter(fileStream);
writer.WriteLine("testulf testesen");
writer.Flush();
writer.Close();

return tempFile;
}

Expand Down
2 changes: 1 addition & 1 deletion Digipost.Api.Client.Send.Tests/MessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Digipost.Api.Client.Send.Tests;

public class MessageTests
{
internal readonly Sender Sender = new Sender(1010);
internal readonly Sender Sender = new(1010);

public class ConstructorMethod : MessageTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void Message()
},
Attachments = new List<Document>
{
new Document(source.Attachment[0].Subject, source.Attachment[0].File_Type, AuthenticationLevel.TwoFactor, SensitivityLevel.Sensitive)
new(source.Attachment[0].Subject, source.Attachment[0].File_Type, AuthenticationLevel.TwoFactor, SensitivityLevel.Sensitive)
{
Guid = source.Attachment[0].Uuid,
ContentHash = new ContentHash {HashAlgoritm = source.Attachment[0].Content_Hash.Hash_Algorithm, Value = source.Attachment[0].Content_Hash.Value}
Expand Down
10 changes: 4 additions & 6 deletions Digipost.Api.Client.Send/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Document(string subject, string fileType, Stream documentStream, Authenti
/// <param name="dataType">Optional metadata for enriching the document when viewed in Digipost</param>
public Document(string subject, string fileType, string path, AuthenticationLevel authenticationLevel = AuthenticationLevel.Password,
SensitivityLevel sensitivityLevel = SensitivityLevel.Normal, ISmsNotification smsNotification = null, IDigipostDataType dataType = null)
: this(subject, fileType, new byte[] { }, authenticationLevel, sensitivityLevel, smsNotification, dataType)
: this(subject, fileType, System.Array.Empty<byte>(), authenticationLevel, sensitivityLevel, smsNotification, dataType)
{
ContentBytes = ExtractBytesFromPath(path);
}
Expand All @@ -63,7 +63,7 @@ public Document(string subject, string fileType, string path, AuthenticationLeve
/// <param name="dataType">Optional metadata for enriching the document when viewed in Digipost</param>
internal Document(string subject, string fileType, AuthenticationLevel authenticationLevel = AuthenticationLevel.Password,
SensitivityLevel sensitivityLevel = SensitivityLevel.Normal, ISmsNotification smsNotification = null, IDigipostDataType dataType = null)
: this(subject, fileType, new byte[] { }, authenticationLevel, sensitivityLevel, smsNotification, dataType)
: this(subject, fileType, System.Array.Empty<byte>(), authenticationLevel, sensitivityLevel, smsNotification, dataType)
{
}

Expand All @@ -87,10 +87,8 @@ internal Document(string subject, string fileType, AuthenticationLevel authentic

static byte[] ExtractBytesFromPath(string path)
{
using (var fileStream = new FileStream(path, FileMode.Open))
{
return ExtractBytesFromStream(fileStream);
}
using var fileStream = new FileStream(path, FileMode.Open);
return ExtractBytesFromStream(fileStream);
}

static byte[] ExtractBytesFromStream(Stream fileStream)
Expand Down
57 changes: 21 additions & 36 deletions Digipost.Api.Client.Send/DocumentStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,44 @@

namespace Digipost.Api.Client.Send;

public class DocumentStatus
public class DocumentStatus(
string guid,
long senderId,
DateTime created,
DocumentStatus.DocumentDeliveryStatus documentDeliveryStatus,
DocumentStatus.Read? read,
DeliveryMethod deliveryMethod,
string contentHash,
DateTime? delivered,
bool? isPrimaryDocument,
HashAlgoritm? contentHashAlgoritm)
{
public DocumentStatus(
string guid,
long senderId,
DateTime created,
DocumentDeliveryStatus documentDeliveryStatus,
Read? read,
DeliveryMethod deliveryMethod,
string contentHash,
DateTime? delivered,
Boolean? isPrimaryDocument,
HashAlgoritm? contentHashAlgoritm
)
{
Guid = guid;
Sender = new Sender(senderId);
Created = created;
DeliveryStatus = documentDeliveryStatus;
DocumentRead = read;
DeliveryMethod = deliveryMethod;
ContentHash = contentHash;
Delivered = delivered;
IsPrimaryDocument = isPrimaryDocument;
ContentHashAlgoritm = contentHashAlgoritm;
}

public string Guid { get; }
public string Guid { get; } = guid;

public Sender Sender { get; }
public Sender Sender { get; } = new(senderId);

public DateTime Created { get; }
public DateTime Created { get; } = created;

/**
* If DeliveryStatus is NOT_DELIVERED, Delivered will not have a value
*/
public DateTime? Delivered { get; }
public DateTime? Delivered { get; } = delivered;

public DocumentDeliveryStatus DeliveryStatus { get; }
public DocumentDeliveryStatus DeliveryStatus { get; } = documentDeliveryStatus;

public Read? DocumentRead { get; }
public Read? DocumentRead { get; } = read;

public DeliveryMethod DeliveryMethod { get; }
public DeliveryMethod DeliveryMethod { get; } = deliveryMethod;

public String ContentHash { get; }
public string ContentHash { get; } = contentHash;

public HashAlgoritm? ContentHashAlgoritm { get; }
public HashAlgoritm? ContentHashAlgoritm { get; } = contentHashAlgoritm;

/**
* isPrimaryDocument has value only if you ask api are the actual sender asking for DocumentStatus.
* If you are, then this will be true for the primary document else false.
*/
public Boolean? IsPrimaryDocument { get; }
public bool? IsPrimaryDocument { get; } = isPrimaryDocument;

public enum DocumentDeliveryStatus
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ SendMessageApi GetDigipostApi(FakeResponseHandler fakeResponseHandler)

var links = new Dictionary<string, Link>
{
["SEARCH"] = new Link(httpClient.BaseAddress + $"{DomainUtility.GetSender().Id}/recipient/search") { Rel = httpClient.BaseAddress + "relations/search" },
["IDENTIFY_RECIPIENT"] = new Link(httpClient.BaseAddress + $"{DomainUtility.GetSender().Id}/identification") { Rel = httpClient.BaseAddress + "relations/identify_recipient" },
["CREATE_MESSAGE"] = new Link(httpClient.BaseAddress + $"{DomainUtility.GetSender().Id}/message") { Rel = httpClient.BaseAddress + "relations/create_message" }
["SEARCH"] = new(httpClient.BaseAddress + $"{DomainUtility.GetSender().Id}/recipient/search") { Rel = httpClient.BaseAddress + "relations/search" },
["IDENTIFY_RECIPIENT"] = new(httpClient.BaseAddress + $"{DomainUtility.GetSender().Id}/identification") { Rel = httpClient.BaseAddress + "relations/identify_recipient" },
["CREATE_MESSAGE"] = new(httpClient.BaseAddress + $"{DomainUtility.GetSender().Id}/message") { Rel = httpClient.BaseAddress + "relations/create_message" }
};
var root = new Root("")
{
Expand Down
Loading

0 comments on commit 096ac28

Please sign in to comment.