From ab1f419394960735c7f73610c586aafed0b6a51b Mon Sep 17 00:00:00 2001 From: Sergey Kozulin Date: Sat, 8 May 2021 08:55:45 +0500 Subject: [PATCH 1/2] EdiApiClient use Vostok.ClusterClient --- CHANGELOG.md | 4 + Directory.Build.props | 2 +- EdiApi.Client/EdiApi.Client.csproj | 10 +- EdiApi.Client/Http/AuthCredentials.cs | 9 + EdiApi.Client/Http/BaseEdiApiHttpClient.cs | 242 +++++++++--------- EdiApi.Client/Http/ClusterClientFactory.cs | 67 +++++ .../TransformerConnectorEdiApiClient.cs | 131 ++++++---- EdiApi.Client/Http/Helpers/UrlBuilder.cs | 54 ---- EdiApi.Client/Http/HttpClientException.cs | 43 ++-- .../Http/Internal/InternalEdiApiHttpClient.cs | 154 +++++++---- .../Http/Messages/MessagesEdiApiHttpClient.cs | 152 +++++++---- EdiApi.Client/Http/WebExtensions.cs | 25 -- global.json | 2 +- version.json | 2 +- 14 files changed, 527 insertions(+), 370 deletions(-) create mode 100644 EdiApi.Client/Http/AuthCredentials.cs create mode 100644 EdiApi.Client/Http/ClusterClientFactory.cs delete mode 100644 EdiApi.Client/Http/Helpers/UrlBuilder.cs delete mode 100644 EdiApi.Client/Http/WebExtensions.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 466aa87..18f8347 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # История изменений +## v1.8.1 - 2021.05.11 +- EdiApiClient переведен на ClusterClient +- Добавлены конструкторы для работы через Singular в классы `TransformerConnectorEdiApiClient`, `InternalEdiApiHttpClient` и `MessagesEdiApiHttpClient`. + ## v1.7.10 - 2020.04.02 - Добавлен параметр `enableKeepAlive` в конструктор классов `TransformerConnectorEdiApiClient`, `InternalEdiApiHttpClient` и `MessagesEdiApiHttpClient`. diff --git a/Directory.Build.props b/Directory.Build.props index 90b1072..7e94621 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,7 +14,7 @@ - + \ No newline at end of file diff --git a/EdiApi.Client/EdiApi.Client.csproj b/EdiApi.Client/EdiApi.Client.csproj index 70007a0..3f3db31 100644 --- a/EdiApi.Client/EdiApi.Client.csproj +++ b/EdiApi.Client/EdiApi.Client.csproj @@ -7,7 +7,15 @@ - + + + + + + + + + diff --git a/EdiApi.Client/Http/AuthCredentials.cs b/EdiApi.Client/Http/AuthCredentials.cs new file mode 100644 index 0000000..82e03e9 --- /dev/null +++ b/EdiApi.Client/Http/AuthCredentials.cs @@ -0,0 +1,9 @@ +namespace SkbKontur.EdiApi.Client.Http +{ + public class AuthCredentials + { + public string PortalSid { get; set; } + public string Login { get; set; } + public string Password { get; set; } + } +} diff --git a/EdiApi.Client/Http/BaseEdiApiHttpClient.cs b/EdiApi.Client/Http/BaseEdiApiHttpClient.cs index 7ebf9b6..9ab6723 100644 --- a/EdiApi.Client/Http/BaseEdiApiHttpClient.cs +++ b/EdiApi.Client/Http/BaseEdiApiHttpClient.cs @@ -4,12 +4,14 @@ using JetBrains.Annotations; -using SkbKontur.EdiApi.Client.Http.Helpers; using SkbKontur.EdiApi.Client.Types.Boxes; using SkbKontur.EdiApi.Client.Types.Organization; using SkbKontur.EdiApi.Client.Types.Parties; using SkbKontur.EdiApi.Client.Types.Serialization; +using Vostok.Clusterclient.Core; +using Vostok.Clusterclient.Core.Model; + using PartyInfo = SkbKontur.EdiApi.Client.Types.Parties.PartyInfo; namespace SkbKontur.EdiApi.Client.Http @@ -21,205 +23,203 @@ protected BaseEdiApiHttpClient( int timeoutInMilliseconds, IWebProxy proxy = null, bool enableKeepAlive = true) { this.apiClientId = apiClientId; - this.BaseUri = baseUri; - this.proxy = proxy; - this.enableKeepAlive = enableKeepAlive; - this.timeoutInMilliseconds = timeoutInMilliseconds; - this.Serializer = serializer; + Serializer = serializer; + clusterClient = ClusterClientFactory.Get(baseUri, timeoutInMilliseconds, proxy, enableKeepAlive); } - [NotNull] - public string Authenticate([NotNull] string portalSid) + protected BaseEdiApiHttpClient( + string apiClientId, string environment, IEdiApiTypesSerializer serializer, + int timeoutInMilliseconds, IWebProxy proxy = null, bool enableKeepAlive = true) { - return DoAuthenticate(string.Format("konturediauth_portalsid={0}", portalSid)); + this.apiClientId = apiClientId; + Serializer = serializer; + clusterClient = ClusterClientFactory.Get(environment, timeoutInMilliseconds, proxy, enableKeepAlive); } [NotNull] - public string Authenticate([NotNull] string login, [NotNull] string password) - { - return DoAuthenticate(string.Format("konturediauth_login={0},konturediauth_password={1}", login, password)); - } + public string Authenticate([NotNull] string portalSid) => + DoAuthenticate(new AuthCredentials {PortalSid = portalSid}); + + [NotNull] + public string Authenticate([NotNull] string login, [NotNull] string password) => + DoAuthenticate(new AuthCredentials {Login = login, Password = password}); [NotNull] - private string DoAuthenticate([NotNull] string authCredentials) + private string DoAuthenticate(AuthCredentials authCredentials) { - var url = new UrlBuilder(BaseUri, "V1/Authenticate").ToUri(); - return MakePostRequestInternal(url, null, null, webRequest => { webRequest.Headers["Authorization"] += string.Format(",{0}", authCredentials); }); + var request = BuildPostRequest("V1/Authenticate", authCredentials, null, Array.Empty()); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return result.Response.Content.ToString(); } [NotNull] public PartiesInfo GetAccessiblePartiesInfo([NotNull] string authToken) { - var url = new UrlBuilder(BaseUri, "V1/Parties/GetAccessiblePartiesInfo").ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Parties/GetAccessiblePartiesInfo", null, authToken); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public PartyInfo GetPartyInfo([NotNull] string authToken, [NotNull] string partyId) { - var url = new UrlBuilder(BaseUri, "V1/Parties/GetPartyInfo") - .AddParameter("partyId", partyId) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Parties/GetPartyInfo", null, authToken) + .WithAdditionalQueryParameter("partyId", partyId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public PartyInfo GetPartyInfoByGln([NotNull] string authToken, [NotNull] string partyGln) { - var url = new UrlBuilder(BaseUri, "V1/Parties/GetPartyInfoByGln") - .AddParameter("partyGln", partyGln) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Parties/GetPartyInfoByGln", null, authToken) + .WithAdditionalQueryParameter("partyGln", partyGln); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public PartyInfo GetPartyInfoByDepartmentGln([NotNull] string authToken, [NotNull] string departmentGln) { - var url = new UrlBuilder(BaseUri, "V1/Parties/GetPartyInfoByDepartmentGln") - .AddParameter("departmentGln", departmentGln) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Parties/GetPartyInfoByDepartmentGln", null, authToken) + .WithAdditionalQueryParameter("departmentGln", departmentGln); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public BoxesInfo GetBoxesInfo([NotNull] string authToken) { - var url = new UrlBuilder(BaseUri, "V1/Boxes/GetBoxesInfo").ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Boxes/GetBoxesInfo", null, authToken); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public BoxInfo GetMainApiBox([NotNull] string authToken, [NotNull] string partyId) { - var url = new UrlBuilder(BaseUri, "V1/Boxes/GetMainApiBox") - .AddParameter("partyId", partyId) - .ToUri(); - return MakeGetRequest(url, authToken); - } + var request = BuildGetRequest("V1/Boxes/GetMainApiBox", null, authToken) + .WithAdditionalQueryParameter("partyId", partyId); - [NotNull] - public OrganizationCatalogueInfo GetOrganizationCatalogueInfo([NotNull] string authToken, [NotNull] string partyId) - { - var url = new UrlBuilder(BaseUri, "V1/Organizations/GetOrganizationCatalogueInfo") - .AddParameter("partyId", partyId) - .ToUri(); - return MakeGetRequest(url, authToken); + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] - public UsersInfo GetUsersInfo([NotNull] string authToken, [NotNull] string partyId) + public OrganizationCatalogueInfo GetOrganizationCatalogueInfo([NotNull] string authToken, [NotNull] string partyId) { - var url = new UrlBuilder(BaseUri, "V1/Users/GetUsersInfo") - .AddParameter("partyId", partyId) - .ToUri(); - return MakeGetRequest(url, authToken); - } + var request = BuildGetRequest("V1/Organizations/GetOrganizationCatalogueInfo", null, authToken) + .WithAdditionalQueryParameter("partyId", partyId); - protected TResult MakeGetRequest(Uri requestUri, string authToken) where TResult : class - { - return Serializer.Deserialize(MakeGetRequestInternal(requestUri, authToken)); - } + var result = clusterClient.Send(request); + EnsureSuccessResult(result); - protected TResult MakePostRequest(Uri requestUri, string authToken, byte[] content) where TResult : class - { - return Serializer.Deserialize(MakePostRequestInternal(requestUri, authToken, content)); + return Serializer.Deserialize(result.Response.Content.ToString()); } - protected void MakeGetRequest(Uri requestUri, string authToken) - { - MakeGetRequestInternal(requestUri, authToken); - } - - protected void MakePostRequest(Uri requestUri, string authToken, byte[] content) + [NotNull] + public UsersInfo GetUsersInfo([NotNull] string authToken, [NotNull] string partyId) { - MakePostRequestInternal(requestUri, authToken, content); - } + var request = BuildGetRequest("V1/Users/GetUsersInfo", null, authToken) + .WithAdditionalQueryParameter("partyId", partyId); - protected void MakePostRequest(Uri requestUri, string authToken, TRequestBody bodyObject) - where TRequestBody : class - { - MakePostRequestInternal(requestUri, authToken, Serializer.Serialize(bodyObject).GetBytes(), req => req.ContentType = Serializer.ContentType); - } + var result = clusterClient.Send(request); + EnsureSuccessResult(result); - protected TResult MakePostRequest(Uri requestUri, string authToken, TRequestBody bodyObject) - where TRequestBody : class - where TResult : class - { - return Serializer.Deserialize(MakePostRequestInternal(requestUri, authToken, Serializer.Serialize(bodyObject).GetBytes(), req => req.ContentType = Serializer.ContentType)); + return Serializer.Deserialize(result.Response.Content.ToString()); } protected Uri BaseUri { get; } protected IEdiApiTypesSerializer Serializer { get; } + protected const int DefaultTimeout = 30 * 1000; - protected virtual string MakePostRequestInternal([NotNull] Uri requestUri, [NotNull] string authToken, [CanBeNull] byte[] content, [CanBeNull] Action customizeRequest = null) + protected virtual Request BuildPostRequest([NotNull] string relativeUrl, AuthCredentials authCredentials, string authToken, [CanBeNull] TContent content) + where TContent : class { - var request = CreateRequest(requestUri, authToken); - request.Method = "POST"; - if (content == null || content.Length == 0) - { - request.Headers.Add("Content", "no"); - content = new byte[] {1}; - } - request.ContentLength = content.Length; - customizeRequest?.Invoke(request); - try + var request = Request.Post(relativeUrl) + .WithHeader("Authorization", BuildAuthorizationHeader(authCredentials, authToken)) + .WithAcceptHeader(Serializer.ContentType); + + var data = content as byte[]; + + if (data == null && content != null) { - using (var requestStream = request.GetRequestStream()) - requestStream.Write(content, 0, content.Length); - using (var response = request.GetResponse()) - return response.GetString(); + data = Encoding.UTF8.GetBytes(Serializer.Serialize(content)); + request = request.WithContentTypeHeader(Serializer.ContentType); } - catch (WebException exception) + + if (data == null || data.Length == 0) { - throw HttpClientException.Create(exception, requestUri); + request = request.WithHeader("Content", "no"); + data = new byte[] {1}; } + + request = request.WithContent(data); + + return request; } - protected virtual string MakeGetRequestInternal([NotNull] Uri requestUri, [NotNull] string authToken) + protected virtual Request BuildGetRequest([NotNull] string relativeUrl, AuthCredentials authCredentials, string authToken) { - var request = CreateRequest(requestUri, authToken); - request.Method = "GET"; - try - { - using (var response = request.GetResponse()) - return response.GetString(); - } - catch (WebException exception) - { - throw HttpClientException.Create(exception, requestUri); - } + var request = Request.Get(relativeUrl) + .WithHeader("Authorization", BuildAuthorizationHeader(authCredentials, authToken)) + .WithAcceptHeader(Serializer.ContentType); + + return request; } - private HttpWebRequest CreateRequest(Uri requestUri, string authToken) + protected virtual void EnsureSuccessResult(ClusterResult result) { - var request = (HttpWebRequest)WebRequest.Create(requestUri); - request.AllowAutoRedirect = false; - request.AllowWriteStreamBuffering = true; - request.KeepAlive = enableKeepAlive; - request.Proxy = proxy; - request.ServicePoint.Expect100Continue = false; - request.ServicePoint.UseNagleAlgorithm = false; - request.ServicePoint.ConnectionLimit = 128; - request.Timeout = timeoutInMilliseconds; - request.Accept = Serializer.ContentType; - request.Headers["Authorization"] = BuildAuthorizationHeader(authToken); - return request; + if (!result.Response.IsSuccessful) + { + throw HttpClientException.Create(result); + } } - private string BuildAuthorizationHeader(string authToken) + private string BuildAuthorizationHeader(AuthCredentials authCredentials, string authToken) { var stringBuilder = new StringBuilder(); stringBuilder.Append("KonturEdiAuth "); stringBuilder.Append("konturediauth_api_client_id=" + apiClientId); if (!string.IsNullOrEmpty(authToken)) + { stringBuilder.Append(",konturediauth_token=" + authToken); + } + if (!string.IsNullOrEmpty(authCredentials?.PortalSid)) + { + stringBuilder.Append("," + $"konturediauth_portalsid={authCredentials.PortalSid}"); + } + if (!string.IsNullOrEmpty(authCredentials?.Login)) + { + stringBuilder.Append("," + $"konturediauth_login={authCredentials.Login},konturediauth_password={authCredentials.Password}"); + } + return stringBuilder.ToString(); } + protected readonly IClusterClient clusterClient; + private readonly string apiClientId; - private readonly IWebProxy proxy; - private readonly bool enableKeepAlive; - private readonly int timeoutInMilliseconds; } } \ No newline at end of file diff --git a/EdiApi.Client/Http/ClusterClientFactory.cs b/EdiApi.Client/Http/ClusterClientFactory.cs new file mode 100644 index 0000000..417bea0 --- /dev/null +++ b/EdiApi.Client/Http/ClusterClientFactory.cs @@ -0,0 +1,67 @@ +using System; +using System.Net; + +using Vostok.Clusterclient.Core; +using Vostok.Clusterclient.Singular; +using Vostok.Clusterclient.Transport; +using Vostok.Logging.Abstractions; + +namespace SkbKontur.EdiApi.Client.Http +{ + internal static class ClusterClientFactory + { + public static IClusterClient Get( + Uri externalUri, + int defaultRequestTimeoutMs, + IWebProxy proxy, + bool enableKeepAlive, + ILog log = null + ) + { + if (externalUri == null) + { + throw new ArgumentNullException(nameof(externalUri)); + } + + return new ClusterClient(log, configuration => + { + configuration.DefaultTimeout = TimeSpan.FromMilliseconds(defaultRequestTimeoutMs); + configuration.SetupExternalUrl(externalUri); + configuration.SetupUniversalTransport( + new UniversalTransportSettings + { + AllowAutoRedirect = false, + Proxy = proxy, + TcpKeepAliveEnabled = enableKeepAlive + }); + }); + } + + public static IClusterClient Get( + string environmentName, + int defaultRequestTimeoutMs, + IWebProxy proxy, + bool enableKeepAlive, + ILog log = null + ) + { + if (string.IsNullOrEmpty(environmentName)) + { + throw new ArgumentOutOfRangeException(nameof(environmentName)); + } + + return new ClusterClient(log, configuration => + { + configuration.DefaultTimeout = TimeSpan.FromMilliseconds(defaultRequestTimeoutMs); + configuration.SetupSingular(new SingularClientSettings(environmentName, "Catalogue_EDI_API_Front")); + configuration.SetupUniversalTransport( + new UniversalTransportSettings + { + AllowAutoRedirect = false, + Proxy = proxy, + TcpKeepAliveEnabled = enableKeepAlive + }); + }); + } + } +} \ No newline at end of file diff --git a/EdiApi.Client/Http/Connectors/TransformerConnectorEdiApiClient.cs b/EdiApi.Client/Http/Connectors/TransformerConnectorEdiApiClient.cs index 4510d70..10e486d 100644 --- a/EdiApi.Client/Http/Connectors/TransformerConnectorEdiApiClient.cs +++ b/EdiApi.Client/Http/Connectors/TransformerConnectorEdiApiClient.cs @@ -1,16 +1,18 @@ -using System; +using System; using System.Globalization; using System.Net; using JetBrains.Annotations; -using SkbKontur.EdiApi.Client.Http.Helpers; using SkbKontur.EdiApi.Client.Types.BoxEvents; using SkbKontur.EdiApi.Client.Types.Common; using SkbKontur.EdiApi.Client.Types.Connectors; using SkbKontur.EdiApi.Client.Types.Connectors.Transformer; using SkbKontur.EdiApi.Client.Types.Serialization; +using Vostok.Clusterclient.Core; +using Vostok.Clusterclient.Core.Model; + namespace SkbKontur.EdiApi.Client.Http.Connectors { public class TransformerConnectorEdiApiClient : BaseEdiApiHttpClient, ITransformerConnectorEdiApiClient @@ -25,68 +27,101 @@ public TransformerConnectorEdiApiClient(string apiClientId, Uri baseUri, IEdiApi { } + public TransformerConnectorEdiApiClient(string apiClientId, string environment, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) + : this(apiClientId, environment, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, enableKeepAlive) + { + } + + public TransformerConnectorEdiApiClient(string apiClientId, string environment, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) + : base(apiClientId, environment, serializer, timeoutInMilliseconds, proxy, enableKeepAlive) + { + } + public void TransformationStarted([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "TransformationStarted") - .AddParameter(boxIdUrlParameterName, connectorBoxId) - .AddParameter(connectorInteractionIdUrlParameterName, connectorInteractionId) - .ToUri(); - MakePostRequest(url, authToken, content : null); + var request = BuildPostRequest("V1/Connectors/Transformers/TransformationStarted", null, authToken, Array.Empty()) + .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) + .WithAdditionalQueryParameter(connectorInteractionIdUrlParameterName, connectorInteractionId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); } public void TransformationPaused([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId, [CanBeNull] string reason) { - var url = new UrlBuilder(BaseUri, relativeUrl + "TransformationPaused") - .AddParameter(boxIdUrlParameterName, connectorBoxId) - .AddParameter(connectorInteractionIdUrlParameterName, connectorInteractionId) - .ToUri(); - MakePostRequest(url, authToken, reason); + var request = BuildPostRequest("V1/Connectors/Transformers/TransformationPaused", null, authToken, reason) + .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) + .WithAdditionalQueryParameter(connectorInteractionIdUrlParameterName, connectorInteractionId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); } public void TransformationResumed([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "TransformationResumed") - .AddParameter(boxIdUrlParameterName, connectorBoxId) - .AddParameter(connectorInteractionIdUrlParameterName, connectorInteractionId) - .ToUri(); - MakePostRequest(url, authToken, content : null); + var request = BuildPostRequest("V1/Connectors/Transformers/TransformationResumed", null, authToken, Array.Empty()) + .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) + .WithAdditionalQueryParameter(connectorInteractionIdUrlParameterName, connectorInteractionId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); } public void TransformationFinished([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId, [NotNull] ConnectorTransformationResult transformationResult) { - var url = new UrlBuilder(BaseUri, relativeUrl + "TransformationFinished") - .AddParameter(boxIdUrlParameterName, connectorBoxId) - .AddParameter(connectorInteractionIdUrlParameterName, connectorInteractionId) - .ToUri(); - MakePostRequest(url, authToken, transformationResult); + var request = BuildPostRequest("V1/Connectors/Transformers/TransformationFinished", null, authToken, transformationResult) + .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) + .WithAdditionalQueryParameter(connectorInteractionIdUrlParameterName, connectorInteractionId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); } [NotNull] public TransformerConnectorBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string connectorBoxId, [CanBeNull] string exclusiveEventId, uint? count = null) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetEvents") - .AddParameter(boxIdUrlParameterName, connectorBoxId) - .AddParameter("exclusiveEventId", exclusiveEventId); + var request = BuildGetRequest("V1/Connectors/Transformers/GetEvents", null, authToken) + .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) + .WithAdditionalQueryParameter("exclusiveEventId", exclusiveEventId); + if (count.HasValue) - url.AddParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); - return GetEvents(authToken, url); + { + request = request.WithAdditionalQueryParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); + } + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + var boxEventBatch = Serializer.Deserialize(result.Response.Content.ToString()); + + boxEventBatch.Events = boxEventBatch.Events ?? new TransformerConnectorBoxEvent[0]; + foreach (var boxEvent in boxEventBatch.Events) + { + boxEvent.EventContent = + boxEventTypeRegistry.IsSupportedEventType(boxEvent.EventType) + ? Serializer.NormalizeDeserializedObjectToType(boxEvent.EventContent, boxEventTypeRegistry.GetEventContentType(boxEvent.EventType)) + : null; + } + return boxEventBatch; } [NotNull] public TransformerConnectorBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string connectorBoxId, DateTime fromDateTime, uint? count = null) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetEventsFrom") - .AddParameter(boxIdUrlParameterName, connectorBoxId) - .AddParameter("fromDateTime", DateTimeUtils.ToString(fromDateTime)); + var request = BuildGetRequest("V1/Connectors/Transformers/GetEventsFrom", null, authToken) + .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) + .WithAdditionalQueryParameter("fromDateTime", DateTimeUtils.ToString(fromDateTime)); + if (count.HasValue) - url.AddParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); - return GetEvents(authToken, url); - } + { + request = request.WithAdditionalQueryParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); + } + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + var boxEventBatch = Serializer.Deserialize(result.Response.Content.ToString()); - [NotNull] - private TransformerConnectorBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] UrlBuilder url) - { - var boxEventBatch = MakeGetRequest(url.ToUri(), authToken); boxEventBatch.Events = boxEventBatch.Events ?? new TransformerConnectorBoxEvent[0]; foreach (var boxEvent in boxEventBatch.Events) { @@ -101,21 +136,27 @@ private TransformerConnectorBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] public MessageEntity GetMessage([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string messageId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetMessage") - .AddParameter(boxIdUrlParameterName, connectorBoxId) - .AddParameter("messageId", messageId) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Connectors/Transformers/GetMessage", null, authToken) + .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) + .WithAdditionalQueryParameter("messageId", messageId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public ConnectorBoxesInfo GetConnectorBoxesInfo([NotNull] string authToken) { - var url = new UrlBuilder(BaseUri, "V1/Boxes/GetConnectorBoxesInfo").ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Boxes/GetConnectorBoxesInfo", null, authToken); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } - private const string relativeUrl = "V1/Connectors/Transformers/"; private const string boxIdUrlParameterName = "connectorBoxId"; private const string connectorInteractionIdUrlParameterName = "connectorInteractionId"; private readonly IBoxEventTypeRegistry boxEventTypeRegistry = new TransformerConnectorBoxEventTypeRegistry(); diff --git a/EdiApi.Client/Http/Helpers/UrlBuilder.cs b/EdiApi.Client/Http/Helpers/UrlBuilder.cs deleted file mode 100644 index a895aca..0000000 --- a/EdiApi.Client/Http/Helpers/UrlBuilder.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace SkbKontur.EdiApi.Client.Http.Helpers -{ - public class UrlBuilder - { - public UrlBuilder(Uri uri, string relativeUrl) - : this(new Uri(uri, relativeUrl)) - { - } - - public UrlBuilder(Uri baseUri) - { - if (!string.IsNullOrEmpty(baseUri.Query)) - throw new ArgumentException(string.Format("Base uri with non empty query is not supported: {0}", baseUri)); - this.baseUri = baseUri; - } - - public UrlBuilder AddParameter(string name, string value) - { - queryParams.Add(name, value); - return this; - } - - public UrlBuilder AddParameter(string name, int value) - { - return AddParameter(name, value.ToString()); - } - - public Uri ToUri() - { - return new UriBuilder(baseUri) {Query = BuildQuery()}.Uri; - } - - private string BuildQuery() - { - var sb = new StringBuilder(); - var isFrist = true; - foreach (var kvp in queryParams) - { - if (!isFrist) - sb.Append("&"); - isFrist = false; - sb.Append(kvp.Key).Append("=").Append(string.IsNullOrEmpty(kvp.Value) ? kvp.Value : Uri.EscapeDataString(kvp.Value)); - } - return sb.ToString(); - } - - private readonly Uri baseUri; - private readonly Dictionary queryParams = new Dictionary(); - } -} \ No newline at end of file diff --git a/EdiApi.Client/Http/HttpClientException.cs b/EdiApi.Client/Http/HttpClientException.cs index a754d8c..8f77107 100644 --- a/EdiApi.Client/Http/HttpClientException.cs +++ b/EdiApi.Client/Http/HttpClientException.cs @@ -1,38 +1,39 @@ -using System; -using System.IO; -using System.Net; -using System.Text; +using System; + +using Vostok.Clusterclient.Core.Model; namespace SkbKontur.EdiApi.Client.Http { public class HttpClientException : Exception { - private HttpClientException(string message, Exception innerException) - : base(message, innerException) - { - } + private HttpClientException(string message, ResponseCode statusCode, Exception innerException) + : base(message, innerException) => + StatusCode = statusCode; + + private HttpClientException(string message, ResponseCode statusCode) + : base(message) => + StatusCode = statusCode; - public static HttpClientException Create(WebException exception, Uri requestUri) + public ResponseCode StatusCode { get; } + + public static HttpClientException Create(ClusterResult result) { - var message = "Request for url '" + requestUri + "' failed"; - if (!(exception.Response is HttpWebResponse response)) - return new HttpClientException(message, exception); - string serverMessage = null; - var responseStream = response.GetResponseStream(); - if (responseStream != null) + var message = "Request for url '" + result.Request.Url + "' failed"; + + var statusCode = result.Response.Code; + + if (!result.Response.HasContent) { - using (var reader = new StreamReader(responseStream, Encoding.UTF8)) - serverMessage = reader.ReadToEnd(); + throw new HttpClientException(message, statusCode); } - var serverException = new HttpClientServerException(serverMessage, exception); - return new HttpClientException(message, serverException); + throw new HttpClientException(message, statusCode, new HttpClientServerException(result.Response.Content.ToString())); } } public class HttpClientServerException : Exception { - protected internal HttpClientServerException(string message, Exception innerException) - : base(message, innerException) + protected internal HttpClientServerException(string message) + : base(message) { } } diff --git a/EdiApi.Client/Http/Internal/InternalEdiApiHttpClient.cs b/EdiApi.Client/Http/Internal/InternalEdiApiHttpClient.cs index acee00c..767a4ad 100644 --- a/EdiApi.Client/Http/Internal/InternalEdiApiHttpClient.cs +++ b/EdiApi.Client/Http/Internal/InternalEdiApiHttpClient.cs @@ -1,10 +1,9 @@ -using System; +using System; using System.Globalization; using System.Net; using JetBrains.Annotations; -using SkbKontur.EdiApi.Client.Http.Helpers; using SkbKontur.EdiApi.Client.Types.Boxes; using SkbKontur.EdiApi.Client.Types.BoxEvents; using SkbKontur.EdiApi.Client.Types.Internal; @@ -13,6 +12,9 @@ using SkbKontur.EdiApi.Client.Types.Parties; using SkbKontur.EdiApi.Client.Types.Serialization; +using Vostok.Clusterclient.Core; +using Vostok.Clusterclient.Core.Model; + using MessageBoxEventBatch = SkbKontur.EdiApi.Client.Types.Internal.MessageBoxEventBatch; namespace SkbKontur.EdiApi.Client.Http.Internal @@ -29,114 +31,173 @@ public InternalEdiApiHttpClient(string apiClientId, Uri baseUri, IEdiApiTypesSer { } + public InternalEdiApiHttpClient(string apiClientId, string environment, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) + : this(apiClientId, environment, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, enableKeepAlive) + { + } + + public InternalEdiApiHttpClient(string apiClientId, string environment, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) + : base(apiClientId, environment, serializer, timeoutInMilliseconds, proxy, enableKeepAlive) + { + } + [CanBeNull] public Document GetDocument([NotNull] string authToken, [NotNull] DocumentId documentId, bool includeRelatedDocuments = true) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetDocument") - .AddParameter("boxId", documentId.BoxId) - .AddParameter("entityId", documentId.EntityId) - .AddParameter("includeRelatedDocuments", includeRelatedDocuments.ToString()) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Internal/GetDocument", null, authToken) + .WithAdditionalQueryParameter("boxId", documentId.BoxId) + .WithAdditionalQueryParameter("entityId", documentId.EntityId) + .WithAdditionalQueryParameter("includeRelatedDocuments", includeRelatedDocuments.ToString()); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public MessageBoxEventBatch GetEvents([NotNull] string authToken, [CanBeNull] string exclusiveEventPointer, int? count = null) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetEvents"); + var request = BuildGetRequest("V1/Internal/GetEvents", null, authToken); + if (!string.IsNullOrWhiteSpace(exclusiveEventPointer)) - url.AddParameter("exclusiveEventPointer", exclusiveEventPointer); + { + request = request.WithAdditionalQueryParameter("exclusiveEventPointer", exclusiveEventPointer); + } if (count.HasValue) - url.AddParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); - var boxEventBatch = MakeGetRequest(url.ToUri(), authToken); - boxEventBatch.Events = boxEventBatch.Events ?? new MessageBoxEvent[0]; + { + request = request.WithAdditionalQueryParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); + } + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + var boxEventBatch = Serializer.Deserialize(result.Response.Content.ToString()); foreach (var boxEvent in boxEventBatch.Events) + { AdjustEventContent(boxEvent); + } + return boxEventBatch; } [NotNull] public MessageBoxEvent[] GetEventsByDocumentCirculationId([NotNull] string authToken, [NotNull] string documentCirculationId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetEventsByDocumentCirculationId") - .AddParameter("documentCirculationId", documentCirculationId); - var boxEvents = MakeGetRequest(url.ToUri(), authToken); + var request = BuildGetRequest("V1/Internal/GetEventsByDocumentCirculationId", null, authToken) + .WithAdditionalQueryParameter("documentCirculationId", documentCirculationId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + var boxEvents = Serializer.Deserialize(result.Response.Content.ToString()); foreach (var boxEvent in boxEvents) + { AdjustEventContent(boxEvent); + } return boxEvents; } [NotNull] public string GetLastEventPointer([NotNull] string authToken, DateTime beforeDateTime) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetLastEventPointer") - .AddParameter("beforeDateTime", DateTimeUtils.ToString(beforeDateTime)); - return MakeGetRequestInternal(url.ToUri(), authToken); + var request = BuildGetRequest("V1/Internal/GetLastEventPointer", null, authToken) + .WithAdditionalQueryParameter("beforeDateTime", DateTimeUtils.ToString(beforeDateTime)); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return result.Response.Content.ToString(); } [NotNull] public BoxesInfo GetBoxesInfo([NotNull] string authToken, [NotNull] string partyId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetBoxesInfo") - .AddParameter("partyId", partyId); - return MakeGetRequest(url.ToUri(), authToken); + var request = BuildGetRequest("V1/Internal/GetBoxesInfo", null, authToken) + .WithAdditionalQueryParameter("partyId", partyId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public InternalPartyInfo GetInternalPartyInfo([NotNull] string authToken, [NotNull] string partyId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetInternalPartyInfo") - .AddParameter("partyId", partyId); - return MakeGetRequest(url.ToUri(), authToken); + var request = BuildGetRequest("V1/Internal/GetInternalPartyInfo", null, authToken) + .WithAdditionalQueryParameter("partyId", partyId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public PartyInfoWithEmployee[] GetPartiesByUser([NotNull] string authToken, [NotNull] string userId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetPartiesByUser") - .AddParameter("userId", userId) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Internal/GetPartiesByUser", null, authToken) + .WithAdditionalQueryParameter("userId", userId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public PartyInfoWithEmployees[] GetPartiesInfoByInn([NotNull] string authToken, [NotNull] string partyInn) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetPartiesInfoByInn") - .AddParameter("partyInn", partyInn) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Internal/GetPartiesInfoByInn", null, authToken) + .WithAdditionalQueryParameter("partyInn", partyInn); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public PartySettings GetPartySettings([NotNull] string authToken, [NotNull] string partyId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetPartySettings") - .AddParameter("partyId", partyId) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Internal/GetPartySettings", null, authToken) + .WithAdditionalQueryParameter("partyId", partyId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public string AddOrUpdateParty([NotNull] string authToken, [NotNull] string partyId, [NotNull] EditablePartySettings editablePartySettings) { - var url = new UrlBuilder(BaseUri, relativeUrl + "AddOrUpdateParty") - .AddParameter("partyId", partyId); - return MakePostRequest(url.ToUri(), authToken, editablePartySettings); + var request = BuildPostRequest("V1/Internal/AddOrUpdateParty", null, authToken, editablePartySettings) + .WithAdditionalQueryParameter("partyId", partyId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } public void AddEmployee([NotNull] string authToken, [NotNull] string partyId, [NotNull] string email) { - var url = new UrlBuilder(BaseUri, relativeUrl + "AddEmployee") - .AddParameter("partyId", partyId) - .AddParameter("email", email); - MakePostRequest(url.ToUri(), authToken, content : null); + var request = BuildPostRequest("V1/Internal/AddEmployee", null, authToken, Array.Empty()) + .WithAdditionalQueryParameter("partyId", partyId) + .WithAdditionalQueryParameter("email", email); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); } public void AddOrUpdateTradingPartnersSettings([NotNull] string authToken, [NotNull] EditableTradingPartnersSettings settingsToWrite) { - var url = new UrlBuilder(BaseUri, relativeUrl + "AddOrUpdateTradingPartnersSettings"); - MakePostRequest(url.ToUri(), authToken, settingsToWrite); + var request = BuildPostRequest("V1/Internal/AddOrUpdateTradingPartnersSettings", null, authToken, settingsToWrite); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); } private void AdjustEventContent(MessageBoxEvent boxEvent) @@ -147,7 +208,6 @@ private void AdjustEventContent(MessageBoxEvent boxEvent) : null; } - private const string relativeUrl = "V1/Internal/"; private readonly IBoxEventTypeRegistry boxEventTypeRegistry = new MessageBoxEventTypeRegistry(); } } \ No newline at end of file diff --git a/EdiApi.Client/Http/Messages/MessagesEdiApiHttpClient.cs b/EdiApi.Client/Http/Messages/MessagesEdiApiHttpClient.cs index aed3c7f..45c667f 100644 --- a/EdiApi.Client/Http/Messages/MessagesEdiApiHttpClient.cs +++ b/EdiApi.Client/Http/Messages/MessagesEdiApiHttpClient.cs @@ -1,16 +1,18 @@ -using System; +using System; using System.Globalization; using System.Net; using JetBrains.Annotations; -using SkbKontur.EdiApi.Client.Http.Helpers; using SkbKontur.EdiApi.Client.Types.BoxEvents; using SkbKontur.EdiApi.Client.Types.Common; using SkbKontur.EdiApi.Client.Types.Messages; using SkbKontur.EdiApi.Client.Types.Messages.BoxEvents; using SkbKontur.EdiApi.Client.Types.Serialization; +using Vostok.Clusterclient.Core; +using Vostok.Clusterclient.Core.Model; + namespace SkbKontur.EdiApi.Client.Http.Messages { public class MessagesEdiApiHttpClient : BaseEdiApiHttpClient, IMessagesEdiApiClient @@ -25,99 +27,144 @@ public MessagesEdiApiHttpClient(string apiClientId, Uri baseUri, IEdiApiTypesSer { } + public MessagesEdiApiHttpClient(string apiClientId, string environment, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) + : this(apiClientId, environment, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, enableKeepAlive) + { + } + + public MessagesEdiApiHttpClient(string apiClientId, string environment, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) + : base(apiClientId, environment, serializer, timeoutInMilliseconds, proxy, enableKeepAlive) + { + } + [NotNull] public BoxDocumentsSettings GetBoxDocumentsSettings([NotNull] string authToken, [NotNull] string boxId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetBoxDocumentsSettings") - .AddParameter("boxId", boxId) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Messages/GetBoxDocumentsSettings", null, authToken) + .WithAdditionalQueryParameter("boxId", boxId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public MessageData GetMessage([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetMessage") - .AddParameter("boxId", boxId) - .AddParameter("messageId", messageId) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Messages/GetMessage", null, authToken) + .WithAdditionalQueryParameter("boxId", boxId) + .WithAdditionalQueryParameter("messageId", messageId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public InboxMessageMeta GetInboxMessageMeta([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetInboxMessageMeta") - .AddParameter("boxId", boxId) - .AddParameter("messageId", messageId) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Messages/GetInboxMessageMeta", null, authToken) + .WithAdditionalQueryParameter("boxId", boxId) + .WithAdditionalQueryParameter("messageId", messageId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public OutboxMessageMeta GetOutboxMessageMeta([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetOutboxMessageMeta") - .AddParameter("boxId", boxId) - .AddParameter("messageId", messageId) - .ToUri(); - return MakeGetRequest(url, authToken); + var request = BuildGetRequest("V1/Messages/GetOutboxMessageMeta", null, authToken) + .WithAdditionalQueryParameter("boxId", boxId) + .WithAdditionalQueryParameter("messageId", messageId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } [NotNull] public OutboxMessageMeta SendMessage([NotNull] string authToken, [NotNull] string boxId, [NotNull] MessageData messageData) { - var url = new UrlBuilder(BaseUri, relativeUrl + "SendMessage") - .AddParameter("boxId", boxId) - .AddParameter("messageFileName", messageData.MessageFileName) - .ToUri(); - return MakePostRequest(url, authToken, messageData.MessageBody); + var request = BuildPostRequest("V1/Messages/SendMessage", null, authToken, messageData.MessageBody) + .WithAdditionalQueryParameter("boxId", boxId) + .WithAdditionalQueryParameter("messageFileName", messageData.MessageFileName); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + return Serializer.Deserialize(result.Response.Content.ToString()); } public void MessageDeliveryStarted([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId) { - var url = new UrlBuilder(BaseUri, relativeUrl + "MessageDeliveryStarted") - .AddParameter("boxId", boxId) - .AddParameter("messageId", messageId) - .ToUri(); - MakePostRequest(url, authToken, content : null); + var request = BuildPostRequest("V1/Messages/MessageDeliveryStarted", null, authToken, Array.Empty()) + .WithAdditionalQueryParameter("boxId", boxId) + .WithAdditionalQueryParameter("messageId", messageId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); } public void MessageDeliveryFinished([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId, [NotNull] MessageDeliveryResult messageDeliveryResult) { - var url = new UrlBuilder(BaseUri, relativeUrl + "MessageDeliveryFinished") - .AddParameter("boxId", boxId) - .AddParameter("messageId", messageId) - .ToUri(); - MakePostRequest(url, authToken, messageDeliveryResult); + var request = BuildPostRequest("V1/Messages/MessageDeliveryFinished", null, authToken, messageDeliveryResult) + .WithAdditionalQueryParameter("boxId", boxId) + .WithAdditionalQueryParameter("messageId", messageId); + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); } [NotNull] public MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string boxId, string exclusiveEventId, uint? count = null) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetEvents") - .AddParameter(boxIdUrlParameterName, boxId) - .AddParameter("exclusiveEventId", exclusiveEventId); + var request = BuildGetRequest("V1/Messages/GetEvents", null, authToken) + .WithAdditionalQueryParameter("boxId", boxId) + .WithAdditionalQueryParameter("exclusiveEventId", exclusiveEventId); + if (count.HasValue) - url.AddParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); - return GetEvents(authToken, url); + { + request = request.WithAdditionalQueryParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); + } + + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + var boxEventBatch = Serializer.Deserialize(result.Response.Content.ToString()); + boxEventBatch.Events = boxEventBatch.Events ?? new MessageBoxEvent[0]; + foreach (var boxEvent in boxEventBatch.Events) + { + boxEvent.EventContent = + boxEventTypeRegistry.IsSupportedEventType(boxEvent.EventType) + ? Serializer.NormalizeDeserializedObjectToType(boxEvent.EventContent, boxEventTypeRegistry.GetEventContentType(boxEvent.EventType)) + : null; + } + + return boxEventBatch; } [NotNull] public MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string boxId, DateTime fromDateTime, uint? count = null) { - var url = new UrlBuilder(BaseUri, relativeUrl + "GetEventsFrom") - .AddParameter(boxIdUrlParameterName, boxId) - .AddParameter("fromDateTime", DateTimeUtils.ToString(fromDateTime)); + var request = BuildGetRequest("V1/Messages/GetEventsFrom", null, authToken) + .WithAdditionalQueryParameter("boxId", boxId) + .WithAdditionalQueryParameter("fromDateTime", DateTimeUtils.ToString(fromDateTime)); + if (count.HasValue) - url.AddParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); - return GetEvents(authToken, url); - } + { + request = request.WithAdditionalQueryParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); + } - [NotNull] - private MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] UrlBuilder url) - { - var boxEventBatch = MakeGetRequest(url.ToUri(), authToken); + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + var boxEventBatch = Serializer.Deserialize(result.Response.Content.ToString()); boxEventBatch.Events = boxEventBatch.Events ?? new MessageBoxEvent[0]; foreach (var boxEvent in boxEventBatch.Events) { @@ -126,11 +173,10 @@ private MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] Url ? Serializer.NormalizeDeserializedObjectToType(boxEvent.EventContent, boxEventTypeRegistry.GetEventContentType(boxEvent.EventType)) : null; } + return boxEventBatch; } - private const string relativeUrl = "V1/Messages/"; - private const string boxIdUrlParameterName = "boxId"; private readonly IBoxEventTypeRegistry boxEventTypeRegistry = new MessageBoxEventTypeRegistry(); } } \ No newline at end of file diff --git a/EdiApi.Client/Http/WebExtensions.cs b/EdiApi.Client/Http/WebExtensions.cs deleted file mode 100644 index 5ec8cf3..0000000 --- a/EdiApi.Client/Http/WebExtensions.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.IO; -using System.Net; -using System.Text; - -namespace SkbKontur.EdiApi.Client.Http -{ - public static class WebExtensions - { - public static byte[] GetBytes(this string data) - { - return Encoding.UTF8.GetBytes(data); - } - - public static string GetString(this WebResponse response) - { - var responseStream = response.GetResponseStream(); - var responseLength = (int)response.ContentLength; - using (var binaryReader = new BinaryReader(responseStream)) - { - var bytes = binaryReader.ReadBytes(responseLength); - return Encoding.UTF8.GetString(bytes); - } - } - } -} \ No newline at end of file diff --git a/global.json b/global.json index 70a59a3..2d85e85 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "3.1.201" + "version": "5.0.202" } } \ No newline at end of file diff --git a/version.json b/version.json index 79e0430..f29c4b8 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.7", + "version": "1.8-pre5", "assemblyVersion": { "precision": "build" }, From 5043a9cc364a1600227e25375fcb49456768e664 Mon Sep 17 00:00:00 2001 From: Sergey Kozulin Date: Wed, 19 May 2021 13:51:15 +0500 Subject: [PATCH 2/2] Fix review notices --- Directory.Build.props | 2 +- EdiApi.Client/Annotations.cs | 225 ------------------ EdiApi.Client/EdiApi.Client.csproj | 5 +- EdiApi.Client/Http/BaseEdiApiHttpClient.cs | 72 +++--- EdiApi.Client/Http/ClusterClientFactory.cs | 24 +- .../TransformerConnectorEdiApiClient.cs | 104 ++++---- EdiApi.Client/Http/HttpClientException.cs | 4 +- .../Http/Internal/InternalEdiApiHttpClient.cs | 73 +++--- .../Http/Messages/MessagesEdiApiHttpClient.cs | 82 +++---- EdiApi.Client/IBaseEdiApiClient.cs | 32 +-- EdiApi.Client/IInternalEdiApiHttpClient.cs | 30 +-- EdiApi.Client/IMessagesEdiApiClient.cs | 30 +-- .../ITransformerConnectorEdiApiClient.cs | 25 +- .../Types/Internal/EditablePartySettings.cs | 68 ++---- .../Outbox/AmendmentRequestedEventContent.cs | 5 +- EdiApi.Client/Types/Parties/PartySettings.cs | 12 +- version.json | 2 +- 17 files changed, 235 insertions(+), 560 deletions(-) delete mode 100644 EdiApi.Client/Annotations.cs diff --git a/Directory.Build.props b/Directory.Build.props index 7e94621..2aebb0e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,7 +14,7 @@ - + \ No newline at end of file diff --git a/EdiApi.Client/Annotations.cs b/EdiApi.Client/Annotations.cs deleted file mode 100644 index af610d5..0000000 --- a/EdiApi.Client/Annotations.cs +++ /dev/null @@ -1,225 +0,0 @@ -/* MIT License - -Copyright (c) 2016 JetBrains http://www.jetbrains.com - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. */ - -using System; - -#pragma warning disable 1591 -// ReSharper disable UnusedMember.Global -// ReSharper disable MemberCanBePrivate.Global -// ReSharper disable UnusedAutoPropertyAccessor.Global -// ReSharper disable IntroduceOptionalParameters.Global -// ReSharper disable MemberCanBeProtected.Global -// ReSharper disable InconsistentNaming -// ReSharper disable once CheckNamespace - -namespace JetBrains.Annotations -{ - /// - /// Indicates that the value of the marked element could be null sometimes, - /// so the check for null is necessary before its usage. - /// - /// - /// - /// [CanBeNull] object Test() => null; - /// - /// void UseTest() { - /// var p = Test(); - /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException' - /// } - /// - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] - internal sealed class CanBeNullAttribute : Attribute - { - } - - /// - /// Indicates that the value of the marked element could never be null. - /// - /// - /// - /// [NotNull] object Foo() { - /// return null; // Warning: Possible 'null' assignment - /// } - /// - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] - internal sealed class NotNullAttribute : Attribute - { - } - - /// - /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task - /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property - /// or of the Lazy.Value property can never be null. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field)] - internal sealed class ItemNotNullAttribute : Attribute - { - } - - /// - /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task - /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property - /// or of the Lazy.Value property can be null. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field)] - internal sealed class ItemCanBeNullAttribute : Attribute - { - } - - /// - /// Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library), - /// so this symbol will not be marked as unused (as well as by other usage inspections). - /// - [AttributeUsage(AttributeTargets.All)] - internal sealed class UsedImplicitlyAttribute : Attribute - { - public UsedImplicitlyAttribute() - : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) - { - } - - public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags) - : this(useKindFlags, ImplicitUseTargetFlags.Default) - { - } - - public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags) - : this(ImplicitUseKindFlags.Default, targetFlags) - { - } - - public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) - { - UseKindFlags = useKindFlags; - TargetFlags = targetFlags; - } - - public ImplicitUseKindFlags UseKindFlags { get; private set; } - - public ImplicitUseTargetFlags TargetFlags { get; private set; } - } - - /// - /// Should be used on attributes and causes ReSharper to not mark symbols marked with such attributes - /// as unused (as well as by other usage inspections) - /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter)] - internal sealed class MeansImplicitUseAttribute : Attribute - { - public MeansImplicitUseAttribute() - : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) - { - } - - public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags) - : this(useKindFlags, ImplicitUseTargetFlags.Default) - { - } - - public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags) - : this(ImplicitUseKindFlags.Default, targetFlags) - { - } - - public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) - { - UseKindFlags = useKindFlags; - TargetFlags = targetFlags; - } - - [UsedImplicitly] - public ImplicitUseKindFlags UseKindFlags { get; private set; } - - [UsedImplicitly] - public ImplicitUseTargetFlags TargetFlags { get; private set; } - } - - [Flags] - internal enum ImplicitUseKindFlags - { - Default = Access | Assign | InstantiatedWithFixedConstructorSignature, - - /// Only entity marked with attribute considered used. - Access = 1, - - /// Indicates implicit assignment to a member. - Assign = 2, - - /// - /// Indicates implicit instantiation of a type with fixed constructor signature. - /// That means any unused constructor parameters won't be reported as such. - /// - InstantiatedWithFixedConstructorSignature = 4, - - /// Indicates implicit instantiation of a type. - InstantiatedNoFixedConstructorSignature = 8, - } - - /// - /// Specify what is considered used implicitly when marked - /// with or . - /// - [Flags] - internal enum ImplicitUseTargetFlags - { - Default = Itself, - Itself = 1, - - /// Members of entity marked with attribute are considered used. - Members = 2, - - /// Entity marked with attribute and all its members considered used. - WithMembers = Itself | Members - } - - /// - /// This attribute is intended to mark publicly available API - /// which should not be removed and so is treated as used. - /// - [MeansImplicitUse(ImplicitUseTargetFlags.WithMembers)] - internal sealed class PublicAPIAttribute : Attribute - { - public PublicAPIAttribute() - { - } - - public PublicAPIAttribute([NotNull] string comment) - { - Comment = comment; - } - - [CanBeNull] - public string Comment { get; } - } -} \ No newline at end of file diff --git a/EdiApi.Client/EdiApi.Client.csproj b/EdiApi.Client/EdiApi.Client.csproj index 3f3db31..e5b68e6 100644 --- a/EdiApi.Client/EdiApi.Client.csproj +++ b/EdiApi.Client/EdiApi.Client.csproj @@ -2,6 +2,7 @@ netstandard2.0 + 8.0 SkbKontur.EdiApi.Client $(AssemblyName) @@ -14,8 +15,4 @@ - - - - diff --git a/EdiApi.Client/Http/BaseEdiApiHttpClient.cs b/EdiApi.Client/Http/BaseEdiApiHttpClient.cs index 9ab6723..6e30ca5 100644 --- a/EdiApi.Client/Http/BaseEdiApiHttpClient.cs +++ b/EdiApi.Client/Http/BaseEdiApiHttpClient.cs @@ -2,8 +2,6 @@ using System.Net; using System.Text; -using JetBrains.Annotations; - using SkbKontur.EdiApi.Client.Types.Boxes; using SkbKontur.EdiApi.Client.Types.Organization; using SkbKontur.EdiApi.Client.Types.Parties; @@ -11,43 +9,43 @@ using Vostok.Clusterclient.Core; using Vostok.Clusterclient.Core.Model; +using Vostok.Tracing.Abstractions; using PartyInfo = SkbKontur.EdiApi.Client.Types.Parties.PartyInfo; +#nullable enable + namespace SkbKontur.EdiApi.Client.Http { public abstract class BaseEdiApiHttpClient : IBaseEdiApiClient { protected BaseEdiApiHttpClient( string apiClientId, Uri baseUri, IEdiApiTypesSerializer serializer, - int timeoutInMilliseconds, IWebProxy proxy = null, bool enableKeepAlive = true) + int timeoutInMilliseconds, IWebProxy? proxy = null) { this.apiClientId = apiClientId; Serializer = serializer; - clusterClient = ClusterClientFactory.Get(baseUri, timeoutInMilliseconds, proxy, enableKeepAlive); + clusterClient = ClusterClientFactory.Get(baseUri, timeoutInMilliseconds, proxy); } protected BaseEdiApiHttpClient( string apiClientId, string environment, IEdiApiTypesSerializer serializer, - int timeoutInMilliseconds, IWebProxy proxy = null, bool enableKeepAlive = true) + int timeoutInMilliseconds, IWebProxy? proxy = null, ITracer? tracer = null) { this.apiClientId = apiClientId; Serializer = serializer; - clusterClient = ClusterClientFactory.Get(environment, timeoutInMilliseconds, proxy, enableKeepAlive); + clusterClient = ClusterClientFactory.Get(environment, timeoutInMilliseconds, proxy, tracer : tracer); } - [NotNull] - public string Authenticate([NotNull] string portalSid) => + public string Authenticate(string portalSid) => DoAuthenticate(new AuthCredentials {PortalSid = portalSid}); - [NotNull] - public string Authenticate([NotNull] string login, [NotNull] string password) => + public string Authenticate(string login, string password) => DoAuthenticate(new AuthCredentials {Login = login, Password = password}); - [NotNull] private string DoAuthenticate(AuthCredentials authCredentials) { - var request = BuildPostRequest("V1/Authenticate", authCredentials, null, Array.Empty()); + var request = BuildPostRequest("V1/Authenticate", authCredentials); var result = clusterClient.Send(request); EnsureSuccessResult(result); @@ -55,10 +53,9 @@ private string DoAuthenticate(AuthCredentials authCredentials) return result.Response.Content.ToString(); } - [NotNull] - public PartiesInfo GetAccessiblePartiesInfo([NotNull] string authToken) + public PartiesInfo GetAccessiblePartiesInfo(string authToken) { - var request = BuildGetRequest("V1/Parties/GetAccessiblePartiesInfo", null, authToken); + var request = BuildGetRequest("V1/Parties/GetAccessiblePartiesInfo", authToken : authToken); var result = clusterClient.Send(request); EnsureSuccessResult(result); @@ -66,10 +63,9 @@ public PartiesInfo GetAccessiblePartiesInfo([NotNull] string authToken) return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public PartyInfo GetPartyInfo([NotNull] string authToken, [NotNull] string partyId) + public PartyInfo GetPartyInfo(string authToken, string partyId) { - var request = BuildGetRequest("V1/Parties/GetPartyInfo", null, authToken) + var request = BuildGetRequest("V1/Parties/GetPartyInfo", authToken : authToken) .WithAdditionalQueryParameter("partyId", partyId); var result = clusterClient.Send(request); @@ -78,10 +74,9 @@ public PartyInfo GetPartyInfo([NotNull] string authToken, [NotNull] string party return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public PartyInfo GetPartyInfoByGln([NotNull] string authToken, [NotNull] string partyGln) + public PartyInfo GetPartyInfoByGln(string authToken, string partyGln) { - var request = BuildGetRequest("V1/Parties/GetPartyInfoByGln", null, authToken) + var request = BuildGetRequest("V1/Parties/GetPartyInfoByGln", authToken : authToken) .WithAdditionalQueryParameter("partyGln", partyGln); var result = clusterClient.Send(request); @@ -90,10 +85,9 @@ public PartyInfo GetPartyInfoByGln([NotNull] string authToken, [NotNull] string return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public PartyInfo GetPartyInfoByDepartmentGln([NotNull] string authToken, [NotNull] string departmentGln) + public PartyInfo GetPartyInfoByDepartmentGln(string authToken, string departmentGln) { - var request = BuildGetRequest("V1/Parties/GetPartyInfoByDepartmentGln", null, authToken) + var request = BuildGetRequest("V1/Parties/GetPartyInfoByDepartmentGln", authToken : authToken) .WithAdditionalQueryParameter("departmentGln", departmentGln); var result = clusterClient.Send(request); @@ -102,10 +96,9 @@ public PartyInfo GetPartyInfoByDepartmentGln([NotNull] string authToken, [NotNul return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public BoxesInfo GetBoxesInfo([NotNull] string authToken) + public BoxesInfo GetBoxesInfo(string authToken) { - var request = BuildGetRequest("V1/Boxes/GetBoxesInfo", null, authToken); + var request = BuildGetRequest("V1/Boxes/GetBoxesInfo", authToken : authToken); var result = clusterClient.Send(request); EnsureSuccessResult(result); @@ -113,10 +106,9 @@ public BoxesInfo GetBoxesInfo([NotNull] string authToken) return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public BoxInfo GetMainApiBox([NotNull] string authToken, [NotNull] string partyId) + public BoxInfo GetMainApiBox(string authToken, string partyId) { - var request = BuildGetRequest("V1/Boxes/GetMainApiBox", null, authToken) + var request = BuildGetRequest("V1/Boxes/GetMainApiBox", authToken : authToken) .WithAdditionalQueryParameter("partyId", partyId); var result = clusterClient.Send(request); @@ -125,10 +117,9 @@ public BoxInfo GetMainApiBox([NotNull] string authToken, [NotNull] string partyI return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public OrganizationCatalogueInfo GetOrganizationCatalogueInfo([NotNull] string authToken, [NotNull] string partyId) + public OrganizationCatalogueInfo GetOrganizationCatalogueInfo(string authToken, string partyId) { - var request = BuildGetRequest("V1/Organizations/GetOrganizationCatalogueInfo", null, authToken) + var request = BuildGetRequest("V1/Organizations/GetOrganizationCatalogueInfo", authToken : authToken) .WithAdditionalQueryParameter("partyId", partyId); var result = clusterClient.Send(request); @@ -137,10 +128,9 @@ public OrganizationCatalogueInfo GetOrganizationCatalogueInfo([NotNull] string a return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public UsersInfo GetUsersInfo([NotNull] string authToken, [NotNull] string partyId) + public UsersInfo GetUsersInfo(string authToken, string partyId) { - var request = BuildGetRequest("V1/Users/GetUsersInfo", null, authToken) + var request = BuildGetRequest("V1/Users/GetUsersInfo", authToken : authToken) .WithAdditionalQueryParameter("partyId", partyId); var result = clusterClient.Send(request); @@ -149,12 +139,14 @@ public UsersInfo GetUsersInfo([NotNull] string authToken, [NotNull] string party return Serializer.Deserialize(result.Response.Content.ToString()); } - protected Uri BaseUri { get; } protected IEdiApiTypesSerializer Serializer { get; } protected const int DefaultTimeout = 30 * 1000; - protected virtual Request BuildPostRequest([NotNull] string relativeUrl, AuthCredentials authCredentials, string authToken, [CanBeNull] TContent content) + protected virtual Request BuildPostRequest(string relativeUrl, AuthCredentials? authCredentials = null, string? authToken = null) + => BuildPostRequest(relativeUrl, authCredentials, authToken, Array.Empty()); + + protected virtual Request BuildPostRequest(string relativeUrl, AuthCredentials? authCredentials, string? authToken, TContent? content) where TContent : class { var request = Request.Post(relativeUrl) @@ -180,7 +172,7 @@ protected virtual Request BuildPostRequest([NotNull] string relativeUr return request; } - protected virtual Request BuildGetRequest([NotNull] string relativeUrl, AuthCredentials authCredentials, string authToken) + protected virtual Request BuildGetRequest(string relativeUrl, AuthCredentials? authCredentials = null, string? authToken = null) { var request = Request.Get(relativeUrl) .WithHeader("Authorization", BuildAuthorizationHeader(authCredentials, authToken)) @@ -197,7 +189,7 @@ protected virtual void EnsureSuccessResult(ClusterResult result) } } - private string BuildAuthorizationHeader(AuthCredentials authCredentials, string authToken) + private string BuildAuthorizationHeader(AuthCredentials? authCredentials, string? authToken) { var stringBuilder = new StringBuilder(); stringBuilder.Append("KonturEdiAuth "); diff --git a/EdiApi.Client/Http/ClusterClientFactory.cs b/EdiApi.Client/Http/ClusterClientFactory.cs index 417bea0..345ed13 100644 --- a/EdiApi.Client/Http/ClusterClientFactory.cs +++ b/EdiApi.Client/Http/ClusterClientFactory.cs @@ -3,8 +3,12 @@ using Vostok.Clusterclient.Core; using Vostok.Clusterclient.Singular; +using Vostok.Clusterclient.Tracing; using Vostok.Clusterclient.Transport; using Vostok.Logging.Abstractions; +using Vostok.Tracing.Abstractions; + +#nullable enable namespace SkbKontur.EdiApi.Client.Http { @@ -13,9 +17,8 @@ internal static class ClusterClientFactory public static IClusterClient Get( Uri externalUri, int defaultRequestTimeoutMs, - IWebProxy proxy, - bool enableKeepAlive, - ILog log = null + IWebProxy? proxy = null, + ILog? log = null ) { if (externalUri == null) @@ -31,8 +34,7 @@ public static IClusterClient Get( new UniversalTransportSettings { AllowAutoRedirect = false, - Proxy = proxy, - TcpKeepAliveEnabled = enableKeepAlive + Proxy = proxy }); }); } @@ -40,9 +42,9 @@ public static IClusterClient Get( public static IClusterClient Get( string environmentName, int defaultRequestTimeoutMs, - IWebProxy proxy, - bool enableKeepAlive, - ILog log = null + IWebProxy? proxy = null, + ILog? log = null, + ITracer? tracer = null ) { if (string.IsNullOrEmpty(environmentName)) @@ -58,9 +60,11 @@ public static IClusterClient Get( new UniversalTransportSettings { AllowAutoRedirect = false, - Proxy = proxy, - TcpKeepAliveEnabled = enableKeepAlive + Proxy = proxy }); + + if(tracer != null) + configuration.SetupDistributedTracing(tracer); }); } } diff --git a/EdiApi.Client/Http/Connectors/TransformerConnectorEdiApiClient.cs b/EdiApi.Client/Http/Connectors/TransformerConnectorEdiApiClient.cs index 10e486d..e5f23ad 100644 --- a/EdiApi.Client/Http/Connectors/TransformerConnectorEdiApiClient.cs +++ b/EdiApi.Client/Http/Connectors/TransformerConnectorEdiApiClient.cs @@ -2,8 +2,6 @@ using System.Globalization; using System.Net; -using JetBrains.Annotations; - using SkbKontur.EdiApi.Client.Types.BoxEvents; using SkbKontur.EdiApi.Client.Types.Common; using SkbKontur.EdiApi.Client.Types.Connectors; @@ -12,34 +10,37 @@ using Vostok.Clusterclient.Core; using Vostok.Clusterclient.Core.Model; +using Vostok.Tracing.Abstractions; + +#nullable enable namespace SkbKontur.EdiApi.Client.Http.Connectors { public class TransformerConnectorEdiApiClient : BaseEdiApiHttpClient, ITransformerConnectorEdiApiClient { - public TransformerConnectorEdiApiClient(string apiClientId, Uri baseUri, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : this(apiClientId, baseUri, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, enableKeepAlive) + public TransformerConnectorEdiApiClient(string apiClientId, Uri baseUri, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null) + : this(apiClientId, baseUri, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy) { } - public TransformerConnectorEdiApiClient(string apiClientId, Uri baseUri, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : base(apiClientId, baseUri, serializer, timeoutInMilliseconds, proxy, enableKeepAlive) + public TransformerConnectorEdiApiClient(string apiClientId, Uri baseUri, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null) + : base(apiClientId, baseUri, serializer, timeoutInMilliseconds, proxy) { } - public TransformerConnectorEdiApiClient(string apiClientId, string environment, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : this(apiClientId, environment, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, enableKeepAlive) + public TransformerConnectorEdiApiClient(string apiClientId, string environment, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null, ITracer? tracer = null) + : this(apiClientId, environment, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, tracer) { } - public TransformerConnectorEdiApiClient(string apiClientId, string environment, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : base(apiClientId, environment, serializer, timeoutInMilliseconds, proxy, enableKeepAlive) + public TransformerConnectorEdiApiClient(string apiClientId, string environment, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null, ITracer? tracer = null) + : base(apiClientId, environment, serializer, timeoutInMilliseconds, proxy, tracer) { } - public void TransformationStarted([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId) + public void TransformationStarted(string authToken, string connectorBoxId, string connectorInteractionId) { - var request = BuildPostRequest("V1/Connectors/Transformers/TransformationStarted", null, authToken, Array.Empty()) + var request = BuildPostRequest("V1/Connectors/Transformers/TransformationStarted", authToken : authToken) .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) .WithAdditionalQueryParameter(connectorInteractionIdUrlParameterName, connectorInteractionId); @@ -47,7 +48,7 @@ public void TransformationStarted([NotNull] string authToken, [NotNull] string c EnsureSuccessResult(result); } - public void TransformationPaused([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId, [CanBeNull] string reason) + public void TransformationPaused(string authToken, string connectorBoxId, string connectorInteractionId, string? reason) { var request = BuildPostRequest("V1/Connectors/Transformers/TransformationPaused", null, authToken, reason) .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) @@ -57,9 +58,9 @@ public void TransformationPaused([NotNull] string authToken, [NotNull] string co EnsureSuccessResult(result); } - public void TransformationResumed([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId) + public void TransformationResumed(string authToken, string connectorBoxId, string connectorInteractionId) { - var request = BuildPostRequest("V1/Connectors/Transformers/TransformationResumed", null, authToken, Array.Empty()) + var request = BuildPostRequest("V1/Connectors/Transformers/TransformationResumed", authToken : authToken) .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) .WithAdditionalQueryParameter(connectorInteractionIdUrlParameterName, connectorInteractionId); @@ -67,7 +68,7 @@ public void TransformationResumed([NotNull] string authToken, [NotNull] string c EnsureSuccessResult(result); } - public void TransformationFinished([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId, [NotNull] ConnectorTransformationResult transformationResult) + public void TransformationFinished(string authToken, string connectorBoxId, string connectorInteractionId, ConnectorTransformationResult transformationResult) { var request = BuildPostRequest("V1/Connectors/Transformers/TransformationFinished", null, authToken, transformationResult) .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) @@ -77,10 +78,9 @@ public void TransformationFinished([NotNull] string authToken, [NotNull] string EnsureSuccessResult(result); } - [NotNull] - public TransformerConnectorBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string connectorBoxId, [CanBeNull] string exclusiveEventId, uint? count = null) + public TransformerConnectorBoxEventBatch GetEvents(string authToken, string connectorBoxId, string? exclusiveEventId, uint? count = null) { - var request = BuildGetRequest("V1/Connectors/Transformers/GetEvents", null, authToken) + var request = BuildGetRequest("V1/Connectors/Transformers/GetEvents", authToken : authToken) .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) .WithAdditionalQueryParameter("exclusiveEventId", exclusiveEventId); @@ -89,26 +89,12 @@ public TransformerConnectorBoxEventBatch GetEvents([NotNull] string authToken, [ request = request.WithAdditionalQueryParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); } - var result = clusterClient.Send(request); - EnsureSuccessResult(result); - - var boxEventBatch = Serializer.Deserialize(result.Response.Content.ToString()); - - boxEventBatch.Events = boxEventBatch.Events ?? new TransformerConnectorBoxEvent[0]; - foreach (var boxEvent in boxEventBatch.Events) - { - boxEvent.EventContent = - boxEventTypeRegistry.IsSupportedEventType(boxEvent.EventType) - ? Serializer.NormalizeDeserializedObjectToType(boxEvent.EventContent, boxEventTypeRegistry.GetEventContentType(boxEvent.EventType)) - : null; - } - return boxEventBatch; + return GetEventsInternal(request); } - - [NotNull] - public TransformerConnectorBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string connectorBoxId, DateTime fromDateTime, uint? count = null) + + public TransformerConnectorBoxEventBatch GetEvents(string authToken, string connectorBoxId, DateTime fromDateTime, uint? count = null) { - var request = BuildGetRequest("V1/Connectors/Transformers/GetEventsFrom", null, authToken) + var request = BuildGetRequest("V1/Connectors/Transformers/GetEventsFrom", authToken : authToken) .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) .WithAdditionalQueryParameter("fromDateTime", DateTimeUtils.ToString(fromDateTime)); @@ -117,26 +103,12 @@ public TransformerConnectorBoxEventBatch GetEvents([NotNull] string authToken, [ request = request.WithAdditionalQueryParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); } - var result = clusterClient.Send(request); - EnsureSuccessResult(result); - - var boxEventBatch = Serializer.Deserialize(result.Response.Content.ToString()); - - boxEventBatch.Events = boxEventBatch.Events ?? new TransformerConnectorBoxEvent[0]; - foreach (var boxEvent in boxEventBatch.Events) - { - boxEvent.EventContent = - boxEventTypeRegistry.IsSupportedEventType(boxEvent.EventType) - ? Serializer.NormalizeDeserializedObjectToType(boxEvent.EventContent, boxEventTypeRegistry.GetEventContentType(boxEvent.EventType)) - : null; - } - return boxEventBatch; + return GetEventsInternal(request); } - [NotNull] - public MessageEntity GetMessage([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string messageId) + public MessageEntity GetMessage(string authToken, string connectorBoxId, string messageId) { - var request = BuildGetRequest("V1/Connectors/Transformers/GetMessage", null, authToken) + var request = BuildGetRequest("V1/Connectors/Transformers/GetMessage", authToken : authToken) .WithAdditionalQueryParameter(boxIdUrlParameterName, connectorBoxId) .WithAdditionalQueryParameter("messageId", messageId); @@ -146,10 +118,9 @@ public MessageEntity GetMessage([NotNull] string authToken, [NotNull] string con return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public ConnectorBoxesInfo GetConnectorBoxesInfo([NotNull] string authToken) + public ConnectorBoxesInfo GetConnectorBoxesInfo(string authToken) { - var request = BuildGetRequest("V1/Boxes/GetConnectorBoxesInfo", null, authToken); + var request = BuildGetRequest("V1/Boxes/GetConnectorBoxesInfo", authToken : authToken); var result = clusterClient.Send(request); EnsureSuccessResult(result); @@ -157,6 +128,25 @@ public ConnectorBoxesInfo GetConnectorBoxesInfo([NotNull] string authToken) return Serializer.Deserialize(result.Response.Content.ToString()); } + private TransformerConnectorBoxEventBatch GetEventsInternal(Request request) + { + var result = clusterClient.Send(request); + EnsureSuccessResult(result); + + var boxEventBatch = Serializer.Deserialize(result.Response.Content.ToString()); + + boxEventBatch.Events ??= new TransformerConnectorBoxEvent[0]; + foreach (var boxEvent in boxEventBatch.Events) + { + boxEvent.EventContent = + boxEventTypeRegistry.IsSupportedEventType(boxEvent.EventType) + ? Serializer.NormalizeDeserializedObjectToType(boxEvent.EventContent, boxEventTypeRegistry.GetEventContentType(boxEvent.EventType)) + : null; + } + + return boxEventBatch; + } + private const string boxIdUrlParameterName = "connectorBoxId"; private const string connectorInteractionIdUrlParameterName = "connectorInteractionId"; private readonly IBoxEventTypeRegistry boxEventTypeRegistry = new TransformerConnectorBoxEventTypeRegistry(); diff --git a/EdiApi.Client/Http/HttpClientException.cs b/EdiApi.Client/Http/HttpClientException.cs index 8f77107..c2a5938 100644 --- a/EdiApi.Client/Http/HttpClientException.cs +++ b/EdiApi.Client/Http/HttpClientException.cs @@ -24,9 +24,9 @@ public static HttpClientException Create(ClusterResult result) if (!result.Response.HasContent) { - throw new HttpClientException(message, statusCode); + return new HttpClientException(message, statusCode); } - throw new HttpClientException(message, statusCode, new HttpClientServerException(result.Response.Content.ToString())); + return new HttpClientException(message, statusCode, new HttpClientServerException(result.Response.Content.ToString())); } } diff --git a/EdiApi.Client/Http/Internal/InternalEdiApiHttpClient.cs b/EdiApi.Client/Http/Internal/InternalEdiApiHttpClient.cs index 767a4ad..44db2c6 100644 --- a/EdiApi.Client/Http/Internal/InternalEdiApiHttpClient.cs +++ b/EdiApi.Client/Http/Internal/InternalEdiApiHttpClient.cs @@ -2,8 +2,6 @@ using System.Globalization; using System.Net; -using JetBrains.Annotations; - using SkbKontur.EdiApi.Client.Types.Boxes; using SkbKontur.EdiApi.Client.Types.BoxEvents; using SkbKontur.EdiApi.Client.Types.Internal; @@ -14,37 +12,39 @@ using Vostok.Clusterclient.Core; using Vostok.Clusterclient.Core.Model; +using Vostok.Tracing.Abstractions; using MessageBoxEventBatch = SkbKontur.EdiApi.Client.Types.Internal.MessageBoxEventBatch; +#nullable enable + namespace SkbKontur.EdiApi.Client.Http.Internal { public class InternalEdiApiHttpClient : BaseEdiApiHttpClient, IInternalEdiApiHttpClient { - public InternalEdiApiHttpClient(string apiClientId, Uri baseUri, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : this(apiClientId, baseUri, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, enableKeepAlive) + public InternalEdiApiHttpClient(string apiClientId, Uri baseUri, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null) + : this(apiClientId, baseUri, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy) { } - public InternalEdiApiHttpClient(string apiClientId, Uri baseUri, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : base(apiClientId, baseUri, serializer, timeoutInMilliseconds, proxy, enableKeepAlive) + public InternalEdiApiHttpClient(string apiClientId, Uri baseUri, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null) + : base(apiClientId, baseUri, serializer, timeoutInMilliseconds, proxy) { } - public InternalEdiApiHttpClient(string apiClientId, string environment, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : this(apiClientId, environment, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, enableKeepAlive) + public InternalEdiApiHttpClient(string apiClientId, string environment, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null, ITracer? tracer = null) + : this(apiClientId, environment, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, tracer) { } - public InternalEdiApiHttpClient(string apiClientId, string environment, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : base(apiClientId, environment, serializer, timeoutInMilliseconds, proxy, enableKeepAlive) + public InternalEdiApiHttpClient(string apiClientId, string environment, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null, ITracer? tracer = null) + : base(apiClientId, environment, serializer, timeoutInMilliseconds, proxy, tracer) { } - [CanBeNull] - public Document GetDocument([NotNull] string authToken, [NotNull] DocumentId documentId, bool includeRelatedDocuments = true) + public Document? GetDocument(string authToken, DocumentId documentId, bool includeRelatedDocuments = true) { - var request = BuildGetRequest("V1/Internal/GetDocument", null, authToken) + var request = BuildGetRequest("V1/Internal/GetDocument", authToken : authToken) .WithAdditionalQueryParameter("boxId", documentId.BoxId) .WithAdditionalQueryParameter("entityId", documentId.EntityId) .WithAdditionalQueryParameter("includeRelatedDocuments", includeRelatedDocuments.ToString()); @@ -55,10 +55,9 @@ public Document GetDocument([NotNull] string authToken, [NotNull] DocumentId doc return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public MessageBoxEventBatch GetEvents([NotNull] string authToken, [CanBeNull] string exclusiveEventPointer, int? count = null) + public MessageBoxEventBatch GetEvents(string authToken, string? exclusiveEventPointer, int? count = null) { - var request = BuildGetRequest("V1/Internal/GetEvents", null, authToken); + var request = BuildGetRequest("V1/Internal/GetEvents", authToken : authToken); if (!string.IsNullOrWhiteSpace(exclusiveEventPointer)) { @@ -81,10 +80,9 @@ public MessageBoxEventBatch GetEvents([NotNull] string authToken, [CanBeNull] st return boxEventBatch; } - [NotNull] - public MessageBoxEvent[] GetEventsByDocumentCirculationId([NotNull] string authToken, [NotNull] string documentCirculationId) + public MessageBoxEvent[] GetEventsByDocumentCirculationId(string authToken, string documentCirculationId) { - var request = BuildGetRequest("V1/Internal/GetEventsByDocumentCirculationId", null, authToken) + var request = BuildGetRequest("V1/Internal/GetEventsByDocumentCirculationId", authToken : authToken) .WithAdditionalQueryParameter("documentCirculationId", documentCirculationId); var result = clusterClient.Send(request); @@ -98,10 +96,9 @@ public MessageBoxEvent[] GetEventsByDocumentCirculationId([NotNull] string authT return boxEvents; } - [NotNull] - public string GetLastEventPointer([NotNull] string authToken, DateTime beforeDateTime) + public string GetLastEventPointer(string authToken, DateTime beforeDateTime) { - var request = BuildGetRequest("V1/Internal/GetLastEventPointer", null, authToken) + var request = BuildGetRequest("V1/Internal/GetLastEventPointer", authToken : authToken) .WithAdditionalQueryParameter("beforeDateTime", DateTimeUtils.ToString(beforeDateTime)); var result = clusterClient.Send(request); @@ -110,10 +107,9 @@ public string GetLastEventPointer([NotNull] string authToken, DateTime beforeDat return result.Response.Content.ToString(); } - [NotNull] - public BoxesInfo GetBoxesInfo([NotNull] string authToken, [NotNull] string partyId) + public BoxesInfo GetBoxesInfo(string authToken, string partyId) { - var request = BuildGetRequest("V1/Internal/GetBoxesInfo", null, authToken) + var request = BuildGetRequest("V1/Internal/GetBoxesInfo", authToken : authToken) .WithAdditionalQueryParameter("partyId", partyId); var result = clusterClient.Send(request); @@ -122,10 +118,9 @@ public BoxesInfo GetBoxesInfo([NotNull] string authToken, [NotNull] string party return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public InternalPartyInfo GetInternalPartyInfo([NotNull] string authToken, [NotNull] string partyId) + public InternalPartyInfo GetInternalPartyInfo(string authToken, string partyId) { - var request = BuildGetRequest("V1/Internal/GetInternalPartyInfo", null, authToken) + var request = BuildGetRequest("V1/Internal/GetInternalPartyInfo", authToken : authToken) .WithAdditionalQueryParameter("partyId", partyId); var result = clusterClient.Send(request); @@ -134,10 +129,9 @@ public InternalPartyInfo GetInternalPartyInfo([NotNull] string authToken, [NotNu return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public PartyInfoWithEmployee[] GetPartiesByUser([NotNull] string authToken, [NotNull] string userId) + public PartyInfoWithEmployee[] GetPartiesByUser(string authToken, string userId) { - var request = BuildGetRequest("V1/Internal/GetPartiesByUser", null, authToken) + var request = BuildGetRequest("V1/Internal/GetPartiesByUser", authToken : authToken) .WithAdditionalQueryParameter("userId", userId); var result = clusterClient.Send(request); @@ -146,8 +140,7 @@ public PartyInfoWithEmployee[] GetPartiesByUser([NotNull] string authToken, [Not return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public PartyInfoWithEmployees[] GetPartiesInfoByInn([NotNull] string authToken, [NotNull] string partyInn) + public PartyInfoWithEmployees[] GetPartiesInfoByInn(string authToken, string partyInn) { var request = BuildGetRequest("V1/Internal/GetPartiesInfoByInn", null, authToken) .WithAdditionalQueryParameter("partyInn", partyInn); @@ -158,10 +151,9 @@ public PartyInfoWithEmployees[] GetPartiesInfoByInn([NotNull] string authToken, return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public PartySettings GetPartySettings([NotNull] string authToken, [NotNull] string partyId) + public PartySettings GetPartySettings(string authToken, string partyId) { - var request = BuildGetRequest("V1/Internal/GetPartySettings", null, authToken) + var request = BuildGetRequest("V1/Internal/GetPartySettings", authToken : authToken) .WithAdditionalQueryParameter("partyId", partyId); var result = clusterClient.Send(request); @@ -170,8 +162,7 @@ public PartySettings GetPartySettings([NotNull] string authToken, [NotNull] stri return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public string AddOrUpdateParty([NotNull] string authToken, [NotNull] string partyId, [NotNull] EditablePartySettings editablePartySettings) + public string AddOrUpdateParty(string authToken, string partyId, EditablePartySettings editablePartySettings) { var request = BuildPostRequest("V1/Internal/AddOrUpdateParty", null, authToken, editablePartySettings) .WithAdditionalQueryParameter("partyId", partyId); @@ -182,9 +173,9 @@ public string AddOrUpdateParty([NotNull] string authToken, [NotNull] string part return Serializer.Deserialize(result.Response.Content.ToString()); } - public void AddEmployee([NotNull] string authToken, [NotNull] string partyId, [NotNull] string email) + public void AddEmployee(string authToken, string partyId, string email) { - var request = BuildPostRequest("V1/Internal/AddEmployee", null, authToken, Array.Empty()) + var request = BuildPostRequest("V1/Internal/AddEmployee", authToken : authToken) .WithAdditionalQueryParameter("partyId", partyId) .WithAdditionalQueryParameter("email", email); @@ -192,7 +183,7 @@ public void AddEmployee([NotNull] string authToken, [NotNull] string partyId, [N EnsureSuccessResult(result); } - public void AddOrUpdateTradingPartnersSettings([NotNull] string authToken, [NotNull] EditableTradingPartnersSettings settingsToWrite) + public void AddOrUpdateTradingPartnersSettings(string authToken, EditableTradingPartnersSettings settingsToWrite) { var request = BuildPostRequest("V1/Internal/AddOrUpdateTradingPartnersSettings", null, authToken, settingsToWrite); diff --git a/EdiApi.Client/Http/Messages/MessagesEdiApiHttpClient.cs b/EdiApi.Client/Http/Messages/MessagesEdiApiHttpClient.cs index 45c667f..2c01a3f 100644 --- a/EdiApi.Client/Http/Messages/MessagesEdiApiHttpClient.cs +++ b/EdiApi.Client/Http/Messages/MessagesEdiApiHttpClient.cs @@ -2,8 +2,6 @@ using System.Globalization; using System.Net; -using JetBrains.Annotations; - using SkbKontur.EdiApi.Client.Types.BoxEvents; using SkbKontur.EdiApi.Client.Types.Common; using SkbKontur.EdiApi.Client.Types.Messages; @@ -12,35 +10,37 @@ using Vostok.Clusterclient.Core; using Vostok.Clusterclient.Core.Model; +using Vostok.Tracing.Abstractions; + +#nullable enable namespace SkbKontur.EdiApi.Client.Http.Messages { public class MessagesEdiApiHttpClient : BaseEdiApiHttpClient, IMessagesEdiApiClient { - public MessagesEdiApiHttpClient(string apiClientId, Uri baseUri, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : this(apiClientId, baseUri, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, enableKeepAlive) + public MessagesEdiApiHttpClient(string apiClientId, Uri baseUri, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null) + : this(apiClientId, baseUri, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy) { } - public MessagesEdiApiHttpClient(string apiClientId, Uri baseUri, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : base(apiClientId, baseUri, serializer, timeoutInMilliseconds, proxy, enableKeepAlive) + public MessagesEdiApiHttpClient(string apiClientId, Uri baseUri, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null) + : base(apiClientId, baseUri, serializer, timeoutInMilliseconds, proxy) { } - public MessagesEdiApiHttpClient(string apiClientId, string environment, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : this(apiClientId, environment, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, enableKeepAlive) + public MessagesEdiApiHttpClient(string apiClientId, string environment, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null, ITracer? tracer = null) + : this(apiClientId, environment, new JsonEdiApiTypesSerializer(), timeoutInMilliseconds, proxy, tracer) { } - public MessagesEdiApiHttpClient(string apiClientId, string environment, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy proxy = null, bool enableKeepAlive = true) - : base(apiClientId, environment, serializer, timeoutInMilliseconds, proxy, enableKeepAlive) + public MessagesEdiApiHttpClient(string apiClientId, string environment, IEdiApiTypesSerializer serializer, int timeoutInMilliseconds = DefaultTimeout, IWebProxy? proxy = null, ITracer? tracer = null) + : base(apiClientId, environment, serializer, timeoutInMilliseconds, proxy, tracer) { } - [NotNull] - public BoxDocumentsSettings GetBoxDocumentsSettings([NotNull] string authToken, [NotNull] string boxId) + public BoxDocumentsSettings GetBoxDocumentsSettings(string authToken, string boxId) { - var request = BuildGetRequest("V1/Messages/GetBoxDocumentsSettings", null, authToken) + var request = BuildGetRequest("V1/Messages/GetBoxDocumentsSettings", authToken : authToken) .WithAdditionalQueryParameter("boxId", boxId); var result = clusterClient.Send(request); @@ -49,10 +49,9 @@ public BoxDocumentsSettings GetBoxDocumentsSettings([NotNull] string authToken, return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public MessageData GetMessage([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId) + public MessageData GetMessage(string authToken, string boxId, string messageId) { - var request = BuildGetRequest("V1/Messages/GetMessage", null, authToken) + var request = BuildGetRequest("V1/Messages/GetMessage", authToken : authToken) .WithAdditionalQueryParameter("boxId", boxId) .WithAdditionalQueryParameter("messageId", messageId); @@ -62,10 +61,9 @@ public MessageData GetMessage([NotNull] string authToken, [NotNull] string boxId return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public InboxMessageMeta GetInboxMessageMeta([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId) + public InboxMessageMeta GetInboxMessageMeta(string authToken, string boxId, string messageId) { - var request = BuildGetRequest("V1/Messages/GetInboxMessageMeta", null, authToken) + var request = BuildGetRequest("V1/Messages/GetInboxMessageMeta", authToken : authToken) .WithAdditionalQueryParameter("boxId", boxId) .WithAdditionalQueryParameter("messageId", messageId); @@ -75,10 +73,9 @@ public InboxMessageMeta GetInboxMessageMeta([NotNull] string authToken, [NotNull return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public OutboxMessageMeta GetOutboxMessageMeta([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId) + public OutboxMessageMeta GetOutboxMessageMeta(string authToken, string boxId, string messageId) { - var request = BuildGetRequest("V1/Messages/GetOutboxMessageMeta", null, authToken) + var request = BuildGetRequest("V1/Messages/GetOutboxMessageMeta", authToken : authToken) .WithAdditionalQueryParameter("boxId", boxId) .WithAdditionalQueryParameter("messageId", messageId); @@ -88,8 +85,7 @@ public OutboxMessageMeta GetOutboxMessageMeta([NotNull] string authToken, [NotNu return Serializer.Deserialize(result.Response.Content.ToString()); } - [NotNull] - public OutboxMessageMeta SendMessage([NotNull] string authToken, [NotNull] string boxId, [NotNull] MessageData messageData) + public OutboxMessageMeta SendMessage(string authToken, string boxId, MessageData messageData) { var request = BuildPostRequest("V1/Messages/SendMessage", null, authToken, messageData.MessageBody) .WithAdditionalQueryParameter("boxId", boxId) @@ -101,9 +97,9 @@ public OutboxMessageMeta SendMessage([NotNull] string authToken, [NotNull] strin return Serializer.Deserialize(result.Response.Content.ToString()); } - public void MessageDeliveryStarted([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId) + public void MessageDeliveryStarted(string authToken, string boxId, string messageId) { - var request = BuildPostRequest("V1/Messages/MessageDeliveryStarted", null, authToken, Array.Empty()) + var request = BuildPostRequest("V1/Messages/MessageDeliveryStarted", authToken: authToken) .WithAdditionalQueryParameter("boxId", boxId) .WithAdditionalQueryParameter("messageId", messageId); @@ -111,7 +107,7 @@ public void MessageDeliveryStarted([NotNull] string authToken, [NotNull] string EnsureSuccessResult(result); } - public void MessageDeliveryFinished([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId, [NotNull] MessageDeliveryResult messageDeliveryResult) + public void MessageDeliveryFinished(string authToken, string boxId, string messageId, MessageDeliveryResult messageDeliveryResult) { var request = BuildPostRequest("V1/Messages/MessageDeliveryFinished", null, authToken, messageDeliveryResult) .WithAdditionalQueryParameter("boxId", boxId) @@ -121,10 +117,9 @@ public void MessageDeliveryFinished([NotNull] string authToken, [NotNull] string EnsureSuccessResult(result); } - [NotNull] - public MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string boxId, string exclusiveEventId, uint? count = null) + public MessageBoxEventBatch GetEvents(string authToken, string boxId, string? exclusiveEventId, uint? count = null) { - var request = BuildGetRequest("V1/Messages/GetEvents", null, authToken) + var request = BuildGetRequest("V1/Messages/GetEvents", authToken : authToken) .WithAdditionalQueryParameter("boxId", boxId) .WithAdditionalQueryParameter("exclusiveEventId", exclusiveEventId); @@ -133,26 +128,12 @@ public MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] stri request = request.WithAdditionalQueryParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); } - var result = clusterClient.Send(request); - EnsureSuccessResult(result); - - var boxEventBatch = Serializer.Deserialize(result.Response.Content.ToString()); - boxEventBatch.Events = boxEventBatch.Events ?? new MessageBoxEvent[0]; - foreach (var boxEvent in boxEventBatch.Events) - { - boxEvent.EventContent = - boxEventTypeRegistry.IsSupportedEventType(boxEvent.EventType) - ? Serializer.NormalizeDeserializedObjectToType(boxEvent.EventContent, boxEventTypeRegistry.GetEventContentType(boxEvent.EventType)) - : null; - } - - return boxEventBatch; + return GetEventsInternal(request); } - [NotNull] - public MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string boxId, DateTime fromDateTime, uint? count = null) + public MessageBoxEventBatch GetEvents(string authToken, string boxId, DateTime fromDateTime, uint? count = null) { - var request = BuildGetRequest("V1/Messages/GetEventsFrom", null, authToken) + var request = BuildGetRequest("V1/Messages/GetEventsFrom", authToken : authToken) .WithAdditionalQueryParameter("boxId", boxId) .WithAdditionalQueryParameter("fromDateTime", DateTimeUtils.ToString(fromDateTime)); @@ -161,11 +142,16 @@ public MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] stri request = request.WithAdditionalQueryParameter("count", count.Value.ToString(CultureInfo.InvariantCulture)); } + return GetEventsInternal(request); + } + + private MessageBoxEventBatch GetEventsInternal(Request request) + { var result = clusterClient.Send(request); EnsureSuccessResult(result); var boxEventBatch = Serializer.Deserialize(result.Response.Content.ToString()); - boxEventBatch.Events = boxEventBatch.Events ?? new MessageBoxEvent[0]; + boxEventBatch.Events ??= new MessageBoxEvent[0]; foreach (var boxEvent in boxEventBatch.Events) { boxEvent.EventContent = diff --git a/EdiApi.Client/IBaseEdiApiClient.cs b/EdiApi.Client/IBaseEdiApiClient.cs index fa454ea..f7c1a02 100644 --- a/EdiApi.Client/IBaseEdiApiClient.cs +++ b/EdiApi.Client/IBaseEdiApiClient.cs @@ -1,41 +1,31 @@ -using JetBrains.Annotations; - using SkbKontur.EdiApi.Client.Types.Boxes; using SkbKontur.EdiApi.Client.Types.Organization; using SkbKontur.EdiApi.Client.Types.Parties; using PartyInfo = SkbKontur.EdiApi.Client.Types.Parties.PartyInfo; +#nullable enable + namespace SkbKontur.EdiApi.Client { - [PublicAPI] public interface IBaseEdiApiClient { - [NotNull] - string Authenticate([NotNull] string portalSid); + string Authenticate(string portalSid); - [NotNull] - string Authenticate([NotNull] string login, [NotNull] string password); + string Authenticate(string login, string password); - [NotNull] - PartiesInfo GetAccessiblePartiesInfo([NotNull] string authToken); + PartiesInfo GetAccessiblePartiesInfo(string authToken); - [NotNull] - PartyInfo GetPartyInfo([NotNull] string authToken, [NotNull] string partyId); + PartyInfo GetPartyInfo(string authToken, string partyId); - [NotNull] - PartyInfo GetPartyInfoByGln([NotNull] string authToken, [NotNull] string partyGln); + PartyInfo GetPartyInfoByGln(string authToken, string partyGln); - [NotNull] - BoxesInfo GetBoxesInfo([NotNull] string authToken); + BoxesInfo GetBoxesInfo(string authToken); - [NotNull] - BoxInfo GetMainApiBox([NotNull] string authToken, [NotNull] string partyId); + BoxInfo GetMainApiBox(string authToken, string partyId); - [NotNull] - OrganizationCatalogueInfo GetOrganizationCatalogueInfo([NotNull] string authToken, [NotNull] string partyId); + OrganizationCatalogueInfo GetOrganizationCatalogueInfo(string authToken, string partyId); - [NotNull] - PartyInfo GetPartyInfoByDepartmentGln([NotNull] string authToken, [NotNull] string departmentGln); + PartyInfo GetPartyInfoByDepartmentGln(string authToken, string departmentGln); } } \ No newline at end of file diff --git a/EdiApi.Client/IInternalEdiApiHttpClient.cs b/EdiApi.Client/IInternalEdiApiHttpClient.cs index 971150f..322cf93 100644 --- a/EdiApi.Client/IInternalEdiApiHttpClient.cs +++ b/EdiApi.Client/IInternalEdiApiHttpClient.cs @@ -1,7 +1,5 @@ using System; -using JetBrains.Annotations; - using SkbKontur.EdiApi.Client.Types.Boxes; using SkbKontur.EdiApi.Client.Types.Internal; using SkbKontur.EdiApi.Client.Types.Messages.BoxEvents; @@ -10,34 +8,28 @@ using MessageBoxEventBatch = SkbKontur.EdiApi.Client.Types.Internal.MessageBoxEventBatch; +#nullable enable + namespace SkbKontur.EdiApi.Client { - [PublicAPI] public interface IInternalEdiApiHttpClient { - [CanBeNull] - Document GetDocument([NotNull] string authToken, [NotNull] DocumentId documentId, bool includeRelatedDocuments = true); + Document? GetDocument(string authToken, DocumentId documentId, bool includeRelatedDocuments = true); - [NotNull] - MessageBoxEventBatch GetEvents([NotNull] string authToken, [CanBeNull] string exclusiveEventPointer, int? count = null); + MessageBoxEventBatch GetEvents(string authToken, string? exclusiveEventPointer, int? count = null); - [NotNull] - MessageBoxEvent[] GetEventsByDocumentCirculationId([NotNull] string authToken, [NotNull] string documentCirculationId); + MessageBoxEvent[] GetEventsByDocumentCirculationId(string authToken, string documentCirculationId); - [NotNull] - string GetLastEventPointer([NotNull] string authToken, DateTime beforeDateTime); + string GetLastEventPointer(string authToken, DateTime beforeDateTime); - [NotNull] - BoxesInfo GetBoxesInfo([NotNull] string authToken, [NotNull] string partyId); + BoxesInfo GetBoxesInfo(string authToken, string partyId); - [NotNull] - InternalPartyInfo GetInternalPartyInfo([NotNull] string authToken, [NotNull] string partyId); + InternalPartyInfo GetInternalPartyInfo(string authToken, string partyId); - [NotNull] - string AddOrUpdateParty([NotNull] string authToken, [NotNull] string partyId, [NotNull] EditablePartySettings editablePartySettings); + string AddOrUpdateParty(string authToken, string partyId, EditablePartySettings editablePartySettings); - void AddEmployee([NotNull] string authToken, [NotNull] string partyId, [NotNull] string email); + void AddEmployee(string authToken, string partyId, string email); - void AddOrUpdateTradingPartnersSettings([NotNull] string authToken, [NotNull] EditableTradingPartnersSettings settingsToWrite); + void AddOrUpdateTradingPartnersSettings(string authToken, EditableTradingPartnersSettings settingsToWrite); } } \ No newline at end of file diff --git a/EdiApi.Client/IMessagesEdiApiClient.cs b/EdiApi.Client/IMessagesEdiApiClient.cs index ce53b27..d8b5118 100644 --- a/EdiApi.Client/IMessagesEdiApiClient.cs +++ b/EdiApi.Client/IMessagesEdiApiClient.cs @@ -1,39 +1,31 @@ using System; -using JetBrains.Annotations; - using SkbKontur.EdiApi.Client.Types.Common; using SkbKontur.EdiApi.Client.Types.Messages; using SkbKontur.EdiApi.Client.Types.Messages.BoxEvents; +#nullable enable + namespace SkbKontur.EdiApi.Client { - [PublicAPI] public interface IMessagesEdiApiClient : IBaseEdiApiClient { - [NotNull] - BoxDocumentsSettings GetBoxDocumentsSettings([NotNull] string authToken, [NotNull] string boxId); + BoxDocumentsSettings GetBoxDocumentsSettings(string authToken, string boxId); - [NotNull] - MessageData GetMessage([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId); + MessageData GetMessage(string authToken, string boxId, string messageId); - [NotNull] - InboxMessageMeta GetInboxMessageMeta([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId); + InboxMessageMeta GetInboxMessageMeta(string authToken, string boxId, string messageId); - [NotNull] - OutboxMessageMeta GetOutboxMessageMeta([NotNull] string authToken, [NotNull] string boxId, [NotNull] string messageId); + OutboxMessageMeta GetOutboxMessageMeta(string authToken, string boxId, string messageId); - [NotNull] - OutboxMessageMeta SendMessage([NotNull] string authToken, [NotNull] string boxId, [NotNull] MessageData messageData); + OutboxMessageMeta SendMessage(string authToken, string boxId, MessageData messageData); - [NotNull] - MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string boxId, [CanBeNull] string exclusiveEventId, uint? count = null); + MessageBoxEventBatch GetEvents(string authToken, string boxId, string? exclusiveEventId, uint? count = null); - [NotNull] - MessageBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string boxId, DateTime fromDateTime, uint? count = null); + MessageBoxEventBatch GetEvents(string authToken, string boxId, DateTime fromDateTime, uint? count = null); - void MessageDeliveryStarted([NotNull] string authToken, [NotNull] string boxId, [NotNull] string documentCirculationId); + void MessageDeliveryStarted(string authToken, string boxId, string documentCirculationId); - void MessageDeliveryFinished([NotNull] string authToken, [NotNull] string boxId, [NotNull] string documentCirculationId, [NotNull] MessageDeliveryResult messageDeliveryResult); + void MessageDeliveryFinished(string authToken, string boxId, string documentCirculationId, MessageDeliveryResult messageDeliveryResult); } } \ No newline at end of file diff --git a/EdiApi.Client/ITransformerConnectorEdiApiClient.cs b/EdiApi.Client/ITransformerConnectorEdiApiClient.cs index 980359b..d08d279 100644 --- a/EdiApi.Client/ITransformerConnectorEdiApiClient.cs +++ b/EdiApi.Client/ITransformerConnectorEdiApiClient.cs @@ -1,34 +1,29 @@ using System; -using JetBrains.Annotations; - using SkbKontur.EdiApi.Client.Types.Common; using SkbKontur.EdiApi.Client.Types.Connectors; using SkbKontur.EdiApi.Client.Types.Connectors.Transformer; +#nullable enable + namespace SkbKontur.EdiApi.Client { - [PublicAPI] public interface ITransformerConnectorEdiApiClient : IBaseEdiApiClient { - void TransformationStarted([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId); + void TransformationStarted(string authToken, string connectorBoxId, string connectorInteractionId); - void TransformationPaused([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId, [CanBeNull] string reason); + void TransformationPaused(string authToken, string connectorBoxId, string connectorInteractionId, string? reason); - void TransformationResumed([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId); + void TransformationResumed(string authToken, string connectorBoxId, string connectorInteractionId); - void TransformationFinished([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string connectorInteractionId, [NotNull] ConnectorTransformationResult transformationResult); + void TransformationFinished(string authToken, string connectorBoxId, string connectorInteractionId, ConnectorTransformationResult transformationResult); - [NotNull] - TransformerConnectorBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string connectorBoxId, [CanBeNull] string exclusiveEventId, uint? count = null); + TransformerConnectorBoxEventBatch GetEvents(string authToken, string connectorBoxId, string? exclusiveEventId, uint? count = null); - [NotNull] - TransformerConnectorBoxEventBatch GetEvents([NotNull] string authToken, [NotNull] string connectorBoxId, DateTime fromDateTime, uint? count = null); + TransformerConnectorBoxEventBatch GetEvents(string authToken, string connectorBoxId, DateTime fromDateTime, uint? count = null); - [NotNull] - MessageEntity GetMessage([NotNull] string authToken, [NotNull] string connectorBoxId, [NotNull] string messageId); + MessageEntity GetMessage(string authToken, string connectorBoxId, string messageId); - [NotNull] - ConnectorBoxesInfo GetConnectorBoxesInfo([NotNull] string authToken); + ConnectorBoxesInfo GetConnectorBoxesInfo(string authToken); } } \ No newline at end of file diff --git a/EdiApi.Client/Types/Internal/EditablePartySettings.cs b/EdiApi.Client/Types/Internal/EditablePartySettings.cs index 7cce99b..282c40d 100644 --- a/EdiApi.Client/Types/Internal/EditablePartySettings.cs +++ b/EdiApi.Client/Types/Internal/EditablePartySettings.cs @@ -1,36 +1,30 @@ using System.Collections.Generic; -using JetBrains.Annotations; - using SkbKontur.EdiApi.Client.Types.Messages; using SkbKontur.EdiApi.Client.Types.Parties; +#nullable enable + namespace SkbKontur.EdiApi.Client.Types.Internal { public class EditablePartySettings { - [NotNull] - public EditablePartyInfo PartyInfo { get; set; } + public EditablePartyInfo PartyInfo { get; set; } = default!; - [NotNull] - public EditableDeliverySettings DeliverySettings { get; set; } + public EditableDeliverySettings DeliverySettings { get; set; } = default!; - [CanBeNull] - public EditableConnectorSettings ConnectorSettings { get; set; } + public EditableConnectorSettings? ConnectorSettings { get; set; } - [CanBeNull] - public EditableWebInterfaceSettings WebInterfaceSettings { get; set; } + public EditableWebInterfaceSettings? WebInterfaceSettings { get; set; } } public class EditableDeliverySettings { public bool UseTestBoxes { get; set; } - [CanBeNull] - public EditableApiSettings ApiBoxSettings { get; set; } + public EditableApiSettings? ApiBoxSettings { get; set; } - [NotNull] - public string XmlEncoding { get; set; } + public string XmlEncoding { get; set; } = default!; public MessageFormat MessageFormat { get; set; } public MessageFormat StatusMessageFormat { get; set; } @@ -45,71 +39,55 @@ public class EditableConnectorSettings { public EditableConnectorSettings() => InboxByDocTypeBoxes = new List(); - [CanBeNull] - public EditableConnectorBox AllOutboxBox { get; set; } + public EditableConnectorBox? AllOutboxBox { get; set; } - [CanBeNull] - public EditableConnectorBox AllInboxBox { get; set; } + public EditableConnectorBox? AllInboxBox { get; set; } - [ItemNotNull] public List InboxByDocTypeBoxes { get; set; } } public class EditableConnectorBox { - [NotNull] - public string Id { get; set; } + public string Id { get; set; } = default!; - [NotNull] - public string Name { get; set; } + public string Name { get; set; } = default!; } public class EditableConnectorBoxForDocType { public DocumentType DocumentType { get; set; } - [NotNull] - public EditableConnectorBox Box { get; set; } + public EditableConnectorBox Box { get; set; } = default!; } public class EditablePartyInfo { public PartyType PartyType { get; set; } - [NotNull] - public string Gln { get; set; } + public string Gln { get; set; } = default!; - [NotNull] - public string Name { get; set; } + public string Name { get; set; } = default!; - [NotNull] - public string Inn { get; set; } + public string Inn { get; set; } = default!; - [NotNull] - public string Kpp { get; set; } + public string Kpp { get; set; } = default!; - [CanBeNull] - public string BillingAccountId { get; set; } + public string? BillingAccountId { get; set; } public bool CreateNewBillingAccount { get; set; } } public class EditableTradingPartnersSettings { - [NotNull] - public string BuyerId { get; set; } + public string BuyerId { get; set; } = default!; - [NotNull] - public string SupplierId { get; set; } + public string SupplierId { get; set; } = default!; - [CanBeNull] - public string BuyerRoamingProviderId { get; set; } + public string? BuyerRoamingProviderId { get; set; } - [CanBeNull] - public string SupplierRoamingProviderId { get; set; } + public string? SupplierRoamingProviderId { get; set; } - [NotNull] - public DocumentType[] UsedMessages { get; set; } + public DocumentType[] UsedMessages { get; set; } = default!; } public class EditableWebInterfaceSettings diff --git a/EdiApi.Client/Types/Messages/BoxEventsContents/Outbox/AmendmentRequestedEventContent.cs b/EdiApi.Client/Types/Messages/BoxEventsContents/Outbox/AmendmentRequestedEventContent.cs index 67e120e..26dff79 100644 --- a/EdiApi.Client/Types/Messages/BoxEventsContents/Outbox/AmendmentRequestedEventContent.cs +++ b/EdiApi.Client/Types/Messages/BoxEventsContents/Outbox/AmendmentRequestedEventContent.cs @@ -1,10 +1,9 @@ -using JetBrains.Annotations; +#nullable enable namespace SkbKontur.EdiApi.Client.Types.Messages.BoxEventsContents.Outbox { public class AmendmentRequestedEventContent : OutboxDiadocEventContentBase { - [CanBeNull] - public string AmendmentRequestMessage { get; set; } + public string? AmendmentRequestMessage { get; set; } } } \ No newline at end of file diff --git a/EdiApi.Client/Types/Parties/PartySettings.cs b/EdiApi.Client/Types/Parties/PartySettings.cs index 41af05e..260bb8c 100644 --- a/EdiApi.Client/Types/Parties/PartySettings.cs +++ b/EdiApi.Client/Types/Parties/PartySettings.cs @@ -1,17 +1,14 @@ -using JetBrains.Annotations; +#nullable enable namespace SkbKontur.EdiApi.Client.Types.Parties { public class PartySettings { - public PartySettings() - { + public PartySettings() => ReportingSettings = new ReportingSettings(); - } public IntegrationType IntegrationType { get; set; } - [NotNull] public ReportingSettings ReportingSettings { get; set; } } @@ -25,15 +22,12 @@ public enum IntegrationType public class ReportingSettings { - public ReportingSettings() - { + public ReportingSettings() => ChestnyZnakReportingProductCategories = new ChestnyZnakReportingProductCategories(); - } public bool Egais { get; set; } public bool Mercury { get; set; } - [NotNull] public ChestnyZnakReportingProductCategories ChestnyZnakReportingProductCategories { get; set; } } diff --git a/version.json b/version.json index f29c4b8..d487fa1 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.8-pre5", + "version": "1.8-pre8", "assemblyVersion": { "precision": "build" },