You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Models/ZeroServiceInfo.cs

88 lines
2.9 KiB

6 years ago
using System;
using System.Runtime.Serialization;
using ZeroLevel.Services.Serialization;
6 years ago
namespace ZeroLevel
6 years ago
{
[Serializable]
[DataContract]
public sealed class ZeroServiceInfo :
IEquatable<ZeroServiceInfo>, IBinarySerializable
6 years ago
{
public const string DEFAULT_GROUP_NAME = "__service_default_group__";
public const string DEFAULT_TYPE_NAME = "__service_default_type__";
[DataMember]
public string Name { get; set; }
6 years ago
/// <summary>
6 years ago
/// Service key, must be unique within the business functionality.
/// two services with same key will be horizontally balanced
6 years ago
/// </summary>
[DataMember]
public string ServiceKey { get; set; }
6 years ago
/// <summary>
6 years ago
/// The group can determine the services working in the same domain
6 years ago
/// </summary>
[DataMember]
public string ServiceGroup { get; set; } = DEFAULT_GROUP_NAME;
6 years ago
/// <summary>
6 years ago
/// The type of service, for filtering, determines membership in a subgroup.
6 years ago
/// </summary>
[DataMember]
public string ServiceType { get; set; } = DEFAULT_TYPE_NAME;
/// <summary>
6 years ago
/// Service version
6 years ago
/// </summary>
[DataMember]
public string Version { get; set; }
6 years ago
public bool Equals(ZeroServiceInfo other)
6 years ago
{
5 months ago
if (other == null!) return false;
6 years ago
if (object.ReferenceEquals(this, other)) return true;
if (string.Compare(this.Name, other.Name, true) != 0) return false;
6 years ago
if (string.Compare(this.ServiceKey, other.ServiceKey, true) != 0) return false;
if (string.Compare(this.ServiceGroup, other.ServiceGroup, true) != 0) return false;
if (string.Compare(this.ServiceType, other.ServiceType, true) != 0) return false;
if (string.Compare(this.Version, other.Version, true) != 0) return false;
return true;
}
public override bool Equals(object obj)
{
5 months ago
return this.Equals((obj as ZeroServiceInfo)!);
6 years ago
}
public override int GetHashCode()
{
6 years ago
return this.ServiceKey.GetHashCode();
6 years ago
}
public void Serialize(IBinaryWriter writer)
{
writer.WriteString(this.Name);
writer.WriteString(this.ServiceKey);
writer.WriteString(this.ServiceGroup);
writer.WriteString(this.ServiceType);
writer.WriteString(this.Version);
}
public void Deserialize(IBinaryReader reader)
{
this.Name = reader.ReadString();
this.ServiceKey = reader.ReadString();
this.ServiceGroup = reader.ReadString();
this.ServiceType = reader.ReadString();
this.Version = reader.ReadString();
}
6 years ago
public override string ToString()
{
return $"{ServiceKey } ({Version})";
6 years ago
}
}
}

Powered by TurnKey Linux.