Skip to content

Commit

Permalink
style: use file-scope namespace and primary constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
xlegalles committed Oct 21, 2024
1 parent 1be2814 commit f3f264c
Show file tree
Hide file tree
Showing 25 changed files with 278 additions and 401 deletions.
47 changes: 23 additions & 24 deletions Client/Impl/Responses/ActivateJobsResponses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@
using GatewayProtocol;
using Zeebe.Client.Api.Responses;

namespace Zeebe.Client.Impl.Responses
namespace Zeebe.Client.Impl.Responses;

public class ActivateJobsResponses : IActivateJobsResponse
{
public class ActivateJobsResponses : IActivateJobsResponse
{
public IList<IJob> Jobs { get; set; }
public IList<IJob> Jobs { get; set; }

public ActivateJobsResponses()
{
Jobs = new List<IJob>();
}
public ActivateJobsResponses()
{
Jobs = new List<IJob>();
}

public ActivateJobsResponses(GatewayProtocol.ActivateJobsResponse jobsResponse)
{
Jobs = ConvertToList(jobsResponse);
}
public ActivateJobsResponses(ActivateJobsResponse jobsResponse)
{
Jobs = ConvertToList(jobsResponse);
}

public void Add(IActivateJobsResponse jobsResponse)
{
((List<IJob>) Jobs).AddRange(jobsResponse.Jobs);
}
public void Add(IActivateJobsResponse jobsResponse)
{
((List<IJob>) Jobs).AddRange(jobsResponse.Jobs);
}

private static List<IJob> ConvertToList(ActivateJobsResponse jobsResponse)
{
return jobsResponse.Jobs
.Select(job => new ActivatedJob(job))
.Cast<IJob>()
.ToList();
}
private static List<IJob> ConvertToList(ActivateJobsResponse jobsResponse)
{
return jobsResponse.Jobs
.Select(job => new ActivatedJob(job))
.Cast<IJob>()
.ToList();
}
}
}
153 changes: 67 additions & 86 deletions Client/Impl/Responses/ActivatedJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,119 +16,100 @@
using System;
using Zeebe.Client.Api.Responses;

namespace Zeebe.Client.Impl.Responses
namespace Zeebe.Client.Impl.Responses;

