From 7660ee72f27656aa19eeb10c64a9a8b1f9cbb110 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Tue, 12 Sep 2023 16:48:28 +0200 Subject: [PATCH] Added filtering and sorting to shipcalls in the list. While doing so, I have also refactored the shipcall processing logic in the main window. All changes now go through the filter and sorting stage before all controls are removed and only the controls matching to the sorted list are added to the stack panel. --- misc/BreCalApi.cs | 335 ++++++++++-------- src/BreCalClient/App.config | 3 + src/BreCalClient/BreCalClient.csproj | 6 +- src/BreCalClient/Extensions.cs | 7 + src/BreCalClient/MainWindow.xaml | 10 +- src/BreCalClient/MainWindow.xaml.cs | 324 +++++++++++++---- .../Properties/Settings.Designer.cs | 9 + src/BreCalClient/Properties/Settings.settings | 3 + src/BreCalClient/ReadMe.md | 18 + .../Resources/Resources.Designer.cs | 18 + src/BreCalClient/Resources/Resources.de.resx | 6 + src/BreCalClient/Resources/Resources.resx | 6 + src/BreCalClient/SearchFilterControl.xaml | 16 +- src/BreCalClient/SearchFilterControl.xaml.cs | 94 +++++ src/BreCalClient/SearchFilterModel.cs | 8 +- src/BreCalClient/ShipcallControlModel.cs | 15 + 16 files changed, 633 insertions(+), 245 deletions(-) create mode 100644 src/BreCalClient/ReadMe.md diff --git a/misc/BreCalApi.cs b/misc/BreCalApi.cs index b6cd9a2..833fdcd 100644 --- a/misc/BreCalApi.cs +++ b/misc/BreCalApi.cs @@ -1,8 +1,8 @@ //---------------------- // -// Generated REST API Client Code Generator v1.7.17.0 on 05.09.2023 16:40:43 -// Using the tool OpenAPI Generator v6.6.0 +// Generated REST API Client Code Generator v1.8.4.0 on 11.09.2023 10:29:36 +// Using the tool OpenAPI Generator v7.0.0 // //---------------------- @@ -29,7 +29,8 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; -using System.Net.Mime; + +using System.Net.Security; using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters; @@ -2334,7 +2335,6 @@ namespace BreCalClient.misc.Client internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer { private readonly IReadableConfiguration _configuration; - private static readonly string _contentType = "application/json"; private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings { // OpenAPI generated types generally hide default constructors. @@ -2435,15 +2435,11 @@ namespace BreCalClient.misc.Client } public ISerializer Serializer => this; public IDeserializer Deserializer => this; - public string[] AcceptedContentTypes => RestSharp.Serializers.ContentType.JsonAccept; + public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept; public SupportsContentType SupportsContentType => contentType => - contentType.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || - contentType.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); - public string ContentType - { - get { return _contentType; } - set { throw new InvalidOperationException("Not allowed to set content type."); } - } + contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) || + contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase); + public ContentType ContentType { get; set; } = RestSharp.ContentType.Json; public DataFormat DataFormat => DataFormat.Json; } /// @@ -2688,7 +2684,7 @@ namespace BreCalClient.misc.Client } return transformed; } - private ApiResponse Exec(RestRequest req, RequestOptions options, IReadableConfiguration configuration) + private ApiResponse Exec(RestRequest request, RequestOptions options, IReadableConfiguration configuration) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; var cookies = new CookieContainer(); @@ -2705,84 +2701,87 @@ namespace BreCalClient.misc.Client CookieContainer = cookies, MaxTimeout = configuration.Timeout, Proxy = configuration.Proxy, - UserAgent = configuration.UserAgent + UserAgent = configuration.UserAgent, + UseDefaultCredentials = configuration.UseDefaultCredentials, + RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); - InterceptRequest(req); - RestResponse response; - if (RetryConfiguration.RetryPolicy != null) + using (RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)))) { - var policy = RetryConfiguration.RetryPolicy; - var policyResult = policy.ExecuteAndCapture(() => client.Execute(req)); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + InterceptRequest(request); + RestResponse response; + if (RetryConfiguration.RetryPolicy != null) { - Request = req, - ErrorException = policyResult.FinalException - }; - } - else - { - response = client.Execute(req); - } - // if the response type is oneOf/anyOf, call FromJSON to deserialize the data - if (typeof(BreCalClient.misc.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T))) - { - try - { - response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content }); - } - catch (Exception ex) - { - throw ex.InnerException != null ? ex.InnerException : ex; - } - } - else if (typeof(T).Name == "Stream") // for binary response - { - response.Data = (T)(object)new MemoryStream(response.RawBytes); - } - else if (typeof(T).Name == "Byte[]") // for byte response - { - response.Data = (T)(object)response.RawBytes; - } - else if (typeof(T).Name == "String") // for string response - { - response.Data = (T)(object)response.Content; - } - InterceptResponse(req, response); - var result = ToApiResponse(response); - if (response.ErrorMessage != null) - { - result.ErrorText = response.ErrorMessage; - } - if (response.Cookies != null && response.Cookies.Count > 0) - { - if (result.Cookies == null) result.Cookies = new List(); - foreach (var restResponseCookie in response.Cookies.Cast()) - { - var cookie = new Cookie( - restResponseCookie.Name, - restResponseCookie.Value, - restResponseCookie.Path, - restResponseCookie.Domain - ) + var policy = RetryConfiguration.RetryPolicy; + var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Comment = restResponseCookie.Comment, - CommentUri = restResponseCookie.CommentUri, - Discard = restResponseCookie.Discard, - Expired = restResponseCookie.Expired, - Expires = restResponseCookie.Expires, - HttpOnly = restResponseCookie.HttpOnly, - Port = restResponseCookie.Port, - Secure = restResponseCookie.Secure, - Version = restResponseCookie.Version + ErrorException = policyResult.FinalException }; - result.Cookies.Add(cookie); } + else + { + response = client.Execute(request); + } + // if the response type is oneOf/anyOf, call FromJSON to deserialize the data + if (typeof(BreCalClient.misc.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T))) + { + try + { + response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content }); + } + catch (Exception ex) + { + throw ex.InnerException != null ? ex.InnerException : ex; + } + } + else if (typeof(T).Name == "Stream") // for binary response + { + response.Data = (T)(object)new MemoryStream(response.RawBytes); + } + else if (typeof(T).Name == "Byte[]") // for byte response + { + response.Data = (T)(object)response.RawBytes; + } + else if (typeof(T).Name == "String") // for string response + { + response.Data = (T)(object)response.Content; + } + InterceptResponse(request, response); + var result = ToApiResponse(response); + if (response.ErrorMessage != null) + { + result.ErrorText = response.ErrorMessage; + } + if (response.Cookies != null && response.Cookies.Count > 0) + { + if (result.Cookies == null) result.Cookies = new List(); + foreach (var restResponseCookie in response.Cookies.Cast()) + { + var cookie = new Cookie( + restResponseCookie.Name, + restResponseCookie.Value, + restResponseCookie.Path, + restResponseCookie.Domain + ) + { + Comment = restResponseCookie.Comment, + CommentUri = restResponseCookie.CommentUri, + Discard = restResponseCookie.Discard, + Expired = restResponseCookie.Expired, + Expires = restResponseCookie.Expires, + HttpOnly = restResponseCookie.HttpOnly, + Port = restResponseCookie.Port, + Secure = restResponseCookie.Secure, + Version = restResponseCookie.Version + }; + result.Cookies.Add(cookie); + } + } + return result; } - return result; } - private async Task> ExecAsync(RestRequest req, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + private async Task> ExecAsync(RestRequest request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl; var clientOptions = new RestClientOptions(baseUrl) @@ -2790,71 +2789,73 @@ namespace BreCalClient.misc.Client ClientCertificates = configuration.ClientCertificates, MaxTimeout = configuration.Timeout, Proxy = configuration.Proxy, - UserAgent = configuration.UserAgent + UserAgent = configuration.UserAgent, + UseDefaultCredentials = configuration.UseDefaultCredentials }; - RestClient client = new RestClient(clientOptions) - .UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)); - InterceptRequest(req); - RestResponse response; - if (RetryConfiguration.AsyncRetryPolicy != null) + using (RestClient client = new RestClient(clientOptions, + configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration)))) { - var policy = RetryConfiguration.AsyncRetryPolicy; - var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false); - response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse + InterceptRequest(request); + RestResponse response; + if (RetryConfiguration.AsyncRetryPolicy != null) { - Request = req, - ErrorException = policyResult.FinalException - }; - } - else - { - response = await client.ExecuteAsync(req, cancellationToken).ConfigureAwait(false); - } - // if the response type is oneOf/anyOf, call FromJSON to deserialize the data - if (typeof(BreCalClient.misc.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T))) - { - response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content }); - } - else if (typeof(T).Name == "Stream") // for binary response - { - response.Data = (T)(object)new MemoryStream(response.RawBytes); - } - else if (typeof(T).Name == "Byte[]") // for byte response - { - response.Data = (T)(object)response.RawBytes; - } - InterceptResponse(req, response); - var result = ToApiResponse(response); - if (response.ErrorMessage != null) - { - result.ErrorText = response.ErrorMessage; - } - if (response.Cookies != null && response.Cookies.Count > 0) - { - if (result.Cookies == null) result.Cookies = new List(); - foreach (var restResponseCookie in response.Cookies.Cast()) - { - var cookie = new Cookie( - restResponseCookie.Name, - restResponseCookie.Value, - restResponseCookie.Path, - restResponseCookie.Domain - ) + var policy = RetryConfiguration.AsyncRetryPolicy; + var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); + response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize(policyResult.Result) : new RestResponse(request) { - Comment = restResponseCookie.Comment, - CommentUri = restResponseCookie.CommentUri, - Discard = restResponseCookie.Discard, - Expired = restResponseCookie.Expired, - Expires = restResponseCookie.Expires, - HttpOnly = restResponseCookie.HttpOnly, - Port = restResponseCookie.Port, - Secure = restResponseCookie.Secure, - Version = restResponseCookie.Version + ErrorException = policyResult.FinalException }; - result.Cookies.Add(cookie); } + else + { + response = await client.ExecuteAsync(request, cancellationToken).ConfigureAwait(false); + } + // if the response type is oneOf/anyOf, call FromJSON to deserialize the data + if (typeof(BreCalClient.misc.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T))) + { + response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content }); + } + else if (typeof(T).Name == "Stream") // for binary response + { + response.Data = (T)(object)new MemoryStream(response.RawBytes); + } + else if (typeof(T).Name == "Byte[]") // for byte response + { + response.Data = (T)(object)response.RawBytes; + } + InterceptResponse(request, response); + var result = ToApiResponse(response); + if (response.ErrorMessage != null) + { + result.ErrorText = response.ErrorMessage; + } + if (response.Cookies != null && response.Cookies.Count > 0) + { + if (result.Cookies == null) result.Cookies = new List(); + foreach (var restResponseCookie in response.Cookies.Cast()) + { + var cookie = new Cookie( + restResponseCookie.Name, + restResponseCookie.Value, + restResponseCookie.Path, + restResponseCookie.Domain + ) + { + Comment = restResponseCookie.Comment, + CommentUri = restResponseCookie.CommentUri, + Discard = restResponseCookie.Discard, + Expired = restResponseCookie.Expired, + Expires = restResponseCookie.Expires, + HttpOnly = restResponseCookie.HttpOnly, + Port = restResponseCookie.Port, + Secure = restResponseCookie.Secure, + Version = restResponseCookie.Version + }; + result.Cookies.Add(cookie); + } + } + return result; } - return result; } #region IAsynchronousClient /// @@ -3521,6 +3522,7 @@ namespace BreCalClient.misc.Client /// Example: http://localhost:3000/v1/ /// private string _basePath; + private bool _useDefaultCredentials = false; /// /// Gets or sets the API key based on the authentication name. /// This is the key and value comprising the "secret" for accessing an API. @@ -3610,11 +3612,20 @@ namespace BreCalClient.misc.Client /// /// Gets or sets the base path for API access. /// - public virtual string BasePath { + public virtual string BasePath + { get { return _basePath; } set { _basePath = value; } } /// + /// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false. + /// + public virtual bool UseDefaultCredentials + { + get { return _useDefaultCredentials; } + set { _useDefaultCredentials = value; } + } + /// /// Gets or sets the default header. /// [Obsolete("Use DefaultHeaders instead.")] @@ -3854,7 +3865,7 @@ namespace BreCalClient.misc.Client /// The operation server URL. public string GetOperationServerUrl(string operation, int index, Dictionary inputVariables) { - if (OperationServers.TryGetValue(operation, out var operationServer)) + if (operation != null && OperationServers.TryGetValue(operation, out var operationServer)) { return GetServerUrl(operationServer, index, inputVariables); } @@ -3905,6 +3916,10 @@ namespace BreCalClient.misc.Client } return url; } + /// + /// Gets and Sets the RemoteCertificateValidationCallback + /// + public RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; set; } #endregion Properties #region Methods /// @@ -3970,6 +3985,8 @@ namespace BreCalClient.misc.Client TempFolderPath = second.TempFolderPath ?? first.TempFolderPath, DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat, ClientCertificates = second.ClientCertificates ?? first.ClientCertificates, + UseDefaultCredentials = second.UseDefaultCredentials, + RemoteCertificateValidationCallback = second.RemoteCertificateValidationCallback ?? first.RemoteCertificateValidationCallback, }; return config; } @@ -4294,6 +4311,10 @@ namespace BreCalClient.misc.Client /// Password. string Password { get; } /// + /// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false. + /// + bool UseDefaultCredentials { get; } + /// /// Get the servers associated with the operation. /// /// Operation servers. @@ -4316,6 +4337,11 @@ namespace BreCalClient.misc.Client /// /// X509 Certificate collection. X509CertificateCollection ClientCertificates { get; } + /// + /// Callback function for handling the validation of remote certificates. Useful for certificate pinning and + /// overriding certificate errors in the scope of a request. + /// + RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; } } } @@ -4877,16 +4903,16 @@ namespace BreCalClient.misc.Model /// id. /// name. /// participantId. - /// _lock. + /// varLock. /// created. /// modified. /// deleted (default to false). - public Berth(int id = default(int), string name = default(string), int? participantId = default(int?), bool? _lock = default(bool?), DateTime created = default(DateTime), DateTime? modified = default(DateTime?), bool deleted = false) + public Berth(int id = default(int), string name = default(string), int? participantId = default(int?), bool? varLock = default(bool?), DateTime created = default(DateTime), DateTime? modified = default(DateTime?), bool deleted = false) { this.Id = id; this.Name = name; this.ParticipantId = participantId; - this.Lock = _lock; + this.VarLock = varLock; this.Created = created; this.Modified = modified; this.Deleted = deleted; @@ -4907,10 +4933,10 @@ namespace BreCalClient.misc.Model [DataMember(Name = "participant_id", EmitDefaultValue = true)] public int? ParticipantId { get; set; } /// - /// Gets or Sets Lock + /// Gets or Sets VarLock /// [DataMember(Name = "lock", EmitDefaultValue = true)] - public bool? Lock { get; set; } + public bool? VarLock { get; set; } /// /// Gets or Sets Created /// @@ -4937,7 +4963,7 @@ namespace BreCalClient.misc.Model sb.Append(" Id: ").Append(Id).Append("\n"); sb.Append(" Name: ").Append(Name).Append("\n"); sb.Append(" ParticipantId: ").Append(ParticipantId).Append("\n"); - sb.Append(" Lock: ").Append(Lock).Append("\n"); + sb.Append(" VarLock: ").Append(VarLock).Append("\n"); sb.Append(" Created: ").Append(Created).Append("\n"); sb.Append(" Modified: ").Append(Modified).Append("\n"); sb.Append(" Deleted: ").Append(Deleted).Append("\n"); @@ -4988,9 +5014,9 @@ namespace BreCalClient.misc.Model this.ParticipantId.Equals(input.ParticipantId)) ) && ( - this.Lock == input.Lock || - (this.Lock != null && - this.Lock.Equals(input.Lock)) + this.VarLock == input.VarLock || + (this.VarLock != null && + this.VarLock.Equals(input.VarLock)) ) && ( this.Created == input.Created || @@ -5025,9 +5051,9 @@ namespace BreCalClient.misc.Model { hashCode = (hashCode * 59) + this.ParticipantId.GetHashCode(); } - if (this.Lock != null) + if (this.VarLock != null) { - hashCode = (hashCode * 59) + this.Lock.GetHashCode(); + hashCode = (hashCode * 59) + this.VarLock.GetHashCode(); } if (this.Created != null) { @@ -6521,6 +6547,7 @@ namespace BreCalClient.misc.Model /// /// Gets or Sets Participants /// + /// [1,5,7] [DataMember(Name = "participants", EmitDefaultValue = true)] public List Participants { get; set; } /// diff --git a/src/BreCalClient/App.config b/src/BreCalClient/App.config index 33176d0..5cb87a6 100644 --- a/src/BreCalClient/App.config +++ b/src/BreCalClient/App.config @@ -16,6 +16,9 @@ !!Bremen calling Testversion!! + + https://www.textbausteine.net/ + \ No newline at end of file diff --git a/src/BreCalClient/BreCalClient.csproj b/src/BreCalClient/BreCalClient.csproj index 1a919fa..3333e8e 100644 --- a/src/BreCalClient/BreCalClient.csproj +++ b/src/BreCalClient/BreCalClient.csproj @@ -95,12 +95,12 @@ - + - - + + diff --git a/src/BreCalClient/Extensions.cs b/src/BreCalClient/Extensions.cs index b908fce..1a93d42 100644 --- a/src/BreCalClient/Extensions.cs +++ b/src/BreCalClient/Extensions.cs @@ -61,6 +61,13 @@ namespace BreCalClient Shifting = 3 } + public enum SortOrder + { + SHIP_NAME, + ETA_ETD, + MODIFIED + } + #endregion #region public helper diff --git a/src/BreCalClient/MainWindow.xaml b/src/BreCalClient/MainWindow.xaml index d03c01a..b87b972 100644 --- a/src/BreCalClient/MainWindow.xaml +++ b/src/BreCalClient/MainWindow.xaml @@ -58,11 +58,17 @@ - + + + +