sharee.bike-App/LockItShared/Model/Bikes/Bike/CopriLock/LockInfo.cs

89 lines
1.9 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +02:00
using System;
2022-04-25 22:15:15 +02:00
using System.Runtime.Serialization;
2022-08-30 15:42:25 +02:00
using Newtonsoft.Json;
2022-04-25 22:15:15 +02:00
2022-08-30 15:42:25 +02:00
namespace TINK.Model.Bikes.BikeInfoNS.CopriLock
2022-04-25 22:15:15 +02:00
{
2022-09-06 16:08:19 +02:00
/// <summary> Locking states. </summary>
public enum LockingState
{
/// <summary> App is not connected to lock.</summary>
UnknownDisconnected,
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Lock is closed. </summary>
Closed,
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Lock is closing. </summary>
Closing,
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Lock is open. </summary>
Open,
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Lock is opening. </summary>
Opening
}
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
[DataContract]
public class LockInfo : ILockInfo
{
/// <summary> Locking state of bluetooth lock. </summary>
[DataMember]
public LockingState State { get; private set; } = LockingState.UnknownDisconnected;
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
public override bool Equals(object obj) => this.Equals(obj as LockInfo);
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
public bool Equals(LockInfo other)
{
if (Object.ReferenceEquals(other, null)) return false;
if (Object.ReferenceEquals(this, other)) return true;
if (this.GetType() != other.GetType()) return false;
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
return ToString() == other.ToString();
}
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
public override int GetHashCode()
{
return ToString().GetHashCode();
}
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
public static bool operator ==(LockInfo lhs, LockInfo rhs)
{
if (Object.ReferenceEquals(lhs, null))
return Object.ReferenceEquals(rhs, null) ? true /*null == null = true*/: false;
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
return lhs.Equals(rhs);
}
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
public static bool operator !=(LockInfo lhs, LockInfo rhs)
{
return !(lhs == rhs);
}
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
public class Builder
{
public Builder(LockInfo lockInfo = null)
{
if (lockInfo == null)
{
return;
}
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
LockInfo = JsonConvert.DeserializeObject<LockInfo>(JsonConvert.SerializeObject(lockInfo));
}
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
private readonly LockInfo LockInfo = new LockInfo();
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
public LockingState State { get => LockInfo.State; set => LockInfo.State = value; }
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
public LockInfo Build() => LockInfo;
}
2022-04-25 22:15:15 +02:00
2022-09-06 16:08:19 +02:00
}
2022-04-25 22:15:15 +02:00
}