public class ActivatedJob(GatewayProtocol.ActivatedJob activatedJob) : IJob
{
public class ActivatedJob : IJob
private static DateTime FromUTCTimestamp(long milliseconds)
{
private static DateTime FromUTCTimestamp(long milliseconds)
{
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dtDateTime = dtDateTime.AddMilliseconds(milliseconds).ToLocalTime();
return dtDateTime;
}
var dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dtDateTime = dtDateTime.AddMilliseconds(milliseconds).ToLocalTime();
return dtDateTime;
}

public ActivatedJob(GatewayProtocol.ActivatedJob activatedJob)
{
Key = activatedJob.Key;
Type = activatedJob.Type;
ProcessInstanceKey = activatedJob.ProcessInstanceKey;
BpmnProcessId = activatedJob.BpmnProcessId;
ProcessDefinitionVersion = activatedJob.ProcessDefinitionVersion;
ProcessDefinitionKey = activatedJob.ProcessDefinitionKey;
ElementId = activatedJob.ElementId;
ElementInstanceKey = activatedJob.ElementInstanceKey;
Worker = activatedJob.Worker;
Retries = activatedJob.Retries;
Deadline = FromUTCTimestamp(activatedJob.Deadline);
Variables = activatedJob.Variables;
CustomHeaders = activatedJob.CustomHeaders;
TenantId = activatedJob.TenantId;
}
public long Key { get; } = activatedJob.Key;

public long Key { get; }
public string Type { get; } = activatedJob.Type;

public string Type { get; }
public long ProcessInstanceKey { get; } = activatedJob.ProcessInstanceKey;

public long ProcessInstanceKey { get; }
public string BpmnProcessId { get; } = activatedJob.BpmnProcessId;

public string BpmnProcessId { get; }
public int ProcessDefinitionVersion { get; } = activatedJob.ProcessDefinitionVersion;

public int ProcessDefinitionVersion { get; }
public long ProcessDefinitionKey { get; } = activatedJob.ProcessDefinitionKey;

public long ProcessDefinitionKey { get; }
public string ElementId { get; } = activatedJob.ElementId;

public string ElementId { get; }
public long ElementInstanceKey { get; } = activatedJob.ElementInstanceKey;

public long ElementInstanceKey { get; }
public string Worker { get; } = activatedJob.Worker;

public string Worker { get; }
public int Retries { get; } = activatedJob.Retries;

public int Retries { get; }
public DateTime Deadline { get; } = FromUTCTimestamp(activatedJob.Deadline);

public DateTime Deadline { get; }
public string Variables { get; } = activatedJob.Variables;

public string Variables { get; }
public string CustomHeaders { get; } = activatedJob.CustomHeaders;

public string CustomHeaders { get; }
public string TenantId { get; } = activatedJob.TenantId;

public string TenantId { get; }
public override string ToString()
{
return
$"{nameof(Key)}: {Key}, {nameof(Type)}: {Type}, {nameof(TenantId)}: {TenantId}, {nameof(ProcessInstanceKey)}: {ProcessInstanceKey}, {nameof(BpmnProcessId)}: {BpmnProcessId}, {nameof(ProcessDefinitionVersion)}: {ProcessDefinitionVersion}, {nameof(ProcessDefinitionKey)}: {ProcessDefinitionKey}, {nameof(ElementId)}: {ElementId}, {nameof(ElementInstanceKey)}: {ElementInstanceKey}, {nameof(Worker)}: {Worker}, {nameof(Retries)}: {Retries}, {nameof(Deadline)}: {Deadline}, {nameof(Variables)}: {Variables}, {nameof(CustomHeaders)}: {CustomHeaders}";
}

public override string ToString()
protected bool Equals(ActivatedJob other)
{
return Key == other.Key && Type == other.Type && ProcessInstanceKey == other.ProcessInstanceKey && TenantId == other.TenantId &&
BpmnProcessId == other.BpmnProcessId &&
ProcessDefinitionVersion == other.ProcessDefinitionVersion && ProcessDefinitionKey == other.ProcessDefinitionKey &&
ElementId == other.ElementId && ElementInstanceKey == other.ElementInstanceKey &&
Worker == other.Worker && Retries == other.Retries && Deadline.Equals(other.Deadline) &&
Variables == other.Variables && CustomHeaders == other.CustomHeaders;
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return
$"{nameof(Key)}: {Key}, {nameof(Type)}: {Type}, {nameof(TenantId)}: {TenantId}, {nameof(ProcessInstanceKey)}: {ProcessInstanceKey}, {nameof(BpmnProcessId)}: {BpmnProcessId}, {nameof(ProcessDefinitionVersion)}: {ProcessDefinitionVersion}, {nameof(ProcessDefinitionKey)}: {ProcessDefinitionKey}, {nameof(ElementId)}: {ElementId}, {nameof(ElementInstanceKey)}: {ElementInstanceKey}, {nameof(Worker)}: {Worker}, {nameof(Retries)}: {Retries}, {nameof(Deadline)}: {Deadline}, {nameof(Variables)}: {Variables}, {nameof(CustomHeaders)}: {CustomHeaders}";
return false;
}

protected bool Equals(ActivatedJob other)
if (ReferenceEquals(this, obj))
{
return Key == other.Key && Type == other.Type && ProcessInstanceKey == other.ProcessInstanceKey && TenantId == other.TenantId &&
BpmnProcessId == other.BpmnProcessId &&
ProcessDefinitionVersion == other.ProcessDefinitionVersion && ProcessDefinitionKey == other.ProcessDefinitionKey &&
ElementId == other.ElementId && ElementInstanceKey == other.ElementInstanceKey &&
Worker == other.Worker && Retries == other.Retries && Deadline.Equals(other.Deadline) &&
Variables == other.Variables && CustomHeaders == other.CustomHeaders;
return true;
}

public override bool Equals(object obj)
if (obj.GetType() != GetType())
{
if (ReferenceEquals(null, obj))
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

if (obj.GetType() != this.GetType())
{
return false;
}

return Equals((ActivatedJob) obj);
return false;
}

public override int GetHashCode()
return Equals((ActivatedJob) obj);
}

public override int GetHashCode()
{
unchecked
{
unchecked
{
var hashCode = Key.GetHashCode();
hashCode = (hashCode * 397) ^ (Type != null ? Type.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (TenantId != null ? TenantId.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ ProcessInstanceKey.GetHashCode();
hashCode = (hashCode * 397) ^ (BpmnProcessId != null ? BpmnProcessId.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ ProcessDefinitionVersion;
hashCode = (hashCode * 397) ^ ProcessDefinitionKey.GetHashCode();
hashCode = (hashCode * 397) ^ (ElementId != null ? ElementId.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ ElementInstanceKey.GetHashCode();
hashCode = (hashCode * 397) ^ (Worker != null ? Worker.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ Retries;
hashCode = (hashCode * 397) ^ Deadline.GetHashCode();
hashCode = (hashCode * 397) ^ (Variables != null ? Variables.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (CustomHeaders != null ? CustomHeaders.GetHashCode() : 0);
return hashCode;
}
var hashCode = Key.GetHashCode();
hashCode = (hashCode * 397) ^ (Type != null ? Type.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (TenantId != null ? TenantId.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ ProcessInstanceKey.GetHashCode();
hashCode = (hashCode * 397) ^ (BpmnProcessId != null ? BpmnProcessId.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ ProcessDefinitionVersion;
hashCode = (hashCode * 397) ^ ProcessDefinitionKey.GetHashCode();
hashCode = (hashCode * 397) ^ (ElementId != null ? ElementId.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ ElementInstanceKey.GetHashCode();
hashCode = (hashCode * 397) ^ (Worker != null ? Worker.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ Retries;
hashCode = (hashCode * 397) ^ Deadline.GetHashCode();
hashCode = (hashCode * 397) ^ (Variables != null ? Variables.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (CustomHeaders != null ? CustomHeaders.GetHashCode() : 0);
return hashCode;
}
}
}
}
57 changes: 28 additions & 29 deletions Client/Impl/Responses/BrokerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,37 @@
using System.Linq;
using Zeebe.Client.Api.Responses;

namespace Zeebe.Client.Impl.Responses
namespace Zeebe.Client.Impl.Responses;

public class BrokerInfo : IBrokerInfo
{
public class BrokerInfo : IBrokerInfo
{
private const char AddressSeparator = ':';
private const char AddressSeparator = ':';

public string Address { get; }
public string Host { get; }
public int NodeId { get; }
public int Port { get; }
public IList<IPartitionInfo> Partitions { get; }
public string Address { get; }
public string Host { get; }
public int NodeId { get; }
public int Port { get; }
public IList<IPartitionInfo> Partitions { get; }

public BrokerInfo(GatewayProtocol.BrokerInfo brokerInfo)
{
Address = brokerInfo.Host + AddressSeparator + brokerInfo.Port;
Host = brokerInfo.Host;
NodeId = brokerInfo.NodeId;
Port = brokerInfo.Port;
public BrokerInfo(GatewayProtocol.BrokerInfo brokerInfo)
{
Address = brokerInfo.Host + AddressSeparator + brokerInfo.Port;
Host = brokerInfo.Host;
NodeId = brokerInfo.NodeId;
Port = brokerInfo.Port;

Partitions = brokerInfo.Partitions
.Select(partition => new PartitionInfo(partition))
.Cast<IPartitionInfo>()
.ToList();
}
Partitions = brokerInfo.Partitions
.Select(partition => new PartitionInfo(partition))
.Cast<IPartitionInfo>()
.ToList();
}

public override string ToString()
{
return $"\n {nameof(Address)}: {Address}," +
$"\n {nameof(Host)}: {Host}," +
$"\n {nameof(NodeId)}: {NodeId}," +
$"\n {nameof(Port)}: {Port}," +
"\n Partitions:\n" + string.Join(", ", Partitions);
}
public override string ToString()
{
return $"\n {nameof(Address)}: {Address}," +
$"\n {nameof(Host)}: {Host}," +
$"\n {nameof(NodeId)}: {NodeId}," +
$"\n {nameof(Port)}: {Port}," +
"\n Partitions:\n" + string.Join(", ", Partitions);
}
}
}
9 changes: 3 additions & 6 deletions Client/Impl/Responses/CancelProcessInstanceResponse.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Zeebe.Client.Api.Responses;

namespace Zeebe.Client.Impl.Responses
{
public class CancelProcessInstanceResponse : ICancelProcessInstanceResponse
{
}
}
namespace Zeebe.Client.Impl.Responses;

public class CancelProcessInstanceResponse : ICancelProcessInstanceResponse;
9 changes: 3 additions & 6 deletions Client/Impl/Responses/CompleteJobResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
// limitations under the License.
using Zeebe.Client.Api.Responses;

namespace Zeebe.Client.Impl.Responses
{
internal class CompleteJobResponse : ICompleteJobResponse
{
}
}
namespace Zeebe.Client.Impl.Responses;

internal class CompleteJobResponse : ICompleteJobResponse;
24 changes: 7 additions & 17 deletions Client/Impl/Responses/DecisionMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,17 @@

namespace Zeebe.Client.Impl.Responses;

public class DecisionMetadata : IDecisionMetadata
public class DecisionMetadata(GatewayProtocol.DecisionMetadata metadata) : IDecisionMetadata
{
public string DmnDecisionId { get; }
public string DmnDecisionId { get; } = metadata.DmnDecisionId;

public string DmnDecisionName { get; }
public string DmnDecisionName { get; } = metadata.DmnDecisionName;

public int Version { get; }
public int Version { get; } = metadata.Version;

public long DecisionKey { get; }
public long DecisionKey { get; } = metadata.DecisionKey;

public string DmnDecisionRequirementsId { get; }
public string DmnDecisionRequirementsId { get; } = metadata.DmnDecisionRequirementsId;

public long DecisionRequirementsKey { get; }

public DecisionMetadata(GatewayProtocol.DecisionMetadata metadata)
{
DmnDecisionId = metadata.DmnDecisionId;
DmnDecisionName = metadata.DmnDecisionName;
Version = metadata.Version;
DecisionKey = metadata.DecisionKey;
DmnDecisionRequirementsId = metadata.DmnDecisionRequirementsId;
DecisionRequirementsKey = metadata.DecisionRequirementsKey;
}
public long DecisionRequirementsKey { get; } = metadata.DecisionRequirementsKey;
}
Loading

0 comments on commit f3f264c

Please sign in to comment.